Skip to content

Commit 7b1b14c

Browse files
Amos LabosoRuhanga
Amos Laboso
authored andcommitted
[#277] - CSV parser to save cached objects once file has been loaded.
1 parent ab9e8c0 commit 7b1b14c

File tree

11 files changed

+54
-26
lines changed

11 files changed

+54
-26
lines changed

.vscode/settings.json

-4
This file was deleted.

api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/PaymentModesCsvParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PaymentModesCsvParser extends CsvParser<PaymentMode, BaseLineProces
1818

1919
@Autowired
2020
public PaymentModesCsvParser(@Qualifier("cashierPaymentModeService") IPaymentModeService paymentModeService,
21-
PaymentModesLineProcessor processor) {
21+
PaymentModesLineProcessor processor) {
2222
super(processor);
2323
this.paymentModeService = paymentModeService;
2424
}

api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/PaymentModesLineProcessor.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArg
2121

2222
String attributes = line.get(HEADER_ATTRIBUTES, false);
2323
if (StringUtils.isNotBlank(attributes)) {
24-
paymentMode.getAttributeTypes().clear();
24+
if (paymentMode.getAttributeTypes() != null) {
25+
paymentMode.getAttributeTypes().clear();
26+
}
2527
for (String attribute : attributes.split(BaseLineProcessor.LIST_SEPARATOR)) {
2628
String[] parts = attribute.trim().split("::");
2729
if (parts.length > 3) {
28-
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), Boolean.parseBoolean(parts[3].trim()));
30+
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(),
31+
Boolean.parseBoolean(parts[3].trim()));
2932
} else if (parts.length > 2) {
3033
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), parts[2].trim(), false);
3134
} else if (parts.length > 1) {
3235
paymentMode.addAttributeType(parts[0].trim(), parts[1].trim(), null, false);
3336
} else {
3437
paymentMode.addAttributeType(parts[0].trim(), null, null, false);
35-
}
38+
}
3639
}
3740
}
3841

api-2.4/src/test/java/org/openmrs/module/initializer/api/PaymentModesLoaderIntegrationTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public void load_shouldLoadPaymentModesAccordingToCsvFiles() {
4949
{
5050
PaymentMode paymentMode = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606");
5151
assertNotNull(paymentMode);
52-
assertEquals("Paypal", paymentMode.getName());
52+
assertEquals("Paypal", paymentMode.getName());
5353

5454
paymentMode.getAttributeTypes().forEach(attributeType -> {
55-
if (attributeType.getName().equals("Maximum")) {
56-
assertEquals("Numeric", attributeType.getFormat());
57-
assertTrue(attributeType.getRequired());
58-
} else {
59-
assertEquals("Minimum", attributeType.getName());
60-
}
61-
});
55+
if (attributeType.getName().equals("Maximum")) {
56+
assertEquals("Numeric", attributeType.getFormat());
57+
assertTrue(attributeType.getRequired());
58+
} else {
59+
assertEquals("Minimum", attributeType.getName());
60+
}
61+
});
6262
}
6363

6464
// Verify edition
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
uuid, Void/Retire, name, attributes
2-
526bf278-ba81-4436-b867-c2f6641d060a, , Visa card edited,
3-
2b1b9aae-5d35-43dd-9214-3fd370fd7737, true, Bank transfer,
4-
e168c141-f5fd-4eec-bd3e-633bed1c9606, , Paypal, Maximum::Numeric::::True;Minimum
1+
uuid,Void/Retire,name,attributes
2+
526bf278-ba81-4436-b867-c2f6641d060a,,Visa card edited,
3+
2b1b9aae-5d35-43dd-9214-3fd370fd7737,true,Bank transfer,
4+
e168c141-f5fd-4eec-bd3e-633bed1c9606,,Paypal,Maximum::Numeric::::True;Minimum

api/src/main/java/org/openmrs/module/initializer/api/CsvParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ public List<String[]> getLines() {
189189
* @return The resulting CsvParserResult instance.
190190
*/
191191
public CsvFailingLines process(List<String[]> lines) {
192+
// Save cached objects to avoid losing them prematurely by other Parsers
193+
// See DisplaysCsvParser#save(OpenmrsObject)
194+
Context.flushSession();
195+
Context.clearSession();
192196

193197
CsvFailingLines result = new CsvFailingLines();
194198
int saved = 0;

api/src/test/java/org/openmrs/module/initializer/api/ProgramWorkflowStatesLoaderIntegrationTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.openmrs.module.initializer.api;
22

3+
import java.util.Arrays;
4+
import java.util.Collections;
35
import java.util.Locale;
46

57
import org.junit.Assert;
68
import org.junit.Before;
79
import org.junit.Test;
810
import org.openmrs.Concept;
11+
import org.openmrs.ConceptDescription;
912
import org.openmrs.ConceptName;
1013
import org.openmrs.ProgramWorkflow;
1114
import org.openmrs.ProgramWorkflowState;
@@ -50,6 +53,7 @@ public void setup() {
5053
{
5154
Concept c = new Concept();
5255
c.setShortName(new ConceptName("Active treatment (initial)", Locale.ENGLISH));
56+
c.setDescriptions(Collections.singleton(new ConceptDescription("Active treatment (initial)", Locale.ENGLISH)));
5357
c.setConceptClass(cs.getConceptClassByName("State"));
5458
c.setDatatype(cs.getConceptDatatypeByName("Text"));
5559
c = cs.saveConcept(c);
@@ -124,8 +128,8 @@ public void load_shouldLoadProgramWorkflowStatesAccordingToCsvFiles() {
124128
Assert.assertEquals(wf, state.getProgramWorkflow());
125129

126130
Assert.assertEquals(cs.getConceptByName("Active treatment (initial)"), state.getConcept());
127-
Assert.assertEquals("Active treatment (initial)", state.getName());
128-
Assert.assertEquals("Active treatment (initial)", state.getDescription());
131+
Assert.assertEquals("Active treatment (initial)", state.getConcept().getName().getName());
132+
Assert.assertEquals("Active treatment (initial)", state.getConcept().getDescription().getDescription());
129133
Assert.assertFalse(state.isRetired());
130134
Assert.assertTrue(state.getInitial());
131135
Assert.assertFalse(state.getTerminal());

api/src/test/java/org/openmrs/module/initializer/api/ProgramWorkflowsLoaderIntegrationTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.openmrs.module.initializer.api;
22

3+
import java.util.Collections;
34
import java.util.Locale;
45

56
import org.junit.Assert;
67
import org.junit.Before;
78
import org.junit.Test;
89
import org.openmrs.Concept;
10+
import org.openmrs.ConceptDescription;
911
import org.openmrs.ConceptName;
1012
import org.openmrs.Program;
1113
import org.openmrs.ProgramWorkflow;
@@ -39,6 +41,8 @@ public static void setupWorkflows(ConceptService cs, ProgramWorkflowService pws)
3941
{
4042
Concept c = new Concept();
4143
c.setShortName(new ConceptName("TB Treatment Status (workflow)", Locale.ENGLISH));
44+
c.setDescriptions(
45+
Collections.singleton(new ConceptDescription("TB Treatment Status (workflow)", Locale.ENGLISH)));
4246
c.setConceptClass(cs.getConceptClassByName("Workflow"));
4347
c.setDatatype(cs.getConceptDatatypeByName("Text"));
4448
c = cs.saveConcept(c);
@@ -133,8 +137,8 @@ public void load_shouldLoadProgramWorkflowsAccordingToCsvFiles() {
133137
Program prog = pws.getProgramByName("TB Program");
134138
Assert.assertEquals(prog, wf.getProgram());
135139
Assert.assertEquals(cs.getConceptByName("TB Treatment Status (workflow)"), wf.getConcept());
136-
Assert.assertEquals("TB Treatment Status (workflow)", wf.getName());
137-
Assert.assertEquals("TB Treatment Status (workflow)", wf.getDescription());
140+
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getName().getName());
141+
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getDescription().getDescription());
138142
Assert.assertFalse(wf.isRetired());
139143
Assert.assertEquals(wf, prog.getWorkflow(wf.getId()));
140144
}

api/src/test/java/org/openmrs/module/initializer/api/RelationshipTypesLoaderIntegrationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
2929
{
3030
RelationshipType rt = ps.getRelationshipTypeByUuid("c86d9979-b8ac-4d8c-85cf-cc04e7f16315");
3131
Assert.assertNotNull(rt);
32-
Assert.assertEquals("Uncle/Nephew", rt.getName());
32+
Assert.assertEquals("Uncle/Nephew", rt.toString());
3333
Assert.assertEquals("A relationship of an uncle and his nephew", rt.getDescription());
3434
Assert.assertEquals("Uncle", rt.getaIsToB());
3535
Assert.assertEquals("Nephew", rt.getbIsToA());
@@ -41,7 +41,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
4141
{
4242
RelationshipType rt = ps.getRelationshipTypeByUuid("53d8a8f3-0084-4a52-8666-c655f5bd2689");
4343
Assert.assertNotNull(rt);
44-
Assert.assertEquals("Supervisor/Supervisee", rt.getName());
44+
Assert.assertEquals("Supervisor/Supervisee", rt.toString());
4545
Assert.assertEquals("A new description for supervisor to supervisee relationship", rt.getDescription());
4646
}
4747

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<openconceptlabVersion>1.2.9</openconceptlabVersion>
7474
<fhir2Version>1.6.0</fhir2Version>
7575
<billingVersion>1.1.0</billingVersion>
76+
<stockmanagementVersion>2.0.2-SNAPSHOT</stockmanagementVersion>
7677

7778
<!-- Modules compatibility > Core 2.3.0 -->
7879
<datafilterVersion>1.0.0</datafilterVersion>

validator/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@
382382
<version>${mysqlTestContainerVersion}</version>
383383
</dependency>
384384

385+
<dependency>
386+
<groupId>org.openmrs.module</groupId>
387+
<artifactId>exti18n-api</artifactId>
388+
<version>${exti18nVersion}</version>
389+
<scope>runtime</scope>
390+
<type>jar</type>
391+
</dependency>
392+
393+
<dependency>
394+
<groupId>org.openmrs.module</groupId>
395+
<artifactId>stockmanagement-api</artifactId>
396+
<version>${stockmanagementVersion}</version>
397+
<scope>runtime</scope>
398+
<type>jar</type>
399+
</dependency>
400+
385401
</dependencies>
386402

387403
<build>

0 commit comments

Comments
 (0)