Skip to content

Commit f82e3f7

Browse files
authored
Merge pull request #254 from folio-org/master
Downport aggies-sprint-8 staging.
2 parents cef73ee + 6e71727 commit f82e3f7

36 files changed

+1400
-305
lines changed

descriptors/ModuleDescriptor-template.json

Lines changed: 74 additions & 139 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.folio.rest.camunda.delegate;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.camunda.bpm.engine.delegate.DelegateExecution;
45
import org.camunda.bpm.engine.delegate.JavaDelegate;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
@@ -10,26 +11,86 @@ public abstract class AbstractDelegate implements JavaDelegate {
1011

1112
private final Logger log;
1213

14+
@Autowired
15+
protected ObjectMapper objectMapper;
16+
1317
AbstractDelegate() {
1418
// The logger is non-static to ensure that the implementing class name is used for the logger.
1519
log = LoggerFactory.getLogger(this.getClass());
1620
}
1721

18-
@Autowired
19-
protected ObjectMapper objectMapper;
22+
/**
23+
* Get the delegate class name.
24+
*
25+
* @return The delegate name.
26+
*/
27+
protected String getDelegateClass() {
28+
String simpleName = getClass().getSimpleName();
29+
30+
return simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1);
31+
}
2032

33+
/**
34+
* Get the delegate name.
35+
*
36+
* @param execution The delegate execution data.
37+
*
38+
* @return The delegate name.
39+
*/
40+
protected String getDelegateName(DelegateExecution execution) {
41+
return execution.getBpmnModelElementInstance().getName();
42+
}
43+
44+
/**
45+
* Get the expression.
46+
*
47+
* @return The formatted expression string.
48+
*/
2149
public String getExpression() {
22-
String simpleName = getClass().getSimpleName();
23-
String delegateName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1);
24-
return String.format("${%s}", delegateName);
50+
return String.format("${%s}", getDelegateClass());
2551
}
2652

53+
/**
54+
* Get the logger.
55+
*
56+
* @return The logger for this class.
57+
*/
2758
public Logger getLogger() {
2859
return log;
2960
}
3061

62+
/**
63+
* Get the Object Mapper.
64+
*
65+
* @return The Object Mapper for this class.
66+
*/
3167
public ObjectMapper getObjectMapper() {
3268
return objectMapper;
3369
}
3470

71+
/**
72+
* Determine the start time of the query and print log.
73+
*
74+
* @param execution The delegate execution data.
75+
* @param args additional string arguments to pass.
76+
*
77+
* @return The start time.
78+
*/
79+
protected long determineStartTime(DelegateExecution execution, Object ...args) {
80+
getLogger().info("{} {} started", getDelegateName(execution), args);
81+
82+
return System.nanoTime();
83+
}
84+
85+
/**
86+
* Given the start time, determine the total time spent.
87+
*
88+
* @param execution The delegate execution data.
89+
*
90+
* @param startTime The time the process started.
91+
*/
92+
protected void determineEndTime(DelegateExecution execution, long startTime) {
93+
getLogger().info("{} finished in {} milliseconds", getDelegateName(execution), (System.nanoTime() - startTime) / (double) 1000000);
94+
}
95+
3596
}

src/main/java/org/folio/rest/camunda/delegate/AbstractRuntimeDelegate.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ public abstract class AbstractRuntimeDelegate extends AbstractDelegate {
77

88
@Autowired
99
protected RuntimeService runtimeService;
10-
1110
}

