Skip to content

Commit cef73ee

Browse files
authored
Merge pull request #252 from folio-org/master
Downport Community Sprint 6
2 parents f7dea00 + ec3b86a commit cef73ee

File tree

64 files changed

+1542
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1542
-54
lines changed

descriptors/ModuleDescriptor-template.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@
418418
"name": "JAVA_OPTIONS",
419419
"value": "-XX:MaxRAMPercentage=66.0"
420420
},
421+
{ "name": "CAMUNDA_BPM_ADMINUSER_EMAIL", "value": "admin@localhost", "description": "The e-mail address of the Camunda administration user." },
422+
{ "name": "CAMUNDA_BPM_ADMINUSER_ID", "value": "admin", "description": "The account name of the Camunda administration user." },
423+
{ "name": "CAMUNDA_BPM_ADMINUSER_PASSWORD", "value": "admin", "description": "The password of the Camunda administration user." },
424+
{ "name": "CAMUNDA_BPM_DATABASE_SCHEMAUPDATE", "value": "true", "description": "If Camunda should auto-update the BPM database schema." },
425+
{ "name": "CAMUNDA_BPM_METRICS", "value": "false", "description": "Enable or disable Camunda metrics by default." },
421426
{ "name": "DB_HOST", "value": "postgres" },
422427
{ "name": "DB_PORT", "value": "5432" },
423428
{ "name": "DB_USERNAME", "value": "folio_admin" },
@@ -426,7 +431,16 @@
426431
{ "name": "DB_QUERYTIMEOUT", "value": "60000" },
427432
{ "name": "DB_CHARSET", "value": "UTF-8" },
428433
{ "name": "DB_MAXPOOLSIZE", "value": "16" },
429-
{ "name": "OKAPI_URL", "value": "http://10.0.2.15:9130", "description": "The URL to the OKAPI service." }
434+
{ "name": "EVENT_QUEUE_NAME", "value": "event.queue", "description": "The ActiveMQ event queue name." },
435+
{ "name": "OKAPI_URL", "value": "http://10.0.2.15:9130", "description": "The URL to the OKAPI service." },
436+
{ "name": "SERVER_PORT", "value": "8081", "description": "The port to listen on that must match the PortBindings." },
437+
{ "name": "SERVER_SERVLET_CONTEXTPATH", "value": "/", "description": "The context path, or base path, to host at." },
438+
{ "name": "SPRING_ACTIVEMQ_BROKERURL", "value": "tcp://localhost:61616", "description": "The URL to the ActiveMQ server." },
439+
{ "name": "SPRING_FLYWAY_ENABLED", "value": "false", "description": "Database migration support via Spring Flyway." },
440+
{ "name": "SPRING_JPA_HIBERNATE_DDLAUTO", "value": "update", "description": "Auto-configure database on startup." },
441+
{ "name": "TENANT_DEFAULTTENANT", "value": "diku", "description": "The name of the default tenant to use." },
442+
{ "name": "TENANT_FORCETENANT", "value": "false", "description": "Forcibly add or overwrite the tenant name using the default tenant." },
443+
{ "name": "TENANT_INITIALIZEDEFAULTTENANT", "value": "true", "description": "Perform initial auto-creation of tenant in the DB (schema, tables, etc..)." }
430444
]
431445
}
432446
}

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,26 @@
322322
<artifactId>maven-surefire-plugin</artifactId>
323323
</plugin>
324324

325+
<plugin>
326+
<groupId>org.jacoco</groupId>
327+
<artifactId>jacoco-maven-plugin</artifactId>
328+
<version>0.8.8</version>
329+
<executions>
330+
<execution>
331+
<goals>
332+
<goal>prepare-agent</goal>
333+
</goals>
334+
</execution>
335+
<execution>
336+
<id>report</id>
337+
<phase>test</phase>
338+
<goals>
339+
<goal>report</goal>
340+
</goals>
341+
</execution>
342+
</executions>
343+
</plugin>
344+
325345
<plugin>
326346
<groupId>org.hibernate.orm.tooling</groupId>
327347
<artifactId>hibernate-enhance-maven-plugin</artifactId>

