Skip to content

Commit

Permalink
Added support for detecting endless synchronizations for DHIS2.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Dec 10, 2018
1 parent cf3955d commit 3b10c92
Show file tree
Hide file tree
Showing 106 changed files with 1,803 additions and 430 deletions.
4 changes: 2 additions & 2 deletions app/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

<configuration debug="false">
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %X{fhirId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %X{fhirId}%X{dhisId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
<property name="FILE_LOG_PATTERN"
value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %X{fhirId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %X{fhirId}%X{dhisId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />

<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity;
package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.trackedentity;

/*
* Copyright (c) 2004-2018, University of Oslo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity;
package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.trackedentity;

/*
* Copyright (c) 2004-2018, University of Oslo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.dhis2.fhir.adapter.model.Identifiable;

import javax.annotation.Nonnull;
import java.time.ZonedDateTime;

/**
* Base interface of DHIS2 Resources.
Expand All @@ -39,6 +40,22 @@
*/
public interface DhisResource extends Identifiable<String>
{
/**
* @return the unique ID of the DHIS 2 organization unit to which this resource belongs,
* or <code>null</code> if this resource does not belong to any DHIS 2 organization unit.
*/
String getOrgUnitId();

/**
* @return the unique ID of the resource (including the type of the resource).
*/
DhisResourceId getResourceId();

/**
* @return the timestamp when the resource has been updated the last time.
*/
ZonedDateTime getLastUpdated();

/**
* @return the concrete resource type of the resource.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import com.google.common.collect.ImmutableMap;
import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
import org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl;
import org.dhis2.fhir.adapter.dhis.sync.DhisResourceQueueItem;
import org.dhis2.fhir.adapter.dhis.sync.impl.DhisSyncConfig;
import org.dhis2.fhir.adapter.dhis.sync.impl.DhisSyncRequestQueueItem;
import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -40,6 +43,7 @@

import javax.annotation.Nonnull;
import javax.jms.ConnectionFactory;
import java.util.Map;

/**
* Configuration of queues that are used by the adapter.
Expand Down Expand Up @@ -117,4 +121,21 @@ protected JmsTemplate dhisResourceQueueJmsTemplate( @Nonnull ConnectionFactory c
jmsTemplate.setMessageConverter( jmsMessageConverter );
return jmsTemplate;
}

@Bean
@Nonnull
protected JmsJsonTypeIdMapping dhisJmsJsonTypeIdMapping()
{
return new JmsJsonTypeIdMapping()
{
@Nonnull
@Override
public Map<String, Class<?>> getTypeIdMappings()
{
return ImmutableMap.of(
"dhisSyncRequest", DhisSyncRequestQueueItem.class,
"dhisResource", DhisResourceQueueItem.class );
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.dhis2.fhir.adapter.dhis.queue;

/*
* Copyright (c) 2004-2018, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import javax.annotation.Nonnull;
import java.util.Map;

/**
* Returns mappings from a class to a type ID that will be stored in a JMS message
* instead of the full qualified class name.
*
* @author volsch
*/
public interface JmsJsonTypeIdMapping
{
@Nonnull
Map<String, Class<?>> getTypeIdMappings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

import javax.annotation.Nonnull;
import javax.jms.ConnectionFactory;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* General configuration of queues that are used by the adapter.
Expand All @@ -56,12 +59,16 @@ public class QueueConfig
@Primary
@Bean
@Nonnull
protected MessageConverter jacksonJmsMessageConverter( @Nonnull ObjectMapper objectMapper )
protected MessageConverter jacksonJmsMessageConverter( @Nonnull ObjectMapper objectMapper, @Nonnull Collection<JmsJsonTypeIdMapping> typeIdMappings )
{
final Map<String, Class<?>> resultingMappings = new HashMap<>();
typeIdMappings.forEach( tim -> resultingMappings.putAll( tim.getTypeIdMappings() ) );

final MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setObjectMapper( objectMapper );
converter.setTargetType( MessageType.TEXT );
converter.setTypeIdPropertyName( "_type" );
converter.setTypeIdMappings( resultingMappings );
return converter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
*/

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.data.model.ProcessedItemInfo;
import org.dhis2.fhir.adapter.data.model.UuidDataGroupId;
import org.dhis2.fhir.adapter.data.processor.DataItemQueueItem;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.UUID;

/**
* Processing request for a DHIS2 resource synchronization that is enqueued and dequeued.
Expand Down Expand Up @@ -70,15 +68,4 @@ public void setDataGroupId( UuidDataGroupId dataGroupId )
{
super.setDataGroupId( dataGroupId );
}

@JsonProperty
public UUID getRemoteSubscriptionResourceId()
{
return (getDataGroupId() == null) ? null : getDataGroupId().getId();
}

public void setRemoteSubscriptionResourceId( UUID remoteSubscriptionResourceId )
{
super.setDataGroupId( (remoteSubscriptionResourceId == null) ? null : new UuidDataGroupId( remoteSubscriptionResourceId ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.dhis2.fhir.adapter.dhis.sync;

/*
* Copyright (c) 2004-2018, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.dhis2.fhir.adapter.dhis.model.DhisResource;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceId;

import javax.annotation.Nonnull;
import java.util.Optional;

/**
* Utility methods to access DHIS resources.
*
* @author volsch
*/
public interface DhisResourceRepository
{
@Nonnull
Optional<? extends DhisResource> findRefreshed( @Nonnull DhisResourceId dhisResourceId );

@Nonnull
Optional<? extends DhisResource> find( @Nonnull DhisResourceId dhisResourceId );

@Nonnull
DhisResource save( @Nonnull DhisResource resource );
}
Loading

0 comments on commit 3b10c92

Please sign in to comment.