dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30787
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15649: various collection fixes in idObjectImporter
------------------------------------------------------------
revno: 15649
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-06-12 12:39:43 +0200
message:
various collection fixes in idObjectImporter
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
--
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 2014-06-12 09:41:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java 2014-06-12 10:39:43 +0000
@@ -72,10 +72,10 @@
private Program program;
- private Set<ProgramStageDataElement> programStageDataElements = new HashSet<ProgramStageDataElement>();
+ private Set<ProgramStageDataElement> programStageDataElements = new HashSet<>();
@Scanned
- private Set<ProgramStageSection> programStageSections = new HashSet<ProgramStageSection>();
+ private Set<ProgramStageSection> programStageSections = new HashSet<>();
private DataEntryForm dataEntryForm;
@@ -83,7 +83,7 @@
private String reportDateDescription;
- private Set<TrackedEntityInstanceReminder> reminders = new HashSet<TrackedEntityInstanceReminder>();
+ private Set<TrackedEntityInstanceReminder> reminders = new HashSet<>();
private Boolean autoGenerateEvent = true;
=== 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 2014-06-12 09:41:31 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2014-06-12 10:39:43 +0000
@@ -73,6 +73,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -160,7 +161,7 @@
private Set<DataElementOperand> compulsoryDataElementOperands = Sets.newHashSet();
private Set<DataElementOperand> greyedFields = Sets.newHashSet();
- private List<ProgramStageDataElement> programStageDataElements = Lists.newArrayList();
+ private Collection<ProgramStageDataElement> programStageDataElements = Lists.newArrayList();
private Set<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = Sets.newHashSet();
public void extract( T object )
@@ -451,13 +452,13 @@
ReflectionUtils.invokeSetterMethod( "programTrackedEntityAttributes", object, programTrackedEntityAttributes );
}
- private List<ProgramStageDataElement> extractProgramStageDataElements( T object )
+ private Collection<ProgramStageDataElement> extractProgramStageDataElements( T object )
{
- List<ProgramStageDataElement> programStageDataElements = Lists.newArrayList();
+ Method method = ReflectionUtils.findGetterMethod( "programStageDataElements", object );
- if ( ReflectionUtils.findGetterMethod( "programStageDataElements", object ) != null )
+ if ( method != null )
{
- programStageDataElements = ReflectionUtils.invokeGetterMethod( "programStageDataElements", object );
+ Collection<ProgramStageDataElement> programStageDataElements = ReflectionUtils.invokeGetterMethod( "programStageDataElements", object );
for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
{
@@ -468,15 +469,23 @@
}
sessionFactory.getCurrentSession().flush();
- ReflectionUtils.invokeSetterMethod( "programStageDataElements", object, Lists.newArrayList() );
+ ReflectionUtils.invokeSetterMethod( "programStageDataElements", object,
+ ReflectionUtils.newCollectionInstance( method.getReturnType() ) );
sessionFactory.getCurrentSession().flush();
+
+ return programStageDataElements;
}
- return programStageDataElements;
+ return null;
}
- private void saveProgramStageDataElements( T object, List<ProgramStageDataElement> programStageDataElements )
+ private void saveProgramStageDataElements( T object, Collection<ProgramStageDataElement> programStageDataElements )
{
+ if ( programStageDataElements == null )
+ {
+ return;
+ }
+
for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
{
Map<Field, Object> identifiableObjects = detachFields( programStageDataElement );