LogoLogo
timvero.comMaven Repository
  • timveroOS SDK guide
  • timveroOS how-to
  • timveroOS admin-side setup
  • Campaigns in timveroOS
    • 7.11
      • Business Context
      • Introduction
      • Core Concept
        • Entity Diagram
        • Lifecycle Diagram
        • Expression
      • Design and Development of the Campaign Model
        • Campaign model
        • Campaign repository
        • Campaign forms
        • Campaign сontroller
        • UI elements
        • Campaign actions
      • Design and Development of the CampaignExecution Model
        • CampaignExecution model
        • CampaignExecution repository
        • CampaignExecution controller
        • UI elements
      • Expression
      • Services
        • CampaignService
        • CampaignExecutionService
      • Campaign Processing
        • Producer
        • Consumer
      • Post-processing
        • Checker
Powered by GitBook
On this page

Was this helpful?

  1. Campaigns in timveroOS
  2. 7.11
  3. Design and Development of the Campaign Model

Campaign actions

CreateCampaignAction, EditCampaignAction, ActivateCampaignAction, DeactivateCampaignAction, StartCampaignAction и StopCampaignAction

All actions are built on top of SimpleActionController or EntityCreateController / EditEntityActionController components provided by timveroOS. These actions are automatically integrated into the UI and appear as buttons or operations on the campaign detail page.


🟢 CreateCampaignAction

Example:

@Controller
public class CreateCampaignAction extends EntityCreateController<Long, Campaign, CampaignForm> {
}

Purpose: Creates a new campaign based on the CampaignForm.

Features:

  • Inherits from EntityCreateController

  • Automatically appears as the "Create" button in the campaign list

📝 Template: /campaign/edit.html

Purpose: Form for creating and editing campaigns using CampaignForm.

Highlights:

  • Fields: name, execution type, products, filtering script

  • UI for scheduling and restartable options

  • Code editor for the script


✏️ EditCampaignAction

Example:

@Controller
public class EditCampaignAction extends EditEntityActionController<Long, Campaign, CampaignForm> {
}

Purpose: Edits an existing campaign. Updating the data creates a new version (HistoryEntity), while the previous version is deactivated.

📝 Template: /campaign/edit.html (Same as for creation)


✅ ActivateCampaignAction

Example:

@Controller
@RequestMapping("/activate")
public class ActivateCampaignAction extends SimpleActionController<Long, Campaign> {
    @Override
    protected EntityAction<? super Campaign, Object> action() {
        return when(not(Campaign::isActive))
            .then((campaign, form, user) -> {
                campaign.setActive(true);
                if (campaign.getExecutionType() == AUTOMATIC &&
                    campaign.getAutomaticCampaignStatus() != SCHEDULED) {
                    campaign.setAutomaticCampaignStatus(SCHEDULED);
                }
            });
    }
}

Purpose: Activates a campaign. For automatic campaigns, it also sets the schedule to SCHEDULED.


⛔ DeactivateCampaignAction

Example:

@Controller
@RequestMapping("/deactivate")
public class DeactivateCampaignAction extends SimpleActionController<Long, Campaign> {
    @Override
    protected EntityAction<? super Campaign, Object> action() {
        return when(Campaign::isActive)
            .then((campaign, form, user) -> {
                campaign.setActive(false);
                if (campaign.getExecutionType() == AUTOMATIC &&
                    campaign.getAutomaticCampaignStatus() == SCHEDULED) {
                    campaign.setAutomaticCampaignStatus(IDLE);
                    campaign.getExecutions().stream()
                        .filter(e -> e.getStatus() == NEW)
                        .forEach(e -> e.setStatus(DISABLED));
                }
            });
    }
}

Purpose: Deactivates the campaign. Automatic campaigns are set to IDLE, and new executions are marked as DISABLED.


▶️ StartCampaignAction

Example:

@Controller
@RequestMapping("/start-campaign")
public class StartCampaignAction extends SimpleActionController<Long, Campaign> {
    
    @Autowired
    private CampaignService campaignService;

    @Override
    protected EntityAction<? super Campaign, Object> action() {
        return when(campaign -> campaign.isActive() &&
            (campaign.getExecutionType() == AUTOMATIC
                ? campaign.getAutomaticCampaignStatus() != SCHEDULED
                : campaign.isNotInExecution()))
            .then((campaign, form, user) -> {
                campaignService.startCampaign(campaign.getId());
            });
    }
}

Purpose: Starts the campaign:

  • For MANUAL — creates and immediately executes a CampaignExecution

  • For AUTOMATIC — switches to SCHEDULED if not already


⏹️ StopCampaignAction

Example:

@Controller
@RequestMapping("/stop-campaign")
public class StopCampaignAction extends SimpleActionController<Long, Campaign> {
    
    @Override
    protected EntityAction<? super Campaign, Object> action() {
        return when(campaign -> campaign.getExecutionType() == AUTOMATIC &&
            campaign.getAutomaticCampaignStatus() == SCHEDULED)
            .then((campaign, form, user) -> {
                campaign.setAutomaticCampaignStatus(IDLE);
                campaign.getExecutions().stream()
                    .filter(e -> e.getStatus() == NEW)
                    .forEach(e -> e.setStatus(STOPPED));
            });
    }
}

Purpose: Stops an automatic campaign:

  • Sets status to IDLE

  • Cancels all new executions (STOPPED)


All templates are fully integrated with the EntityTabController tab system, CampaignForm forms, scripts, and other components of timveroOS.

PreviousUI elementsNextDesign and Development of the CampaignExecution Model

Last updated 18 days ago

Was this helpful?