src/main/java/org/folio/rest/camunda/delegate/CompressFileDelegate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.commons.compress.compressors.CompressorStreamFactory;
2121
import org.camunda.bpm.engine.delegate.DelegateExecution;
2222
import org.camunda.bpm.engine.delegate.Expression;
23-
import org.camunda.bpm.model.bpmn.instance.FlowElement;
2423
import org.folio.rest.workflow.enums.CompressFileContainer;
2524
import org.folio.rest.workflow.enums.CompressFileFormat;
2625
import org.folio.rest.workflow.model.CompressFileTask;
@@ -51,11 +50,7 @@ public class CompressFileDelegate extends AbstractWorkflowIODelegate {
5150

5251
@Override
5352
public void execute(DelegateExecution execution) throws Exception {
54-
long startTime = System.nanoTime();
55-
FlowElement bpmnModelElement = execution.getBpmnModelElementInstance();
56-
String delegateName = bpmnModelElement.getName();
57-
58-
getLogger().info("{} started", delegateName);
53+
final long startTime = determineStartTime(execution);
5954

6055
String sourcePathTemplate = this.source.getValue(execution).toString();
6156
String destinationPathTemplate = this.destination.getValue(execution).toString();
@@ -165,8 +160,7 @@ public void execute(DelegateExecution execution) throws Exception {
165160
}
166161
}
167162

168-
long endTime = System.nanoTime();
169-
getLogger().info("{} finished in {} milliseconds", delegateName, (endTime - startTime) / (double) 1000000);
163+
determineEndTime(execution, startTime);
170164
}
171165

