diff --git a/common/src/main/java/org/dhis2/fhir/adapter/jackson/PersistentBagConverter.java b/common/src/main/java/org/dhis2/fhir/adapter/jackson/PersistentBagConverter.java new file mode 100644 index 00000000..2c737098 --- /dev/null +++ b/common/src/main/java/org/dhis2/fhir/adapter/jackson/PersistentBagConverter.java @@ -0,0 +1,68 @@ +package org.dhis2.fhir.adapter.jackson; + +/* + * 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 com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.databind.util.Converter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Converts lists (especially persistent bag) to a list. + * This is required when class name is serialized and used sorted set class + * cannot be instantiated otherwise. + * + * @author volsch + */ +public class PersistentBagConverter implements Converter, List> +{ + @Override + public List convert( List value ) + { + if ( value == null ) + { + return null; + } + return new ArrayList<>( value ); + } + + @Override + public JavaType getInputType( TypeFactory typeFactory ) + { + return typeFactory.constructCollectionType( List.class, Object.class ); + } + + @Override + public JavaType getOutputType( TypeFactory typeFactory ) + { + return typeFactory.constructCollectionType( ArrayList.class, Object.class ); + } +} diff --git a/common/src/main/java/org/dhis2/fhir/adapter/jackson/TypedPersistentSortedSetConverter.java b/common/src/main/java/org/dhis2/fhir/adapter/jackson/TypedPersistentSortedSetConverter.java new file mode 100644 index 00000000..8533f12e --- /dev/null +++ b/common/src/main/java/org/dhis2/fhir/adapter/jackson/TypedPersistentSortedSetConverter.java @@ -0,0 +1,77 @@ +package org.dhis2.fhir.adapter.jackson; + +/* + * 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 com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.databind.util.Converter; + +import javax.annotation.Nonnull; +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * Converts sorted sets (especially persistent sorted set) to a tree set. + * This is required when class name is serialized and used sorted set class + * cannot be instantiated otherwise. + * + * @param the concrete type of the item class. + * @author volsch + */ +public class TypedPersistentSortedSetConverter implements Converter, TreeSet> +{ + private final Class itemClass; + + public TypedPersistentSortedSetConverter( @Nonnull Class itemClass ) + { + this.itemClass = itemClass; + } + + @Override + public TreeSet convert( SortedSet value ) + { + if ( value == null ) + { + return null; + } + return new TreeSet<>( value ); + } + + @Override + public JavaType getInputType( TypeFactory typeFactory ) + { + return typeFactory.constructCollectionType( SortedSet.class, itemClass ); + } + + @Override + public JavaType getOutputType( TypeFactory typeFactory ) + { + return typeFactory.constructCollectionType( TreeSet.class, itemClass ); + } +} diff --git a/common/src/main/java/org/dhis2/fhir/adapter/rest/RestBadRequestException.java b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestBadRequestException.java new file mode 100644 index 00000000..0f749a7b --- /dev/null +++ b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestBadRequestException.java @@ -0,0 +1,71 @@ +package org.dhis2.fhir.adapter.rest; + +/* + * 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.springframework.http.HttpStatus; + +import javax.annotation.Nonnull; + +/** + * Thrown if the request cannot be handled because the input data is invalid. + * The exception contains status code 400 that should be returned to a client. + * + * @author volsch + */ +public class RestBadRequestException extends RestResponseEntityException +{ + private static final long serialVersionUID = -7487909336857881610L; + + public RestBadRequestException() + { + super(); + } + + public RestBadRequestException( String message ) + { + super( message ); + } + + public RestBadRequestException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RestBadRequestException( Throwable cause ) + { + super( cause ); + } + + @Nonnull + @Override + public HttpStatus getHttpStatus() + { + return HttpStatus.BAD_REQUEST; + } +} diff --git a/common/src/main/java/org/dhis2/fhir/adapter/rest/RestError.java b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestError.java new file mode 100644 index 00000000..9427d960 --- /dev/null +++ b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestError.java @@ -0,0 +1,59 @@ +package org.dhis2.fhir.adapter.rest; + +/* + * 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 com.fasterxml.jackson.annotation.JsonProperty; +import reactor.util.annotation.NonNull; + +import javax.annotation.Nonnull; +import java.io.Serializable; + +/** + * Error message that is serialized to the client in case of an error. + * + * @author volsch + */ +public class RestError implements Serializable +{ + private static final long serialVersionUID = 1604874907010817024L; + + private final String message; + + public RestError( @Nonnull String message ) + { + this.message = message; + } + + @JsonProperty + @NonNull + public String getMessage() + { + return message; + } +} diff --git a/common/src/main/java/org/dhis2/fhir/adapter/rest/RestExceptionHandler.java b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestExceptionHandler.java index 92275e5c..bfcd027c 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/rest/RestExceptionHandler.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/rest/RestExceptionHandler.java @@ -46,8 +46,8 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler( value = { RestResponseEntityException.class } ) @ResponseBody - public ResponseEntity handleResponseEntityException( RestResponseEntityException e, WebRequest request ) + public ResponseEntity handleResponseEntityException( RestResponseEntityException e, WebRequest request ) { - return new ResponseEntity<>( e.getMessage(), e.getHttpStatus() ); + return new ResponseEntity<>( new RestError( e.getMessage() ), e.getHttpStatus() ); } } diff --git a/common/src/test/java/org/dhis2/fhir/adapter/rest/RestExceptionHandlerTest.java b/common/src/test/java/org/dhis2/fhir/adapter/rest/RestExceptionHandlerTest.java index 8d538fda..1bf81d89 100644 --- a/common/src/test/java/org/dhis2/fhir/adapter/rest/RestExceptionHandlerTest.java +++ b/common/src/test/java/org/dhis2/fhir/adapter/rest/RestExceptionHandlerTest.java @@ -55,8 +55,9 @@ public class RestExceptionHandlerTest @Test public void test() { - final ResponseEntity entity = restExceptionHandler.handleResponseEntityException( new RestResourceNotFoundException( "This is a test." ), webRequest ); + final ResponseEntity entity = restExceptionHandler.handleResponseEntityException( new RestResourceNotFoundException( "This is a test." ), webRequest ); Assert.assertEquals( HttpStatus.NOT_FOUND, entity.getStatusCode() ); - Assert.assertEquals( "This is a test.", entity.getBody() ); + Assert.assertNotNull( entity.getBody() ); + Assert.assertEquals( "This is a test.", entity.getBody().getMessage() ); } } \ No newline at end of file diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/Reference.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/Reference.java index 7fa65d49..009d32bf 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/Reference.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/Reference.java @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import javax.annotation.Nonnull; import java.io.Serializable; import java.util.Objects; @@ -57,7 +60,8 @@ public static Reference createIdReference( @Nonnull String name ) * @param name the code or name to which the reference refers to. * @param type the type of the reference (either a reference by code or by name). */ - public Reference( @Nonnull String name, @Nonnull ReferenceType type ) + @JsonCreator + public Reference( @Nonnull @JsonProperty( "value" ) String name, @Nonnull @JsonProperty( "type" ) ReferenceType type ) { this.value = name; this.type = type; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java index 8d1aff28..b014d355 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/AbstractRule.java @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import javax.annotation.Nonnull; @@ -60,7 +63,12 @@ "WHERE r.fhirResourceType=:fhirResourceType AND r.applicableCodeSet IS NULL AND r.enabled=true" ), @NamedQuery( name = AbstractRule.FIND_RULES_BY_TYPE_CODES_NAMED_QUERY, query = "SELECT r FROM AbstractRule r JOIN r.applicableCodeSet acs JOIN acs.codeSetValues csv ON csv.enabled=true JOIN csv.id.code c " + "JOIN c.systemCodes sc ON sc.systemCode=:code JOIN sc.system s ON s.systemUri=:system AND s.enabled=true WHERE r.fhirResourceType=:fhirResourceType AND r.enabled=true" ) } ) -public abstract class AbstractRule extends BaseMetadata implements Serializable, Comparable +@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "dhisResourceType" ) +@JsonSubTypes( { + @JsonSubTypes.Type( value = TrackedEntityRule.class, name = "TRACKED_ENTITY" ), + @JsonSubTypes.Type( value = ProgramStageRule.class, name = "PROGRAM_STAGE_EVENT" ) +} ) +public abstract class AbstractRule extends VersionedBaseMetadata implements Serializable, Comparable { private static final long serialVersionUID = 3426378271314934021L; @@ -68,6 +76,8 @@ public abstract class AbstractRule extends BaseMetadata implements Serializable, public static final String FIND_RULES_BY_TYPE_CODES_NAMED_QUERY = "findRulesByTypeAndCodes"; + public static final int MAX_NAME_LENGTH = 230; + private String name; private String description; private boolean enabled; @@ -78,6 +88,16 @@ public abstract class AbstractRule extends BaseMetadata implements Serializable, private CodeSet applicableCodeSet; private ExecutableScript transformInScript; + protected AbstractRule() + { + super(); + } + + protected AbstractRule( @Nonnull DhisResourceType dhisResourceType ) + { + this.dhisResourceType = dhisResourceType; + } + @Basic @Column( name = "name", nullable = false, length = 230 ) public String getName() @@ -140,8 +160,9 @@ public void setFhirResourceType( FhirResourceType fhirResourceType ) } @Basic - @Column( name = "dhis_resource_type", nullable = false, length = 30 ) + @Column( name = "dhis_resource_type", nullable = false, updatable = false, length = 30 ) @Enumerated( EnumType.STRING ) + @JsonProperty( access = JsonProperty.Access.READ_ONLY ) public DhisResourceType getDhisResourceType() { return dhisResourceType; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java index c4c97271..c0c43e9e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Code.java @@ -28,6 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; + import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -52,10 +54,14 @@ */ @Entity @Table( name = "fhir_code" ) -public class Code extends BaseMetadata implements Serializable +public class Code extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 6376382638316116368L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 50; + private String name; private String code; private String description; @@ -98,7 +104,7 @@ public void setDescription( String description ) this.description = description; } - @ManyToOne + @ManyToOne( optional = false ) @JoinColumn( name = "code_category_id", referencedColumnName = "id", nullable = false ) public CodeCategory getCodeCategory() { @@ -112,6 +118,7 @@ public void setCodeCategory( CodeCategory codeCategory ) @OneToMany( mappedBy = "code" ) @OrderBy( "id" ) + @JsonIgnore public List getSystemCodes() { return systemCodes; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java index c7afc92f..d2d69629 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeCategory.java @@ -41,10 +41,14 @@ */ @Entity @Table( name = "fhir_code_category" ) -public class CodeCategory extends BaseMetadata implements Serializable +public class CodeCategory extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 2265589184934267879L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 50; + private String name; private String code; private String description; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java index c7fdf01e..7351c388 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSet.java @@ -28,101 +28,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.dhis2.fhir.adapter.jackson.PersistentSortedSetConverter; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Version; import java.io.Serializable; -import java.time.ZonedDateTime; import java.util.Objects; import java.util.SortedSet; -import java.util.UUID; @Entity @Table( name = "fhir_code_set" ) -public class CodeSet implements Serializable +public class CodeSet extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 1177970691904984600L; - private UUID id; - private Long version; - private ZonedDateTime createdAt; - private String lastUpdatedBy; - private ZonedDateTime lastUpdatedAt; private CodeCategory codeCategory; private String name; private String code; private String description; private SortedSet codeSetValues; - @Id - @Column( name = "id", nullable = false ) - public UUID getId() - { - return id; - } - - public void setId( UUID id ) - { - this.id = id; - } - - @Version - @Column( name = "version", nullable = false ) - public Long getVersion() - { - return version; - } - - public void setVersion( Long version ) - { - this.version = version; - } - - @Basic - @Column( name = "created_at", nullable = false ) - public ZonedDateTime getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( ZonedDateTime createdAt ) - { - this.createdAt = createdAt; - } - - @Basic - @Column( name = "last_updated_by", length = 11 ) - @JsonInclude( JsonInclude.Include.NON_NULL ) - public String getLastUpdatedBy() - { - return lastUpdatedBy; - } - - public void setLastUpdatedBy( String lastUpdatedBy ) - { - this.lastUpdatedBy = lastUpdatedBy; - } - - @Basic - @Column( name = "last_updated_at", nullable = false ) - public ZonedDateTime getLastUpdatedAt() - { - return lastUpdatedAt; - } - - public void setLastUpdatedAt( ZonedDateTime lastUpdatedAt ) - { - this.lastUpdatedAt = lastUpdatedAt; - } - @Basic @Column( name = "name", nullable = false, length = 230 ) public String getName() @@ -162,6 +93,7 @@ public void setDescription( String description ) @SuppressWarnings( "JpaAttributeTypeInspection" ) @OneToMany( orphanRemoval = true, mappedBy = "id.codeSet", cascade = CascadeType.ALL ) @OrderBy( "id.codeSet.id,id.code.id" ) + @JsonSerialize( converter = PersistentSortedSetConverter.class ) public SortedSet getCodeSetValues() { return codeSetValues; @@ -169,6 +101,11 @@ public SortedSet getCodeSetValues() public void setCodeSetValues( SortedSet codeSetValues ) { + if ( codeSetValues != null ) + { + codeSetValues.stream().filter( csv -> (csv.getCodeSet() == null) ) + .forEach( csv -> csv.setCodeSet( this ) ); + } this.codeSetValues = codeSetValues; } @@ -179,13 +116,13 @@ public boolean equals( Object o ) if ( o == null || getClass() != o.getClass() ) return false; CodeSet that = (CodeSet) o; return - Objects.equals( id, that.id ) && + Objects.equals( getId(), that.getId() ) && Objects.equals( name, that.name ); } @Override public int hashCode() { - return Objects.hash( id, name ); + return Objects.hash( getId(), name ); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValue.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValue.java index 646f1b0c..0cdf0213 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValue.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValue.java @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirAdapterMetadata; + import javax.annotation.Nonnull; import javax.persistence.Column; import javax.persistence.EmbeddedId; @@ -39,7 +42,7 @@ @Entity @Table( name = "fhir_code_set_value" ) -public class CodeSetValue implements Serializable, Comparable +public class CodeSetValue implements Serializable, Comparable, FhirAdapterMetadata { private static final long serialVersionUID = 8365594386802303061L; @@ -69,6 +72,7 @@ public void setId( CodeSetValueId id ) this.id = id; } + @JsonIgnore @Transient public CodeSet getCodeSet() { @@ -84,6 +88,7 @@ public void setCodeSet( CodeSet codeSet ) id.setCodeSet( codeSet ); } + @JsonIgnore @Transient public Code getCode() { @@ -117,7 +122,8 @@ public int hashCode() @Override public int compareTo( @Nonnull CodeSetValue o ) { - int value = getCodeSet().getId().compareTo( o.getCodeSet().getId() ); + int value = ((getCodeSet() == null) && (o.getCodeSet() == null)) ? 0 : + getCodeSet().getId().compareTo( o.getCodeSet().getId() ); if ( value != 0 ) { return value; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValueId.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValueId.java index b80e2955..560e3f7c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValueId.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/CodeSetValueId.java @@ -28,6 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; + import javax.persistence.Embeddable; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -44,6 +46,7 @@ public class CodeSetValueId implements Serializable @ManyToOne( optional = false ) @JoinColumn( name = "code_set_id", nullable = false ) + @JsonIgnore public CodeSet getCodeSet() { return codeSet; @@ -80,4 +83,10 @@ public int hashCode() { return Objects.hash( codeSet, code ); } + + @Override + public String toString() + { + return "[" + "codeSetId=" + ((codeSet == null) ? "" : codeSet.getId()) + ", codeId=" + ((code == null) ? "" : code.getId()) + ']'; + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Constant.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Constant.java index 406db024..5feb48e6 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Constant.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Constant.java @@ -44,10 +44,16 @@ */ @Entity @Table( name = "fhir_constant" ) -public class Constant extends BaseMetadata implements Serializable +public class Constant extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -4219974054617859678L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 50; + + public static final int MAX_VALUE_LENGTH = 250; + private String name; private String description; private ConstantCategory category; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScript.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScript.java index 744f5974..665a391e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScript.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScript.java @@ -28,15 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.hibernate.annotations.GenericGenerator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.dhis2.fhir.adapter.jackson.PersistentBagConverter; +import org.springframework.data.rest.core.annotation.RestResource; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -54,10 +55,14 @@ */ @Entity @Table( name = "fhir_executable_script" ) -public class ExecutableScript implements Serializable +public class ExecutableScript extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -2006842064596779970L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 100; + private UUID id; private Script script; private String name; @@ -65,22 +70,9 @@ public class ExecutableScript implements Serializable private String description; private List overrideArguments; - @GeneratedValue( generator = "uuid2" ) - @GenericGenerator( name = "uuid2", strategy = "uuid2" ) - @Id - @Column( name = "id", nullable = false ) - public UUID getId() - { - return id; - } - - public void setId( UUID id ) - { - this.id = id; - } - @ManyToOne @JoinColumn( name = "script_id", referencedColumnName = "id", nullable = false ) + @JsonIgnore public Script getScript() { return script; @@ -129,6 +121,8 @@ public void setDescription( String description ) @OneToMany( mappedBy = "script", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER ) @OrderBy( "id" ) + @RestResource + @JsonSerialize( converter = PersistentBagConverter.class ) public List getOverrideArguments() { return overrideArguments; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptArg.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptArg.java index 13d66a96..bcce9142 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptArg.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptArg.java @@ -28,13 +28,20 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirAdapterMetadata; +import org.hibernate.annotations.GenericGenerator; + import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import java.io.Serializable; +import java.util.UUID; /** * The arguments of an {@linkplain ExecutableScript executable script}. All arguments of the underlying @@ -44,15 +51,31 @@ */ @Entity @Table( name = "fhir_executable_script_argument" ) -public class ExecutableScriptArg extends BaseMetadata implements Serializable +public class ExecutableScriptArg implements Serializable, FhirAdapterMetadata { private static final long serialVersionUID = 487628755797899218L; + private UUID id; private String overrideValue; private ExecutableScript script; private ScriptArg argument; private boolean enabled; + @Override + @GeneratedValue( generator = "uuid2" ) + @GenericGenerator( name = "uuid2", strategy = "uuid2" ) + @Id + @Column( name = "id", nullable = false ) + public UUID getId() + { + return id; + } + + public void setId( UUID id ) + { + this.id = id; + } + @Basic @Column( name = "override_value", length = 230 ) public String getOverrideValue() @@ -67,6 +90,7 @@ public void setOverrideValue( String overrideValue ) @ManyToOne @JoinColumn( name = "executable_script_id", referencedColumnName = "id", nullable = false ) + @JsonIgnore public ExecutableScript getScript() { return script; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptInfo.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptInfo.java new file mode 100644 index 00000000..d918b142 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ExecutableScriptInfo.java @@ -0,0 +1,76 @@ +package org.dhis2.fhir.adapter.fhir.metadata.model; + +/* + * 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 com.fasterxml.jackson.annotation.JsonProperty; +import reactor.util.annotation.NonNull; + +import javax.annotation.Nonnull; +import java.io.Serializable; + +/** + * The executable script prepared to be processed by a script executor. + * + * @author volsch + */ +public class ExecutableScriptInfo implements Serializable +{ + private static final long serialVersionUID = 7675659610124741889L; + + private final ExecutableScript executableScript; + + private final Script script; + + private final ScriptSource scriptSource; + + public ExecutableScriptInfo( @JsonProperty( "executableScript" ) @NonNull ExecutableScript executableScript, @JsonProperty( "script" ) @Nonnull Script script, @JsonProperty( "scriptSource" ) @Nonnull ScriptSource scriptSource ) + { + this.executableScript = executableScript; + this.script = script; + this.scriptSource = scriptSource; + } + + @Nonnull + public ExecutableScript getExecutableScript() + { + return executableScript; + } + + @Nonnull + public Script getScript() + { + return script; + } + + @Nonnull + public ScriptSource getScriptSource() + { + return scriptSource; + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirResourceMapping.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirResourceMapping.java index 4b200ca8..b70abb1a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirResourceMapping.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirResourceMapping.java @@ -46,7 +46,7 @@ @Entity @Table( name = "fhir_resource_mapping" ) -public class FhirResourceMapping extends BaseMetadata implements Serializable +public class FhirResourceMapping extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 7669881610498151697L; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgram.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgram.java index 83656a7f..f2f30f67 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgram.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgram.java @@ -47,7 +47,7 @@ */ @Entity @Table( name = "fhir_tracker_program" ) -public class MappedTrackerProgram extends BaseMetadata implements Serializable +public class MappedTrackerProgram extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -2784006479143123933L; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgramStage.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgramStage.java index a3774275..f4e22e88 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgramStage.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/MappedTrackerProgramStage.java @@ -28,11 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.annotation.JsonInclude; import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.dhis.model.ReferenceAttributeConverter; import org.dhis2.fhir.adapter.dhis.tracker.program.EventStatus; -import org.hibernate.annotations.GenericGenerator; import javax.persistence.Basic; import javax.persistence.Column; @@ -40,27 +38,17 @@ import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Version; import java.io.Serializable; -import java.sql.Timestamp; -import java.util.UUID; @Entity @Table( name = "fhir_tracker_program_stage" ) -public class MappedTrackerProgramStage implements Serializable +public class MappedTrackerProgramStage extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 7561285892767275117L; - private UUID id; - private Long version; - private Timestamp createdAt; - private String lastUpdatedBy; - private Timestamp lastUpdatedAt; private String name; private String description; private Reference programStageReference; @@ -78,69 +66,6 @@ public class MappedTrackerProgramStage implements Serializable private EventPeriodDayType afterPeriodDayType; private int afterPeriodDays; - @GeneratedValue( generator = "uuid2" ) - @GenericGenerator( name = "uuid2", strategy = "uuid2" ) - @Id - @Column( name = "id", nullable = false ) - public UUID getId() - { - return id; - } - - public void setId( UUID id ) - { - this.id = id; - } - - @Column( name = "version", nullable = false ) - @Version - public Long getVersion() - { - return version; - } - - public void setVersion( Long version ) - { - this.version = version; - } - - @Basic - @Column( name = "created_at", nullable = false ) - public Timestamp getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Timestamp createdAt ) - { - this.createdAt = createdAt; - } - - @Basic - @Column( name = "last_updated_by", length = 11 ) - @JsonInclude( JsonInclude.Include.NON_NULL ) - public String getLastUpdatedBy() - { - return lastUpdatedBy; - } - - public void setLastUpdatedBy( String lastUpdatedBy ) - { - this.lastUpdatedBy = lastUpdatedBy; - } - - @Basic - @Column( name = "last_updated_at", nullable = false ) - public Timestamp getLastUpdatedAt() - { - return lastUpdatedAt; - } - - public void setLastUpdatedAt( Timestamp lastUpdatedAt ) - { - this.lastUpdatedAt = lastUpdatedAt; - } - @Basic @Column( name = "name", nullable = false, length = 230 ) public String getName() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ProgramStageRule.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ProgramStageRule.java index 26b728fe..a3669a72 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ProgramStageRule.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ProgramStageRule.java @@ -29,6 +29,7 @@ */ import com.fasterxml.jackson.annotation.JsonIgnore; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import javax.persistence.Basic; import javax.persistence.Column; @@ -66,6 +67,11 @@ public class ProgramStageRule extends AbstractRule private ApplicableEventStatus applicableEventStatus; private EventStatusUpdate eventStatusUpdate; + public ProgramStageRule() + { + super( DhisResourceType.PROGRAM_STAGE_EVENT ); + } + @Basic @Column( name = "enrollment_creation_enabled", nullable = false ) public boolean isEnrollmentCreationEnabled() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscription.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscription.java index 0b2e778b..36cf3935 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscription.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscription.java @@ -56,10 +56,14 @@ @Entity @Table( name = "fhir_remote_subscription" ) @JsonFilter( ToManyPropertyFilter.FILTER_NAME ) -public class RemoteSubscription extends BaseMetadata implements Serializable +public class RemoteSubscription extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -2488855592701580509L; + public static final int MAX_NAME_LENGTH = 50; + + public static final int MAX_CODE_LENGTH = 20; + private String name; private String code; private boolean enabled; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionResource.java index e8be56a8..25957faa 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionResource.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionResource.java @@ -50,7 +50,7 @@ */ @Entity @Table( name = "fhir_remote_subscription_resource" ) -public class RemoteSubscriptionResource extends BaseMetadata implements Serializable +public class RemoteSubscriptionResource extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -6797001318266984453L; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionSystem.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionSystem.java index 202c1140..9832f7bc 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionSystem.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionSystem.java @@ -40,10 +40,12 @@ @Entity @Table( name = "fhir_remote_subscription_system" ) -public class RemoteSubscriptionSystem extends BaseMetadata implements Serializable +public class RemoteSubscriptionSystem extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -930459310559544662L; + public static final int MAX_CODE_PREFIX_LENGTH = 20; + private RemoteSubscription remoteSubscription; private FhirResourceType fhirResourceType; private System system; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RequestHeader.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RequestHeader.java index 52e5677b..6ff5788a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RequestHeader.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RequestHeader.java @@ -46,6 +46,10 @@ public class RequestHeader implements Serializable, Comparable, C { private static final long serialVersionUID = 9147646500873557921L; + public static final int MAX_NAME_LENGTH = 50; + + public static final int MAX_VALUE_LENGTH = 200; + private String name; @JsonProperty diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Script.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Script.java index 4ea73b17..acd73fe0 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Script.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/Script.java @@ -28,6 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.dhis2.fhir.adapter.fhir.metadata.model.jackson.ScriptVariablePersistentSortedSetConverter; +import org.dhis2.fhir.adapter.jackson.PersistentBagConverter; + import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.CollectionTable; @@ -54,10 +59,14 @@ */ @Entity @Table( name = "fhir_script" ) -public class Script extends BaseMetadata implements Serializable +public class Script extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 2166269559735726192L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 50; + private String name; private String description; private String code; @@ -159,6 +168,7 @@ public void setOutputType( TransformDataType outputType ) @OneToMany( mappedBy = "script" ) @OrderBy( "id" ) + @JsonSerialize( converter = PersistentBagConverter.class ) public List getArguments() { return arguments; @@ -175,6 +185,7 @@ public void setArguments( List scriptVariables ) @Column( name = "variable" ) @Enumerated( EnumType.STRING ) @OrderBy + @JsonSerialize( converter = ScriptVariablePersistentSortedSetConverter.class ) public SortedSet getVariables() { return variables; @@ -187,6 +198,7 @@ public void setVariables( SortedSet variables ) @OneToMany( mappedBy = "script", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER ) @OrderBy( "id" ) + @JsonIgnore public List getSources() { return sources; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptArg.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptArg.java index ebf8e787..51f2b673 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptArg.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptArg.java @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; + +import javax.annotation.Nullable; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -37,6 +40,7 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; import java.io.Serializable; +import java.util.regex.Pattern; /** * Defines a single argument of a script. Arguments of a script have names (are not referenced by their position) and @@ -46,10 +50,18 @@ */ @Entity @Table( name = "fhir_script_argument" ) -public class ScriptArg extends BaseMetadata implements Serializable +public class ScriptArg extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = -5052962742547037363L; + public static final int MAX_NAME_LENGTH = 30; + + public static final int MAX_DEFAULT_VALUE_LENGTH = 230; + + public static final String ARRAY_SEPARATOR = "|"; + + protected static final String ARRAY_SEPARATOR_REGEXP = Pattern.quote( ARRAY_SEPARATOR ); + private String name; private DataType dataType; private boolean mandatory; @@ -131,8 +143,9 @@ public void setDescription( String description ) this.description = description; } - @ManyToOne + @ManyToOne( optional = false ) @JoinColumn( name = "script_id", referencedColumnName = "id", nullable = false ) + @JsonIgnore public Script getScript() { return script; @@ -142,4 +155,14 @@ public void setScript( Script script ) { this.script = script; } + + @Nullable + public static String[] splitArrayValues( @Nullable String values ) + { + if ( values == null ) + { + return null; + } + return values.split( ARRAY_SEPARATOR_REGEXP ); + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptSource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptSource.java index e96078c2..446f784b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptSource.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/ScriptSource.java @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.dhis2.fhir.adapter.fhir.metadata.model.jackson.FhirVersionPersistentSortedSetConverter; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import javax.persistence.Basic; @@ -51,7 +54,7 @@ */ @Entity @Table( name = "fhir_script_source" ) -public class ScriptSource extends BaseMetadata implements Serializable +public class ScriptSource extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 6002604151209645784L; @@ -87,6 +90,7 @@ public void setSourceType( ScriptSourceType language ) @ManyToOne @JoinColumn( name = "script_id", referencedColumnName = "id", nullable = false ) + @JsonIgnore public Script getScript() { return script; @@ -103,6 +107,7 @@ public void setScript( Script script ) @Column( name = "fhir_version" ) @Enumerated( EnumType.STRING ) @OrderBy + @JsonSerialize( converter = FhirVersionPersistentSortedSetConverter.class ) public SortedSet getFhirVersions() { return fhirVersions; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionAdapterEndpoint.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionAdapterEndpoint.java index 7a268030..9593615e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionAdapterEndpoint.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionAdapterEndpoint.java @@ -45,6 +45,10 @@ public class SubscriptionAdapterEndpoint implements Serializable { private static final long serialVersionUID = -7323248001298960849L; + public static final int MAX_BASE_URL_LENGTH = 200; + + public static final int MAX_AUTHORIZATION_HEADER_LENGTH = 200; + private String baseUrl; private String authorizationHeader; private SubscriptionType subscriptionType = SubscriptionType.REST_HOOK; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionDhisEndpoint.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionDhisEndpoint.java index 865f85e8..ef02f060 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionDhisEndpoint.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionDhisEndpoint.java @@ -51,6 +51,10 @@ public class SubscriptionDhisEndpoint implements Serializable { private static final long serialVersionUID = 4975058445234438007L; + public static final int MAX_USERNAME_LENGTH = 200; + + public static final int MAX_PASSWORD_LENGTH = 200; + private AuthenticationMethod authenticationMethod; private String username; private String password; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionFhirEndpoint.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionFhirEndpoint.java index 4cbf473e..95405982 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionFhirEndpoint.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SubscriptionFhirEndpoint.java @@ -52,6 +52,8 @@ public class SubscriptionFhirEndpoint implements Serializable { private static final long serialVersionUID = 5238213075216094777L; + public static final int MAX_BASE_URL_LENGTH = 200; + private String baseUrl; private boolean logging; private boolean verboseLogging; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/System.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/System.java index 524d9f7b..42994c93 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/System.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/System.java @@ -36,10 +36,14 @@ @Entity @Table( name = "fhir_system" ) -public class System extends BaseMetadata implements Serializable +public class System extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 1072841132452061822L; + public static final int MAX_NAME_LENGTH = 230; + + public static final int MAX_CODE_LENGTH = 50; + private String name; private String code; private String systemUri; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SystemCode.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SystemCode.java index 77151288..2c6701ea 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SystemCode.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/SystemCode.java @@ -53,10 +53,12 @@ */ @Entity @Table( name = "fhir_system_code" ) -public class SystemCode extends BaseMetadata implements Serializable +public class SystemCode extends VersionedBaseMetadata implements Serializable { private static final long serialVersionUID = 7048763667494469394L; + public static final int MAX_SYSTEM_CODE_LENGTH = 120; + private System system; private String systemCode; private Code code; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TrackedEntityRule.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TrackedEntityRule.java index 6807d6d3..1b28584c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TrackedEntityRule.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TrackedEntityRule.java @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.dhis.model.ReferenceAttributeConverter; @@ -56,6 +57,11 @@ public class TrackedEntityRule extends AbstractRule private Reference trackedEntityIdentifierReference; private boolean trackedEntityIdentifierFq; + public TrackedEntityRule() + { + super( DhisResourceType.TRACKED_ENTITY ); + } + @Basic @Column( name = "tracked_entity_ref", nullable = false, length = 230 ) @Convert( converter = ReferenceAttributeConverter.class ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TransformDataType.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TransformDataType.java index 7da3b8d0..ef128a18 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TransformDataType.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/TransformDataType.java @@ -28,6 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import javax.annotation.Nullable; + /** * The data type of the input or output variable of a transformation. * @@ -35,11 +37,24 @@ */ public enum TransformDataType { - DHIS_TRACKED_ENTITY_INSTANCE, - DHIS_ENROLLMENT, - DHIS_EVENT, - FHIR_PATIENT, - FHIR_IMMUNIZATION, - FHIR_OBSERVATION, - FHIR_DIAGNOSTIC_REPORT + DHIS_TRACKED_ENTITY_INSTANCE( null ), + DHIS_ENROLLMENT( null ), + DHIS_EVENT( null ), + FHIR_PATIENT( FhirResourceType.PATIENT ), + FHIR_IMMUNIZATION( FhirResourceType.PATIENT ), + FHIR_OBSERVATION( FhirResourceType.OBSERVATION ), + FHIR_DIAGNOSTIC_REPORT( FhirResourceType.DIAGNOSTIC_REPORT ); + + private final FhirResourceType fhirResourceType; + + TransformDataType( @Nullable FhirResourceType fhirResourceType ) + { + this.fhirResourceType = fhirResourceType; + } + + @Nullable + public FhirResourceType getFhirResourceType() + { + return fhirResourceType; + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/BaseMetadata.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/VersionedBaseMetadata.java similarity index 94% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/BaseMetadata.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/VersionedBaseMetadata.java index 12c40bb6..0c7028f2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/BaseMetadata.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/VersionedBaseMetadata.java @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirAdapterMetadata; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.LastModifiedDate; @@ -43,9 +44,11 @@ /** * Base metadata class that contains the base metadata properties. + * + * @author volsch */ @MappedSuperclass -public class BaseMetadata implements Serializable +public class VersionedBaseMetadata implements Serializable, FhirAdapterMetadata { private static final long serialVersionUID = 7500268787032387101L; @@ -55,6 +58,7 @@ public class BaseMetadata implements Serializable private String lastUpdatedBy; private LocalDateTime lastUpdatedAt; + @Override @GeneratedValue( generator = "uuid2" ) @GenericGenerator( name = "uuid2", strategy = "uuid2" ) @Id diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/FhirVersionPersistentSortedSetConverter.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/FhirVersionPersistentSortedSetConverter.java new file mode 100644 index 00000000..2a0d7006 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/FhirVersionPersistentSortedSetConverter.java @@ -0,0 +1,45 @@ +package org.dhis2.fhir.adapter.fhir.metadata.model.jackson; + +/* + * 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.fhir.model.FhirVersion; +import org.dhis2.fhir.adapter.jackson.TypedPersistentSortedSetConverter; + +/** + * Converter for {@link FhirVersion}. + * + * @author volsch + */ +public class FhirVersionPersistentSortedSetConverter extends TypedPersistentSortedSetConverter +{ + public FhirVersionPersistentSortedSetConverter() + { + super( FhirVersion.class ); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/ScriptVariablePersistentSortedSetConverter.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/ScriptVariablePersistentSortedSetConverter.java new file mode 100644 index 00000000..d3c89445 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/jackson/ScriptVariablePersistentSortedSetConverter.java @@ -0,0 +1,45 @@ +package org.dhis2.fhir.adapter.fhir.metadata.model.jackson; + +/* + * 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.fhir.metadata.model.ScriptVariable; +import org.dhis2.fhir.adapter.jackson.TypedPersistentSortedSetConverter; + +/** + * Converter for {@link ScriptVariable}. + * + * @author volsch + */ +public class ScriptVariablePersistentSortedSetConverter extends TypedPersistentSortedSetConverter +{ + public ScriptVariablePersistentSortedSetConverter() + { + super( ScriptVariable.class ); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeCategoryRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeCategoryRepository.java index da4b7608..5e34a795 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeCategoryRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeCategoryRepository.java @@ -29,8 +29,15 @@ */ import org.dhis2.fhir.adapter.fhir.metadata.model.CodeCategory; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; +import javax.annotation.Nonnull; +import java.util.List; import java.util.UUID; /** @@ -38,6 +45,49 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "codeCategory" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('CODE_MAPPING')" ) public interface CodeCategoryRepository extends JpaRepository { + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull CodeCategory entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeRepository.java index a65437de..a7c9ed67 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeRepository.java @@ -29,8 +29,15 @@ */ import org.dhis2.fhir.adapter.fhir.metadata.model.Code; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; +import javax.annotation.Nonnull; +import java.util.List; import java.util.UUID; /** @@ -38,6 +45,49 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "code" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('CODE_MAPPING')" ) public interface CodeRepository extends JpaRepository { + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull Code entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ConstantRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ConstantRepository.java index e44a13cc..c0ae7dad 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ConstantRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ConstantRepository.java @@ -30,10 +30,18 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.Constant; import org.dhis2.fhir.adapter.fhir.metadata.model.ConstantResolver; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -42,6 +50,9 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "constant" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('CODE_MAPPING')" ) public interface ConstantRepository extends JpaRepository, ConstantResolver { /** @@ -50,6 +61,49 @@ public interface ConstantRepository extends JpaRepository, Const * @param code the code of the constant that should be resolved. * @return the constant with the specified code, or null if no such constant exists. */ + @RestResource( exported = false ) @Nonnull + @Cacheable( key = "{#root.methodName, #a0}" ) Optional findOneByCode( @Param( "code" ) @Nonnull String code ); + + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull Constant entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomExecutableScriptRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomExecutableScriptRepository.java new file mode 100644 index 00000000..52f96431 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomExecutableScriptRepository.java @@ -0,0 +1,50 @@ +package org.dhis2.fhir.adapter.fhir.metadata.repository; + +/* + * 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.fhir.metadata.model.ExecutableScript; +import org.dhis2.fhir.adapter.fhir.metadata.model.ExecutableScriptInfo; +import org.dhis2.fhir.adapter.fhir.model.FhirVersion; +import org.springframework.data.rest.core.annotation.RestResource; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Optional; + +/** + * Custom repository for {@link org.dhis2.fhir.adapter.fhir.metadata.model.ExecutableScript}. + * + * @author volsch + */ +public interface CustomExecutableScriptRepository +{ + @RestResource( exported = false ) + @Nonnull + Optional findInfo( @Nullable ExecutableScript executableScript, @Nonnull FhirVersion fhirVersion ); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRemoteSubscriptionResourceUpdateRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRemoteSubscriptionResourceUpdateRepository.java index cadc7255..b3940071 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRemoteSubscriptionResourceUpdateRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRemoteSubscriptionResourceUpdateRepository.java @@ -30,6 +30,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResource; import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResourceUpdate; +import org.springframework.data.rest.core.annotation.RestResource; import javax.annotation.Nonnull; import java.time.LocalDateTime; @@ -41,8 +42,10 @@ */ public interface CustomRemoteSubscriptionResourceUpdateRepository { + @RestResource( exported = false ) @Nonnull LocalDateTime getRemoteLastUpdated( @Nonnull RemoteSubscriptionResource remoteSubscriptionResource ); + @RestResource( exported = false ) boolean updateRemoteLastUpdated( @Nonnull RemoteSubscriptionResource remoteSubscriptionResource, @Nonnull LocalDateTime lastUpdated ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRuleRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRuleRepository.java index 61e96723..4b7d77dd 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRuleRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CustomRuleRepository.java @@ -41,5 +41,5 @@ public interface CustomRuleRepository { @Nonnull - List findRulesByInputData( @Nonnull @Param( "fhirResourceType" ) FhirResourceType fhirResourceType, @Nullable Collection systemCodeValues ); + List findAllByInputData( @Nonnull @Param( "fhirResourceType" ) FhirResourceType fhirResourceType, @Nullable Collection systemCodeValues ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptArgRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptArgRepository.java index 1a7d54e5..0c50d97d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptArgRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptArgRepository.java @@ -28,14 +28,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.dhis2.fhir.adapter.fhir.metadata.model.ExecutableScript; import org.dhis2.fhir.adapter.fhir.metadata.model.ExecutableScriptArg; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import javax.annotation.Nonnull; -import java.util.Collection; +import java.util.List; import java.util.UUID; /** @@ -43,9 +43,47 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "executableScriptArg" ) public interface ExecutableScriptArgRepository extends JpaRepository { - @Query( "SELECT sa FROM #{#entityName} sa WHERE sa.script=:script AND sa.enabled=true" ) + @Override @Nonnull - Collection findAllEnabledByScript( @Param( "script" ) @Nonnull ExecutableScript executableScript ); + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull ExecutableScriptArg entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java index cc3e5304..fd48187f 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ExecutableScriptRepository.java @@ -29,8 +29,15 @@ */ import org.dhis2.fhir.adapter.fhir.metadata.model.ExecutableScript; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; +import javax.annotation.Nonnull; +import java.util.List; import java.util.UUID; /** @@ -38,6 +45,49 @@ * * @author volsch */ -public interface ExecutableScriptRepository extends JpaRepository +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "executableScript" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('DATA_MAPPING')" ) +public interface ExecutableScriptRepository extends JpaRepository, CustomExecutableScriptRepository { + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull ExecutableScript entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionQueue.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirAdapterMetadata.java similarity index 83% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionQueue.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirAdapterMetadata.java index 4276b7db..f5d8d6c9 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/RemoteSubscriptionQueue.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirAdapterMetadata.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.metadata.model; +package org.dhis2.fhir.adapter.fhir.metadata.repository; /* * Copyright (c) 2004-2018, University of Oslo @@ -28,6 +28,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -public class RemoteSubscriptionQueue +import java.io.Serializable; + +/** + * Interface that must be implemented by all FHIR adapter metadata. + * + * @param the concrete type of the ID of the entity. + * @author volsch + */ +public interface FhirAdapterMetadata extends Serializable { + I getId(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepository.java index 2eda93df..6e6914c3 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepository.java @@ -30,10 +30,18 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceMapping; import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -42,8 +50,54 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "resourceMapping" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('DATA_MAPPING')" ) public interface FhirResourceMappingRepository extends JpaRepository { + @RestResource( exported = false ) @Nonnull + @Cacheable( key = "{#root.methodName, #a0}" ) Optional findByFhirResourceType( @Param( "fhirResourceType" ) @Nonnull FhirResourceType fhirResourceType ); + + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull FhirResourceMapping entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionRepository.java index 60a18bac..2bc6522a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionRepository.java @@ -51,7 +51,7 @@ */ @CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "remoteSubscription" ) @RepositoryRestResource -@PreAuthorize( "(authentication==null) or hasRole('ADMINISTRATION')" ) +@PreAuthorize( "hasRole('ADMINISTRATION')" ) public interface RemoteSubscriptionRepository extends JpaRepository, CustomRemoteSubscriptionRepository { @RestResource( exported = false ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionResourceRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionResourceRepository.java index b80e7a48..8c5ead0e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionResourceRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionResourceRepository.java @@ -40,6 +40,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; import java.util.List; @@ -53,12 +54,14 @@ */ @CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "remoteSubscriptionResource" ) @RepositoryRestResource +@PreAuthorize( "hasRole('ADMINISTRATION')" ) public interface RemoteSubscriptionResourceRepository extends JpaRepository { @RestResource( exported = false ) @Query( "SELECT r FROM #{#entityName} r JOIN FETCH r.remoteSubscription s WHERE r.id=:id" ) @Nonnull @Cacheable( key = "#a0" ) + @PreAuthorize( "permitAll()" ) Optional findByIdCached( @Param( "id" ) @Nonnull UUID id ); @RestResource( exported = false ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionSystemRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionSystemRepository.java index 2f7a64fa..63da3344 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionSystemRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RemoteSubscriptionSystemRepository.java @@ -39,6 +39,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; import java.util.Collection; @@ -52,6 +53,7 @@ */ @CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "remoteSubscriptionSystem" ) @RepositoryRestResource +@PreAuthorize( "hasRole('ADMINISTRATION')" ) public interface RemoteSubscriptionSystemRepository extends JpaRepository { @RestResource( exported = false ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RuleRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RuleRepository.java index d2665725..cb68a577 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RuleRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/RuleRepository.java @@ -29,8 +29,15 @@ */ import org.dhis2.fhir.adapter.fhir.metadata.model.AbstractRule; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; +import javax.annotation.Nonnull; +import java.util.List; import java.util.UUID; /** @@ -38,6 +45,49 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "rule" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('DATA_MAPPING')" ) public interface RuleRepository extends JpaRepository, CustomRuleRepository { + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull AbstractRule entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptArgRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptArgRepository.java index 4ec2beeb..670ed5db 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptArgRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptArgRepository.java @@ -28,12 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.dhis2.fhir.adapter.fhir.metadata.model.Script; import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptArg; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; import javax.annotation.Nonnull; -import java.util.Collection; +import java.util.List; import java.util.UUID; /** @@ -41,8 +45,49 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "scriptArg" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('DATA_MAPPING')" ) public interface ScriptArgRepository extends JpaRepository { + @Override @Nonnull - Collection findAllByScript( @Nonnull Script script ); + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAllInBatch(); + + @Override + @CacheEvict( key = "#a0" ) + void deleteById( @Nonnull UUID id ); + + @Override + @CacheEvict( key = "#a0.id" ) + void delete( @Nonnull ScriptArg entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll( @Nonnull Iterable entities ); + + @Override + @CacheEvict( allEntries = true ) + void deleteAll(); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java index 09107abe..4ccdfb9e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/ScriptRepository.java @@ -29,8 +29,15 @@ */ import org.dhis2.fhir.adapter.fhir.metadata.model.Script; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.security.access.prepost.PreAuthorize; +import javax.annotation.Nonnull; +import java.util.List; import java.util.UUID; /** @@ -38,6 +45,49 @@ * * @author volsch */ +@CacheConfig( cacheManager = "metadataCacheManager", cacheNames = "script" ) +@RepositoryRestResource +@PreAuthorize( "hasRole('DATA_MAPPING')" ) public interface ScriptRepository extends JpaRepository { + @Override + @Nonnull + @CacheEvict( allEntries = true ) + List saveAll( @Nonnull Iterable entities ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S saveAndFlush( @Nonnull S entity ); + + @Override + @Nonnull + @CachePut( key = "#a0.id" ) + @CacheEvict( allEntries = true ) + S save( @Nonnull S entity ); + + @Override + @CacheEvict( allEntries = true ) + void deleteInBatch( @Nonnull Iterable