dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16891
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6555: more refactoring, removed need to have separate import classes
------------------------------------------------------------
revno: 6555
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-04-13 04:16:51 +0300
message:
more refactoring, removed need to have separate import classes
removed:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/ConstantImporter.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/IndicatorImporter.java
added:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java
modified:
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/ImportService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java
dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml
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/webdomain/Resources.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-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-04-11 20:16:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-13 01:16:51 +0000
@@ -27,13 +27,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.constant.Constant;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.importsummary.ImportCount;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.importers.DefaultImporter;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorGroup;
+import org.hisp.dhis.indicator.IndicatorGroupSet;
+import org.hisp.dhis.indicator.IndicatorType;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -50,7 +62,7 @@
// Dependencies
//-------------------------------------------------------------------------------------------------------
- @Autowired
+ @Autowired( required = false )
private Set<Importer> importerClasses = new HashSet<Importer>();
private <T> Importer<T> findImporterClass( List<?> clazzes )
@@ -98,20 +110,52 @@
//-------------------------------------------------------------------------------------------------------
@Override
- public ImportSummary importDxf2( MetaData dxf2 )
+ public ImportSummary importMetaData( MetaData metaData )
{
- return importDxf2( dxf2, ImportOptions.getDefaultImportOptions() );
+ return importMetaData( metaData, ImportOptions.getDefaultImportOptions() );
}
@Override
- public ImportSummary importDxf2( MetaData dxf2, ImportOptions importOptions )
+ public ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions )
{
ImportSummary importSummary = new ImportSummary();
// Imports.. this could be made even more generic, just need to make sure that everything is imported in
// the correct order
- doImport( dxf2.getConstants(), importOptions, importSummary );
- doImport( dxf2.getIndicators(), importOptions, importSummary );
+
+ // FIXME this is not currently in the "correct" order
+ doImport( metaData.getAttributeTypes(), importOptions, importSummary );
+ doImport( metaData.getCategories(), importOptions, importSummary );
+ doImport( metaData.getCategoryCombos(), importOptions, importSummary );
+ doImport( metaData.getCategoryOptions(), importOptions, importSummary );
+ doImport( metaData.getCategoryOptionCombos(), importOptions, importSummary );
+ doImport( metaData.getDataElements(), importOptions, importSummary );
+ doImport( metaData.getDataElementGroups(), importOptions, importSummary );
+ doImport( metaData.getDataElementGroupSets(), importOptions, importSummary );
+ doImport( metaData.getCharts(), importOptions, importSummary );
+ doImport( metaData.getConstants(), importOptions, importSummary );
+ doImport( metaData.getDataSets(), importOptions, importSummary );
+ doImport( metaData.getDocuments(), importOptions, importSummary );
+ doImport( metaData.getIndicatorTypes(), importOptions, importSummary );
+ doImport( metaData.getIndicators(), importOptions, importSummary );
+ doImport( metaData.getIndicatorGroups(), importOptions, importSummary );
+ doImport( metaData.getIndicatorGroupSets(), importOptions, importSummary );
+ doImport( metaData.getMaps(), importOptions, importSummary );
+ doImport( metaData.getMapLegends(), importOptions, importSummary );
+ doImport( metaData.getMapLegendSets(), importOptions, importSummary );
+ doImport( metaData.getMapLayers(), importOptions, importSummary );
+ doImport( metaData.getMessageConversations(), importOptions, importSummary );
+ doImport( metaData.getOrganisationUnits(), importOptions, importSummary );
+ doImport( metaData.getOrganisationUnitGroups(), importOptions, importSummary );
+ doImport( metaData.getOrganisationUnitGroupSets(), importOptions, importSummary );
+ doImport( metaData.getReports(), importOptions, importSummary );
+ doImport( metaData.getReportTables(), importOptions, importSummary );
+ doImport( metaData.getSqlViews(), importOptions, importSummary );
+ doImport( metaData.getUsers(), importOptions, importSummary );
+ doImport( metaData.getUserGroups(), importOptions, importSummary );
+ doImport( metaData.getUserAuthorityGroups(), importOptions, importSummary );
+ doImport( metaData.getValidationRules(), importOptions, importSummary );
+ doImport( metaData.getValidationRuleGroups(), importOptions, importSummary );
return importSummary;
}
=== 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-11 15:11:09 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2012-04-13 01:16:51 +0000
@@ -36,7 +36,7 @@
@Service
public interface ImportService
{
- ImportSummary importDxf2( MetaData dxf2 );
+ ImportSummary importMetaData( MetaData metaData );
- ImportSummary importDxf2( MetaData dxf2, ImportOptions importOptions );
+ ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions );
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2012-04-11 15:11:09 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2012-04-13 01:16:51 +0000
@@ -619,7 +619,7 @@
@Override
public String toString()
{
- return "DXF2{" +
+ return "MetaData{" +
"attributeTypes=" + attributeTypes.size() +
", users=" + users.size() +
", userAuthorityGroups=" + userAuthorityGroups.size() +
=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 2012-04-11 20:16:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 1970-01-01 00:00:00 +0000
@@ -1,570 +0,0 @@
-package org.hisp.dhis.dxf2.metadata.importers;
-
-/*
- * Copyright (c) 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 java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.CodeGenerator;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.NameableObject;
-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.importexport.ImportStrategy;
-import org.hisp.dhis.system.util.ReflectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * Abstract importer that can handle IdentifiableObject and NameableObject.
- *
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public abstract class AbstractImporter<T extends BaseIdentifiableObject>
- implements Importer<T>
-{
- private static final Log log = LogFactory.getLog( AbstractImporter.class );
-
- //-------------------------------------------------------------------------------------------------------
- // Dependencies
- //-------------------------------------------------------------------------------------------------------
-
- @Autowired
- protected IdentifiableObjectManager manager;
-
- //-------------------------------------------------------------------------------------------------------
- // Current import counts
- //-------------------------------------------------------------------------------------------------------
-
- protected int imported;
-
- protected int updated;
-
- protected int ignored;
-
- //-------------------------------------------------------------------------------------------------------
- // Mappings from identifier (uid, name, code) to a db object.
- //
- // WARNING: These maps might be out-of-date, depending on if new inserts has been made after the were
- // fetched.
- //-------------------------------------------------------------------------------------------------------
-
- protected Map<String, T> uidMap;
-
- protected Map<String, T> codeMap;
-
- protected Map<String, T> nameMap;
-
- protected Map<String, T> shortNameMap;
-
- protected Map<String, T> alternativeNameMap;
-
- //-------------------------------------------------------------------------------------------------------
- // Generic implementations of newObject and updatedObject
- //-------------------------------------------------------------------------------------------------------
-
- /**
- * Called every time a new object is to be imported.
- *
- * @param object Object to import
- * @param options Current import options
- * @return An ImportConflict instance if there was a conflict, otherwise null
- */
- protected ImportConflict newObject( T object, ImportOptions options )
- {
- if ( options.isDryRun() )
- {
- return null;
- }
-
- log.info( "Trying to save new object with UID: " + object.getUid() );
-
- findAndUpdateCollections( object );
- //manager.save( object );
- //updateIdMaps( object );
-
- log.info( "Save successful." );
-
- return null;
- }
-
- /**
- * Update object from old => new.
- *
- * @param object Object to import
- * @param oldObject The current version of the object
- * @param options Current import options
- * @return An ImportConflict instance if there was a conflict, otherwise null
- */
- protected ImportConflict updatedObject( T object, T oldObject, ImportOptions options )
- {
- if ( options.isDryRun() )
- {
- return null;
- }
-
- log.info( "Trying to update object with UID: " + oldObject.getUid() );
-
- findAndUpdateCollections( object );
- // oldObject.mergeWith( object );
- // manager.update( oldObject );
-
- log.info( "Update successful." );
-
- return null;
- }
-
- private void findAndUpdateCollections( T object )
- {
- Field[] fields = object.getClass().getDeclaredFields();
-
- for ( Field field : fields )
- {
- if ( ReflectionUtils.isType( field, IdentifiableObject.class ) )
- {
- IdentifiableObject identifiableObject = ReflectionUtils.invokeGetterMethod( field.getName(), object );
- log.info( identifiableObject );
- }
- else
- {
- boolean b = ReflectionUtils.isCollection( field.getName(), object, IdentifiableObject.class );
-
- if ( b )
- {
- Collection<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod( field.getName(), object );
- log.info( identifiableObjects );
- }
- }
- }
- }
-
- /**
- * Current object name, used to fill name part of a ImportConflict
- *
- * @return Name of object
- */
- protected abstract String getObjectName();
-
- //-------------------------------------------------------------------------------------------------------
- // Importer<T> Implementation
- //-------------------------------------------------------------------------------------------------------
-
- @Override
- public List<ImportConflict> importObjects( List<T> objects, ImportOptions options )
- {
- List<ImportConflict> conflicts = new ArrayList<ImportConflict>();
-
- if ( objects.isEmpty() )
- {
- return conflicts;
- }
-
- reset( objects.get( 0 ) );
-
- for ( T object : objects )
- {
- ImportConflict importConflict = importObjectLocal( object, options );
-
- if ( importConflict != null )
- {
- conflicts.add( importConflict );
- }
- }
-
- return conflicts;
- }
-
- @Override
- public ImportConflict importObject( T object, ImportOptions options )
- {
- if ( object != null )
- {
- reset( object );
- }
-
- return importObjectLocal( object, options );
- }
-
- @Override
- public ImportCount getCurrentImportCount()
- {
- return new ImportCount( imported, updated, ignored );
- }
-
- //-------------------------------------------------------------------------------------------------------
- // Internal methods
- //-------------------------------------------------------------------------------------------------------
-
- private void reset( T type )
- {
- imported = 0;
- updated = 0;
- ignored = 0;
-
- uidMap = manager.getIdMap( (Class<T>) type.getClass(), IdentifiableObject.IdentifiableProperty.UID );
- codeMap = manager.getIdMap( (Class<T>) type.getClass(), IdentifiableObject.IdentifiableProperty.CODE );
- nameMap = manager.getIdMap( (Class<T>) type.getClass(), IdentifiableObject.IdentifiableProperty.NAME );
-
- if ( NameableObject.class.isInstance( type ) )
- {
- shortNameMap = (Map<String, T>) manager.getIdMap( (Class<? extends NameableObject>) type.getClass(), NameableObject.NameableProperty.SHORT_NAME );
- alternativeNameMap = (Map<String, T>) manager.getIdMap( (Class<? extends NameableObject>) type.getClass(), NameableObject.NameableProperty.ALTERNATIVE_NAME );
- }
- }
-
- private ImportConflict importObjectLocal( T object, ImportOptions options )
- {
- ImportConflict conflict = validateIdentifiableObject( object, options );
-
- if ( conflict == null )
- {
- conflict = startImport( object, options );
- }
-
- if ( conflict != null )
- {
- ignored++;
- }
-
- return conflict;
- }
-
- private ImportConflict startImport( T object, ImportOptions options )
- {
- T oldObject = getObject( object );
- ImportConflict conflict;
-
- if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
- {
- prepareIdentifiableObject( object );
- conflict = newObject( object, options );
-
- if ( conflict != null )
- {
- return conflict;
- }
-
- imported++;
- }
- else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
- {
- conflict = updatedObject( object, oldObject, options );
-
- if ( conflict != null )
- {
- return conflict;
- }
-
- updated++;
- }
- else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
- {
- if ( oldObject != null )
- {
- conflict = updatedObject( object, oldObject, options );
-
- if ( conflict != null )
- {
- return conflict;
- }
-
- updated++;
- }
- else
- {
- prepareIdentifiableObject( object );
- conflict = newObject( object, options );
-
- if ( conflict != null )
- {
- return conflict;
- }
-
- imported++;
- }
- }
-
- return null;
- }
-
- private ImportConflict validateIdentifiableObject( T object, ImportOptions options )
- {
- T uidObject = uidMap.get( object.getUid() );
- T codeObject = codeMap.get( object.getCode() );
- T nameObject = nameMap.get( object.getName() );
-
- T shortNameObject = null;
- T alternativeNameObject = null;
-
- if ( NameableObject.class.isInstance( object ) )
- {
- NameableObject nameableObject = (NameableObject) object;
-
- shortNameObject = shortNameMap.get( nameableObject.getShortName() );
- alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
- }
-
- ImportConflict conflict = null;
-
- if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
- {
- conflict = validateForNewStrategy( object, options );
- }
- else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
- {
- conflict = validateForUpdatesStrategy( object, options );
- }
- 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 ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
- {
- conflict = validateForUpdatesStrategy( object, options );
- }
- else
- {
- conflict = validateForNewStrategy( object, options );
- }
- }
-
- return conflict;
- }
-
- private ImportConflict validateForUpdatesStrategy( T object, ImportOptions options )
- {
- T uidObject = uidMap.get( object.getUid() );
- T codeObject = codeMap.get( object.getCode() );
- T nameObject = nameMap.get( object.getName() );
-
- T shortNameObject = null;
- T alternativeNameObject = null;
-
- if ( NameableObject.class.isInstance( object ) )
- {
- NameableObject nameableObject = (NameableObject) object;
-
- shortNameObject = shortNameMap.get( nameableObject.getShortName() );
- alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
- }
-
- ImportConflict conflict = null;
-
- Set<T> nonNullObjects = new HashSet<T>();
-
- if ( uidObject != null )
- {
- nonNullObjects.add( uidObject );
- }
-
- if ( codeObject != null )
- {
- nonNullObjects.add( codeObject );
- }
-
- if ( nameObject != null )
- {
- nonNullObjects.add( nameObject );
- }
-
- if ( shortNameObject != null )
- {
- nonNullObjects.add( shortNameObject );
- }
-
- if ( alternativeNameObject != null )
- {
- nonNullObjects.add( alternativeNameObject );
- }
-
- if ( nonNullObjects.isEmpty() )
- {
- conflict = reportLookupConflict( object, options );
- }
- else if ( nonNullObjects.size() > 1 )
- {
- conflict = reportMoreThanOneConflict( object, options );
- }
-
- return conflict;
- }
-
- private ImportConflict validateForNewStrategy( T object, ImportOptions options )
- {
- T uidObject = uidMap.get( object.getUid() );
- T codeObject = codeMap.get( object.getCode() );
- T nameObject = nameMap.get( object.getName() );
-
- T shortNameObject = null;
- T alternativeNameObject = null;
-
- if ( NameableObject.class.isInstance( object ) )
- {
- NameableObject nameableObject = (NameableObject) object;
-
- shortNameObject = shortNameMap.get( nameableObject.getShortName() );
- alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
- }
-
- ImportConflict conflict = null;
-
- if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
- {
- conflict = reportConflict( object, options );
- }
-
- return conflict;
- }
-
- private ImportConflict reportLookupConflict( IdentifiableObject object, ImportOptions options )
- {
- return new ImportConflict( getDisplayName( object ), "Object does not exist." );
- }
-
- private ImportConflict reportMoreThanOneConflict( IdentifiableObject object, ImportOptions options )
- {
- return new ImportConflict( getDisplayName( object ), "More than one object matches identifiers." );
- }
-
- private ImportConflict reportConflict( IdentifiableObject object, ImportOptions options )
- {
- return new ImportConflict( getDisplayName( object ), "Object already exists." );
- }
-
- private T getObject( T object )
- {
- T matchedObject = uidMap.get( object.getUid() );
-
- if ( matchedObject != null )
- {
- return matchedObject;
- }
-
- matchedObject = codeMap.get( object.getCode() );
-
- if ( matchedObject != null )
- {
- return matchedObject;
- }
-
- matchedObject = nameMap.get( object.getName() );
-
- if ( matchedObject != null )
- {
- return matchedObject;
- }
-
- if ( NameableObject.class.isInstance( object ) )
- {
- NameableObject nameableObject = (NameableObject) object;
-
- matchedObject = shortNameMap.get( nameableObject.getShortName() );
-
- if ( matchedObject != null )
- {
- return matchedObject;
- }
-
- matchedObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
-
- if ( matchedObject != null )
- {
- return matchedObject;
- }
- }
-
- return matchedObject;
- }
-
- //-------------------------------------------------------------------------------------------------------
- // Protected methods
- //-------------------------------------------------------------------------------------------------------
-
- protected void updateIdMaps( T object )
- {
- if ( object.getUid() != null )
- {
- uidMap.put( object.getUid(), object );
- }
-
- if ( object.getCode() != null )
- {
- codeMap.put( object.getCode(), object );
- }
-
- if ( object.getName() != null )
- {
- nameMap.put( object.getName(), object );
- }
-
- if ( NameableObject.class.isInstance( object ) )
- {
- NameableObject nameableObject = (NameableObject) object;
-
- if ( nameableObject.getShortName() != null )
- {
- shortNameMap.put( nameableObject.getShortName(), object );
- }
-
- if ( nameableObject.getAlternativeName() != null )
- {
- alternativeNameMap.put( nameableObject.getAlternativeName(), object );
- }
- }
- }
-
- protected void prepareIdentifiableObject( BaseIdentifiableObject object )
- {
- if ( object.getUid() == null && object.getLastUpdated() == null )
- {
- object.setAutoFields();
- }
- else if ( object.getUid() == null )
- {
- object.setUid( CodeGenerator.generateCode() );
- }
- }
-
- /**
- * @param object Object to get display name for
- * @return A usable display name
- */
- protected String getDisplayName( IdentifiableObject object )
- {
- return object.getClass().getName();
- }
-}
=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/ConstantImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/ConstantImporter.java 2012-04-11 15:11:09 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/ConstantImporter.java 1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
-package org.hisp.dhis.dxf2.metadata.importers;
-
-/*
- * Copyright (c) 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 org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.constant.Constant;
-import org.springframework.stereotype.Component;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Component
-public class ConstantImporter
- extends AbstractImporter<Constant>
-{
- private static final Log log = LogFactory.getLog( ConstantImporter.class );
-
- @Override
- protected String getObjectName()
- {
- return this.getClass().getName();
- }
-
- @Override
- public boolean canHandle( Class<?> clazz )
- {
- return Constant.class.equals( clazz );
- }
-}
=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java 2012-04-13 01:16:51 +0000
@@ -0,0 +1,589 @@
+package org.hisp.dhis.dxf2.metadata.importers;
+
+/*
+ * Copyright (c) 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.*;
+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.importexport.ImportStrategy;
+import org.hisp.dhis.system.util.ReflectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.lang.reflect.Field;
+import java.util.*;
+
+/**
+ * Importer that can handle IdentifiableObject and NameableObject.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultImporter<T extends BaseIdentifiableObject>
+ implements Importer<T>
+{
+ private static final Log log = LogFactory.getLog( DefaultImporter.class );
+
+ //-------------------------------------------------------------------------------------------------------
+ // Dependencies
+ //-------------------------------------------------------------------------------------------------------
+
+ @Autowired
+ protected IdentifiableObjectManager manager;
+
+ //-------------------------------------------------------------------------------------------------------
+ // Constructor
+ //-------------------------------------------------------------------------------------------------------
+
+ public DefaultImporter( Class<T> importerClass )
+ {
+ this.importerClass = importerClass;
+ this.nameable = NameableObject.class.isAssignableFrom( importerClass );
+ }
+
+ private final Class<T> importerClass;
+
+ private final boolean nameable;
+
+ //-------------------------------------------------------------------------------------------------------
+ // Current import counts
+ //-------------------------------------------------------------------------------------------------------
+
+ protected int imported;
+
+ protected int updated;
+
+ protected int ignored;
+
+ //-------------------------------------------------------------------------------------------------------
+ // Mappings from identifier (uid, name, code) to a db object.
+ //
+ // WARNING: These maps might be out-of-date, depending on if new inserts has been made after the were
+ // fetched.
+ //-------------------------------------------------------------------------------------------------------
+
+ protected Map<String, T> uidMap;
+
+ protected Map<String, T> codeMap;
+
+ protected Map<String, T> nameMap;
+
+ protected Map<String, T> shortNameMap;
+
+ protected Map<String, T> alternativeNameMap;
+
+ //-------------------------------------------------------------------------------------------------------
+ // Generic implementations of newObject and updatedObject
+ //-------------------------------------------------------------------------------------------------------
+
+ /**
+ * Called every time a new object is to be imported.
+ *
+ * @param object Object to import
+ * @param options Current import options
+ * @return An ImportConflict instance if there was a conflict, otherwise null
+ */
+ protected ImportConflict newObject( T object, ImportOptions options )
+ {
+ if ( options.isDryRun() )
+ {
+ return null;
+ }
+
+ log.info( "Trying to save new object with UID: " + object.getUid() );
+
+ findAndUpdateReferences( object );
+ //manager.save( object );
+ //updateIdMaps( object );
+
+ log.info( "Save successful." );
+
+ return null;
+ }
+
+ /**
+ * Update object from old => new.
+ *
+ * @param object Object to import
+ * @param oldObject The current version of the object
+ * @param options Current import options
+ * @return An ImportConflict instance if there was a conflict, otherwise null
+ */
+ protected ImportConflict updatedObject( T object, T oldObject, ImportOptions options )
+ {
+ if ( options.isDryRun() )
+ {
+ return null;
+ }
+
+ log.info( "Trying to update object with UID: " + oldObject.getUid() );
+
+ findAndUpdateReferences( object );
+ // oldObject.mergeWith( object );
+ // manager.update( oldObject );
+
+ log.info( "Update successful." );
+
+ return null;
+ }
+
+ private void findAndUpdateReferences( T object )
+ {
+ Field[] fields = object.getClass().getDeclaredFields();
+
+ for ( Field field : fields )
+ {
+ if ( ReflectionUtils.isType( field, IdentifiableObject.class ) )
+ {
+ IdentifiableObject identifiableObject = ReflectionUtils.invokeGetterMethod( field.getName(), object );
+
+ if ( identifiableObject != null )
+ {
+ log.info( "VERIFYING: " + identifiableObject );
+ }
+ }
+ else
+ {
+ boolean b = ReflectionUtils.isCollection( field.getName(), object, IdentifiableObject.class );
+
+ if ( b )
+ {
+ Collection<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod( field.getName(), object );
+
+ if ( !identifiableObjects.isEmpty() )
+ {
+ log.info( "VERIFYING: " + identifiableObjects );
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Current object name, used to fill name part of a ImportConflict
+ *
+ * @return Name of object
+ */
+ protected String getObjectName()
+ {
+ return importerClass.getSimpleName();
+ }
+
+ @Override
+ public boolean canHandle( Class<?> clazz )
+ {
+ return importerClass.equals( clazz );
+ }
+
+ //-------------------------------------------------------------------------------------------------------
+ // Importer<T> Implementation
+ //-------------------------------------------------------------------------------------------------------
+
+ @Override
+ public List<ImportConflict> importObjects( List<T> objects, ImportOptions options )
+ {
+ List<ImportConflict> conflicts = new ArrayList<ImportConflict>();
+
+ if ( objects.isEmpty() )
+ {
+ return conflicts;
+ }
+
+ reset();
+
+ for ( T object : objects )
+ {
+ ImportConflict importConflict = importObjectLocal( object, options );
+
+ if ( importConflict != null )
+ {
+ conflicts.add( importConflict );
+ }
+ }
+
+ return conflicts;
+ }
+
+ @Override
+ public ImportConflict importObject( T object, ImportOptions options )
+ {
+ reset();
+
+ return importObjectLocal( object, options );
+ }
+
+ @Override
+ public ImportCount getCurrentImportCount()
+ {
+ return new ImportCount( imported, updated, ignored );
+ }
+
+ //-------------------------------------------------------------------------------------------------------
+ // Internal methods
+ //-------------------------------------------------------------------------------------------------------
+
+ private void reset()
+ {
+ imported = 0;
+ updated = 0;
+ ignored = 0;
+
+ uidMap = manager.getIdMap( importerClass, IdentifiableObject.IdentifiableProperty.UID );
+ codeMap = manager.getIdMap( importerClass, IdentifiableObject.IdentifiableProperty.CODE );
+ nameMap = manager.getIdMap( importerClass, IdentifiableObject.IdentifiableProperty.NAME );
+
+ if ( nameable )
+ {
+ shortNameMap = (Map<String, T>) manager.getIdMap( (Class<? extends NameableObject>) importerClass, NameableObject.NameableProperty.SHORT_NAME );
+ alternativeNameMap = (Map<String, T>) manager.getIdMap( (Class<? extends NameableObject>) importerClass, NameableObject.NameableProperty.ALTERNATIVE_NAME );
+ }
+ }
+
+ private ImportConflict importObjectLocal( T object, ImportOptions options )
+ {
+ ImportConflict conflict = validateIdentifiableObject( object, options );
+
+ if ( conflict == null )
+ {
+ conflict = startImport( object, options );
+ }
+
+ if ( conflict != null )
+ {
+ ignored++;
+ }
+
+ return conflict;
+ }
+
+ private ImportConflict startImport( T object, ImportOptions options )
+ {
+ T oldObject = getObject( object );
+ ImportConflict conflict;
+
+ if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
+ {
+ prepareIdentifiableObject( object );
+ conflict = newObject( object, options );
+
+ if ( conflict != null )
+ {
+ return conflict;
+ }
+
+ imported++;
+ }
+ else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
+ {
+ conflict = updatedObject( object, oldObject, options );
+
+ if ( conflict != null )
+ {
+ return conflict;
+ }
+
+ updated++;
+ }
+ else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
+ {
+ if ( oldObject != null )
+ {
+ conflict = updatedObject( object, oldObject, options );
+
+ if ( conflict != null )
+ {
+ return conflict;
+ }
+
+ updated++;
+ }
+ else
+ {
+ prepareIdentifiableObject( object );
+ conflict = newObject( object, options );
+
+ if ( conflict != null )
+ {
+ return conflict;
+ }
+
+ imported++;
+ }
+ }
+
+ return null;
+ }
+
+ private ImportConflict validateIdentifiableObject( T object, ImportOptions options )
+ {
+ T uidObject = uidMap.get( object.getUid() );
+ T codeObject = codeMap.get( object.getCode() );
+ T nameObject = nameMap.get( object.getName() );
+
+ T shortNameObject = null;
+ T alternativeNameObject = null;
+
+ if ( nameable )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ shortNameObject = shortNameMap.get( nameableObject.getShortName() );
+ alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
+ }
+
+ ImportConflict conflict = null;
+
+ if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
+ {
+ conflict = validateForNewStrategy( object, options );
+ }
+ else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
+ {
+ conflict = validateForUpdatesStrategy( object, options );
+ }
+ 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 ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
+ {
+ conflict = validateForUpdatesStrategy( object, options );
+ }
+ else
+ {
+ conflict = validateForNewStrategy( object, options );
+ }
+ }
+
+ return conflict;
+ }
+
+ private ImportConflict validateForUpdatesStrategy( T object, ImportOptions options )
+ {
+ T uidObject = uidMap.get( object.getUid() );
+ T codeObject = codeMap.get( object.getCode() );
+ T nameObject = nameMap.get( object.getName() );
+
+ T shortNameObject = null;
+ T alternativeNameObject = null;
+
+ if ( nameable )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ shortNameObject = shortNameMap.get( nameableObject.getShortName() );
+ alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
+ }
+
+ ImportConflict conflict = null;
+
+ Set<T> nonNullObjects = new HashSet<T>();
+
+ if ( uidObject != null )
+ {
+ nonNullObjects.add( uidObject );
+ }
+
+ if ( codeObject != null )
+ {
+ nonNullObjects.add( codeObject );
+ }
+
+ if ( nameObject != null )
+ {
+ nonNullObjects.add( nameObject );
+ }
+
+ if ( shortNameObject != null )
+ {
+ nonNullObjects.add( shortNameObject );
+ }
+
+ if ( alternativeNameObject != null )
+ {
+ nonNullObjects.add( alternativeNameObject );
+ }
+
+ if ( nonNullObjects.isEmpty() )
+ {
+ conflict = reportLookupConflict( object, options );
+ }
+ else if ( nonNullObjects.size() > 1 )
+ {
+ conflict = reportMoreThanOneConflict( object, options );
+ }
+
+ return conflict;
+ }
+
+ private ImportConflict validateForNewStrategy( T object, ImportOptions options )
+ {
+ T uidObject = uidMap.get( object.getUid() );
+ T codeObject = codeMap.get( object.getCode() );
+ T nameObject = nameMap.get( object.getName() );
+
+ T shortNameObject = null;
+ T alternativeNameObject = null;
+
+ if ( nameable )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ shortNameObject = shortNameMap.get( nameableObject.getShortName() );
+ alternativeNameObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
+ }
+
+ ImportConflict conflict = null;
+
+ if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
+ {
+ conflict = reportConflict( object, options );
+ }
+
+ return conflict;
+ }
+
+ private ImportConflict reportLookupConflict( IdentifiableObject object, ImportOptions options )
+ {
+ return new ImportConflict( getDisplayName( object ), "Object does not exist." );
+ }
+
+ private ImportConflict reportMoreThanOneConflict( IdentifiableObject object, ImportOptions options )
+ {
+ return new ImportConflict( getDisplayName( object ), "More than one object matches identifiers." );
+ }
+
+ private ImportConflict reportConflict( IdentifiableObject object, ImportOptions options )
+ {
+ return new ImportConflict( getDisplayName( object ), "Object already exists." );
+ }
+
+ private T getObject( T object )
+ {
+ T matchedObject = uidMap.get( object.getUid() );
+
+ if ( matchedObject != null )
+ {
+ return matchedObject;
+ }
+
+ matchedObject = codeMap.get( object.getCode() );
+
+ if ( matchedObject != null )
+ {
+ return matchedObject;
+ }
+
+ matchedObject = nameMap.get( object.getName() );
+
+ if ( matchedObject != null )
+ {
+ return matchedObject;
+ }
+
+ if ( nameable )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ matchedObject = shortNameMap.get( nameableObject.getShortName() );
+
+ if ( matchedObject != null )
+ {
+ return matchedObject;
+ }
+
+ matchedObject = alternativeNameMap.get( nameableObject.getAlternativeName() );
+
+ if ( matchedObject != null )
+ {
+ return matchedObject;
+ }
+ }
+
+ return matchedObject;
+ }
+
+ //-------------------------------------------------------------------------------------------------------
+ // Protected methods
+ //-------------------------------------------------------------------------------------------------------
+
+ protected void updateIdMaps( T object )
+ {
+ if ( object.getUid() != null )
+ {
+ uidMap.put( object.getUid(), object );
+ }
+
+ if ( object.getCode() != null )
+ {
+ codeMap.put( object.getCode(), object );
+ }
+
+ if ( object.getName() != null )
+ {
+ nameMap.put( object.getName(), object );
+ }
+
+ if ( nameable )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ if ( nameableObject.getShortName() != null )
+ {
+ shortNameMap.put( nameableObject.getShortName(), object );
+ }
+
+ if ( nameableObject.getAlternativeName() != null )
+ {
+ alternativeNameMap.put( nameableObject.getAlternativeName(), object );
+ }
+ }
+ }
+
+ protected void prepareIdentifiableObject( BaseIdentifiableObject object )
+ {
+ if ( object.getUid() == null && object.getLastUpdated() == null )
+ {
+ object.setAutoFields();
+ }
+ else if ( object.getUid() == null )
+ {
+ object.setUid( CodeGenerator.generateCode() );
+ }
+ }
+
+ /**
+ * @param object Object to get display name for
+ * @return A usable display name
+ */
+ protected String getDisplayName( IdentifiableObject object )
+ {
+ return object.getClass().getName();
+ }
+}
=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/IndicatorImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/IndicatorImporter.java 2012-04-11 15:11:09 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/IndicatorImporter.java 1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
-package org.hisp.dhis.dxf2.metadata.importers;
-
-/*
- * Copyright (c) 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 org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.indicator.Indicator;
-import org.springframework.stereotype.Component;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Component
-public class IndicatorImporter
- extends AbstractImporter<Indicator>
-{
- private static final Log log = LogFactory.getLog( IndicatorImporter.class );
-
- @Override
- protected String getObjectName()
- {
- return this.getClass().getName();
- }
-
- @Override
- public boolean canHandle( Class<?> clazz )
- {
- return Indicator.class.equals( clazz );
- }
-}
=== modified file 'dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2012-04-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2012-04-13 01:16:51 +0000
@@ -11,4 +11,135 @@
<bean id="org.hisp.dhis.dxf2.datavalueset.DataValueSetStore"
class="org.hisp.dhis.dxf2.datavalueset.SpringDataValueSetStore" />
+ <!-- register importers -->
+
+ <bean id="attributeTypeImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.attribute.Attribute"/>
+ </bean>
+
+ <bean id="categoryImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementCategory"/>
+ </bean>
+
+ <bean id="categoryComboImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementCategoryCombo"/>
+ </bean>
+
+ <bean id="categoryOptionImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementCategoryOption"/>
+ </bean>
+
+ <bean id="categoryOptionComboImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo"/>
+ </bean>
+
+ <bean id="dataElementImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElement"/>
+ </bean>
+
+ <bean id="dataElementGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementGroup"/>
+ </bean>
+
+ <bean id="dataElementGroupSetImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataelement.DataElementGroupSet"/>
+ </bean>
+
+ <bean id="chartImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.chart.Chart"/>
+ </bean>
+
+ <bean id="constantImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.constant.Constant"/>
+ </bean>
+
+ <bean id="dataSetImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.dataset.DataSet"/>
+ </bean>
+
+ <bean id="documentImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.document.Document"/>
+ </bean>
+
+ <bean id="indicatorImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.indicator.Indicator"/>
+ </bean>
+
+ <bean id="indicatorTypeImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.indicator.IndicatorType"/>
+ </bean>
+
+ <bean id="indicatorGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.indicator.IndicatorGroup"/>
+ </bean>
+
+ <bean id="indicatorGroupSetImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.indicator.IndicatorGroupSet"/>
+ </bean>
+
+ <bean id="mapViewImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.mapping.MapView"/>
+ </bean>
+
+ <bean id="mapLegendImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.mapping.MapLegend"/>
+ </bean>
+
+ <bean id="mapLegendSetImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.mapping.MapLegendSet"/>
+ </bean>
+
+ <bean id="mapLayerImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.mapping.MapLayer"/>
+ </bean>
+
+ <bean id="messageConversationImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.message.MessageConversation"/>
+ </bean>
+
+ <bean id="organisationUnitImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.organisationunit.OrganisationUnit"/>
+ </bean>
+
+ <bean id="organisationUnitGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.organisationunit.OrganisationUnitGroup"/>
+ </bean>
+
+ <bean id="organisationUnitGroupSetImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.organisationunit.OrganisationUnitGroupSet"/>
+ </bean>
+
+ <bean id="reportImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.report.Report"/>
+ </bean>
+
+ <bean id="reportTableImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.reporttable.ReportTable"/>
+ </bean>
+
+ <bean id="sqlViewImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.sqlview.SqlView"/>
+ </bean>
+
+ <bean id="userImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.user.User"/>
+ </bean>
+
+ <bean id="userGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.user.UserGroup"/>
+ </bean>
+
+ <bean id="userAuthorityGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.user.UserAuthorityGroup"/>
+ </bean>
+
+ <bean id="validationRuleImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.validation.ValidationRule"/>
+ </bean>
+
+ <bean id="validationRuleGroupImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultImporter">
+ <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.validation.ValidationRuleGroup"/>
+ </bean>
+
+
</beans>
=== 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-04-11 15:11:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-04-13 01:16:51 +0000
@@ -124,7 +124,7 @@
MetaData dxf2 = JacksonUtils.fromXml( request.getInputStream(), MetaData.class );
System.err.println( dxf2 );
- ImportSummary summary = importService.importDxf2( dxf2, importOptions );
+ ImportSummary summary = importService.importMetaData( dxf2, importOptions );
response.setContentType( MediaType.APPLICATION_XML.toString() );
JacksonUtils.toXml( response.getOutputStream(), summary );
@@ -137,7 +137,7 @@
MetaData dxf2 = JacksonUtils.fromJson( request.getInputStream(), MetaData.class );
System.err.println( dxf2 );
- ImportSummary summary = importService.importDxf2( dxf2, importOptions );
+ ImportSummary summary = importService.importMetaData( dxf2, importOptions );
response.setContentType( MediaType.APPLICATION_JSON.toString() );
JacksonUtils.toJson( response.getOutputStream(), summary );
@@ -153,7 +153,7 @@
MetaData dxf2 = JacksonUtils.fromXml( zip, MetaData.class );
System.err.println( dxf2 );
- ImportSummary summary = importService.importDxf2( dxf2, importOptions );
+ ImportSummary summary = importService.importMetaData( dxf2, importOptions );
response.setContentType( MediaType.APPLICATION_XML.toString() );
JacksonUtils.toXml( response.getOutputStream(), summary );
@@ -169,7 +169,7 @@
MetaData dxf2 = JacksonUtils.fromJson( zip, MetaData.class );
System.err.println( dxf2 );
- ImportSummary summary = importService.importDxf2( dxf2, importOptions );
+ ImportSummary summary = importService.importMetaData( dxf2, importOptions );
response.setContentType( MediaType.APPLICATION_JSON.toString() );
JacksonUtils.toJson( response.getOutputStream(), summary );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java 2012-04-13 01:16:51 +0000
@@ -115,18 +115,18 @@
resources.add( new Resource( "CategoryCombos", DataElementCategoryCombos.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "CategoryOptions", DataElementCategoryOptions.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "CategoryOptionCombos", DataElementCategoryOptionCombos.class, requestMethods, mediaTypes ) );
- resources.add( new Resource( "Charts", Charts.class, requestMethods, mediaTypes ) );
- resources.add( new Resource( "Constants", Constants.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "DataElements", DataElements.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "DataElementGroups", DataElementGroups.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "DataElementGroupSets", DataElementGroupSets.class, requestMethods, mediaTypes ) );
+ resources.add( new Resource( "Charts", Charts.class, requestMethods, mediaTypes ) );
+ resources.add( new Resource( "Constants", Constants.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "DataSets", DataSets.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "DataValueSets", DataValueSets.class, requestMethods, mediaTypes.subList( 0, 0 ) ) );
resources.add( new Resource( "Documents", Documents.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "Indicators", Indicators.class, requestMethods, mediaTypes ) );
+ resources.add( new Resource( "IndicatorTypes", IndicatorTypes.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "IndicatorGroups", IndicatorGroups.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "IndicatorGroupSets", IndicatorGroupSets.class, requestMethods, mediaTypes ) );
- resources.add( new Resource( "IndicatorTypes", IndicatorTypes.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "Maps", Maps.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "MapLegends", MapLegends.class, requestMethods, mediaTypes ) );
resources.add( new Resource( "MapLegendSets", MapLegendSets.class, requestMethods, mediaTypes ) );