diff --git a/.gitignore b/.gitignore
index 7e013aa1..7ec2f080 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ target/
.project
.classpath
*.iml
+.qodo
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..bf5e052e
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,4 @@
+{
+ "java.compile.nullAnalysis.mode": "disabled",
+ "java.configuration.updateBuildConfiguration": "interactive"
+}
\ No newline at end of file
diff --git a/api-2.0/pom.xml b/api-2.0/pom.xml
index c8247b95..41214e3b 100644
--- a/api-2.0/pom.xml
+++ b/api-2.0/pom.xml
@@ -1,69 +1,63 @@
-
- 4.0.0
+
+ 4.0.0
-
- org.openmrs.module
- metadatasharing
- 1.10.0-SNAPSHOT
-
+
+ org.openmrs.module
+ metadatasharing
+ 1.10.0-SNAPSHOT
+
- metadatasharing-api-2.0
- jar
- Metadata Sharing Module API 2.0
- API 2.0 project for Metadata Sharing Module
+ metadatasharing-api-2.0
+ jar
+ Metadata Sharing Module API 2.0
+ API 2.0 project for Metadata Sharing Module
-
- 2.0.0-alpha
-
-
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-common
- ${project.parent.version}
-
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-common
- ${project.parent.version}
- tests
- test
-
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-1.11
- ${project.parent.version}
-
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-1.11
- ${project.parent.version}
- tests
- test
-
-
-
- org.openmrs.api
- openmrs-api
- ${openmrs.2.0.api.version}
-
+
+ 2.5.0
+ 1.8
+
-
- org.openmrs.api
- openmrs-api
- ${openmrs.2.0.api.version}
- tests
-
-
-
- org.openmrs.test
- openmrs-test
- ${openmrs.2.0.api.version}
- pom
-
-
-
+
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api-common
+ ${project.parent.version}
+
+
+
+
+ org.hibernate
+ hibernate-core
+ 5.6.14.Final
+ provided
+
+
+
+ org.openmrs.api
+ openmrs-api
+ ${openmrs.2.0.api.version}
+ provided
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ ${java.version}
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java b/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java
index a3eb53da..73966166 100644
--- a/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java
+++ b/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java
@@ -1,66 +1,56 @@
-/**
- * The contents of this file are subject to the OpenMRS Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://license.openmrs.org
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * Copyright (C) OpenMRS, LLC. All Rights Reserved.
- */
package org.openmrs.module.metadatasharing.serializer.converter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import org.hibernate.collection.internal.PersistentList;
-import org.hibernate.collection.internal.PersistentMap;
-import org.hibernate.collection.internal.PersistentSet;
-import org.hibernate.collection.internal.PersistentSortedMap;
-import org.hibernate.collection.internal.PersistentSortedSet;
-import org.hibernate.collection.spi.PersistentCollection;
-import org.openmrs.annotation.OpenmrsProfile;
-
+import org.hibernate.collection.internal.*;
import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import java.util.*;
+
+import org.hibernate.collection.spi.PersistentCollection;
+
+public class CollectionConverterCompatibility2_0 {
-@OpenmrsProfile(openmrsPlatformVersion = "2.*")
-public class CollectionConverterCompatibility2_0 implements CollectionConverterCompatibility {
+ /**
+ * Converts Hibernate persistent collections to regular Java collections before marshaling
+ */
+ public void marshal(Object source, HierarchicalStreamWriter writer,
+ MarshallingContext context, ConverterLookup converterLookup) {
+
+ Object convertedSource = convertHibernateCollection(source);
+
+ // delegate the collection to the appropriate converter
+ converterLookup.lookupConverterForType(convertedSource.getClass())
+ .marshal(convertedSource, writer, context);
+ }
- @Override
- public boolean canConvert(Class type) {
- return PersistentCollection.class.isAssignableFrom(type);
- }
+ /**
+ * Converts Hibernate persistent collections to standard Java collections
+ */
+ public static Object convertHibernateCollection(Object source) {
+ if (source instanceof PersistentBag || source instanceof PersistentList) {
+ return new ArrayList<>((Collection>) source);
+ } else if (source instanceof PersistentMap) {
+ return new HashMap<>((Map, ?>) source);
+ } else if (source instanceof PersistentSortedMap) {
+ return new TreeMap<>((SortedMap, ?>) source);
+ } else if (source instanceof PersistentSortedSet) {
+ return new TreeSet<>((SortedSet>) source);
+ } else if (source instanceof PersistentSet) {
+ return new HashSet<>((Set>) source);
+ }
+ return source;
+ }
- @Override
- public void marshal(Object source, HierarchicalStreamWriter writer,
- MarshallingContext context, ConverterLookup converterLookup) {
-
- if (source instanceof PersistentList) {
- source = new ArrayList((Collection) source);
- } else if (source instanceof PersistentMap) {
- source = new HashMap((Map) source);
- } else if (source instanceof PersistentSortedMap) {
- source = new TreeMap((SortedMap) source);
- } else if (source instanceof PersistentSortedSet) {
- source = new TreeSet((SortedSet) source);
- } else if (source instanceof PersistentSet) {
- source = new HashSet((Set) source);
- }
-
- // delegate the collection to the appropriate converter
- converterLookup.lookupConverterForType(source.getClass()).marshal(source, writer, context);
- }
-}
+ /**
+ * Checks if the object is a Hibernate persistent collection
+ */
+ public static boolean isHibernateCollection(Object source) {
+ return source instanceof PersistentCollection ||
+ source instanceof PersistentBag ||
+ source instanceof PersistentList ||
+ source instanceof PersistentMap ||
+ source instanceof PersistentSortedMap ||
+ source instanceof PersistentSortedSet ||
+ source instanceof PersistentSet;
+ }
+}
\ No newline at end of file
diff --git a/api-test/pom.xml b/api-test/pom.xml
index 39b12f74..305b232a 100644
--- a/api-test/pom.xml
+++ b/api-test/pom.xml
@@ -1,87 +1,138 @@
-
- 4.0.0
+
+ 4.0.0
-
- org.openmrs.module
- metadatasharing
- 1.10.0-SNAPSHOT
-
+
+ org.openmrs.module
+ metadatasharing
+ 1.10.0-SNAPSHOT
+
- metadatasharing-api-test
- Metadata Sharing Module API Test
- API Test project for Metadata Sharing Module
+ metadatasharing-api-test
+ Metadata Sharing Module API Test
+ API Test project for Metadata Sharing Module
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api
- ${project.parent.version}
-
-
- javassist
- javassist
-
-
-
-
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-common
- ${project.parent.version}
- tests
-
-
- javassist
- javassist
-
-
-
+
+ 1.8
+ ${java.version}
+ ${java.version}
+
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-1.9
- ${project.parent.version}
- tests
-
-
- javassist
- javassist
-
-
-
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api
+ ${project.parent.version}
+
+
+ javassist
+ javassist
+
+
+
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api-common
+ ${project.parent.version}
+ tests
+
+
+ javassist
+ javassist
+
+
+
-
- ${project.parent.groupId}
- ${project.parent.artifactId}-api-1.11
- ${project.parent.version}
- tests
-
-
- javassist
- javassist
-
-
-
-
- org.powermock
- powermock-module-junit4
- 1.5
-
-
-
- org.powermock
- powermock-api-mockito
- 1.5
-
-
- mockito-all
- org.mockito
-
-
-
-
-
-
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api-1.9
+ ${project.parent.version}
+ tests
+
+
+ javassist
+ javassist
+
+
+
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api-1.11
+ ${project.parent.version}
+ tests
+
+
+ javassist
+ javassist
+
+
+
+
+
+ org.powermock
+ powermock-module-junit4
+ 1.6.6
+ test
+
+
+
+ org.powermock
+ powermock-api-mockito
+ 1.6.6
+ test
+
+
+ mockito-all
+ org.mockito
+
+
+
+
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ ${java.version}
+ ${java.version}
+ 1.8
+ true
+ true
+ true
+
+ -Xlint:all
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+ -Xmx1024m
+
+ **/*Test.java
+
+
+
+
+
+
\ No newline at end of file
diff --git a/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataServiceTest.java b/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataServiceTest.java
index b549f84d..98caf7e0 100644
--- a/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataServiceTest.java
+++ b/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataServiceTest.java
@@ -37,4 +37,4 @@ public void getItemById_shouldReturnTheItemMatchingThePassedInTypeAndId() throws
Assert.assertEquals("8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
Context.getService(MetadataService.class).getItemById(Location.class, 1).getUuid());
}
-}
+}
\ No newline at end of file
diff --git a/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataSharingServiceTest.java b/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataSharingServiceTest.java
index c0f11e4b..6aa5a883 100644
--- a/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataSharingServiceTest.java
+++ b/api-test/src/test/java/org/openmrs/module/metadatasharing/api/MetadataSharingServiceTest.java
@@ -124,4 +124,4 @@ public void getSubscriptionById_shouldReturnASubscriptionWithTheGivenIDIfItExist
service.saveImportedPackage(getMockSubscription(100));
Assert.assertEquals((Integer) 100, service.getImportedPackageById(100).getId());
}
-}
+}
\ No newline at end of file
diff --git a/api-test/src/test/java/org/openmrs/module/metadatasharing/converter/ConceptMapConverterTest.java b/api-test/src/test/java/org/openmrs/module/metadatasharing/converter/ConceptMapConverterTest.java
index d507739f..780e7cfd 100644
--- a/api-test/src/test/java/org/openmrs/module/metadatasharing/converter/ConceptMapConverterTest.java
+++ b/api-test/src/test/java/org/openmrs/module/metadatasharing/converter/ConceptMapConverterTest.java
@@ -1,3 +1,95 @@
+// /**
+// * The contents of this file are subject to the OpenMRS Public License
+// * Version 1.0 (the "License"); you may not use this file except in
+// * compliance with the License. You may obtain a copy of the License at
+// * http://license.openmrs.org
+// *
+// * Software distributed under the License is distributed on an "AS IS"
+// * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// * License for the specific language governing rights and limitations
+// * under the License.
+// *
+// * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+// */
+// package org.openmrs.module.metadatasharing.converter;
+
+// import java.io.File;
+// import java.io.StringWriter;
+
+// import javax.xml.parsers.DocumentBuilderFactory;
+// import javax.xml.transform.Transformer;
+// import javax.xml.transform.TransformerFactory;
+// import javax.xml.transform.dom.DOMSource;
+// import javax.xml.transform.stream.StreamResult;
+
+// import org.apache.commons.io.FileUtils;
+// import org.junit.Assert;
+// import org.junit.Before;
+// import org.junit.Test;
+// import org.openmrs.module.metadatasharing.converter.BaseConverter.ConverterContext;
+// import org.openmrs.module.metadatasharing.util.Version;
+// import org.openmrs.test.BaseContextSensitiveTest;
+// import org.openmrs.test.BaseModuleContextSensitiveTest;
+// import org.openmrs.test.Verifies;
+// import org.w3c.dom.Document;
+
+// public class ConceptMapConverterTest extends BaseModuleContextSensitiveTest {
+
+// private static final String TEXT_CONCEPT_MAP_XML_FILE = "testConceptMapXmlFile.xml";
+
+// private static Document document;
+
+// private static String originalXml;
+
+// private static final String CONCEPT_MAP_TYPE = "conceptMapType";
+
+// private static final String CONCEPT_REFERENCE_TERM = "conceptReferenceTerm";
+
+// @Before
+// public void before() throws Exception {
+// File file = new File(ClassLoader.getSystemResource(TEXT_CONCEPT_MAP_XML_FILE).getPath());
+// originalXml = FileUtils.readFileToString(file, "UTF-8");
+// document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+// .parse(ClassLoader.getSystemResourceAsStream(TEXT_CONCEPT_MAP_XML_FILE));
+// }
+
+// /**
+// * @see {@link ConceptMapConverter#convert(Document,Version,Version,ConverterContext)}
+// */
+// @Test
+// @Verifies(value = "should replace source if the from version is pre one nine", method = "convert(Document,Version,Version,ConverterContext)")
+// public void convert_shouldReplaceSourceIfTheFromVersionIsPreOneNine() throws Exception {
+// Assert.assertTrue(originalXml.indexOf(CONCEPT_MAP_TYPE) < 0);
+// Assert.assertTrue(originalXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
+// String convertedXml = convertXml("1.8.3", "1.10.0");
+// Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) > 0);
+// Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) > 0);
+// }
+
+// /**
+// * @see {@link ConceptMapConverter#convert(Document,Version,Version,ConverterContext)}
+// */
+// @Test
+// @Verifies(value = "should replace nothing if the to version is post one nine", method = "convert(Document,Version,Version,ConverterContext)")
+// public void convert_shouldReplaceNothingIfTheToVersionIsPostOneNine() throws Exception {
+// String convertedXml = convertXml("1.9.0", "1.9.1");
+// Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) < 0);
+// Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
+// }
+
+// private static String convertXml(String formVersion, String toVersion) throws Exception {
+// new ConceptMapConverter().convert(document, new Version(formVersion), new Version(toVersion),
+// new BaseConverter.ConverterContext());
+
+// Transformer transformer = TransformerFactory.newInstance().newTransformer();
+// StringWriter stringWriter = new StringWriter();
+// transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
+// return stringWriter.toString();
+// }
+// }
+
+
+
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
@@ -11,10 +103,17 @@
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
+
+
package org.openmrs.module.metadatasharing.converter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
@@ -28,62 +127,75 @@
import org.junit.Test;
import org.openmrs.module.metadatasharing.converter.BaseConverter.ConverterContext;
import org.openmrs.module.metadatasharing.util.Version;
-import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.Verifies;
import org.w3c.dom.Document;
public class ConceptMapConverterTest extends BaseModuleContextSensitiveTest {
-
- private static final String TEXT_CONCEPT_MAP_XML_FILE = "testConceptMapXmlFile.xml";
-
- private static Document document;
-
- private static String originalXml;
-
- private static final String CONCEPT_MAP_TYPE = "conceptMapType";
-
- private static final String CONCEPT_REFERENCE_TERM = "conceptReferenceTerm";
-
- @Before
- public void before() throws Exception {
- File file = new File(ClassLoader.getSystemResource(TEXT_CONCEPT_MAP_XML_FILE).getPath());
- originalXml = FileUtils.readFileToString(file, "UTF-8");
- document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
- .parse(ClassLoader.getSystemResourceAsStream(TEXT_CONCEPT_MAP_XML_FILE));
- }
-
- /**
- * @see {@link ConceptMapConverter#convert(Document,Version,Version,ConverterContext)}
- */
- @Test
- @Verifies(value = "should replace source if the from version is pre one nine", method = "convert(Document,Version,Version,ConverterContext)")
- public void convert_shouldReplaceSourceIfTheFromVersionIsPreOneNine() throws Exception {
- Assert.assertTrue(originalXml.indexOf(CONCEPT_MAP_TYPE) < 0);
- Assert.assertTrue(originalXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
- String convertedXml = convertXml("1.8.3", "1.10.0");
- Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) > 0);
- Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) > 0);
- }
-
- /**
- * @see {@link ConceptMapConverter#convert(Document,Version,Version,ConverterContext)}
- */
- @Test
- @Verifies(value = "should replace nothing if the to version is post one nine", method = "convert(Document,Version,Version,ConverterContext)")
- public void convert_shouldReplaceNothingIfTheToVersionIsPostOneNine() throws Exception {
- String convertedXml = convertXml("1.9.0", "1.9.1");
- Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) < 0);
- Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
- }
-
- private static String convertXml(String formVersion, String toVersion) throws Exception {
- new ConceptMapConverter().convert(document, new Version(formVersion), new Version(toVersion),
- new BaseConverter.ConverterContext());
-
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
- StringWriter stringWriter = new StringWriter();
- transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
- return stringWriter.toString();
- }
+
+ private static final String TEXT_CONCEPT_MAP_XML_FILE = "testConceptMapXmlFile.xml";
+
+ private static Document document;
+
+ private static String originalXml;
+
+ private static final String CONCEPT_MAP_TYPE = "conceptMapType";
+
+ private static final String CONCEPT_REFERENCE_TERM = "conceptReferenceTerm";
+
+ @Before
+ public void before() throws Exception {
+ File file = new File(ClassLoader.getSystemResource(TEXT_CONCEPT_MAP_XML_FILE).getPath());
+ originalXml = FileUtils.readFileToString(file, "UTF-8");
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+ .parse(ClassLoader.getSystemResourceAsStream(TEXT_CONCEPT_MAP_XML_FILE));
+ }
+
+ /**
+ * @see ConceptMapConverter#convert(Document,Version,Version,ConverterContext)
+ */
+ @Test
+ @Verifies(value = "should replace source if the from version is pre one nine", method = "convert(Document,Version,Version,ConverterContext)")
+ public void convert_shouldReplaceSourceIfTheFromVersionIsPreOneNine() throws Exception {
+ Assert.assertTrue(originalXml.indexOf(CONCEPT_MAP_TYPE) < 0);
+ Assert.assertTrue(originalXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
+ String convertedXml = convertXml("1.8.3", "1.10.0");
+ Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) > 0);
+ Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) > 0);
+ }
+
+ /**
+ * @see ConceptMapConverter#convert(Document,Version,Version,ConverterContext)
+ */
+ @Test
+ @Verifies(value = "should replace nothing if the to version is post one nine", method = "convert(Document,Version,Version,ConverterContext)")
+ public void convert_shouldReplaceNothingIfTheToVersionIsPostOneNine() throws Exception {
+ String convertedXml = convertXml("1.9.0", "1.9.1");
+ Assert.assertTrue(convertedXml.indexOf(CONCEPT_MAP_TYPE) < 0);
+ Assert.assertTrue(convertedXml.indexOf(CONCEPT_REFERENCE_TERM) < 0);
+ }
+
+ private String convertXml(String formVersion, String toVersion) throws Exception {
+ new ConceptMapConverter().convert(document, new Version(formVersion), new Version(toVersion),
+ new BaseConverter.ConverterContext());
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ StringWriter stringWriter = new StringWriter();
+ transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
+ return stringWriter.toString();
+ }
+
+ @Test
+public void shouldConvertCollectionToArrayList() {
+ // Create a test collection
+ Collection testCollection = new ArrayList();
+ testCollection.add("item1");
+ testCollection.add("item2");
+
+ // Test conversion logic
+ Collection> convertedCollection = new ArrayList