Skip to content

Commit

Permalink
SYNCT-294: Sync 2 - support of OpenMRS 1.x (#133)
Browse files Browse the repository at this point in the history
* SYNCT-294: Changed the JDK version to 1.7 and the version of OpenMRS platform to 1.9.10. Added support of new and old UI.

* SYNCT-294: Fixed issue with the objects serialization and fixed issue with the beans injection

* SYNCT-294: Fixed issue with AuditMessage resource

* SYNCT-294: Fixed issue with the page redirects

* SYNCT-294: Fixed issue with the person address conversion (sync fail when the address was empty)

* SYNCT-294: Changed supported OpenMRS versions in the audit message resource

* SYNCT-294: Fixed issue with the Audit Messages

* SYNCT-294: Fixed issue with the UI (UI crash when the wrong message UUID was set)

* SYNCT-294: Fixed issue with PersonResource in OpenMRS 1.11.3

* SYNCT-294: Fixed issue with the code indentation
  • Loading branch information
areklalo committed Jan 21, 2019
1 parent 51a662b commit 3d8b600
Show file tree
Hide file tree
Showing 71 changed files with 879 additions and 432 deletions.
29 changes: 29 additions & 0 deletions api-1.9/pom.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sync2</artifactId>
<groupId>org.openmrs.module</groupId>
<version>1.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sync2-api-1.9</artifactId>
<packaging>jar</packaging>
<name>Sync2 Module API 1.9</name>
<description>API project for Sync2 Module</description>

<properties>
<openmrsPlatformVersion>1.9.10</openmrsPlatformVersion>
</properties>

<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,16 @@
package org.openmrs.module.sync2.api19.helper;

import org.openmrs.activelist.Allergy;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.sync2.api.helper.AllergyHelper;
import org.springframework.stereotype.Component;

@Component(value = "sync2.AllergyHelper1_9")
@OpenmrsProfile(openmrsPlatformVersion = "1.9.* - 1.11.*")
public class AllergyHelperImpl1_9 implements AllergyHelper {

@Override
public Class getAllergyClass() {
return Allergy.class;
}
}
29 changes: 29 additions & 0 deletions api-2.0/pom.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sync2</artifactId>
<groupId>org.openmrs.module</groupId>
<version>1.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sync2-api-2.0</artifactId>
<packaging>jar</packaging>
<name>Sync2 Module API 1.9</name>
<description>API project for Sync2 Module</description>

<properties>
<openmrsPlatformVersion>2.0.5</openmrsPlatformVersion>
</properties>

<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,16 @@
package org.openmrs.module.sync2.api20.helper;

import org.openmrs.Allergy;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.sync2.api.helper.AllergyHelper;
import org.springframework.stereotype.Component;

@Component(value = "sync2.AllergyHelper2_0")
@OpenmrsProfile(openmrsPlatformVersion = "2.0.*")
public class AllergyHelperImpl2_0 implements AllergyHelper {

@Override
public Class getAllergyClass() {
return Allergy.class;
}
}
70 changes: 47 additions & 23 deletions api/pom.xml
Expand Up @@ -17,6 +17,12 @@
<artifactId>openmrs-web</artifactId>
<scope>provided</scope>
<version>${openmrsPlatformVersion}</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
Expand All @@ -30,40 +36,58 @@
<scope>provided</scope>
<version>${atomfeedVersion}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<type>jar</type>
<version>${jacksonVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<type>jar</type>
<version>${jacksonVersion}</version>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod</artifactId>
<version>${webservices.restVersion}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
<version>${webservices.restVersion}</version>
<classifier>tests</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
</project>
6 changes: 6 additions & 0 deletions api/src/main/java/org/openmrs/module/sync2/SyncConstants.java
Expand Up @@ -86,5 +86,11 @@ public class SyncConstants {

public static final String ATOMFEED_EVENT_HANDLER = "atomfeed";

public static final String SYNC_PUSH_SERVICE_BEAN = "sync2.syncPushService";

public static final String SYNC_PULL_SERVICE_BEAN = "sync2.syncPullService";

public static final String SYNC_CATEGORY_HELPER = "sync2.categoryHelper";

private SyncConstants() {}
}
Expand Up @@ -34,7 +34,7 @@ public MergeResult<SyncObject> resolveDiff(Class<? extends SyncObject> clazz, Sy

private MergeResult<SyncObject> resolveConflict(SyncObject source, SyncObject target) {
Class storedClass = SimpleObject.class;
MergeResult<SyncObject> result = new MergeConflict<>(storedClass, source.getSimpleObject(), target.getSimpleObject());
MergeResult result = new MergeConflict<>(storedClass, source.getSimpleObject(), target.getSimpleObject());
Map<String, Object> sourceAuditInfo = source.getSimpleObject().get(AUDIT_INFO_KEY);
String sourceDateChangedStr = sourceAuditInfo != null ? (String) sourceAuditInfo.get(DATE_CHANGED_KEY) : null;

Expand Down
Expand Up @@ -28,10 +28,10 @@ public MergeResult<SyncObject> resolveDiff(Class<? extends SyncObject> clazz, Sy

private MergeResult<SyncObject> revolveConflict(SyncObject source, SyncObject target) {
Class storedClass = SimpleObject.class;
MergeResult<SyncObject> result = new MergeConflict<>(storedClass, source.getSimpleObject(), target.getSimpleObject());
MergeResult result = new MergeConflict<>(storedClass, source.getSimpleObject(), target.getSimpleObject());
String sourceHashCode = SyncHashcodeUtils.getHashcode(source.getSimpleObject());
String targetHashCode = SyncHashcodeUtils.getHashcode(target.getSimpleObject());
String objectUuid = (source.getSimpleObject() != null ) ? source.getSimpleObject().get(UUID_KEY) : null;
String objectUuid = (source.getSimpleObject() != null ) ? (String) source.getSimpleObject().get(UUID_KEY) : null;
ParentObjectHashcode previousHashCode = parentObjectHashcodeService.getByObjectUuid(objectUuid);

if (StringUtils.isNotBlank(sourceHashCode) && StringUtils.isNotBlank(targetHashCode)) {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public Set<String> getAllCreatorIds() {
.add(Restrictions.isNotNull(SyncConstants.AUDIT_MESSAGE_CREATOR_INSTANCE_ID))
.setProjection(Projections.distinct(
Projections.property(SyncConstants.AUDIT_MESSAGE_CREATOR_INSTANCE_ID)));
return new HashSet<>(Collections.checkedList(selectCriteria.list(), String.class));
return new HashSet<String>(Collections.checkedList(selectCriteria.list(), String.class));
}

public Long getCountOfMessages() {
Expand Down
@@ -1,8 +1,8 @@
package org.openmrs.module.sync2.api.filter;

import org.openmrs.module.sync2.api.model.enums.CategoryEnum;
import org.openmrs.module.sync2.api.model.SyncCategory;

public interface FilterService {

boolean shouldBeSynced(CategoryEnum category, Object object, String action);
boolean shouldBeSynced(SyncCategory category, Object object, String action);
}
Expand Up @@ -3,7 +3,7 @@
import org.openmrs.module.sync2.api.filter.FilterConstant;
import org.openmrs.module.sync2.api.filter.FilterService;
import org.openmrs.module.sync2.api.filter.ObjectFilter;
import org.openmrs.module.sync2.api.model.enums.CategoryEnum;
import org.openmrs.module.sync2.api.model.SyncCategory;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +13,7 @@ public class PullFilterService implements FilterService {
private static final boolean DEFAULT_RESULT = true;

@Override
public boolean shouldBeSynced(CategoryEnum category, Object object, String action) {
public boolean shouldBeSynced(SyncCategory category, Object object, String action) {
ObjectFilter objectFilter = getFilter(category.getCategory());
if (objectFilter != null) {
return objectFilter.shouldObjectBeSynced(object, action);
Expand Down
Expand Up @@ -3,7 +3,7 @@
import org.openmrs.module.sync2.api.filter.FilterConstant;
import org.openmrs.module.sync2.api.filter.FilterService;
import org.openmrs.module.sync2.api.filter.ObjectFilter;
import org.openmrs.module.sync2.api.model.enums.CategoryEnum;
import org.openmrs.module.sync2.api.model.SyncCategory;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +13,7 @@ public class PushFilterService implements FilterService {
private static final boolean DEFAULT_RESULT = true;

@Override
public boolean shouldBeSynced(CategoryEnum category, Object object, String action) {
public boolean shouldBeSynced(SyncCategory category, Object object, String action) {
ObjectFilter objectFilter = getFilter(category.getCategory());
if (objectFilter != null) {
return objectFilter.shouldObjectBeSynced(object, action);
Expand Down
@@ -0,0 +1,6 @@
package org.openmrs.module.sync2.api.helper;

public interface AllergyHelper {

Class getAllergyClass();
}
@@ -0,0 +1,8 @@
package org.openmrs.module.sync2.api.helper;

import org.openmrs.module.sync2.api.model.SyncCategory;

public interface CategoryHelper {

SyncCategory getByCategory(String category);
}
@@ -0,0 +1,38 @@
package org.openmrs.module.sync2.api.helper.impl;

import org.openmrs.module.fhir.api.util.FHIRConstants;
import org.openmrs.module.sync2.SyncConstants;
import org.openmrs.module.sync2.api.helper.CategoryHelper;
import org.openmrs.module.sync2.api.model.SyncCategory;
import org.openmrs.module.sync2.api.model.enums.CategoryEnum;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.springframework.stereotype.Component;

@Component(value = SyncConstants.SYNC_CATEGORY_HELPER)
public class CategoryHelperImpl implements CategoryHelper {

@Override
public SyncCategory getByCategory(String category) {
SyncCategory syncCategory = null;
if (category.equalsIgnoreCase(FHIRConstants.CATEGORY_ALLERGY)) {
syncCategory = buildSyncCategoryObject(category, ContextUtils.getAllergyHelper().getAllergyClass());
} else {
syncCategory = buildSyncCategoryObject(CategoryEnum.getByCategory(category));
}
if (syncCategory == null) {
throw new UnsupportedOperationException(String.format("Category %s is not supported", category));
}
return syncCategory;
}

private SyncCategory buildSyncCategoryObject(CategoryEnum categoryEnum) {
if (categoryEnum == null) {
return null;
}
return buildSyncCategoryObject(categoryEnum.getCategory(), categoryEnum.getClazz());
}

private SyncCategory buildSyncCategoryObject(String category, Class clazz) {
return new SyncCategory(category, clazz);
}
}
@@ -1,15 +1,21 @@
package org.openmrs.module.sync2.api.mapper.impl;

import org.openmrs.api.context.Context;
import org.openmrs.module.sync2.api.mapper.MergeConflictMapper;
import org.openmrs.module.sync2.api.model.MergeConflict;
import org.openmrs.module.sync2.api.utils.SimpleObjectSerializationUtils;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.serialization.SerializationException;
import org.openmrs.serialization.SimpleXStreamSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.SerializationUtils;

@Component("sync.mergeConflictMapper")
public class MergeConflictMapperImpl implements MergeConflictMapper {

private static final Logger LOGGER = LoggerFactory.getLogger(MergeConflictMapperImpl.class);

public MergeConflict map(org.openmrs.module.fhir.api.merge.MergeConflict mergeConflictDto) {
MergeConflict mergeConflict = new MergeConflict();
mergeConflict.setMessage(mergeConflictDto.getMessage().getValue());
Expand All @@ -21,8 +27,14 @@ public MergeConflict map(org.openmrs.module.fhir.api.merge.MergeConflict mergeCo
mergeConflict.setOrgForeign(SimpleObjectSerializationUtils.serialize(
(SimpleObject) mergeConflictDto.getOrgForeign()).getBytes());
} else {
mergeConflict.setOrgLocal(SerializationUtils.serialize(mergeConflictDto.getOrgLocal()));
mergeConflict.setOrgForeign(SerializationUtils.serialize(mergeConflictDto.getOrgForeign()));
try {
mergeConflict.setOrgForeign(Context.getSerializationService().serialize(mergeConflictDto.getOrgForeign(),
SimpleXStreamSerializer.class).getBytes());
mergeConflict.setOrgLocal(Context.getSerializationService().serialize(mergeConflictDto.getOrgLocal(),
SimpleXStreamSerializer.class).getBytes());
} catch (SerializationException e) {
LOGGER.error("Serialization error has occurred", e.getMessage());
}
}
return mergeConflict;
}
Expand All @@ -38,13 +50,16 @@ public org.openmrs.module.fhir.api.merge.MergeConflict map(MergeConflict mergeCo
local = SimpleObjectSerializationUtils.deserialize(new String(mergeConflict.getOrgLocal()));
foreign = SimpleObjectSerializationUtils.deserialize(new String(mergeConflict.getOrgForeign()));
} else {
local = SerializationUtils.deserialize(mergeConflict.getOrgLocal());
foreign = SerializationUtils.deserialize(mergeConflict.getOrgForeign());
local = Context.getSerializationService().deserialize(new String(mergeConflict.getOrgLocal()),
objectsClass, SimpleXStreamSerializer.class);
foreign = Context.getSerializationService().deserialize(new String(mergeConflict.getOrgForeign()),
objectsClass, SimpleXStreamSerializer.class);
}
mergeConflictDto = new org.openmrs.module.fhir.api.merge.MergeConflict(objectsClass, local, foreign);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
LOGGER.error("Not found {} class during mapping the MergeConflict.", mergeConflict.getFullClassName());
} catch (SerializationException e) {
LOGGER.error("Serialization error has occurred.", e.getMessage());
}
return mergeConflictDto;
}
Expand Down

0 comments on commit 3d8b600

Please sign in to comment.