Skip to content

Commit

Permalink
Prepares transformer classes split for easier handling of metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Jul 23, 2019
1 parent 14e638b commit 8fb32c8
Show file tree
Hide file tree
Showing 69 changed files with 1,768 additions and 671 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dhis2.fhir.adapter.dhis.config;

/*
* Copyright (c) 2004-2018, University of Oslo
* Copyright (c) 2004-2019, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -28,11 +28,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.apache.commons.lang3.StringUtils;
import org.dhis2.fhir.adapter.cache.AbstractSimpleCacheConfig;
import org.dhis2.fhir.adapter.cache.RequestCacheService;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.AbstractCacheResolver;
import org.springframework.cache.interceptor.CacheOperationInvocationContext;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand All @@ -42,6 +47,8 @@
import org.springframework.validation.annotation.Validated;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;

/**
* Cache configuration for FHIR Resources.
Expand Down Expand Up @@ -70,4 +77,27 @@ protected CacheManager dhisCacheManager( @Nonnull RequestCacheService requestCac
{
return createCacheManager( requestCacheService, redisConnectionFactoryProvider, redisSerializer );
}

@Nonnull
@Bean
protected CacheResolver dhisMetadataCacheResolver( @Nonnull @Qualifier( "dhisCacheManager" ) CacheManager cacheManager )
{
return new AbstractCacheResolver( cacheManager )
{
@Override
protected Collection<String> getCacheNames( @Nonnull CacheOperationInvocationContext<?> context )
{
String name = context.getTarget().getClass().getSimpleName();

final int index = name.indexOf( "Service" );

if ( index > 0 )
{
name = name.substring( 0, index );
}

return Collections.singletonList( StringUtils.uncapitalize( name ) );
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
import java.util.Set;

/**
* Abstract implementation of {@link DhisType}.
* Abstract implementation of {@link DhisMetadata}.
*
* @author volsch
*/
public abstract class AbstractDhisType implements DhisType, Serializable
public abstract class AbstractDhisMetadata implements DhisMetadata, Serializable
{
private static final long serialVersionUID = 7960220674294587120L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author volsch
*/
@Scriptable
public interface DataElement extends DhisType
public interface DataElement extends DhisMetadata
{
String getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
import java.util.Set;

/**
* Implemented by DHIS 2 types.
* Implemented by DHIS 2 metadata.
*
* @author volsch
*/
public interface DhisType extends Identifiable<String>
public interface DhisMetadata extends Identifiable<String>
{
/**
* @return the unique code of the type or <code>null</code> if the type has no code.
* @return the unique code of the metadata or <code>null</code> if the type has no code.
*/
String getCode();

/**
* @return the unique name of the type.
* @return the unique name of the metadata.
*/
String getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @author volsch
*/
public class WritableDataElement extends AbstractDhisType implements DataElement, Serializable
public class WritableDataElement extends AbstractDhisMetadata implements DataElement, Serializable
{
private static final long serialVersionUID = -3933887626350878763L;

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

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dhis2.fhir.adapter.dhis.model.AbstractDhisMetadata;
import org.dhis2.fhir.adapter.dhis.model.DhisMetadata;
import org.dhis2.fhir.adapter.dhis.model.DhisResource;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceId;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceType;
Expand All @@ -43,7 +45,7 @@
*
* @author volsch
*/
public class OrganizationUnit implements DhisResource, Serializable
public class OrganizationUnit extends AbstractDhisMetadata implements DhisResource, DhisMetadata, Serializable
{
private static final long serialVersionUID = 3976508569865955265L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.dhis2.fhir.adapter.data.model.ProcessedItemInfo;
import org.dhis2.fhir.adapter.dhis.metadata.model.DhisSyncGroup;
import org.dhis2.fhir.adapter.dhis.model.DhisResourceResult;
import org.dhis2.fhir.adapter.dhis.model.Reference;
import org.dhis2.fhir.adapter.dhis.model.UriFilterApplier;

import javax.annotation.Nonnull;
import java.time.Instant;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import org.dhis2.fhir.adapter.dhis.service.DhisMetadataService;

/**
* Service that provides access to DHIS2 organization unit metadata.
*
* @author volsch
*/
public interface OrganizationUnitService
public interface OrganizationUnitService extends DhisMetadataService<OrganizationUnit>
{
@Nonnull
Optional<OrganizationUnit> findMetadataByReference( @Nonnull Reference reference );

@Nonnull
Optional<OrganizationUnit> findMetadataRefreshedByReference( @Nonnull Reference reference );

@Nonnull
Optional<OrganizationUnit> findOneByReference( @Nonnull Reference reference );

@Nonnull
DhisResourceResult<OrganizationUnit> find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max );

@Nonnull
Instant poll( @Nonnull DhisSyncGroup group, @Nonnull Instant lastUpdated, int toleranceMillis,
int maxSearchCount, @Nonnull Set<String> excludedStoredBy, @Nonnull Consumer<Collection<ProcessedItemInfo>> consumer );
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,29 @@
*/

import com.fasterxml.jackson.annotation.JsonProperty;
import org.dhis2.fhir.adapter.dhis.model.Pager;
import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnit;
import org.dhis2.fhir.adapter.dhis.service.impl.DhisMetadataItems;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* Container object used for DHIS2 organization units.
*
* @author volsch
*/
public class DhisOrganizationUnits implements Serializable
public class DhisOrganizationUnits extends DhisMetadataItems<OrganizationUnit> implements Serializable
{
private static final long serialVersionUID = -671810199580040339L;

private Pager pager;

@JsonProperty( "organisationUnits" )
private List<OrganizationUnit> organizationUnits;

public Pager getPager()
{
return pager;
}

public void setPager( Pager pager )
{
this.pager = pager;
}

@Nonnull
public List<OrganizationUnit> getOrganizationUnits()
{
if ( organizationUnits == null )
{
organizationUnits = new ArrayList<>();
}
return organizationUnits;
return getItems();
}

public void setOrganizationUnits( List<OrganizationUnit> organizationUnits )
{
this.organizationUnits = organizationUnits;
setItems( organizationUnits );
}
}
Loading

0 comments on commit 8fb32c8

Please sign in to comment.