Skip to content

Commit

Permalink
Merge pull request #1079 from axonivy-market/IVYPORTAL-17644-add-back…
Browse files Browse the repository at this point in the history
…-CronByGlobalVariableTriggerStartEventBean

IVYPORTAL-17644-add-back-CronByGlobalVariableTriggerStartEventBean
  • Loading branch information
chnam-axonivy authored Sep 24, 2024
2 parents 0071724 + 1613183 commit 941ea41
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema" : "https://json-schema.axonivy.com/process/11.3.0/process.json",
"id" : "1626C02D46BF5153",
"description" : "This is a scheduled process of Portal",
"config" : {
"data" : "ch.ivy.add.portalkit.Data"
},
"elements" : [ {
"id" : "f6",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 120, "y" : 320 }
}
}, {
"id" : "f5",
"type" : "ProgramStart",
"name" : "PortalCleanObsoleteData",
"config" : {
"javaClass" : "ch.ivy.addon.portalkit.util.CronByGlobalVariableTriggerStartEventBean",
"userConfig" : {
"variable" : "PortalStartTimeCleanObsoletedDataExpression"
},
"link" : "eventLink.ivp"
},
"visual" : {
"at" : { "x" : 120, "y" : 104 },
"labelOffset" : { "x" : 104, "y" : 20 },
"description" : "This is a scheduled process of Portal"
},
"connect" : [
{ "id" : "f4", "to" : "f2" }
]
}, {
"id" : "f2",
"type" : "Script",
"name" : [
"Delete finished hidden",
"system cases"
],
"config" : {
"output" : {
"code" : [
"import ch.ivy.addon.portalkit.service.DeleteFinishedHiddenCasesService;",
"DeleteFinishedHiddenCasesService deletFinishedHiddenCasesService = new DeleteFinishedHiddenCasesService();",
"deletFinishedHiddenCasesService.deleteFinishedHiddenCases();"
]
},
"sudo" : true
},
"visual" : {
"at" : { "x" : 120, "y" : 208 },
"size" : { "width" : 144 }
},
"connect" : [
{ "id" : "f1", "to" : "f6" }
]
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ch.ivy.addon.portalkit.util;

import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

import ch.ivyteam.ivy.process.eventstart.AbstractProcessStartEventBean;
import ch.ivyteam.ivy.process.eventstart.IProcessStartEventBeanRuntime;
import ch.ivyteam.ivy.process.extension.ProgramConfig;
import ch.ivyteam.ivy.process.extension.ui.ExtensionUiBuilder;
import ch.ivyteam.ivy.process.extension.ui.UiEditorExtension;
import ch.ivyteam.ivy.request.RequestException;
import ch.ivyteam.ivy.vars.Variable;
import ch.ivyteam.ivy.vars.Variables;
import ch.ivyteam.util.IvyRuntimeException;

public class CronByGlobalVariableTriggerStartEventBean extends AbstractProcessStartEventBean {

private static final String PORTAL_DELETE_ALL_FINISHED_HIDDEN_CASE = "PortalDeleteAllFinishedHiddenCases";
private static final String VARIABLE = "variable";
public CronByGlobalVariableTriggerStartEventBean() {
super("Portal Clean Obsolete Data", "This is a scheduled process of Portal");
}

@Override
public void initialize(IProcessStartEventBeanRuntime eventRuntime, ProgramConfig configuration) {
super.initialize(eventRuntime, configuration);
try {
Variable var =
Variables.of(eventRuntime.getProcessModelVersion().getApplication()).variable(configuration.get(VARIABLE));
Variable deleteAllFinishedHiddenCasesVar = Variables.of(eventRuntime.getProcessModelVersion().getApplication())
.variable(PORTAL_DELETE_ALL_FINISHED_HIDDEN_CASE);
if (var != null) {
String pattern = var.value();
Boolean isJobTrigger = Optional.of(deleteAllFinishedHiddenCasesVar).map(Variable::value).map(Boolean::parseBoolean).orElse(false);
if (StringUtils.isNotBlank(pattern) && isJobTrigger) {
eventRuntime.poll().asDefinedByExpression(pattern);
} else {
eventRuntime.poll().disable();
}
}
} catch (Exception ex) {
throw new IvyRuntimeException("Cannot evaluate the ivyScript configuration ", ex);
}
}


@Override
public void poll() {
try {
getEventBeanRuntime().processStarter()
.withReason("Time elapsed or reached cron pattern " + getConfig().get(VARIABLE)).start();
} catch (RequestException ex) {
throw new IvyRuntimeException("Cannot start process", ex);
}
}

public static class Editor extends UiEditorExtension {

@Override
public void initUiFields(ExtensionUiBuilder ui) {
ui.textField(VARIABLE).create();
}
}
}

0 comments on commit 941ea41

Please sign in to comment.