diff --git a/doc/scenarioreference/README.md b/doc/scenarioreference/README.md index 550f751..a51e5ca 100644 --- a/doc/scenarioreference/README.md +++ b/doc/scenarioreference/README.md @@ -270,7 +270,7 @@ the variable `loopcrawl` will be a list of 500 random string. **generateuniqueid()** Generate a unique sequential number. -The prefix is used to allo wmultiple counter +The prefix is used to allow multiple counter Example: ```` "tidblue": "generateuniqueid(blue)" @@ -278,6 +278,13 @@ Example: ```` Variables `tidblue` and `tidred` got a unique id, each following a different counter. +**now(LOCALDATETIME|DATE|ZONEDATETIME|LOCALDATE)** +Generate a String object, containing the current date and time. + + +**stringToDate(LOCALDATETIME|DATE|ZONEDATETIME|LOCALDATE, dateSt)** +Transform a String to a Date (LocalDateTime, Date, ZoneDateTime or LocalDate) + ## Verification diff --git a/doc/unittestscenario/resources/ScoreAcceptance.bpmn b/doc/unittestscenario/resources/ScoreAcceptance.bpmn index f7f46ec..a4cecb8 100644 --- a/doc/unittestscenario/resources/ScoreAcceptance.bpmn +++ b/doc/unittestscenario/resources/ScoreAcceptance.bpmn @@ -29,10 +29,6 @@ Flow_09z898p - - Flow_0wya675 - Flow_1pxztl2 - Flow_1pxztl2 @@ -44,6 +40,13 @@ Flow_0a4sjzy Flow_0wya675 + + + + + Flow_0wya675 + Flow_1pxztl2 + @@ -79,14 +82,13 @@ - - - - + + + diff --git a/doc/unittestscenario/resources/ScoreAcceptanceScn.json b/doc/unittestscenario/resources/ScoreAcceptanceScn.json index 81546bb..bd37dea 100644 --- a/doc/unittestscenario/resources/ScoreAcceptanceScn.json +++ b/doc/unittestscenario/resources/ScoreAcceptanceScn.json @@ -77,12 +77,24 @@ "variables": { "phoneNumber": "(+1) 542 778 2352" } + }, + { + "type": "SERVICETASK", + "taskId": "ActSendRejection", + "topic": "send-rejection", + "waitingTime": "PT0S", + "modeExecution": "ASYNCHRONOUS", + "variablesOperation": { + "sendMessage": "now(LocalDateTime)" + } } + + ], "verifications": { "activities": [ { - "type": "TASK", + "type": "SERVICETASK", "taskId": "ActSendRejection" }, { diff --git a/pom.xml b/pom.xml index 4764ae2..06480bd 100644 --- a/pom.xml +++ b/pom.xml @@ -64,28 +64,6 @@ - - - - io.camunda spring-boot-starter-camunda-sdk @@ -96,7 +74,7 @@ io.camunda.spring java-client-operate - 8.6.2 + 8.6.3 @@ -106,7 +84,6 @@ 8.6.6 : incompatible types: io.camunda.common.auth.Authentication cannot be converted to io.camunda.tasklist.auth.Authentication 8.5.10 Bug fix on ZeebeUserTask (actually, no) 8.6.6 last version available--> - io.camunda camunda-tasklist-client-java diff --git a/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java b/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java index 4d9ec1a..9eaec4c 100644 --- a/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java +++ b/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java @@ -346,6 +346,7 @@ public void executeServiceTask(String serviceTaskId, String workerId, Map searchTasksByProcessInstanceId(String pr BpmnEngine.TaskDescription taskDescription = new BpmnEngine.TaskDescription(); taskDescription.taskId = t.getFlowNodeId(); taskDescription.processInstanceId = String.valueOf(t.getProcessInstanceKey()); - taskDescription.startDate = t.getStartDate().getDate(); - taskDescription.endDate = t.getEndDate().getDate(); + taskDescription.startDate = t.getStartDate()==null? null: t.getStartDate().getDate(); + taskDescription.endDate = t.getEndDate()==null? null : t.getEndDate().getDate(); taskDescription.type = getTaskType(t.getType()); // to implement taskDescription.isCompleted = FlowNodeInstanceState.COMPLETED.equals(t.getState()); // to implement return taskDescription; @@ -337,7 +337,7 @@ public long countNumberOfProcessInstancesCreated(String processId, Date startDat searchQuery.setSize(SEARCH_MAX_SIZE); searchResult = operateClient.searchProcessInstanceResults(searchQuery); - cumul += searchResult.getItems().stream().filter(t -> t.getStartDate().getDate().after(startDate)).count(); + cumul += searchResult.getItems().stream().filter(t -> t.getStartDate()!=null && t.getStartDate().getDate().after(startDate)).count(); } while (searchResult.getItems().size() >= SEARCH_MAX_SIZE && maxLoop < 1000); return cumul; @@ -372,7 +372,7 @@ public long countNumberOfProcessInstancesEnded(String processId, Date startDate, SearchQuery searchQuery = queryBuilder.build(); searchQuery.setSize(SEARCH_MAX_SIZE); searchResult = operateClient.searchProcessInstanceResults(searchQuery); - cumul += searchResult.getItems().stream().filter(t -> t.getStartDate().getDate().after(startDate)).count(); + cumul += searchResult.getItems().stream().filter(t -> t.getStartDate() !=null && t.getStartDate().getDate().after(startDate)).count(); } while (searchResult.getItems().size() >= SEARCH_MAX_SIZE && maxLoop < 1000); return cumul; diff --git a/src/main/java/org/camunda/automator/bpmnengine/camunda8/TaskListClient.java b/src/main/java/org/camunda/automator/bpmnengine/camunda8/TaskListClient.java index 3fe8ea2..49a193e 100644 --- a/src/main/java/org/camunda/automator/bpmnengine/camunda8/TaskListClient.java +++ b/src/main/java/org/camunda/automator/bpmnengine/camunda8/TaskListClient.java @@ -61,7 +61,7 @@ public void connectTaskList(StringBuilder analysis) throws AutomatorException { taskListBuilder.taskListUrl(taskListUrl) .saaSAuthentication(serverDefinition.taskListClientId, serverDefinition.taskListClientSecret); } catch (Exception e) { - logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); + logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage()); throw new AutomatorException( "Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : " + e.getMessage()); @@ -107,56 +107,10 @@ public void connectTaskList(StringBuilder analysis) throws AutomatorException { analysis.append("successfully, "); } catch (Exception e) { - logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); + logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage()); throw new AutomatorException( "Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage()); } - - /* 1.6.1 - boolean isOk = true; - io.camunda.tasklist.auth.AuthInterface saTaskList; - - // ---------------------------- Camunda Saas - if (BpmnEngineList.CamundaEngine.CAMUNDA_8_SAAS.equals(this.typeCamundaEngine)) { - try { - saTaskList = new io.camunda.tasklist.auth.SaasAuthentication(serverDefinition.zeebeSaasClientId, - serverDefinition.zeebeSaasClientSecret); - } catch (Exception e) { - logger.error("Can't connect to SaaS environment[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); - throw new AutomatorException( - "Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : " - + e.getMessage()); - } - - //---------------------------- Camunda 8 Self Manage - } else if (BpmnEngineList.CamundaEngine.CAMUNDA_8.equals(this.typeCamundaEngine)) { - saTaskList = new io.camunda.tasklist.auth.SimpleAuthentication(serverDefinition.operateUserName, - serverDefinition.operateUserPassword); - } else - throw new AutomatorException("Invalid configuration"); - - if (!isOk) - throw new AutomatorException("Invalid configuration " + analysis); - - // ---------------- connection - try { - isOk = engineCamunda8.stillOk(serverDefinition.taskListUrl, "taskListUrl", analysis, false, isOk); - analysis.append("Tasklist ..."); - - taskClient = new CamundaTaskListClient.Builder().taskListUrl(serverDefinition.taskListUrl) - .authentication(saTaskList) - .build(); - analysis.append("successfully, "); - //get tasks assigned to demo - logger.info("Zeebe: OK, Operate: OK, TaskList:OK " + analysis); - - } catch (Exception e) { - logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); - throw new AutomatorException( - "Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage()); - } - */ - } public List searchUserTasksByProcessInstance(String processInstanceId, String userTaskId, int maxResult) @@ -199,7 +153,7 @@ public List searchUserTasksByProcessInstance(String processInstanceId, S return listTasksResult; } catch (TaskListException e) { - logger.error("TaskListClient: error during search task [{}]", e.getMessage()); + logger.error("TaskListClient: error during search task: {}", e.getMessage()); throw new AutomatorException("Can't search users task " + e.getMessage()); } } @@ -227,6 +181,7 @@ public List searchUserTasks(String userTaskId, int maxResult) throws Aut return listTasksResult; } catch (TaskListException e) { + logger.error("SearchUserTask: userId[{}] : {}", userTaskId, e.getMessage()); throw new AutomatorException("Can't search users task " + e.getMessage()); } } @@ -237,8 +192,10 @@ public void executeUserTask(String userTaskId, String userId, Map getListErrors() { public void addError(ScenarioStep step, String explanation) { this.listErrors.add(new ErrorDescription(step, explanation)); logger.error((step == null ? "" : step.getType().toString()) + " " + explanation); - } public void addError(ScenarioStep step, AutomatorException e) { @@ -205,7 +204,7 @@ public void merge(RunResult result) { /** * Two execution on the exact same execution: we go for a merge plus one step more, we collect additionnal information, like processinstanceIdList - * @param result + * @param result the result to merge */ public void mergeDuplicateExecution(RunResult result) { merge(result); @@ -245,8 +244,8 @@ public List getListProcessInstancesId() { return listProcessInstancesId; } - public void addListProcessInstancesId(List listProcessInstancesId) { - listProcessInstancesId.addAll(listProcessInstancesId); + public void addListProcessInstancesId(List listProcessInstancesIdParam) { + listProcessInstancesId.addAll(listProcessInstancesIdParam); } public List getProcessInstanceId() { return this.listProcessInstancesId; @@ -310,7 +309,7 @@ public String getSynthesis(boolean fullDetail) { synthesis.append(runScenario.getScenario().getProcessId()); synthesis.append("): "); - StringBuilder append = synthesis.append(timeExecution); + synthesis.append(timeExecution); synthesis.append(" timeExecution(ms), "); RecordCreationPI recordCreationPI = recordCreationPIMap.get(runScenario.getScenario().getProcessId()); synthesis.append(recordCreationPI == null ? 0 : recordCreationPI.nbCreated); diff --git a/src/main/java/org/camunda/automator/services/dataoperation/DataOperationNow.java b/src/main/java/org/camunda/automator/services/dataoperation/DataOperationNow.java new file mode 100644 index 0000000..e96d2dc --- /dev/null +++ b/src/main/java/org/camunda/automator/services/dataoperation/DataOperationNow.java @@ -0,0 +1,73 @@ +package org.camunda.automator.services.dataoperation; + +import org.camunda.automator.engine.AutomatorException; +import org.camunda.automator.engine.RunScenario; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +@Component + +public class DataOperationNow extends DataOperation { + + public static final String FCT_LOCALDATETIME = "LOCALDATETIME"; + public static final String FCT_DATE = "DATE"; + public static final String FCT_ZONEDATETIME = "ZONEDATETIME"; + public static final String FCT_LOCALDATE = "LOCALDATE"; + public static final String ISO_8601_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + public static final String ISO_8601_DATE_FORMAT = "yyyy-MM-dd"; + + @Override + public boolean match(String value) { + return matchFunction(value, "now"); + } + + @Override + public String getName() { + return "Now"; + } + + @Override + public String getHelp() { + return "now(" + FCT_LOCALDATETIME + "|" + FCT_DATE + "|" + FCT_ZONEDATETIME + "|" + + FCT_LOCALDATE + ")"; + } + + @Override + public Object execute(String value, RunScenario runScenario, int index) throws AutomatorException { + List args = extractArgument(value, true); + + if (args.size() != 1) { + throw new AutomatorException("Bad argument: " + getHelp()); + } + String formatArgs = args.get(0).toUpperCase(Locale.ROOT); + + try { + if (FCT_LOCALDATETIME.equals(formatArgs)) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ISO_8601_DATETIME_FORMAT); + return LocalDateTime.now().format(formatter); + } else if (FCT_DATE.equals(formatArgs)) { + SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_8601_DATETIME_FORMAT); + return dateFormat.format(new Date()); + } else if (FCT_ZONEDATETIME.equals(formatArgs)) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ISO_8601_DATETIME_FORMAT); + return ZonedDateTime.now().format(formatter); + } else if (FCT_LOCALDATE.equals(formatArgs)) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ISO_8601_DATE_FORMAT); + return LocalDate.now().format(formatter); + } else + throw new AutomatorException("Unknown date formatter [" + formatArgs + "]"); + } catch (Exception e) { + throw new AutomatorException( + "parsing error function[" + formatArgs + "] : " + e.getMessage()); + } + + } +}