172166
public void setSource(Expression source) {

src/main/java/org/folio/rest/camunda/delegate/DatabaseConnectionDelegate.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.folio.rest.camunda.delegate;
22

33
import java.util.Properties;
4-
54
import org.camunda.bpm.engine.delegate.DelegateExecution;
65
import org.camunda.bpm.engine.delegate.Expression;
7-
import org.camunda.bpm.model.bpmn.instance.FlowElement;
86
import org.folio.rest.workflow.model.DatabaseConnectionTask;
97
import org.springframework.context.annotation.Scope;
108
import org.springframework.stereotype.Service;
@@ -19,11 +17,7 @@ public class DatabaseConnectionDelegate extends AbstractDatabaseDelegate {
1917

2018
@Override
2119
public void execute(DelegateExecution execution) throws Exception {
22-
long startTime = System.nanoTime();
23-
FlowElement bpmnModelElement = execution.getBpmnModelElementInstance();
24-
String delegateName = bpmnModelElement.getName();
25-
26-
getLogger().info("{} started", delegateName);
20+
final long startTime = determineStartTime(execution);
2721

2822
String urlValue = this.url.getValue(execution).toString();
2923
String key = this.designation.getValue(execution).toString();
@@ -34,8 +28,7 @@ public void execute(DelegateExecution execution) throws Exception {
3428

3529
connectionService.createPool(key, urlValue, info);
3630

37-
long endTime = System.nanoTime();
38-
getLogger().info("{} finished in {} milliseconds", delegateName, (endTime - startTime) / (double) 1000000);
31+
determineEndTime(execution, startTime);
3932
}
4033

4134
public void setUrl(Expression url) {

src/main/java/org/folio/rest/camunda/delegate/DatabaseDisconnectDelegate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.folio.rest.camunda.delegate;
22

33
import org.camunda.bpm.engine.delegate.DelegateExecution;
4-
import org.camunda.bpm.model.bpmn.instance.FlowElement;
54
import org.folio.rest.workflow.model.DatabaseDisconnectTask;
65
import org.springframework.context.annotation.Scope;
76
import org.springframework.stereotype.Service;
@@ -12,18 +11,13 @@ public class DatabaseDisconnectDelegate extends AbstractDatabaseDelegate {
1211

1312
@Override
1413
public void execute(DelegateExecution execution) throws Exception {
15-
long startTime = System.nanoTime();
16-
FlowElement bpmnModelElement = execution.getBpmnModelElementInstance();
17-
String delegateName = bpmnModelElement.getName();
18-
19-
getLogger().info("{} started", delegateName);
14+
final long startTime = determineStartTime(execution);
2015

2116
String key = this.designation.getValue(execution).toString();
2217

2318
connectionService.destroyConnection(key);
2419

25-
long endTime = System.nanoTime();
26-
getLogger().info("{} finished in {} milliseconds", delegateName, (endTime - startTime) / (double) 1000000);
20+
determineEndTime(execution, startTime);
2721
}
2822

2923
@Override

src/main/java/org/folio/rest/camunda/delegate/DatabaseQueryDelegate.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.folio.rest.camunda.delegate;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.node.ObjectNode;
6+
import freemarker.cache.StringTemplateLoader;
7+
import freemarker.template.Configuration;
38
import java.io.FileWriter;
49
import java.io.IOException;
510
import java.sql.Connection;
@@ -11,22 +16,13 @@
1116
import java.util.List;
1217
import java.util.Map;
1318
import java.util.Objects;
14-
1519
import org.camunda.bpm.engine.delegate.DelegateExecution;
1620
import org.camunda.bpm.engine.delegate.Expression;
17-
import org.camunda.bpm.model.bpmn.instance.FlowElement;
1821
import org.folio.rest.workflow.model.DatabaseQueryTask;
1922
import org.springframework.context.annotation.Scope;
2023
import org.springframework.stereotype.Service;
2124
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
2225

23-
import com.fasterxml.jackson.core.JsonProcessingException;
24-
import com.fasterxml.jackson.databind.JsonNode;
25-
import com.fasterxml.jackson.databind.node.ObjectNode;
26-
27-
import freemarker.cache.StringTemplateLoader;
28-
import freemarker.template.Configuration;
29-
3026
@Service
3127
@Scope("prototype")
3228
public class DatabaseQueryDelegate extends AbstractDatabaseOutputDelegate {
@@ -41,11 +37,7 @@ public class DatabaseQueryDelegate extends AbstractDatabaseOutputDelegate {
4137

4238
@Override
4339
public void execute(DelegateExecution execution) throws Exception {
44-
long startTime = System.nanoTime();
45-
FlowElement bpmnModelElement = execution.getBpmnModelElementInstance();
46-
String delegateName = bpmnModelElement.getName();
47-
48-
getLogger().info("{} started", delegateName);
40+
final long startTime = determineStartTime(execution);
4941

5042
String queryTemplate = this.query.getValue(execution).toString();
5143

@@ -95,7 +87,7 @@ public void execute(DelegateExecution execution) throws Exception {
9587
if (hasOutputVariable(execution)) {
9688
setOutput(execution, count);
9789
} else {
98-
getLogger().info("{} did not specify output variable for result count", delegateName);
90+
getLogger().info("{} did not specify output variable for result count", getDelegateName(execution));
9991
}
10092
}
10193

@@ -105,8 +97,7 @@ public void execute(DelegateExecution execution) throws Exception {
10597
conn.close();
10698
}
10799

108-
long endTime = System.nanoTime();
109-
getLogger().info("{} finished in {} milliseconds", delegateName, (endTime - startTime) / (double) 1000000);
100+
determineEndTime(execution, startTime);
110101
}
111102

112103
public void setQuery(Expression query) {

src/main/java/org/folio/rest/camunda/delegate/EmailDelegate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Optional;
1010
import org.camunda.bpm.engine.delegate.DelegateExecution;
1111
import org.camunda.bpm.engine.delegate.Expression;
12-
import org.camunda.bpm.model.bpmn.instance.FlowElement;
1312
import org.folio.rest.workflow.model.EmailTask;
1413
import org.springframework.beans.factory.annotation.Autowired;
1514
import org.springframework.context.annotation.Scope;
@@ -50,11 +49,7 @@ public EmailDelegate(JavaMailSender emailSender) {
5049

5150
@Override
5251
public void execute(DelegateExecution execution) throws Exception {
53-
long startTime = System.nanoTime();
54-
FlowElement bpmnModelElement = execution.getBpmnModelElementInstance();
55-
String delegateName = bpmnModelElement.getName();
56-
57-
getLogger().info("{} started", delegateName);
52+
final long startTime = determineStartTime(execution);
5853

5954
String subjectTemplate = this.mailSubject.getValue(execution).toString();
6055
String textTemplate = this.mailText.getValue(execution).toString();
@@ -135,8 +130,7 @@ public void prepare(MimeMessage mimeMessage) throws Exception {
135130

136131
emailSender.send(preparator);
137132

138-
long endTime = System.nanoTime();
139-
getLogger().info("{} finished in {} milliseconds", delegateName, (endTime - startTime) / (double) 1000000);
133+
determineEndTime(execution, startTime);
140134
}
141135

142136
public void setMailTo(Expression mailTo) {

0 commit comments

Comments
 (0)