dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17758
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7196: made meta-data importer give correct importSummary
------------------------------------------------------------
revno: 7196
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-06-05 17:36:07 +0200
message:
made meta-data importer give correct importSummary
added:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.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/ExchangeClasses.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.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/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.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/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-03-28 07:40:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-06-05 15:36:07 +0000
@@ -5,6 +5,7 @@
import java.io.Serializable;
import java.util.Collection;
+import java.util.Date;
import java.util.Map;
/*
@@ -92,6 +93,10 @@
*/
Collection<User> getAllUsers();
+ Collection<User> getAllUsersBetween(int first, int max);
+
+ Collection<User> getUsersByLastUpdated(Date lastUpdated);
+
/**
* Returns a Collection of the Users which are not associated with any
* OrganisationUnits.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2012-04-25 13:48:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2012-06-05 15:36:07 +0000
@@ -82,6 +82,10 @@
*/
Collection<User> getAllUsers();
+ Collection<User> getAllUsersBetween(int first, int max);
+
+ Collection<User> getUsersByLastUpdated(Date lastUpdated);
+
/**
* Returns a Collection of the Users which are not associated with any
* OrganisationUnits.
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java 2012-04-11 20:16:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java 2012-06-05 15:36:07 +0000
@@ -30,8 +30,9 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.Dxf2Namespace;
-@JacksonXmlRootElement( localName = "count" )
+@JacksonXmlRootElement( localName = "count", namespace = Dxf2Namespace.NAMESPACE )
public class ImportCount
{
private int imported;
@@ -40,6 +41,10 @@
private int ignored;
+ public ImportCount()
+ {
+ }
+
public ImportCount( int imported, int updated, int ignored )
{
this.imported = imported;
@@ -48,7 +53,7 @@
}
@JsonProperty
- @JacksonXmlProperty( isAttribute = true )
+ @JacksonXmlProperty( isAttribute = true, namespace = Dxf2Namespace.NAMESPACE )
public int getImported()
{
return imported;
@@ -60,7 +65,7 @@
}
@JsonProperty
- @JacksonXmlProperty( isAttribute = true )
+ @JacksonXmlProperty( isAttribute = true, namespace = Dxf2Namespace.NAMESPACE )
public int getUpdated()
{
return updated;
@@ -72,7 +77,7 @@
}
@JsonProperty
- @JacksonXmlProperty( isAttribute = true )
+ @JacksonXmlProperty( isAttribute = true, namespace = Dxf2Namespace.NAMESPACE )
public int getIgnored()
{
return ignored;
@@ -88,4 +93,34 @@
{
return "[imports=" + imported + ", updates=" + updated + ", ignores=" + ignored + "]";
}
+
+ public void incrementImported()
+ {
+ imported++;
+ }
+
+ public void incrementUpdated()
+ {
+ updated++;
+ }
+
+ public void incrementIgnored()
+ {
+ ignored++;
+ }
+
+ public void incrementImported( int n )
+ {
+ imported += n;
+ }
+
+ public void incrementUpdated( int n )
+ {
+ updated += n;
+ }
+
+ public void incrementIgnored( int n )
+ {
+ ignored += n;
+ }
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2012-06-03 15:04:33 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2012-06-05 15:36:07 +0000
@@ -39,9 +39,9 @@
public class ImportSummary
{
private ImportStatus status;
-
+
private String description;
-
+
private ImportCount dataValueCount;
private List<ImportConflict> conflicts = new ArrayList<ImportConflict>();
@@ -51,13 +51,13 @@
public ImportSummary()
{
}
-
+
public ImportSummary( ImportStatus status, String description )
{
this.status = status;
this.description = description;
}
-
+
@JsonProperty
@JacksonXmlProperty
public ImportStatus getStatus()
@@ -95,8 +95,8 @@
}
@JsonProperty
- @JacksonXmlElementWrapper(localName = "conflicts")
- @JacksonXmlProperty(localName = "conflict")
+ @JacksonXmlElementWrapper( localName = "conflicts" )
+ @JacksonXmlProperty( localName = "conflict" )
public List<ImportConflict> getConflicts()
{
return conflicts;
=== 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 2012-06-04 09:29:45 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-06-05 15:36:07 +0000
@@ -32,8 +32,6 @@
import org.hibernate.SessionFactory;
import org.hisp.dhis.cache.HibernateCacheManager;
import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.dxf2.importsummary.ImportConflict;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -103,7 +101,14 @@
{
List<?> objects = new ArrayList<Object>( (Collection<?>) value );
log.info( "Importing " + objects.size() + " " + StringUtils.capitalize( entry.getValue() ) );
- doImport( objects, importOptions, importSummary );
+
+ ImportTypeSummary importTypeSummary = doImport( objects, importOptions );
+
+ if ( importTypeSummary != null )
+ {
+ importSummary.getImportTypeSummaries().add( importTypeSummary );
+ importSummary.incrementImportCount( importTypeSummary.getImportCount() );
+ }
}
else
{
@@ -157,7 +162,7 @@
return null;
}
- private <T> void doImport( List<T> objects, ImportOptions importOptions, ImportSummary importSummary )
+ private <T> ImportTypeSummary doImport( List<T> objects, ImportOptions importOptions )
{
if ( !objects.isEmpty() )
{
@@ -165,15 +170,14 @@
if ( importer != null )
{
- List<ImportConflict> importConflicts = importer.importObjects( objects, importOptions );
-
- importSummary.getConflicts().addAll( importConflicts );
- // importSummary.getCounts().add( count ); //FIXME
+ return importer.importObjects( objects, importOptions );
}
else
{
log.info( "Importer for object of type " + objects.get( 0 ).getClass().getSimpleName() + " not found." );
}
}
+
+ return null;
}
}
=== 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 2012-06-04 13:02:01 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2012-06-05 15:36:07 +0000
@@ -68,9 +68,9 @@
*/
final public class ExchangeClasses
{
- final private static Map<Class<? extends IdentifiableObject>, String> exportClasses;
+ private static Map<Class<? extends IdentifiableObject>, String> exportClasses;
- final private static Map<Class<? extends IdentifiableObject>, String> importClasses;
+ private static Map<Class<? extends IdentifiableObject>, String> importClasses;
static
{
@@ -119,16 +119,21 @@
exportClasses.put( MapLegendSet.class, "mapLegendSets" );
exportClasses.put( MapLayer.class, "mapLayers" );
- /*
exportClasses.put( User.class, "users" );
exportClasses.put( UserGroup.class, "userGroups" );
exportClasses.put( UserAuthorityGroup.class, "userRoles" );
- */
exportClasses.put( MessageConversation.class, "messageConversations" );
exportClasses.put( Interpretation.class, "interpretations" );
- importClasses = exportClasses;
+ importClasses = new LinkedHashMap<Class<? extends IdentifiableObject>, String>( exportClasses );
+
+ importClasses.remove( User.class );
+ importClasses.remove( UserAuthorityGroup.class );
+ importClasses.remove( UserGroup.class );
+
+ importClasses.remove( MessageConversation.class );
+ importClasses.remove( Interpretation.class );
}
public static Map<Class<? extends IdentifiableObject>, String> getExportMap()
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2012-04-13 01:16:51 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2012-06-05 15:36:07 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.springframework.stereotype.Service;
/**
=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java 2012-06-05 15:36:07 +0000
@@ -0,0 +1,78 @@
+package org.hisp.dhis.dxf2.metadata;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+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.common.Dxf2Namespace;
+import org.hisp.dhis.dxf2.importsummary.ImportCount;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "importSummary", namespace = Dxf2Namespace.NAMESPACE )
+public class ImportSummary
+{
+ private ImportCount importCount = new ImportCount();
+
+ private List<ImportTypeSummary> importTypeSummaries = new ArrayList<ImportTypeSummary>();
+
+ public ImportSummary()
+ {
+
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
+ public ImportCount getImportCount()
+ {
+ return importCount;
+ }
+
+ public void setImportCount( ImportCount importCount )
+ {
+ this.importCount = importCount;
+ }
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( localName = "typeSummaries", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "typeSummary", namespace = Dxf2Namespace.NAMESPACE )
+ public List<ImportTypeSummary> getImportTypeSummaries()
+ {
+ return importTypeSummaries;
+ }
+
+ public void setImportTypeSummaries( List<ImportTypeSummary> importTypeSummaries )
+ {
+ this.importTypeSummaries = importTypeSummaries;
+ }
+
+ //-------------------------------------------------------------------------
+ // Helpers
+ //-------------------------------------------------------------------------
+
+ public void incrementImportCount( ImportCount importCount )
+ {
+ this.importCount.incrementImported( importCount.getImported() );
+ this.importCount.incrementUpdated( importCount.getUpdated() );
+ this.importCount.incrementIgnored( importCount.getIgnored() );
+ }
+
+ public void incrementImported( int n )
+ {
+ importCount.incrementImported( n );
+ }
+
+ public void incrementUpdated( int n )
+ {
+ importCount.incrementUpdated( n );
+ }
+
+ public void incrementIgnored( int n )
+ {
+ importCount.incrementIgnored( n );
+ }
+}
=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java 2012-06-05 15:36:07 +0000
@@ -0,0 +1,115 @@
+package org.hisp.dhis.dxf2.metadata;
+
+/*
+ * Copyright (c) 2004-2012, 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 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.common.Dxf2Namespace;
+import org.hisp.dhis.dxf2.importsummary.ImportConflict;
+import org.hisp.dhis.dxf2.importsummary.ImportCount;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "typeSummary", namespace = Dxf2Namespace.NAMESPACE )
+public class ImportTypeSummary
+ extends ImportSummary
+{
+ private String type;
+
+ private ImportCount importCount = new ImportCount();
+
+ private List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+
+ public ImportTypeSummary( String type )
+ {
+ this.type = type;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true, namespace = Dxf2Namespace.NAMESPACE )
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
+ public ImportCount getImportCount()
+ {
+ return importCount;
+ }
+
+ public void setImportCount( ImportCount importCount )
+ {
+ this.importCount = importCount;
+ }
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( localName = "conflicts", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "conflict", namespace = Dxf2Namespace.NAMESPACE )
+ public List<ImportConflict> getImportConflicts()
+ {
+ return importConflicts;
+ }
+
+ public void setImportConflicts( List<ImportConflict> importConflicts )
+ {
+ this.importConflicts = importConflicts;
+ }
+
+ //-------------------------------------------------------------------------
+ // Helpers
+ //-------------------------------------------------------------------------
+
+ public void incrementImported()
+ {
+ importCount.incrementImported();
+ }
+
+ public void incrementUpdated()
+ {
+ importCount.incrementUpdated();
+ }
+
+ public void incrementIgnored()
+ {
+ importCount.incrementIgnored();
+ }
+}
=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportUtils.java 2012-06-05 15:36:07 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.dxf2.metadata;
+
+import org.hisp.dhis.common.IdentifiableObject;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ImportUtils
+{
+ /**
+ * @param object Object to get display name for
+ * @return A usable display name
+ */
+ public static String getDisplayName( Object object )
+ {
+ if ( object == null )
+ {
+ return "[ object is null ]";
+ }
+ else if ( IdentifiableObject.class.isInstance( object ) )
+ {
+ IdentifiableObject identifiableObject = (IdentifiableObject) object;
+
+ if ( identifiableObject.getName() != null && identifiableObject.getName().length() > 0 )
+ {
+ return identifiableObject.getName();
+ }
+ else if ( identifiableObject.getUid() != null && identifiableObject.getName().length() > 0 )
+ {
+ return identifiableObject.getUid();
+ }
+ else if ( identifiableObject.getCode() != null && identifiableObject.getName().length() > 0 )
+ {
+ return identifiableObject.getCode();
+ }
+
+ }
+
+ return object.getClass().getName();
+ }
+}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-04-23 14:12:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-06-05 15:36:07 +0000
@@ -27,9 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.dxf2.importsummary.ImportConflict;
-import org.hisp.dhis.dxf2.importsummary.ImportCount;
-
import java.util.List;
/**
@@ -47,7 +44,7 @@
* @param options Import options
* @return ImportConflict instance if a conflict occurred, if not null
*/
- List<ImportConflict> importObject( T object, ImportOptions options );
+ ImportTypeSummary importObject( T object, ImportOptions options );
/**
* Import a collection of objects.
@@ -56,14 +53,7 @@
* @param options Import options
* @return List of all the ImportConflicts encountered
*/
- List<ImportConflict> importObjects( List<T> objects, ImportOptions options );
-
- /**
- * Get an ImportCount instance for the current import numbers.
- *
- * @return ImportCount instance filled with current values
- */
- ImportCount getCurrentImportCount();
+ ImportTypeSummary importObjects( List<T> objects, ImportOptions options );
/**
* Can this importer handle a certain Class type?
=== 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 2012-06-05 07:58:08 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-05 15:36:07 +0000
@@ -39,10 +39,7 @@
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementOperandService;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
-import org.hisp.dhis.dxf2.importsummary.ImportCount;
-import org.hisp.dhis.dxf2.metadata.ImportOptions;
-import org.hisp.dhis.dxf2.metadata.Importer;
-import org.hisp.dhis.dxf2.metadata.ObjectBridge;
+import org.hisp.dhis.dxf2.metadata.*;
import org.hisp.dhis.dxf2.metadata.handlers.FieldHandler;
import org.hisp.dhis.dxf2.metadata.handlers.ObjectHandler;
import org.hisp.dhis.expression.Expression;
@@ -115,11 +112,7 @@
// Internal state
//-------------------------------------------------------------------------------------------------------
- protected int totalImported;
-
- protected int totalUpdated;
-
- protected int totalIgnored;
+ protected ImportTypeSummary summaryType;
protected ImportOptions options;
@@ -133,33 +126,31 @@
* @param object Object to import
* @return An ImportConflict instance if there was a conflict, otherwise null
*/
- protected List<ImportConflict> newObject( T object )
+ protected boolean newObject( T object )
{
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-
// make sure that the internalId is 0, so that the system will generate a ID
object.setId( 0 );
// FIXME add uidValidator.. part of bean validation impl?
// object.setUid( CodeGenerator.generateCode() );
- log.debug( "Trying to save new object => " + getDisplayName( object ) + " (" + object.getClass().getSimpleName() + ")" );
+ log.debug( "Trying to save new object => " + ImportUtils.getDisplayName( object ) + " (" + object.getClass().getSimpleName() + ")" );
Map<Field, Object> fields = detachFields( object );
- importConflicts.addAll( reattachFields( object, fields ) );
+ reattachFields( object, fields );
Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
objectBridge.saveObject( object );
updatePeriodTypes( object );
- importConflicts.addAll( reattachCollectionFields( object, collectionFields ) );
+ reattachCollectionFields( object, collectionFields );
objectBridge.updateObject( object );
log.debug( "Save successful." );
- return importConflicts;
+ return true;
}
/**
@@ -169,28 +160,26 @@
* @param oldObject The current version of the object
* @return An ImportConflict instance if there was a conflict, otherwise null
*/
- protected List<ImportConflict> updatedObject( T object, T oldObject )
+ protected boolean updatedObject( T object, T oldObject )
{
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-
- log.debug( "Starting update of object " + getDisplayName( oldObject ) + " (" + oldObject.getClass()
+ log.debug( "Starting update of object " + ImportUtils.getDisplayName( oldObject ) + " (" + oldObject.getClass()
.getSimpleName() + ")" );
Map<Field, Object> fields = detachFields( object );
- importConflicts.addAll( reattachFields( object, fields ) );
+ reattachFields( object, fields );
Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
oldObject.mergeWith( object );
updatePeriodTypes( oldObject );
- importConflicts.addAll( reattachCollectionFields( oldObject, collectionFields ) );
+ reattachCollectionFields( oldObject, collectionFields );
objectBridge.updateObject( oldObject );
log.debug( "Update successful." );
- return importConflicts;
+ return true;
}
// FIXME to static ATM, should be refactor out.. "type handler", not idObject
@@ -213,17 +202,16 @@
@Override
@SuppressWarnings( "unchecked" )
- public List<ImportConflict> importObjects( List<T> objects, ImportOptions options )
+ public ImportTypeSummary importObjects( List<T> objects, ImportOptions options )
{
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+ this.options = options;
+ this.summaryType = new ImportTypeSummary( importerClass.getSimpleName() );
if ( objects.isEmpty() )
{
- return importConflicts;
+ return summaryType;
}
- init( options );
-
preObjectsHandlers( objects );
for ( T object : objects )
@@ -237,8 +225,7 @@
Expression leftSide = getAndClearExpression( object, "leftSide" );
Expression rightSide = getAndClearExpression( object, "rightSide" );
- List<ImportConflict> conflicts = importObjectLocal( object );
- importConflicts.addAll( conflicts );
+ importObjectLocal( object );
if ( !options.isDryRun() )
{
@@ -258,7 +245,7 @@
postObjectsHandlers( objects );
- return importConflicts;
+ return summaryType;
}
@@ -433,17 +420,14 @@
}
@Override
- public List<ImportConflict> importObject( T object, ImportOptions options )
- {
- init( options );
-
- return importObjectLocal( object );
- }
-
- @Override
- public ImportCount getCurrentImportCount()
- {
- return new ImportCount( totalImported, totalUpdated, totalIgnored );
+ public ImportTypeSummary importObject( T object, ImportOptions options )
+ {
+ this.options = options;
+ this.summaryType = new ImportTypeSummary( importerClass.getSimpleName() );
+
+ importObjectLocal( object );
+
+ return summaryType;
}
@Override
@@ -453,131 +437,68 @@
}
//-------------------------------------------------------------------------------------------------------
- // Protected methods
- //-------------------------------------------------------------------------------------------------------
-
- /**
- * @param object Object to get display name for
- * @return A usable display name
- */
- protected String getDisplayName( Object object )
- {
- if ( object == null )
- {
- return "[ object is null ]";
- }
- else if ( IdentifiableObject.class.isInstance( object ) )
- {
- IdentifiableObject identifiableObject = (IdentifiableObject) object;
-
- if ( identifiableObject.getName() != null && identifiableObject.getName().length() > 0 )
- {
- return identifiableObject.getName();
- }
- else if ( identifiableObject.getUid() != null && identifiableObject.getName().length() > 0 )
- {
- return identifiableObject.getUid();
- }
- else if ( identifiableObject.getCode() != null && identifiableObject.getName().length() > 0 )
- {
- return identifiableObject.getCode();
- }
-
- }
-
- return object.getClass().getName();
- }
-
- //-------------------------------------------------------------------------------------------------------
// Helpers
//-------------------------------------------------------------------------------------------------------
- private void init( ImportOptions options )
- {
- this.options = options;
- totalImported = 0;
- totalUpdated = 0;
- totalIgnored = 0;
- }
-
- private List<ImportConflict> importObjectLocal( T object )
- {
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
- ImportConflict importConflict = validateIdentifiableObject( object );
-
- if ( importConflict == null )
+ private void importObjectLocal( T object )
+ {
+ if ( validateIdentifiableObject( object ) )
{
- importConflicts.addAll( startImport( object ) );
+ startImport( object );
}
else
{
- importConflicts.add( importConflict );
- }
-
- if ( importConflicts.isEmpty() )
- {
- totalIgnored++;
- }
-
- return importConflicts;
+ summaryType.incrementIgnored();
+ }
}
- private List<ImportConflict> startImport( T object )
+ private void startImport( T object )
{
T oldObject = objectBridge.getObject( object );
List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
{
- importConflicts.addAll( newObject( object ) );
-
- if ( importConflicts.isEmpty() )
+ if ( newObject( object ) )
{
- totalImported++;
+ summaryType.incrementImported();
}
}
else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
{
- importConflicts.addAll( updatedObject( object, oldObject ) );
-
- if ( importConflicts.isEmpty() )
+ if ( updatedObject( object, oldObject ) )
{
- totalUpdated++;
+ summaryType.incrementUpdated();
}
}
else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
{
if ( oldObject != null )
{
- importConflicts.addAll( updatedObject( object, oldObject ) );
-
- if ( importConflicts.isEmpty() )
+ if ( updatedObject( object, oldObject ) )
{
- totalUpdated++;
+ summaryType.incrementUpdated();
}
}
else
{
- importConflicts.addAll( newObject( object ) );
-
- if ( importConflicts.isEmpty() )
+ if ( newObject( object ) )
{
- totalImported++;
+ summaryType.incrementImported();
}
}
}
-
- return importConflicts;
}
- private ImportConflict validateIdentifiableObject( T object )
+ private boolean validateIdentifiableObject( T object )
{
ImportConflict conflict = null;
+ boolean success = true;
// FIXME add bean validation for this
if ( object.getName() == null || object.getName().length() == 0 )
{
- return new ImportConflict( getDisplayName( object ), "Empty name for object " + object );
+ conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty name for object " + object );
}
if ( NameableObject.class.isInstance( object ) )
@@ -586,36 +507,40 @@
if ( nameableObject.getShortName() == null || nameableObject.getShortName().length() == 0 )
{
- return new ImportConflict( getDisplayName( object ), "Empty shortName for object " + object );
+ conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty shortName for object " + object );
}
}
- // end
+
+ if ( conflict != null )
+ {
+ summaryType.getImportConflicts().add( conflict );
+ }
if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
{
- conflict = validateForNewStrategy( object );
+ success = validateForNewStrategy( object );
}
else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
{
- conflict = validateForUpdatesStrategy( object );
+ success = validateForUpdatesStrategy( object );
}
else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
{
// if we have a match on at least one of the objects, then assume update
if ( objectBridge.getObjects( object ).size() > 0 )
{
- conflict = validateForUpdatesStrategy( object );
+ success = validateForUpdatesStrategy( object );
}
else
{
- conflict = validateForNewStrategy( object );
+ success = validateForNewStrategy( object );
}
}
- return conflict;
+ return success;
}
- private ImportConflict validateForUpdatesStrategy( T object )
+ private boolean validateForUpdatesStrategy( T object )
{
ImportConflict conflict = null;
Collection<T> objects = objectBridge.getObjects( object );
@@ -629,10 +554,15 @@
conflict = reportMoreThanOneConflict( object );
}
- return conflict;
+ if ( conflict != null )
+ {
+ summaryType.getImportConflicts().add( conflict );
+ }
+
+ return true;
}
- private ImportConflict validateForNewStrategy( T object )
+ private boolean validateForNewStrategy( T object )
{
ImportConflict conflict = null;
Collection<T> objects = objectBridge.getObjects( object );
@@ -642,22 +572,27 @@
conflict = reportConflict( object );
}
- return conflict;
+ if ( conflict != null )
+ {
+ summaryType.getImportConflicts().add( conflict );
+ }
+
+ return true;
}
private ImportConflict reportLookupConflict( IdentifiableObject object )
{
- return new ImportConflict( getDisplayName( object ), "Object does not exist." );
+ return new ImportConflict( ImportUtils.getDisplayName( object ), "Object does not exist." );
}
private ImportConflict reportMoreThanOneConflict( IdentifiableObject object )
{
- return new ImportConflict( getDisplayName( object ), "More than one object matches identifiers." );
+ return new ImportConflict( ImportUtils.getDisplayName( object ), "More than one object matches identifiers." );
}
private ImportConflict reportConflict( IdentifiableObject object )
{
- return new ImportConflict( getDisplayName( object ), "Object already exists." );
+ return new ImportConflict( ImportUtils.getDisplayName( object ), "Object already exists." );
}
private IdentifiableObject findObjectByReference( IdentifiableObject identifiableObject )
@@ -706,10 +641,8 @@
return fieldMap;
}
- private List<ImportConflict> reattachFields( Object object, Map<Field, Object> fields )
+ private void reattachFields( Object object, Map<Field, Object> fields )
{
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-
for ( Field field : fields.keySet() )
{
IdentifiableObject idObject = (IdentifiableObject) fields.get( field );
@@ -717,7 +650,10 @@
if ( ref == null )
{
- reportReferenceError(object, importConflicts, idObject);
+ if ( ExchangeClasses.getImportMap().get( idObject.getClass() ) != null )
+ {
+ reportReferenceError( object, idObject );
+ }
}
if ( !options.isDryRun() )
@@ -725,8 +661,6 @@
ReflectionUtils.invokeSetterMethod( field.getName(), object, ref );
}
}
-
- return importConflicts;
}
private Map<Field, Collection<Object>> detachCollectionFields( final Object object )
@@ -753,10 +687,8 @@
return collectionFields;
}
- private List<ImportConflict> reattachCollectionFields( Object object, Map<Field, Collection<Object>> collectionFields )
+ private void reattachCollectionFields( Object object, Map<Field, Collection<Object>> collectionFields )
{
- List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
-
for ( Field field : collectionFields.keySet() )
{
Collection<Object> collection = collectionFields.get( field );
@@ -772,7 +704,10 @@
}
else
{
- reportReferenceError( object, importConflicts, idObject );
+ if ( ExchangeClasses.getImportMap().get( idObject.getClass() ) != null )
+ {
+ reportReferenceError( object, idObject );
+ }
}
}
@@ -781,11 +716,9 @@
ReflectionUtils.invokeSetterMethod( field.getName(), object, objects );
}
}
-
- return importConflicts;
}
- private void reportReferenceError( Object object, List<ImportConflict> importConflicts, Object idObject )
+ private void reportReferenceError( Object object, Object idObject )
{
String referenceName = idObject != null ? idObject.getClass().getSimpleName() : "null";
String objectName = object != null ? object.getClass().getSimpleName() : "null";
@@ -795,7 +728,7 @@
log.warn( logMsg );
- ImportConflict importConflict = new ImportConflict( getDisplayName( object ), logMsg );
- importConflicts.add( importConflict );
+ ImportConflict importConflict = new ImportConflict( ImportUtils.getDisplayName( object ), logMsg );
+ summaryType.getImportConflicts().add( importConflict );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-03-28 07:40:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-06-05 15:36:07 +0000
@@ -172,6 +172,18 @@
return userStore.getAllUsers();
}
+ @Override
+ public Collection<User> getAllUsersBetween( int first, int max )
+ {
+ return userStore.getAllUsersBetween( first, max );
+ }
+
+ @Override
+ public Collection<User> getUsersByLastUpdated( Date lastUpdated )
+ {
+ return userStore.getUsersByLastUpdated( lastUpdated );
+ }
+
public User getUser( int userId )
{
return userStore.getUser( userId );
@@ -214,7 +226,7 @@
}
public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit unit, String userName,
- int first, int max )
+ int first, int max )
{
return userStore.getUsersByOrganisationUnitBetweenByName( unit, userName, first, max );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-03-28 07:40:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-06-05 15:36:07 +0000
@@ -100,6 +100,27 @@
return session.createQuery( "from User" ).list();
}
+ @Override
+ public Collection<User> getAllUsersBetween( int first, int max )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Query query = session.createQuery( "from User" );
+ query.setFirstResult( first );
+ query.setMaxResults( max );
+
+ return query.list();
+ }
+
+ @Override
+ public Collection<User> getUsersByLastUpdated( Date lastUpdated )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( User.class );
+ return criteria.add( Restrictions.ge( "lastUpdated", lastUpdated ) ).list();
+ }
+
public Collection<User> getUsersWithoutOrganisationUnit()
{
Collection<User> users = getAllUsers();
@@ -258,7 +279,7 @@
}
public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
- int first, int max )
+ int first, int max )
{
return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max );
}
=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java 2012-04-16 15:48:50 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java 2012-06-05 15:36:07 +0000
@@ -27,25 +27,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.InputStream;
-
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ImportSummary;
import org.hisp.dhis.dxf2.metadata.MetaData;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import java.io.InputStream;
+
/**
* @author bobj
*/
-public class Dxf2MetaDataProducer
+public class Dxf2MetaDataProducer
extends DefaultProducer
{
private static final Log log = LogFactory.getLog( Dxf2MetaDataProducer.class );
- public Dxf2MetaDataProducer( Dxf2MetaDataEndpoint endpoint)
+ public Dxf2MetaDataProducer( Dxf2MetaDataEndpoint endpoint )
{
super( endpoint );
}
@@ -54,11 +54,11 @@
public void process( Exchange exchange ) throws Exception
{
log.info( this.getEndpoint().getEndpointUri() + " : " + exchange.getIn().getBody() );
-
+
Dxf2MetaDataEndpoint endpoint = (Dxf2MetaDataEndpoint) this.getEndpoint();
MetaData metadata = JacksonUtils.fromXml( (InputStream) exchange.getIn().getBody(), MetaData.class );
-
- ImportSummary summary = endpoint.getImportService().importMetaData(metadata, endpoint.getImportOptions());
- exchange.getOut().setBody(JacksonUtils.toXmlAsString( summary ) );
+
+ ImportSummary summary = endpoint.getImportService().importMetaData( metadata, endpoint.getImportOptions() );
+ exchange.getOut().setBody( JacksonUtils.toXmlAsString( summary ) );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-06-04 20:01:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-06-05 15:36:07 +0000
@@ -30,7 +30,6 @@
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.common.view.ExportView;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.*;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java 2012-05-28 14:25:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java 2012-06-05 15:36:07 +0000
@@ -28,10 +28,19 @@
*/
import org.hisp.dhis.api.controller.AbstractCrudController;
+import org.hisp.dhis.api.controller.WebMetaData;
+import org.hisp.dhis.api.controller.WebOptions;
+import org.hisp.dhis.common.Pager;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -41,4 +50,41 @@
extends AbstractCrudController<User>
{
public static final String RESOURCE_PATH = "/users";
+
+ @Autowired
+ private UserService userService;
+
+ @Override
+ protected List<User> getEntityList( WebMetaData metaData, WebOptions options )
+ {
+ List<User> entityList;
+
+ Date lastUpdated = options.getLastUpdated();
+
+ if ( lastUpdated != null )
+ {
+ entityList = new ArrayList<User>( userService.getUsersByLastUpdated( lastUpdated ) );
+ }
+ else if ( options.hasPaging() )
+ {
+ int count = userService.getUserCount();
+
+ Pager pager = new Pager( options.getPage(), count );
+ metaData.setPager( pager );
+
+ entityList = new ArrayList<User>( userService.getAllUsersBetween( pager.getOffset(), pager.getPageSize() ) );
+ }
+ else
+ {
+ entityList = new ArrayList<User>( userService.getAllUsers() );
+ }
+
+ return entityList;
+ }
+
+ @Override
+ protected User getEntity( String uid )
+ {
+ return userService.getUser( uid );
+ }
}