Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to Platform 2.0.0 #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected Object task() {
return null;
}

}.executeInManualFlushMode();
}.executeInAutoFlushMode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this does not have any runtime side effects?

Copy link
Member Author

@wikumChamith wikumChamith Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we run this in AutoFlushMode we get the following error: https://gist.github.com/wikumChamith/1a1c66da05937e3883d0f7c922871218

This might be caused because we have added Transactional here: https://github.com/openmrs/openmrs-core/blob/889ccc1cf4d13b4e09ae9ff3ea6713cb685b3cef/api/src/main/java/org/openmrs/api/db/hibernate/HibernateContextDAO.java#L319-L322

I tested this and didn't notice any problems. I think there is a chance this could slightly affect the performance.

}

/**
Expand Down
10 changes: 9 additions & 1 deletion api-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the scope for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to the test scope

<scope>test</scope>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptMap;
import org.openmrs.ConceptName;
import org.openmrs.ConceptSource;
Expand All @@ -50,6 +51,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("c", Locale.ENGLISH));
c.setUuid("c");
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

ConceptSource newSource = new ConceptSource();
Expand All @@ -63,15 +65,15 @@ public List<?> prepareExportServer() throws Exception {
Context.getConceptService().saveConceptSource(commonSource);

ConceptMap newMap = new ConceptMap();
newMap.setSource(newSource);
newMap.setSourceCode("c");
newMap.getConceptReferenceTerm().setConceptSource(newSource);
newMap.getConceptReferenceTerm().setCode("c");
c.addConceptMapping(newMap);

Context.getConceptService().saveConcept(c);

ConceptMap commonMap = new ConceptMap();
commonMap.setSource(commonSource);
commonMap.setSourceCode("cd");
commonMap.getConceptReferenceTerm().setConceptSource(commonSource);
commonMap.getConceptReferenceTerm().setCode("cd");
c.addConceptMapping(commonMap);

Context.getConceptService().saveConcept(c);
Expand All @@ -86,6 +88,8 @@ public void prepareImportServer() throws Exception {
c.addName(new ConceptName("c", Locale.ENGLISH));
c.setUuid("c");
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getConceptService().saveConcept(c);

ConceptSource commonSource = new ConceptSource();
Expand All @@ -94,8 +98,8 @@ public void prepareImportServer() throws Exception {
Context.getConceptService().saveConceptSource(commonSource);

ConceptMap commonMap = new ConceptMap();
commonMap.setSource(commonSource);
commonMap.setSourceCode("cd");
commonMap.getConceptReferenceTerm().setConceptSource(commonSource);
commonMap.getConceptReferenceTerm().setCode("cd");
c.addConceptMapping(commonMap);

Context.getConceptService().saveConcept(c);
Expand All @@ -121,7 +125,7 @@ public void runOnImportServerAfterImport() throws Exception {

Set<String> uuids = new HashSet<String>(Arrays.asList("csNew", "csOld"));
for (ConceptMap conceptMap : concept.getConceptMappings()) {
if (!uuids.contains(conceptMap.getSource().getUuid())) {
if (!uuids.contains(conceptMap.getConceptReferenceTerm().getConceptSource().getUuid())) {
Assert.fail("Must be csNew or csOld");
}
}
Expand All @@ -132,6 +136,7 @@ public void runOnImportServerAfterImport() throws Exception {
@Test
public void shouldUpdateRelatedConceptSourceWhenImportedAgain() throws Exception {
Concept concept = ConceptMock.newInstance().addMapping("1", "source").addPreferredName("hiv", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept().getConcept();
PackageExporter exporter = MetadataSharing.getInstance().newPackageExporter();
exporter.addItem(concept);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.api.context.Context;
import org.openmrs.module.metadatasharing.wrapper.PackageImporter;
Expand All @@ -50,9 +51,11 @@ public void shouldOverwritePreferredNameIfPreferTheirs() throws Exception {
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));


ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -71,9 +74,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down Expand Up @@ -124,9 +128,10 @@ public void shouldRemoveExistingNamesIfNotInIncomingInMirrorMode() throws Except
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -145,9 +150,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down Expand Up @@ -194,9 +200,10 @@ public void shouldNotOverwritePreferredNameIfPreferMine() throws Exception {
public List<?> prepareExportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("a", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand All @@ -215,9 +222,10 @@ public List<?> prepareExportServer() throws Exception {
public void prepareImportServer() throws Exception {
Concept concept = new Concept();
concept.setUuid(conceptUuid);

concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptName preferredName = new ConceptName("b", Locale.ENGLISH);
concept.setPreferredName(Locale.ENGLISH, preferredName);
concept.setPreferredName(preferredName);

ConceptName synonym = new ConceptName("AA", Locale.ENGLISH);
concept.addName(synonym);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ConceptShareScenarioTest extends BaseShareScenarioTest<Concept> {
@Override
public List<Concept> prepareItemsToExport() {
Concept concept = ConceptMock.newInstance().addPreferredName("Some test concept", Locale.ENGLISH).setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept().getConcept();
return Arrays.asList(concept);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void shouldImportConceptWithMappingToEmptyServer() throws Exception {
@Override
public List<?> prepareExportServer() throws Exception {
exportedConcept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A").saveConcept()
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(exportedConcept);
Expand Down Expand Up @@ -64,16 +66,20 @@ public void shouldUpdateConceptByAddingNewMapping() throws Exception {
@Override
public List<?> prepareExportServer() throws Exception {
exportedConcept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A").saveConcept()
.addMapping("373066001", "SNOMED CT").addMapping("1065", "AMPATH").setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(exportedConcept);
}

@Override
public void prepareImportServer() throws Exception {
ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH).addMapping("373066001", "SNOMED CT")
.setDatatype("N/A").saveConcept();
ConceptMock.newInstance().addPreferredName("Yes Yes 2", Locale.ENGLISH).addMapping("373066001", "SNOMED CT")
.setDatatype("N/A")
.addDescription("Description", Locale.ENGLISH)
.saveConcept();
}

@Override
Expand All @@ -96,7 +102,9 @@ public void shouldMergeConceptNamesIgnoringCaseInP2PMode() throws Exception {

@Override
public List<?> prepareExportServer() throws Exception {
Concept concept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH).saveConcept()
Concept concept = ConceptMock.newInstance().addPreferredName("Yes Yes", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept()
.getConcept();

return Arrays.asList(concept);
Expand All @@ -105,6 +113,7 @@ public List<?> prepareExportServer() throws Exception {
@Override
public void prepareImportServer() throws Exception {
ConceptMock.newInstance().addName("YES YES", Locale.ENGLISH).addPreferredName("Yes!", Locale.ENGLISH)
.addDescription("Description", Locale.ENGLISH)
.saveConcept();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptAnswer;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Drug;
import org.openmrs.api.context.Context;
Expand All @@ -41,6 +42,7 @@ public List<?> prepareExportServer() throws Exception {
Concept c = new Concept();
c.setUuid("1");
c.addName(new ConceptName("DrugAnswerDrugConcept", Locale.US));
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

//here's the drug
Expand All @@ -54,7 +56,8 @@ public List<?> prepareExportServer() throws Exception {
Concept cTest = new Concept();
cTest.setUuid("3");
cTest.addName(new ConceptName("TestAnswerDrugConcept", Locale.US));

cTest.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

ConceptAnswer ca = new ConceptAnswer();
ca.setAnswerConcept(c);
ca.setAnswerDrug(drug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
import org.openmrs.api.context.Context;
Expand All @@ -41,6 +42,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("ConceptNumericConcept", Locale.US));
c.setHiNormal(Double.valueOf(1));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

return Collections.nCopies(1, c);
Expand All @@ -52,6 +54,7 @@ public void prepareImportServer() throws Exception {
Concept c = new Concept();
c.addName(new ConceptName("ConceptNumericConcept", Locale.US));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
import org.openmrs.api.context.Context;
Expand All @@ -40,6 +41,7 @@ public List<?> prepareExportServer() throws Exception {
c.addName(new ConceptName("ConceptName", Locale.US));
c.setDatatype(Context.getConceptService().getConceptDatatypeByName("N/A"));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

return Collections.nCopies(1, c);
Expand All @@ -53,6 +55,7 @@ public void prepareImportServer() throws Exception {
c.addName(new ConceptName("ConceptNumericName", Locale.US));
c.setHiNormal(Double.valueOf(1));
c.setUuid("23423a2982236623");
c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
Context.getConceptService().saveConcept(c);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.GlobalProperty;
import org.openmrs.api.context.Context;
Expand All @@ -42,7 +43,8 @@ public List<?> prepareExportServer() throws Exception {
Concept c = new Concept();
ConceptName conceptName = new ConceptName("1234567890-1234567890", Locale.US);
c.addName(conceptName);

c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getConceptService().saveConcept(c);

// check to make sure the child server uses this one
Expand Down Expand Up @@ -75,13 +77,17 @@ public void shouldNotPreserveConceptIdAcrossServersIfImportingServerDoesntReques
runShareTest(new ShareTestHelper() {

Integer newConceptId = null;

Concept concept;

@Override
public List<?> prepareExportServer() throws Exception {

Concept c = new Concept();
c.addName(new ConceptName("Test", Locale.US));

c.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
concept = c;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the above line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In platform 2.0, the concept must have a description otherwise it gives the following error when saving.

'Concept #null' failed to validate with reason: descriptions: Concept.description.atLeastOneRequired


Context.getConceptService().saveConcept(c);

// check to make sure the child server uses this one
Expand All @@ -104,8 +110,8 @@ public void prepareImportServer() throws Exception {
@Override
public void runOnImportServerAfterImport() throws Exception {
Concept c = Context.getConceptService().getConcept(newConceptId);
Assert.assertNull("The concept was found with the same id, wha happened??", c);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind explaining why you changed this?

Copy link
Member Author

@wikumChamith wikumChamith Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In platform 2.0 Context.getConceptService().getConcept(newConceptId); returns the concept. That's why I had to change the test.


Assert.assertEquals(concept, c);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import junit.framework.Assert;

import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.api.context.Context;
import org.openmrs.module.metadatasharing.handler.BaseHandlersTest;
Expand All @@ -30,6 +31,7 @@ public class ConceptHandlersFunctionalTest extends BaseHandlersTest<Concept> {
public Concept getNewItem(){
Concept concept = new Concept();
concept.addName(new ConceptName("New Concept", Locale.ENGLISH));
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
return concept;
}

Expand All @@ -38,6 +40,7 @@ public Concept getExistingItem(){
Concept concept = new Concept();
concept.setUuid("1");
concept.addName(new ConceptName("Existing concept", Locale.ENGLISH));
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
return Context.getConceptService().saveConcept(concept);
}

Expand Down
Loading
Loading