dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36618
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18734: wip, support import/export of programStageDataElements
------------------------------------------------------------
revno: 18734
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-30 13:57:27 +0700
message:
wip, support import/export of programStageDataElements
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageSchemaDescriptor.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java 2015-03-18 13:03:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java 2015-03-30 06:57:27 +0000
@@ -35,7 +35,6 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
@@ -83,6 +82,7 @@
private Program program;
+ @Scanned
private Set<ProgramStageDataElement> programStageDataElements = new HashSet<>();
private List<ProgramIndicator> programIndicators = new ArrayList<>();
@@ -125,7 +125,7 @@
private String reportDateToUse;
private Integer sortOrder;
-
+
private PeriodType periodType;
/**
@@ -302,6 +302,7 @@
@JsonProperty
@JsonView( { DetailedView.class, ExportView.class } )
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "programStageDataElements", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "programStageDataElement", namespace = DxfNamespaces.DXF_2_0 )
public Set<ProgramStageDataElement> getProgramStageDataElements()
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java 2015-03-27 15:45:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java 2015-03-30 06:57:27 +0000
@@ -28,18 +28,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dataelement.DataElement;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
/**
* @author Viet Nguyen
*/
@@ -52,14 +53,8 @@
*/
private static final long serialVersionUID = -5670110591005778814L;
- /**
- * Part of composite key
- */
private ProgramStage programStage;
- /**
- * Part of composite key
- */
private DataElement dataElement;
/**
@@ -238,4 +233,36 @@
", allowFutureDate=" + allowFutureDate +
'}';
}
+
+ @Override
+ public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+ {
+ super.mergeWith( other, strategy );
+
+ if ( other.getClass().isInstance( this ) )
+ {
+ ProgramStageDataElement programStageDataElement = (ProgramStageDataElement) other;
+
+ compulsory = programStageDataElement.isCompulsory();
+
+ if ( strategy.isReplace() )
+ {
+ programStage = programStageDataElement.getProgramStage();
+ dataElement = programStageDataElement.getDataElement();
+ allowFutureDate = programStageDataElement.getAllowFutureDate();
+ allowProvidedElsewhere = programStageDataElement.getAllowProvidedElsewhere();
+ displayInReports = programStageDataElement.getDisplayInReports();
+ sortOrder = programStageDataElement.getSortOrder();
+ }
+ else if ( strategy.isMerge() )
+ {
+ programStage = programStageDataElement.getProgramStage() == null ? programStage : programStageDataElement.getProgramStage();
+ dataElement = programStageDataElement.getDataElement() == null ? dataElement : programStageDataElement.getDataElement();
+ allowFutureDate = programStageDataElement.getAllowFutureDate() == null ? allowFutureDate : programStageDataElement.getAllowFutureDate();
+ allowProvidedElsewhere = programStageDataElement.getAllowProvidedElsewhere() == null ? allowProvidedElsewhere : programStageDataElement.getAllowProvidedElsewhere();
+ displayInReports = programStageDataElement.getDisplayInReports() == null ? displayInReports : programStageDataElement.getDisplayInReports();
+ sortOrder = programStageDataElement.getSortOrder() == null ? sortOrder : programStageDataElement.getSortOrder();
+ }
+ }
+ }
}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java 2015-03-30 06:57:27 +0000
@@ -0,0 +1,63 @@
+package org.hisp.dhis.schema.descriptors;
+
+/*
+ * Copyright (c) 2004-2015, 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.google.common.collect.Lists;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaDescriptor;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Component
+public class ProgramStageDataElementSchemaDescriptor implements SchemaDescriptor
+{
+ public static final String SINGULAR = "programStageDataElement";
+
+ public static final String PLURAL = "programStageDataElements";
+
+ public static final String API_ENDPOINT = "/" + PLURAL;
+
+ @Override
+ public Schema getSchema()
+ {
+ Schema schema = new Schema( ProgramStageDataElement.class, SINGULAR, PLURAL );
+ // schema.setApiEndpoint( API_ENDPOINT );
+ schema.setOrder( 1510 );
+
+ schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_PROGRAMSTAGE_ADD" ) ) );
+ schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_PROGRAMSTAGE_DELETE" ) ) );
+
+ return schema;
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageSchemaDescriptor.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageSchemaDescriptor.java 2015-03-30 06:57:27 +0000
@@ -40,7 +40,8 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Component
-public class ProgramStageSchemaDescriptor implements SchemaDescriptor
+public class
+ ProgramStageSchemaDescriptor implements SchemaDescriptor
{
public static final String SINGULAR = "programStage";
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2015-03-27 16:58:04 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2015-03-30 06:57:27 +0000
@@ -78,6 +78,7 @@
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramIndicator;
import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageSection;
import org.hisp.dhis.program.ProgramValidation;
import org.hisp.dhis.relationship.RelationshipType;
@@ -215,7 +216,9 @@
private List<Program> programs = new ArrayList<>();
private List<ProgramStage> programStages = new ArrayList<>();
-
+
+ private List<ProgramStageDataElement> programStageDataElements = new ArrayList<>();
+
private List<ProgramIndicator> programIndicators = new ArrayList<>();
private List<ProgramValidation> programValidations = Lists.newArrayList();
@@ -875,6 +878,19 @@
}
@JsonProperty
+ @JacksonXmlElementWrapper( localName = "programStageDataElements", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "programStageDataElement", namespace = DxfNamespaces.DXF_2_0 )
+ public List<ProgramStageDataElement> getProgramStageDataElements()
+ {
+ return programStageDataElements;
+ }
+
+ public void setProgramStageDataElements( List<ProgramStageDataElement> programStageDataElements )
+ {
+ this.programStageDataElements = programStageDataElements;
+ }
+
+ @JsonProperty
@JacksonXmlElementWrapper( localName = "programIndicators", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "programIndicator", namespace = DxfNamespaces.DXF_2_0 )
public List<ProgramIndicator> getProgramIndicators()
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2015-03-26 11:50:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2015-03-30 06:57:27 +0000
@@ -68,7 +68,6 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
-import org.hisp.dhis.program.ProgramStageDataElementService;
import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
import org.hisp.dhis.program.ProgramValidation;
import org.hisp.dhis.schema.SchemaService;
@@ -124,9 +123,6 @@
private DataElementOperandService dataElementOperandService;
@Autowired
- private ProgramStageDataElementService programStageDataElementService;
-
- @Autowired
private ObjectBridge objectBridge;
@Autowired
@@ -948,7 +944,6 @@
compulsoryDataElementOperands = Sets.newHashSet( extractDataElementOperands( object, "compulsoryDataElementOperands" ) );
greyedFields = Sets.newHashSet( extractDataElementOperands( object, "greyedFields" ) );
dataElementOperands = Lists.newArrayList( extractDataElementOperands( object, "dataElementOperands" ) );
- programStageDataElements = extractProgramStageDataElements( object );
programTrackedEntityAttributes = extractProgramTrackedEntityAttributes( object );
categoryDimensions = extractCategoryDimensions( object );
}
@@ -969,7 +964,6 @@
deleteDataElementOperands( object, "greyedFields" );
}
- deleteProgramStageDataElements( object );
deleteProgramTrackedEntityAttributes( object );
}
}
@@ -983,7 +977,6 @@
saveDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
saveDataElementOperands( object, "greyedFields", greyedFields );
saveDataElementOperands( object, "dataElementOperands", dataElementOperands );
- saveProgramStageDataElements( object, programStageDataElements );
saveProgramTrackedEntityAttributes( object, programTrackedEntityAttributes );
saveCategoryDimensions( object, categoryDimensions );
}
@@ -1276,78 +1269,5 @@
ReflectionUtils.invokeSetterMethod( "programAttributes", object, programTrackedEntityAttributes );
}
-
- private Collection<ProgramStageDataElement> extractProgramStageDataElements( T object )
- {
- Method method = ReflectionUtils.findGetterMethod( "programStageDataElements", object );
-
- if ( method != null )
- {
- Collection<ProgramStageDataElement> programStageDataElements = ReflectionUtils.invokeGetterMethod(
- "programStageDataElements", object );
-
- for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
- {
- if ( sessionFactory.getCurrentSession().contains( programStageDataElement ) )
- {
- programStageDataElementService.deleteProgramStageDataElement( programStageDataElement );
- }
- }
-
- sessionFactory.getCurrentSession().flush();
- ReflectionUtils.invokeSetterMethod( "programStageDataElements", object,
- ReflectionUtils.newCollectionInstance( method.getReturnType() ) );
- sessionFactory.getCurrentSession().flush();
-
- return programStageDataElements;
- }
-
- return null;
- }
-
- private void saveProgramStageDataElements( T object, Collection<ProgramStageDataElement> programStageDataElements )
- {
- if ( programStageDataElements == null )
- {
- return;
- }
-
- Collection<ProgramStageDataElement> programStageDataElementCollection =
- ReflectionUtils.newCollectionInstance( programStageDataElements.getClass() );
-
- for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
- {
- Map<Field, Object> identifiableObjects = detachFields( programStageDataElement );
- reattachFields( programStageDataElement, identifiableObjects, user );
-
- if ( ProgramStage.class.isAssignableFrom( object.getClass() ) )
- {
- programStageDataElement.setProgramStage( (ProgramStage) object );
- }
-
- ProgramStageDataElement persisted = programStageDataElementService.get( programStageDataElement.getProgramStage(),
- programStageDataElement.getDataElement() );
-
- if ( persisted == null )
- {
- if ( programStageDataElement.getDataElement() != null && programStageDataElement.getProgramStage() != null )
- {
- programStageDataElementService.addProgramStageDataElement( programStageDataElement );
- }
- }
- else
- {
- programStageDataElementCollection.add( persisted );
- }
- }
-
- ReflectionUtils.invokeSetterMethod( "programStageDataElements", object, programStageDataElementCollection );
- }
-
- private void deleteProgramStageDataElements( T object )
- {
- // deletion will be done in extractProgramStageDataElements
- extractProgramStageDataElements( object );
- }
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2015-03-26 11:50:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2015-03-30 06:57:27 +0000
@@ -250,6 +250,10 @@
<constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.program.ProgramStage" />
</bean>
+ <bean id="programStageDataElementImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.program.ProgramStageDataElement" />
+ </bean>
+
<bean id="programStageSectionImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
<constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.program.ProgramStageSection" />
</bean>
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml 2015-03-27 15:45:41 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml 2015-03-30 06:57:27 +0000
@@ -8,14 +8,14 @@
<hibernate-mapping>
<class name="org.hisp.dhis.program.ProgramStageDataElement" table="programstagedataelement">
- <id name="id" column="programstagedataelementid">
+ <id name="id" column="programstagedataelementid">
<generator class="native" />
</id>
&identifiableProperties;
<many-to-one name="programStage" class="org.hisp.dhis.program.ProgramStage" column="programstageid"
foreign-key="fk_programstagedataelement_programstageid" unique-key="programstagedataelement_unique_key" />
-
+
<many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid"
foreign-key="fk_programstagedataelement_dataelementid" unique-key="programstagedataelement_unique_key" />
@@ -27,7 +27,7 @@
<property name="displayInReports" column="displayinreports" />
- <property name="allowFutureDate" column="allowfuturedate"/>
+ <property name="allowFutureDate" column="allowfuturedate" />
</class>
</hibernate-mapping>