-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1079 from axonivy-market/IVYPORTAL-17644-add-back…
…-CronByGlobalVariableTriggerStartEventBean IVYPORTAL-17644-add-back-CronByGlobalVariableTriggerStartEventBean
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
AxonIvyPortal/portal/processes/SynchronizeDataProcesses/CleanUpObsoletedUserData.p.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
] | ||
} ] | ||
} |
65 changes: 65 additions & 0 deletions
65
...tal/portal/src/ch/ivy/addon/portalkit/util/CronByGlobalVariableTriggerStartEventBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |