Skip to content

Commit

Permalink
mekomsolutions#277 - CSV parser should save cached objects once file …
Browse files Browse the repository at this point in the history
…has been loaded.
  • Loading branch information
Amos Laboso committed Sep 10, 2024
1 parent ab9e8c0 commit 89060c1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ public void load_shouldLoadPaymentModesAccordingToCsvFiles() {
{
PaymentMode paymentMode = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606");
assertNotNull(paymentMode);
assertEquals("Paypal", paymentMode.getName());

paymentMode.getAttributeTypes().forEach(attributeType -> {
if (attributeType.getName().equals("Maximum")) {
assertEquals("Numeric", attributeType.getFormat());
assertTrue(attributeType.getRequired());
} else {
assertEquals("Minimum", attributeType.getName());
}
});
assertEquals("Nutrition Cash Item", paymentMode.getName());
}

// Verify edition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uuid, Void/Retire, name, attributes
526bf278-ba81-4436-b867-c2f6641d060a, , Visa card edited,
2b1b9aae-5d35-43dd-9214-3fd370fd7737, true, Bank transfer,
e168c141-f5fd-4eec-bd3e-633bed1c9606, , Paypal, Maximum::Numeric::::True;Minimum
uuid,Void/Retire,name,attributes
526bf278-ba81-4436-b867-c2f6641d060a,,Visa card edited,
2b1b9aae-5d35-43dd-9214-3fd370fd7737,true,Bank transfer,
fd0ff4ff-dec2-47f5-bb19-5c93b400e94c,,Paypal,Maximum::Numeric::::True;Minimum
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public CsvFailingLines process(List<String[]> lines) {
}
}

Context.flushSession();
Context.clearSession();

return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.openmrs.module.initializer.api;

import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ProgramWorkflow;
import org.openmrs.ProgramWorkflowState;
Expand Down Expand Up @@ -50,6 +53,7 @@ public void setup() {
{
Concept c = new Concept();
c.setShortName(new ConceptName("Active treatment (initial)", Locale.ENGLISH));
c.setDescriptions(Collections.singleton(new ConceptDescription("Active treatment (initial)", Locale.ENGLISH)));
c.setConceptClass(cs.getConceptClassByName("State"));
c.setDatatype(cs.getConceptDatatypeByName("Text"));
c = cs.saveConcept(c);
Expand Down Expand Up @@ -124,8 +128,8 @@ public void load_shouldLoadProgramWorkflowStatesAccordingToCsvFiles() {
Assert.assertEquals(wf, state.getProgramWorkflow());

Assert.assertEquals(cs.getConceptByName("Active treatment (initial)"), state.getConcept());
Assert.assertEquals("Active treatment (initial)", state.getName());
Assert.assertEquals("Active treatment (initial)", state.getDescription());
Assert.assertEquals("Active treatment (initial)", state.getConcept().getName().getName());
Assert.assertEquals("Active treatment (initial)", state.getConcept().getDescription().getDescription());
Assert.assertFalse(state.isRetired());
Assert.assertTrue(state.getInitial());
Assert.assertFalse(state.getTerminal());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.openmrs.module.initializer.api;

import java.util.Collections;
import java.util.Locale;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Program;
import org.openmrs.ProgramWorkflow;
Expand Down Expand Up @@ -39,6 +41,8 @@ public static void setupWorkflows(ConceptService cs, ProgramWorkflowService pws)
{
Concept c = new Concept();
c.setShortName(new ConceptName("TB Treatment Status (workflow)", Locale.ENGLISH));
c.setDescriptions(
Collections.singleton(new ConceptDescription("TB Treatment Status (workflow)", Locale.ENGLISH)));
c.setConceptClass(cs.getConceptClassByName("Workflow"));
c.setDatatype(cs.getConceptDatatypeByName("Text"));
c = cs.saveConcept(c);
Expand Down Expand Up @@ -133,8 +137,8 @@ public void load_shouldLoadProgramWorkflowsAccordingToCsvFiles() {
Program prog = pws.getProgramByName("TB Program");
Assert.assertEquals(prog, wf.getProgram());
Assert.assertEquals(cs.getConceptByName("TB Treatment Status (workflow)"), wf.getConcept());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getName());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getDescription());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getName().getName());
Assert.assertEquals("TB Treatment Status (workflow)", wf.getConcept().getDescription().getDescription());
Assert.assertFalse(wf.isRetired());
Assert.assertEquals(wf, prog.getWorkflow(wf.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
{
RelationshipType rt = ps.getRelationshipTypeByUuid("c86d9979-b8ac-4d8c-85cf-cc04e7f16315");
Assert.assertNotNull(rt);
Assert.assertEquals("Uncle/Nephew", rt.getName());
Assert.assertEquals("Uncle/Nephew", rt.toString());
Assert.assertEquals("A relationship of an uncle and his nephew", rt.getDescription());
Assert.assertEquals("Uncle", rt.getaIsToB());
Assert.assertEquals("Nephew", rt.getbIsToA());
Expand All @@ -41,7 +41,7 @@ public void load_shouldLoadRelationshipTypesAccordingToCsvFiles() {
{
RelationshipType rt = ps.getRelationshipTypeByUuid("53d8a8f3-0084-4a52-8666-c655f5bd2689");
Assert.assertNotNull(rt);
Assert.assertEquals("Supervisor/Supervisee", rt.getName());
Assert.assertEquals("Supervisor/Supervisee", rt.toString());
Assert.assertEquals("A new description for supervisor to supervisee relationship", rt.getDescription());
}

Expand Down

0 comments on commit 89060c1

Please sign in to comment.