Campaigns in timveroOS 7.11 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:
Copy @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:
Copy @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:
Copy @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:
Copy @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:
Copy @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:
Copy @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:
Cancels all new executions (STOPPED
)
All templates are fully integrated with the EntityTabController
tab system, CampaignForm
forms, scripts, and other components of timveroOS .