src/main/java/org/folio/rest/camunda/aspect/DelegateExecutionExceptionAspect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class DelegateExecutionExceptionAspect {
3232

3333
@Autowired
3434
public DelegateExecutionExceptionAspect(JavaMailSender emailSender) {
35-
this.emailSender = emailSender;
35+
this.emailSender = emailSender;
3636
}
3737

3838
@AfterThrowing(pointcut = "execution(* org.camunda.bpm.engine.delegate.JavaDelegate.execute (org.camunda.bpm.engine.delegate.DelegateExecution)) && args(execution))", throwing = "exception")

src/main/java/org/folio/rest/camunda/aspect/TenantInjectionDelegateAspect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TenantInjectionDelegateAspect {
1818

1919
@Autowired
2020
public TenantInjectionDelegateAspect(TenantProperties tenantProperties) {
21-
this.tenantProperties = tenantProperties;
21+
this.tenantProperties = tenantProperties;
2222
}
2323

2424
@Before("execution(* org.camunda.bpm.engine.delegate.JavaDelegate.execute (org.camunda.bpm.engine.delegate.DelegateExecution)) && args(execution)")

src/main/java/org/folio/rest/camunda/utility/MappingUtility.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.fasterxml.jackson.databind.ObjectMapper;
1212
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
1313
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
14-
14+
import io.vertx.core.json.JsonObject;
1515
import org.folio.AlternativeTitleType;
1616
import org.folio.Alternativetitletypes;
1717
import org.folio.CallNumberType;
@@ -72,44 +72,43 @@
7272
import org.springframework.http.ResponseEntity;
7373
import org.springframework.web.client.RestTemplate;
7474

75-
import io.vertx.core.json.JsonObject;
76-
7775
public class MappingUtility {
7876

7977
private static final int SETTING_LIMIT = 1000;
8078

81-
private static final String IDENTIFIER_TYPES_URL = "/identifier-types?limit=" + SETTING_LIMIT;
82-
private static final String CLASSIFICATION_TYPES_URL = "/classification-types?limit=" + SETTING_LIMIT;
83-
private static final String INSTANCE_TYPES_URL = "/instance-types?limit=" + SETTING_LIMIT;
84-
private static final String INSTANCE_FORMATS_URL = "/instance-formats?limit=" + SETTING_LIMIT;
85-
private static final String CONTRIBUTOR_TYPES_URL = "/contributor-types?limit=" + SETTING_LIMIT;
86-
private static final String CONTRIBUTOR_NAME_TYPES_URL = "/contributor-name-types?limit=" + SETTING_LIMIT;
87-
private static final String ELECTRONIC_ACCESS_URL = "/electronic-access-relationships?limit=" + SETTING_LIMIT;
88-
private static final String INSTANCE_NOTE_TYPES_URL = "/instance-note-types?limit=" + SETTING_LIMIT;
89-
private static final String INSTANCE_ALTERNATIVE_TITLE_TYPES_URL = "/alternative-title-types?limit=" + SETTING_LIMIT;
90-
private static final String ISSUANCE_MODES_URL = "/modes-of-issuance?limit=" + SETTING_LIMIT;
91-
private static final String INSTANCE_STATUSES_URL = "/instance-statuses?limit=" + SETTING_LIMIT;
92-
private static final String NATURE_OF_CONTENT_TERMS_URL = "/nature-of-content-terms?limit=" + SETTING_LIMIT;
93-
private static final String INSTANCE_RELATIONSHIP_TYPES_URL = "/instance-relationship-types?limit=" + SETTING_LIMIT;
94-
private static final String HOLDINGS_TYPES_URL = "/holdings-types?limit=" + SETTING_LIMIT;
95-
private static final String HOLDINGS_NOTE_TYPES_URL = "/holdings-note-types?limit=" + SETTING_LIMIT;
96-
private static final String ILL_POLICIES_URL = "/ill-policies?limit=" + SETTING_LIMIT;
97-
private static final String CALL_NUMBER_TYPES_URL = "/call-number-types?limit=" + SETTING_LIMIT;
98-
private static final String STATISTICAL_CODES_URL = "/statistical-codes?limit=" + SETTING_LIMIT;
99-
private static final String STATISTICAL_CODE_TYPES_URL = "/statistical-code-types?limit=" + SETTING_LIMIT;
100-
private static final String LOCATIONS_URL = "/locations?limit=" + SETTING_LIMIT;
101-
private static final String MATERIAL_TYPES_URL = "/material-types?limit=" + SETTING_LIMIT;
102-
private static final String ITEM_DAMAGED_STATUSES_URL = "/item-damaged-statuses?limit=" + SETTING_LIMIT;
103-
private static final String LOAN_TYPES_URL = "/loan-types?limit=" + SETTING_LIMIT;
104-
private static final String ITEM_NOTE_TYPES_URL = "/item-note-types?limit=" + SETTING_LIMIT;
105-
private static final String FIELD_PROTECTION_SETTINGS_URL = "/field-protection-settings/marc?limit=" + SETTING_LIMIT;
106-
107-
private static final RestTemplate restTemplate = new RestTemplate();
108-
10979
private static final MarcToInstanceMapper marcToInstanceMapper = new MarcToInstanceMapper();
11080

11181
private static final ObjectMapper objectMapper = new ObjectMapper();
11282

83+
static RestTemplate restTemplate = new RestTemplate();
84+
85+
static final String MAPPING_RULES_URL = "/mapping-rules/marc-bib";
86+
static final String IDENTIFIER_TYPES_URL = "/identifier-types?limit=" + SETTING_LIMIT;
87+
static final String CLASSIFICATION_TYPES_URL = "/classification-types?limit=" + SETTING_LIMIT;
88+
static final String INSTANCE_TYPES_URL = "/instance-types?limit=" + SETTING_LIMIT;
89+
static final String ELECTRONIC_ACCESS_URL = "/electronic-access-relationships?limit=" + SETTING_LIMIT;
90+
static final String INSTANCE_FORMATS_URL = "/instance-formats?limit=" + SETTING_LIMIT;
91+
static final String CONTRIBUTOR_TYPES_URL = "/contributor-types?limit=" + SETTING_LIMIT;
92+
static final String CONTRIBUTOR_NAME_TYPES_URL = "/contributor-name-types?limit=" + SETTING_LIMIT;
93+
static final String INSTANCE_NOTE_TYPES_URL = "/instance-note-types?limit=" + SETTING_LIMIT;
94+
static final String INSTANCE_ALTERNATIVE_TITLE_TYPES_URL = "/alternative-title-types?limit=" + SETTING_LIMIT;
95+
static final String NATURE_OF_CONTENT_TERMS_URL = "/nature-of-content-terms?limit=" + SETTING_LIMIT;
96+
static final String INSTANCE_STATUSES_URL = "/instance-statuses?limit=" + SETTING_LIMIT;
97+
static final String INSTANCE_RELATIONSHIP_TYPES_URL = "/instance-relationship-types?limit=" + SETTING_LIMIT;
98+
static final String HOLDINGS_TYPES_URL = "/holdings-types?limit=" + SETTING_LIMIT;
99+
static final String HOLDINGS_NOTE_TYPES_URL = "/holdings-note-types?limit=" + SETTING_LIMIT;
100+
static final String ILL_POLICIES_URL = "/ill-policies?limit=" + SETTING_LIMIT;
101+
static final String CALL_NUMBER_TYPES_URL = "/call-number-types?limit=" + SETTING_LIMIT;
102+
static final String STATISTICAL_CODES_URL = "/statistical-codes?limit=" + SETTING_LIMIT;
103+
static final String STATISTICAL_CODE_TYPES_URL = "/statistical-code-types?limit=" + SETTING_LIMIT;
104+
static final String LOCATIONS_URL = "/locations?limit=" + SETTING_LIMIT;
105+
static final String MATERIAL_TYPES_URL = "/material-types?limit=" + SETTING_LIMIT;
106+
static final String ITEM_DAMAGED_STATUSES_URL = "/item-damaged-statuses?limit=" + SETTING_LIMIT;
107+
static final String LOAN_TYPES_URL = "/loan-types?limit=" + SETTING_LIMIT;
108+
static final String ITEM_NOTE_TYPES_URL = "/item-note-types?limit=" + SETTING_LIMIT;
109+
static final String FIELD_PROTECTION_SETTINGS_URL = "/field-protection-settings/marc?limit=" + SETTING_LIMIT;
110+
static final String ISSUANCE_MODES_URL = "/modes-of-issuance?limit=" + SETTING_LIMIT;
111+
113112
private MappingUtility() {
114113

115114
}
@@ -119,6 +118,7 @@ public static String mapRecordToInsance(String marcJson, String okapiUrl, String
119118
JsonObject mappingRules = fetchRules(okapiUrl, tenant, token);
120119
MappingParameters mappingParameters = getMappingParamaters(okapiUrl, tenant, token);
121120
Instance instance = marcToInstanceMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
121+
122122
return objectMapper.writeValueAsString(instance);
123123
}
124124

@@ -135,7 +135,7 @@ public static String mapCsvToJson(String csv) throws IOException {
135135

136136
private static JsonObject fetchRules(String okapiUrl, String tenant, String token) {
137137
HttpEntity<?> entity = new HttpEntity<>(headers(tenant, token));
138-
String url = okapiUrl + "/mapping-rules/marc-bib";
138+
String url = okapiUrl + MAPPING_RULES_URL;
139139
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
140140
return new JsonObject(response.getBody());
141141
}
@@ -171,7 +171,7 @@ private static MappingParameters getMappingParamaters(String okapiUrl, String te
171171
.withItemNoteTypes(getItemNoteTypes(okapiUrl, headers))
172172
.withMarcFieldProtectionSettings(getMarcFieldProtectionSettings(okapiUrl, headers));
173173
}
174-
174+
175175
private static List<IdentifierType> getIdentifierTypes(String okapiUrl, HttpHeaders headers) {
176176
HttpEntity<Identifiertypes> entity = new HttpEntity<>(headers);
177177
String url = okapiUrl + IDENTIFIER_TYPES_URL;

src/main/java/org/folio/rest/camunda/utility/MarcUtility.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MarcUtility {
4343

4444
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
4545

46-
private static final ObjectMapper mapper = new ObjectMapper();
46+
protected static final ObjectMapper mapper = new ObjectMapper();
4747

4848
private MarcUtility() {
4949

@@ -154,7 +154,7 @@ public static String getFieldsFromMarcJson(String marcJson, String[] tags)
154154

155155
private static Record marcJsonToRecord(String marcJson)
156156
throws MarcException, IOException {
157-
logger.info("Attempting to read MARC JSON to Record: {}", marcJson);
157+
logger.debug("Attempting to read MARC JSON to Record: {}", marcJson);
158158
try (InputStream in = new ByteArrayInputStream(marcJson.getBytes())) {
159159
final MarcJsonReader reader = new MarcJsonReader(in);
160160
if (reader.hasNext()) {
@@ -167,7 +167,7 @@ private static Record marcJsonToRecord(String marcJson)
167167

168168
private static Record rawMarcToRecord(String rawMarc)
169169
throws MarcException, IOException {
170-
logger.info("Attempting to read raw MARC to Record: {}", rawMarc);
170+
logger.debug("Attempting to read raw MARC to Record: {}", rawMarc);
171171
try (InputStream in = new ByteArrayInputStream(rawMarc.getBytes(DEFAULT_CHARSET))) {
172172
final MarcStreamReader reader = new MarcStreamReader(in, DEFAULT_CHARSET.name());
173173
if (reader.hasNext()) {

src/main/resources/application.yaml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ logging:
1313
springframework: INFO
1414

1515
server:
16-
port: 9000
16+
port: 8081
1717
servlet:
1818
context-path: /
1919
encoding:
@@ -55,7 +55,7 @@ spring:
5555
password: ${DB_PASSWORD:folio_admin}
5656

5757
flyway:
58-
enabled: true
58+
enabled: false
5959
encoding: UTF-8
6060

6161
h2:
@@ -71,7 +71,7 @@ spring:
7171

7272
properties.hibernate.jdbc.lob.non_contextual_creation: true
7373
generate-ddl: false
74-
hibernate.ddl-auto: none
74+
hibernate.ddl-auto: update
7575
open-in-view: true
7676
show-sql: false
7777

@@ -102,7 +102,7 @@ camunda:
102102
bpm:
103103
auto-deployment-enabled: false
104104
database:
105-
schema-update: false
105+
schema-update: true
106106
filter:
107107
create: All Tasks
108108
admin-user:
@@ -157,13 +157,23 @@ tenant:
157157
# https://github.com/camunda/camunda-bpm-platform/tree/master/engine/src/main/resources/org/camunda/bpm/engine/db/create
158158
# be sure to match datasource platform
159159
schema-scripts:
160-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql
161-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.history.sql
162-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.identity.sql
163-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.case.engine.sql
164-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.case.history.sql
165-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql
166-
- classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql
160+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.engine.sql
161+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.history.sql
162+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.identity.sql
163+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.case.engine.sql
164+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.case.history.sql
165+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.decision.engine.sql
166+
- classpath:/org/camunda/bpm/engine/db/create/activiti.postgres.create.decision.history.sql
167+
168+
# H2 schema scripts.
169+
#schema-scripts:
170+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql
171+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.history.sql
172+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.identity.sql
173+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.case.engine.sql
174+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.case.history.sql
175+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql
176+
# - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql
167177

168178
okapi.url: ${OKAPI_URL:http://localhost:9130}
169179

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.folio.rest.camunda.aspect;
2+
3+
import static org.mockito.ArgumentMatchers.any;
4+
import static org.mockito.Mockito.doNothing;
5+
import static org.mockito.Mockito.verify;
6+
import static org.mockito.Mockito.when;
7+
8+
import org.camunda.bpm.engine.ProcessEngineServices;
9+
import org.camunda.bpm.engine.RepositoryService;
10+
import org.camunda.bpm.engine.delegate.DelegateExecution;
11+
import org.camunda.bpm.engine.repository.ProcessDefinition;
12+
import org.camunda.bpm.engine.repository.ProcessDefinitionQuery;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.ExtendWith;
15+
import org.mockito.InjectMocks;
16+
import org.mockito.Mock;
17+
import org.mockito.junit.jupiter.MockitoExtension;
18+
import org.springframework.mail.SimpleMailMessage;
19+
import org.springframework.mail.javamail.JavaMailSender;
20+
import org.springframework.test.context.junit.jupiter.SpringExtension;
21+
import org.springframework.test.util.ReflectionTestUtils;
22+
23+
@ExtendWith(SpringExtension.class)
24+
@ExtendWith(MockitoExtension.class)
25+
class DelegateExecutionExceptionAspectTest {
26+
27+
@Mock
28+
private JavaMailSender emailSender;
29+
30+
@Mock
31+
private DelegateExecution execution;
32+
33+
@Mock
34+
private RepositoryService repositoryService;
35+
36+
@Mock
37+
private ProcessEngineServices processEngineServices;
38+
39+
@Mock
40+
private ProcessDefinitionQuery processDefinitionQuery;
41+
42+
@Mock
43+
private ProcessDefinition processDefinition;
44+
45+
@Mock
46+
private StackTraceElement stackTraceElement;
47+
48+
@Mock
49+
private Throwable exception;
50+
51+
@InjectMocks
52+
private DelegateExecutionExceptionAspect delegateExecutionExceptionAspect;
53+
54+
@Test
55+
void testAfterDelegateExecutionThrowsException() {
56+
ReflectionTestUtils.setField(delegateExecutionExceptionAspect, "errorHandlingEnvironment", "DEV");
57+
ReflectionTestUtils.setField(delegateExecutionExceptionAspect, "errorHandlingEmailFrom", "helpdesk@library.tamu.edu");
58+
ReflectionTestUtils.setField(delegateExecutionExceptionAspect, "errorHandlingEmailTo", "helpdesk@library.tamu.edu");
59+
60+
when(execution.getCurrentActivityName()).thenReturn("taskName");
61+
when(execution.getTenantId()).thenReturn("tenant");
62+
when(execution.getProcessDefinitionId()).thenReturn("id");
63+
when(processDefinition.getName()).thenReturn("workflowName");
64+
when(processDefinitionQuery.singleResult()).thenReturn(processDefinition);
65+
66+
when(processDefinitionQuery.processDefinitionId(execution.getProcessDefinitionId())).thenReturn(processDefinitionQuery);
67+
68+
when(repositoryService.createProcessDefinitionQuery()).thenReturn(processDefinitionQuery);
69+
when(processEngineServices.getRepositoryService()).thenReturn(repositoryService);
70+
when(execution.getProcessEngineServices()).thenReturn(processEngineServices);
71+
72+
when(exception.getStackTrace()).thenReturn(new StackTraceElement[] { stackTraceElement });
73+
when(stackTraceElement.toString()).thenReturn("");
74+
75+
doNothing().when(emailSender).send(any(SimpleMailMessage.class));
76+
77+
delegateExecutionExceptionAspect.afterDelegateExecutionThrowsException(execution, exception);
78+
79+
verify(emailSender).send(any(SimpleMailMessage.class));
80+
}
81+
82+
}

0 commit comments

Comments
 (0)