dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21149
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9930: more fixes for dxf2 importer
------------------------------------------------------------
revno: 9930
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-28 22:20:20 +0700
message:
more fixes for dxf2 importer
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/concept/Concept.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLayer.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.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/attribute/Attribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java 2013-02-28 15:20:20 +0000
@@ -87,53 +87,6 @@
this.valueType = valueType;
}
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
- if ( !super.equals( o ) ) return false;
-
- Attribute attribute = (Attribute) o;
-
- if ( dataElementAttribute != attribute.dataElementAttribute ) return false;
- if ( indicatorAttribute != attribute.indicatorAttribute ) return false;
- if ( mandatory != attribute.mandatory ) return false;
- if ( organisationUnitAttribute != attribute.organisationUnitAttribute ) return false;
- if ( userAttribute != attribute.userAttribute ) return false;
- if ( dataElementGroupAttribute != null ? !dataElementGroupAttribute.equals( attribute.dataElementGroupAttribute ) : attribute.dataElementGroupAttribute != null )
- return false;
- if ( indicatorGroupAttribute != null ? !indicatorGroupAttribute.equals( attribute.indicatorGroupAttribute ) : attribute.indicatorGroupAttribute != null )
- return false;
- if ( organisationUnitGroupAttribute != null ? !organisationUnitGroupAttribute.equals( attribute.organisationUnitGroupAttribute ) : attribute.organisationUnitGroupAttribute != null )
- return false;
- if ( sortOrder != null ? !sortOrder.equals( attribute.sortOrder ) : attribute.sortOrder != null ) return false;
- if ( userGroupAttribute != null ? !userGroupAttribute.equals( attribute.userGroupAttribute ) : attribute.userGroupAttribute != null )
- return false;
- if ( valueType != null ? !valueType.equals( attribute.valueType ) : attribute.valueType != null ) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = super.hashCode();
- result = 31 * result + (valueType != null ? valueType.hashCode() : 0);
- result = 31 * result + (dataElementAttribute ? 1 : 0);
- result = 31 * result + (dataElementGroupAttribute != null ? dataElementGroupAttribute.hashCode() : 0);
- result = 31 * result + (indicatorAttribute ? 1 : 0);
- result = 31 * result + (indicatorGroupAttribute != null ? indicatorGroupAttribute.hashCode() : 0);
- result = 31 * result + (organisationUnitAttribute ? 1 : 0);
- result = 31 * result + (organisationUnitGroupAttribute != null ? organisationUnitGroupAttribute.hashCode() : 0);
- result = 31 * result + (userAttribute ? 1 : 0);
- result = 31 * result + (userGroupAttribute != null ? userGroupAttribute.hashCode() : 0);
- result = 31 * result + (mandatory ? 1 : 0);
- result = 31 * result + (sortOrder != null ? sortOrder.hashCode() : 0);
-
- return result;
- }
-
@JsonProperty
@JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/concept/Concept.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/concept/Concept.java 2013-02-26 18:33:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/concept/Concept.java 2013-02-28 15:20:20 +0000
@@ -70,12 +70,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- return name.hashCode();
- }
-
- @Override
public boolean equals( Object o )
{
if ( this == o )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java 2013-02-28 15:20:20 +0000
@@ -79,12 +79,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- return name.hashCode();
- }
-
- @Override
public boolean equals( Object o )
{
if ( this == o )
@@ -107,12 +101,6 @@
return name.equals( other.getName() );
}
- @Override
- public String toString()
- {
- return "[" + name + "]";
- }
-
// -------------------------------------------------------------------------
// Getter & Setter
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2013-02-25 12:33:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2013-02-28 15:20:20 +0000
@@ -102,7 +102,6 @@
int result = 1;
result = prime * result + ((categoryCombo == null) ? 0 : categoryCombo.hashCode());
-
result = prime * result + ((categoryOptions == null) ? 0 : categoryOptions.hashCode());
return result;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2013-02-28 05:58:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2013-02-28 15:20:20 +0000
@@ -58,7 +58,7 @@
/**
* This class is used for defining the standardized DataSets. A DataSet consists
* of a collection of DataElements.
- *
+ *
* @author Kristian Nordal
*/
@JacksonXmlRootElement( localName = "dataSet", namespace = DxfNamespaces.DXF_2_0 )
@@ -297,7 +297,7 @@
removeOrganisationUnitGroup( group );
}
}
-
+
for ( OrganisationUnitGroup group : updates )
{
addOrganisationUnitGroup( group );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLayer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLayer.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLayer.java 2013-02-28 15:20:20 +0000
@@ -83,12 +83,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- return name.hashCode();
- }
-
- @Override
public boolean equals( Object object )
{
if ( this == object )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java 2013-02-28 15:20:20 +0000
@@ -70,12 +70,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- return name == null ? 0 : name.hashCode();
- }
-
- @Override
public boolean equals( Object object )
{
if ( this == object )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java 2013-02-28 15:20:20 +0000
@@ -73,12 +73,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- return name == null ? 0 : name.hashCode();
- }
-
- @Override
public boolean equals( Object object )
{
if ( this == object )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2013-02-28 15:20:20 +0000
@@ -153,6 +153,12 @@
// -------------------------------------------------------------------------
@Override
+ public boolean haveUniqueNames()
+ {
+ return false;
+ }
+
+ @Override
public String getName()
{
return indicator != null ? indicator.getName() : dataElement != null ? dataElement.getName() : uid;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2013-02-28 15:20:20 +0000
@@ -63,13 +63,6 @@
this.name = name;
}
-
- @Override
- public int hashCode()
- {
- return name.hashCode();
- }
-
@Override
public boolean equals( Object o )
{
@@ -133,7 +126,6 @@
OptionSet optionSet = (OptionSet) other;
removeAllOptions();
-
options.addAll( optionSet.getOptions() );
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2013-02-22 06:30:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2013-02-28 15:20:20 +0000
@@ -593,12 +593,6 @@
return name.equals( other.getName() );
}
- @Override
- public String toString()
- {
- return "[" + name + "]";
- }
-
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java 2013-02-28 05:58:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroup.java 2013-02-28 15:20:20 +0000
@@ -97,12 +97,6 @@
return name;
}
- @Override
- public String getCode()
- {
- return (name != null && name.length() > 50) ? name.substring( 0, 50 ) : name;
- }
-
public void addOrganisationUnit( OrganisationUnit organisationUnit )
{
members.add( organisationUnit );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2013-02-28 15:20:20 +0000
@@ -83,16 +83,6 @@
// -------------------------------------------------------------------------
@Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + id;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @Override
public boolean equals( Object obj )
{
if ( this == obj )
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2013-02-28 15:20:20 +0000
@@ -123,8 +123,6 @@
log.info( "User '" + currentUserService.getCurrentUsername() + "' started import at " + new Date() );
}
- long totalStartTime = System.nanoTime();
-
for ( Map.Entry<Class<? extends IdentifiableObject>, String> entry : ExchangeClasses.getImportMap().entrySet() )
{
Object value = ReflectionUtils.invokeGetterMethod( entry.getValue(), metaData );
@@ -148,15 +146,9 @@
log.info( message );
}
- long startTime = System.nanoTime();
ImportTypeSummary importTypeSummary = doImport( objects, importOptions );
// TODO do we need this?
sessionFactory.getCurrentSession().flush();
- long endTime = System.nanoTime();
- long duration = endTime - startTime;
- double seconds = (double) duration / 1000000000.0;
-
- System.err.println( "Duration: " + seconds );
if ( importTypeSummary != null )
{
@@ -176,12 +168,6 @@
}
}
- long endTime = System.nanoTime();
- long duration = endTime - totalStartTime;
- double seconds = (double) duration / 1000000000.0;
-
- System.err.println( "Total Duration: " + seconds );
-
if ( importOptions.isDryRun() )
{
sessionFactory.getCurrentSession().clear();
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2013-02-28 05:17:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2013-02-28 15:20:20 +0000
@@ -42,6 +42,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -67,7 +68,7 @@
private static final List<Class<?>> registeredTypes = new ArrayList<Class<?>>();
- private Map<Class<?>, Collection<?>> masterMap;
+ private HashMap<Class<?>, Set<?>> masterMap;
private Map<String, PeriodType> periodTypeMap;
@@ -98,7 +99,7 @@
{
log.info( "Started updating lookup maps at " + new Date() );
- masterMap = new HashMap<Class<?>, Collection<?>>();
+ masterMap = new HashMap<Class<?>, Set<?>>();
periodTypeMap = new HashMap<String, PeriodType>();
uidMap = new HashMap<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>();
codeMap = new HashMap<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>();
@@ -135,17 +136,14 @@
@SuppressWarnings( "unchecked" )
private void populateIdentifiableObjectMap( Class<?> clazz )
{
- Collection<IdentifiableObject> map = new ArrayList<IdentifiableObject>();
+ Set<IdentifiableObject> map = new HashSet<IdentifiableObject>();
if ( IdentifiableObject.class.isAssignableFrom( clazz ) )
{
- map = manager.getAll( (Class<IdentifiableObject>) clazz );
+ map = new HashSet<IdentifiableObject>( manager.getAll( (Class<IdentifiableObject>) clazz ) );
}
- if ( map != null )
- {
- masterMap.put( clazz, map );
- }
+ masterMap.put( clazz, map );
}
@SuppressWarnings( "unchecked" )
@@ -202,7 +200,7 @@
}
}
- masterMap.put( clazz, periodTypes );
+ masterMap.put( clazz, new HashSet<Object>( periodTypes ) );
}
//-------------------------------------------------------------------------------------------------------
@@ -219,7 +217,7 @@
manager.save( (IdentifiableObject) object );
}
- _updateInternalMaps( object );
+ // _updateInternalMaps( object );
}
else
{
@@ -248,7 +246,7 @@
@Override
public <T> T getObject( T object )
{
- Collection<T> objects = _findMatches( object );
+ Set<T> objects = _findMatches( object );
if ( objects.size() == 1 )
{
@@ -284,26 +282,16 @@
}
@Override
- public <T> Collection<T> getObjects( T object )
+ public <T> Set<T> getObjects( T object )
{
return _findMatches( object );
}
@Override
@SuppressWarnings( "unchecked" )
- public <T> Collection<T> getAllObjects( Class<T> clazz )
- {
- return (Collection<T>) masterMap.get( clazz );
- }
-
- public Map<Class<?>, Collection<?>> getMasterMap()
- {
- return masterMap;
- }
-
- public void setMasterMap( Map<Class<?>, Collection<?>> masterMap )
- {
- this.masterMap = masterMap;
+ public <T> Set<T> getAllObjects( Class<T> clazz )
+ {
+ return (Set<T>) masterMap.get( clazz );
}
@Override
@@ -323,9 +311,9 @@
//-------------------------------------------------------------------------------------------------------
@SuppressWarnings( "unchecked" )
- private <T> Collection<T> _findMatches( T object )
+ private <T> Set<T> _findMatches( T object )
{
- Collection<T> objects = new HashSet<T>();
+ Set<T> objects = new HashSet<T>();
if ( PeriodType.class.isInstance( object ) )
{
@@ -418,7 +406,7 @@
map = nameMap.get( identifiableObject.getClass().getSuperclass() );
}
- map.put( identifiableObject.getCode(), identifiableObject );
+ map.put( identifiableObject.getName(), identifiableObject );
}
}
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-02-28 15:20:20 +0000
@@ -1,7 +1,7 @@
package org.hisp.dhis.dxf2.metadata;
/*
- * Copyright (c) 2012, University of Oslo
+ * Copyright (c) 2012-2013, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java 2013-02-28 15:20:20 +0000
@@ -28,6 +28,7 @@
*/
import java.util.Collection;
+import java.util.Set;
/**
* Acts as a bridge between the importer and the persistence/cache layer.
@@ -72,7 +73,7 @@
* @param object Object to match against
* @return A collection of matched objects
*/
- <T> Collection<T> getObjects( T object );
+ <T> Set<T> getObjects( T object );
/**
* Get all objects for a specified class. These objects might not be persisted
@@ -81,7 +82,7 @@
* @param clazz Clazz to match against
* @return Collection of matches
*/
- <T> Collection<T> getAllObjects( Class<T> clazz );
+ <T> Set<T> getAllObjects( Class<T> clazz );
/**
* Enable or disable writing to the persistence store.
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java 2012-10-25 16:44:59 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/handlers/ObjectHandlerUtils.java 2013-02-28 15:20:20 +0000
@@ -1,11 +1,38 @@
package org.hisp.dhis.dxf2.metadata.handlers;
+/*
+ * Copyright (c) 2012-2013, 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 java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-public class ObjectHandlerUtils
+public final class ObjectHandlerUtils
{
public static <T> void preObjectHandlers( T object, List<ObjectHandler<T>> objectHandlers )
{
@@ -31,7 +58,7 @@
public static <T> void preObjectsHandlers( List<T> objects, List<ObjectHandler<T>> objectHandlers )
{
- if ( objects.size() > 0 )
+ if ( !objects.isEmpty() )
{
for ( ObjectHandler<T> objectHandler : objectHandlers )
{
@@ -45,7 +72,7 @@
public static <T> void postObjectsHandlers( List<T> objects, List<ObjectHandler<T>> objectHandlers )
{
- if ( objects.size() > 0 )
+ if ( !objects.isEmpty() )
{
for ( ObjectHandler<T> objectHandler : objectHandlers )
{
@@ -57,4 +84,7 @@
}
}
+ private ObjectHandlerUtils()
+ {
+ }
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-02-28 05:17:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-02-28 15:20:20 +0000
@@ -1,7 +1,7 @@
package org.hisp.dhis.dxf2.metadata.importers;
/*
- * Copyright (c) 2012, University of Oslo
+ * Copyright (c) 2012-2013, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,8 @@
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementOperandService;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.metadata.ExchangeClasses;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
@@ -93,6 +95,9 @@
private ExpressionService expressionService;
@Autowired
+ private DataEntryFormService dataEntryFormService;
+
+ @Autowired
private DataElementOperandService dataElementOperandService;
@Autowired
@@ -101,7 +106,7 @@
@Autowired
private SessionFactory sessionFactory;
- @Autowired(required = false)
+ @Autowired( required = false )
private List<ObjectHandler<T>> objectHandlers;
//-------------------------------------------------------------------------------------------------------
@@ -134,11 +139,14 @@
private Set<DataElementOperand> compulsoryDataElementOperands = new HashSet<DataElementOperand>();
private Set<DataElementOperand> greyedFields = new HashSet<DataElementOperand>();
+ private DataEntryForm dataEntryForm;
+
public void extract( T object )
{
attributeValues = extractAttributeValues( object );
leftSide = extractExpression( object, "leftSide" );
rightSide = extractExpression( object, "rightSide" );
+ dataEntryForm = extractDataEntryForm( object, "dataEntryForm" );
compulsoryDataElementOperands = extractDataElementOperands( object, "compulsoryDataElementOperands" );
greyedFields = extractDataElementOperands( object, "greyedFields" );
}
@@ -150,8 +158,11 @@
deleteAttributeValues( object );
deleteExpression( object, "leftSide" );
deleteExpression( object, "rightSide" );
+ // deleteDataEntryForm( object, "dataEntryForm" );
// deleteDataElementOperands( idObject, "compulsoryDataElementOperands" );
deleteDataElementOperands( object, "greyedFields" );
+
+ sessionFactory.getCurrentSession().flush();
}
}
@@ -160,10 +171,52 @@
saveAttributeValues( object, attributeValues );
saveExpression( object, "leftSide", leftSide );
saveExpression( object, "rightSide", rightSide );
+ // saveDataEntryForm( object, "dataEntryForm", dataEntryForm );
// saveDataElementOperands( idObject, "compulsoryDataElementOperands", compulsoryDataElementOperands );
saveDataElementOperands( object, "greyedFields", greyedFields );
}
+ private void saveDataEntryForm( T object, String fieldName, DataEntryForm dataEntryForm )
+ {
+ if ( dataEntryForm != null )
+ {
+ Map<Field, Collection<Object>> identifiableObjectCollections = detachCollectionFields( dataEntryForm );
+ reattachCollectionFields( dataEntryForm, identifiableObjectCollections );
+
+ dataEntryForm.setId( 0 );
+ dataEntryFormService.addDataEntryForm( dataEntryForm );
+
+ ReflectionUtils.invokeSetterMethod( fieldName, object, dataEntryForm );
+ }
+ }
+
+ private DataEntryForm extractDataEntryForm( T object, String fieldName )
+ {
+ DataEntryForm dataEntryForm = null;
+
+ if ( ReflectionUtils.findGetterMethod( fieldName, object ) != null )
+ {
+ dataEntryForm = ReflectionUtils.invokeGetterMethod( fieldName, object );
+
+ if ( dataEntryForm != null )
+ {
+ ReflectionUtils.invokeSetterMethod( fieldName, object, new Object[]{ null } );
+ }
+ }
+
+ return dataEntryForm;
+ }
+
+ private void deleteDataEntryForm( T object, String fieldName )
+ {
+ DataEntryForm dataEntryForm = extractDataEntryForm( object, fieldName );
+
+ if ( dataEntryForm != null )
+ {
+ dataEntryFormService.deleteDataEntryForm( dataEntryForm );
+ }
+ }
+
private Expression extractExpression( T object, String fieldName )
{
Expression expression = null;
@@ -354,9 +407,7 @@
if ( !options.isDryRun() )
{
- // sessionFactory.getCurrentSession().flush();
nonIdentifiableObjects.save( object );
- // sessionFactory.getCurrentSession().flush();
}
log.debug( "Save successful." );
@@ -399,9 +450,7 @@
if ( !options.isDryRun() )
{
- // sessionFactory.getCurrentSession().flush();
nonIdentifiableObjects.save( persistedObject );
- //sessionFactory.getCurrentSession().flush();
}
log.debug( "Update successful." );
@@ -631,7 +680,9 @@
return period;
}
- return objectBridge.getObject( identifiableObject );
+ IdentifiableObject reference = objectBridge.getObject( identifiableObject );
+
+ return reference;
}
private Map<Field, Object> detachFields( final Object object )
@@ -662,9 +713,9 @@
for ( Field field : fields.keySet() )
{
IdentifiableObject idObject = (IdentifiableObject) fields.get( field );
- IdentifiableObject ref = findObjectByReference( idObject );
+ IdentifiableObject reference = findObjectByReference( idObject );
- if ( ref == null )
+ if ( reference == null )
{
if ( ExchangeClasses.getImportMap().get( idObject.getClass() ) != null )
{
@@ -674,7 +725,7 @@
if ( !options.isDryRun() )
{
- ReflectionUtils.invokeSetterMethod( field.getName(), object, ref );
+ ReflectionUtils.invokeSetterMethod( field.getName(), object, reference );
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2013-02-28 15:20:20 +0000
@@ -332,6 +332,13 @@
map.put( object.getUid(), object );
}
}
+ else if ( IdentifiableProperty.CODE.equals( property ) )
+ {
+ if ( object.getCode() != null )
+ {
+ map.put( object.getCode(), object );
+ }
+ }
else if ( IdentifiableProperty.NAME.equals( property ) )
{
if ( object.getName() != null )
@@ -339,13 +346,6 @@
map.put( object.getName(), object );
}
}
- else if ( IdentifiableProperty.CODE.equals( property ) )
- {
- if ( object.getCode() != null )
- {
- map.put( object.getCode(), object );
- }
- }
}
return map;