dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16779
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6468: wip, importer of meta-data
------------------------------------------------------------
revno: 6468
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-04-03 12:24:37 +0200
message:
wip, importer of meta-data
added:
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/
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
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.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/metadata/DXF2.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.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/ImportStrategy.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/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2012-03-29 16:45:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2012-04-03 10:24:37 +0000
@@ -27,28 +27,28 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+
import java.util.Map;
-import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
-
/**
* @author Lars Helge Overland
*/
public interface IdentifiableObjectManager
{
void save( IdentifiableObject object );
-
+
void update( IdentifiableObject object );
-
+
void get( Class<IdentifiableObject> clazz, String uid );
-
+
void delete( IdentifiableObject object );
-
+
<T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property );
-
+
<T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String id );
-
+
IdentifiableObject getObject( String uid, String simpleClassName );
-
+
IdentifiableObject getObject( int id, String simpleClassName );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2012-04-03 10:24:37 +0000
@@ -38,7 +38,6 @@
* Defines the functionality for persisting DataElements and DataElementGroups.
*
* @author Torgeir Lorange Ostby
- * @version $Id: DataElementStore.java 6289 2008-11-14 17:53:24Z larshelg $
*/
public interface DataElementStore
extends GenericNameableObjectStore<DataElement>
=== 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-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java 2012-04-03 10:24:37 +0000
@@ -42,6 +42,11 @@
private int ignores;
+ public ImportCount( String object )
+ {
+ this.object = object;
+ }
+
public ImportCount( String object, int imports, int updates, int ignores )
{
this.object = object;
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DXF2.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DXF2.java 2012-04-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DXF2.java 2012-04-03 10:24:37 +0000
@@ -63,8 +63,8 @@
import org.hisp.dhis.validation.ValidationRule;
import org.hisp.dhis.validation.ValidationRuleGroup;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -72,77 +72,77 @@
@JacksonXmlRootElement( localName = "dxf2", namespace = Dxf2Namespace.NAMESPACE )
public class DXF2
{
- private Set<Attribute> attributeTypes = new HashSet<Attribute>();
-
- private Set<User> users = new HashSet<User>();
-
- private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();
-
- private Set<UserGroup> userGroups = new HashSet<UserGroup>();
-
- private Set<MessageConversation> messageConversations = new HashSet<MessageConversation>();
-
- private Set<DataElement> dataElements = new HashSet<DataElement>();
-
- private Set<OptionSet> optionSets = new HashSet<OptionSet>();
-
- private Set<DataElementGroup> dataElementGroups = new HashSet<DataElementGroup>();
-
- private Set<DataElementGroupSet> dataElementGroupSets = new HashSet<DataElementGroupSet>();
-
- private Set<Concept> concepts = new HashSet<Concept>();
-
- private Set<DataElementCategory> categories = new HashSet<DataElementCategory>();
-
- private Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
-
- private Set<DataElementCategoryCombo> categoryCombos = new HashSet<DataElementCategoryCombo>();
-
- private Set<DataElementCategoryOptionCombo> categoryOptionCombos = new HashSet<DataElementCategoryOptionCombo>();
-
- private Set<Indicator> indicators = new HashSet<Indicator>();
-
- private Set<IndicatorGroup> indicatorGroups = new HashSet<IndicatorGroup>();
-
- private Set<IndicatorGroupSet> indicatorGroupSets = new HashSet<IndicatorGroupSet>();
-
- private Set<IndicatorType> indicatorTypes = new HashSet<IndicatorType>();
-
- private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
-
- private Set<OrganisationUnitGroup> organisationUnitGroups = new HashSet<OrganisationUnitGroup>();
-
- private Set<OrganisationUnitGroupSet> organisationUnitGroupSets = new HashSet<OrganisationUnitGroupSet>();
-
- private Set<OrganisationUnitLevel> organisationUnitLevels = new HashSet<OrganisationUnitLevel>();
-
- private Set<DataSet> dataSets = new HashSet<DataSet>();
-
- private Set<ValidationRule> validationRules = new HashSet<ValidationRule>();
-
- private Set<ValidationRuleGroup> validationRuleGroups = new HashSet<ValidationRuleGroup>();
-
- private Set<SqlView> sqlViews = new HashSet<SqlView>();
-
- private Set<Chart> charts = new HashSet<Chart>();
-
- private Set<Report> reports = new HashSet<Report>();
-
- private Set<ReportTable> reportTables = new HashSet<ReportTable>();
-
- private Set<Document> documents = new HashSet<Document>();
-
- private Set<Constant> constants = new HashSet<Constant>();
-
- private Set<MapView> maps = new HashSet<MapView>();
-
- private Set<MapLegend> mapLegends = new HashSet<MapLegend>();
-
- private Set<MapLegendSet> mapLegendSets = new HashSet<MapLegendSet>();
-
- private Set<MapLayer> mapLayers = new HashSet<MapLayer>();
-
- private Set<DataDictionary> dataDictionaries = new HashSet<DataDictionary>();
+ private List<Attribute> attributeTypes = new ArrayList<Attribute>();
+
+ private List<User> users = new ArrayList<User>();
+
+ private List<UserAuthorityGroup> userAuthorityGroups = new ArrayList<UserAuthorityGroup>();
+
+ private List<UserGroup> userGroups = new ArrayList<UserGroup>();
+
+ private List<MessageConversation> messageConversations = new ArrayList<MessageConversation>();
+
+ private List<DataElement> dataElements = new ArrayList<DataElement>();
+
+ private List<OptionSet> optionSets = new ArrayList<OptionSet>();
+
+ private List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>();
+
+ private List<DataElementGroupSet> dataElementGroupSets = new ArrayList<DataElementGroupSet>();
+
+ private List<Concept> concepts = new ArrayList<Concept>();
+
+ private List<DataElementCategory> categories = new ArrayList<DataElementCategory>();
+
+ private List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+
+ private List<DataElementCategoryCombo> categoryCombos = new ArrayList<DataElementCategoryCombo>();
+
+ private List<DataElementCategoryOptionCombo> categoryOptionCombos = new ArrayList<DataElementCategoryOptionCombo>();
+
+ private List<Indicator> indicators = new ArrayList<Indicator>();
+
+ private List<IndicatorGroup> indicatorGroups = new ArrayList<IndicatorGroup>();
+
+ private List<IndicatorGroupSet> indicatorGroupSets = new ArrayList<IndicatorGroupSet>();
+
+ private List<IndicatorType> indicatorTypes = new ArrayList<IndicatorType>();
+
+ private List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
+
+ private List<OrganisationUnitGroup> organisationUnitGroups = new ArrayList<OrganisationUnitGroup>();
+
+ private List<OrganisationUnitGroupSet> organisationUnitGroupSets = new ArrayList<OrganisationUnitGroupSet>();
+
+ private List<OrganisationUnitLevel> organisationUnitLevels = new ArrayList<OrganisationUnitLevel>();
+
+ private List<DataSet> dataSets = new ArrayList<DataSet>();
+
+ private List<ValidationRule> validationRules = new ArrayList<ValidationRule>();
+
+ private List<ValidationRuleGroup> validationRuleGroups = new ArrayList<ValidationRuleGroup>();
+
+ private List<SqlView> sqlViews = new ArrayList<SqlView>();
+
+ private List<Chart> charts = new ArrayList<Chart>();
+
+ private List<Report> reports = new ArrayList<Report>();
+
+ private List<ReportTable> reportTables = new ArrayList<ReportTable>();
+
+ private List<Document> documents = new ArrayList<Document>();
+
+ private List<Constant> constants = new ArrayList<Constant>();
+
+ private List<MapView> maps = new ArrayList<MapView>();
+
+ private List<MapLegend> mapLegends = new ArrayList<MapLegend>();
+
+ private List<MapLegendSet> mapLegendSets = new ArrayList<MapLegendSet>();
+
+ private List<MapLayer> mapLayers = new ArrayList<MapLayer>();
+
+ private List<DataDictionary> dataDictionaries = new ArrayList<DataDictionary>();
public DXF2()
{
@@ -151,12 +151,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "attributeTypes", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "attributeType", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Attribute> getAttributeTypes()
+ public List<Attribute> getAttributeTypes()
{
return attributeTypes;
}
- public void setAttributeTypes( Set<Attribute> attributeTypes )
+ public void setAttributeTypes( List<Attribute> attributeTypes )
{
this.attributeTypes = attributeTypes;
}
@@ -164,12 +164,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "users", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "user", namespace = Dxf2Namespace.NAMESPACE )
- public Set<User> getUsers()
+ public List<User> getUsers()
{
return users;
}
- public void setUsers( Set<User> users )
+ public void setUsers( List<User> users )
{
this.users = users;
}
@@ -177,12 +177,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "userAuthorityGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "userAuthorityGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<UserAuthorityGroup> getUserAuthorityGroups()
+ public List<UserAuthorityGroup> getUserAuthorityGroups()
{
return userAuthorityGroups;
}
- public void setUserAuthorityGroups( Set<UserAuthorityGroup> userAuthorityGroups )
+ public void setUserAuthorityGroups( List<UserAuthorityGroup> userAuthorityGroups )
{
this.userAuthorityGroups = userAuthorityGroups;
}
@@ -190,12 +190,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "userGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "userGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<UserGroup> getUserGroups()
+ public List<UserGroup> getUserGroups()
{
return userGroups;
}
- public void setUserGroups( Set<UserGroup> userGroups )
+ public void setUserGroups( List<UserGroup> userGroups )
{
this.userGroups = userGroups;
}
@@ -203,12 +203,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "messageConversations", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "messageConversation", namespace = Dxf2Namespace.NAMESPACE )
- public Set<MessageConversation> getMessageConversations()
+ public List<MessageConversation> getMessageConversations()
{
return messageConversations;
}
- public void setMessageConversations( Set<MessageConversation> messageConversations )
+ public void setMessageConversations( List<MessageConversation> messageConversations )
{
this.messageConversations = messageConversations;
}
@@ -216,12 +216,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "dataElements", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "dataElement", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElement> getDataElements()
+ public List<DataElement> getDataElements()
{
return dataElements;
}
- public void setDataElements( Set<DataElement> dataElements )
+ public void setDataElements( List<DataElement> dataElements )
{
this.dataElements = dataElements;
}
@@ -229,12 +229,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "optionSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "optionSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<OptionSet> getOptionSets()
+ public List<OptionSet> getOptionSets()
{
return optionSets;
}
- public void setOptionSets( Set<OptionSet> optionSets )
+ public void setOptionSets( List<OptionSet> optionSets )
{
this.optionSets = optionSets;
}
@@ -242,12 +242,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "dataElementGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "dataElementGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementGroup> getDataElementGroups()
+ public List<DataElementGroup> getDataElementGroups()
{
return dataElementGroups;
}
- public void setDataElementGroups( Set<DataElementGroup> dataElementGroups )
+ public void setDataElementGroups( List<DataElementGroup> dataElementGroups )
{
this.dataElementGroups = dataElementGroups;
}
@@ -255,12 +255,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "dataElementGroupSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "dataElementGroupSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementGroupSet> getDataElementGroupSets()
+ public List<DataElementGroupSet> getDataElementGroupSets()
{
return dataElementGroupSets;
}
- public void setDataElementGroupSets( Set<DataElementGroupSet> dataElementGroupSets )
+ public void setDataElementGroupSets( List<DataElementGroupSet> dataElementGroupSets )
{
this.dataElementGroupSets = dataElementGroupSets;
}
@@ -268,12 +268,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "concepts", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "concept", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Concept> getConcepts()
+ public List<Concept> getConcepts()
{
return concepts;
}
- public void setConcepts( Set<Concept> concepts )
+ public void setConcepts( List<Concept> concepts )
{
this.concepts = concepts;
}
@@ -281,12 +281,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "categories", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "category", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementCategory> getCategories()
+ public List<DataElementCategory> getCategories()
{
return categories;
}
- public void setCategories( Set<DataElementCategory> categories )
+ public void setCategories( List<DataElementCategory> categories )
{
this.categories = categories;
}
@@ -294,12 +294,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "categoryOptions", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "categoryOption", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementCategoryOption> getCategoryOptions()
+ public List<DataElementCategoryOption> getCategoryOptions()
{
return categoryOptions;
}
- public void setCategoryOptions( Set<DataElementCategoryOption> categoryOptions )
+ public void setCategoryOptions( List<DataElementCategoryOption> categoryOptions )
{
this.categoryOptions = categoryOptions;
}
@@ -307,12 +307,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "categoryCombos", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "categoryCombo", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementCategoryCombo> getCategoryCombos()
+ public List<DataElementCategoryCombo> getCategoryCombos()
{
return categoryCombos;
}
- public void setCategoryCombos( Set<DataElementCategoryCombo> categoryCombos )
+ public void setCategoryCombos( List<DataElementCategoryCombo> categoryCombos )
{
this.categoryCombos = categoryCombos;
}
@@ -320,12 +320,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "categoryOptionCombos", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "categoryOptionCombo", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataElementCategoryOptionCombo> getCategoryOptionCombos()
+ public List<DataElementCategoryOptionCombo> getCategoryOptionCombos()
{
return categoryOptionCombos;
}
- public void setCategoryOptionCombos( Set<DataElementCategoryOptionCombo> categoryOptionCombos )
+ public void setCategoryOptionCombos( List<DataElementCategoryOptionCombo> categoryOptionCombos )
{
this.categoryOptionCombos = categoryOptionCombos;
}
@@ -333,12 +333,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "indicators", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "indicator", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Indicator> getIndicators()
+ public List<Indicator> getIndicators()
{
return indicators;
}
- public void setIndicators( Set<Indicator> indicators )
+ public void setIndicators( List<Indicator> indicators )
{
this.indicators = indicators;
}
@@ -346,12 +346,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "indicatorGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "indicatorGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<IndicatorGroup> getIndicatorGroups()
+ public List<IndicatorGroup> getIndicatorGroups()
{
return indicatorGroups;
}
- public void setIndicatorGroups( Set<IndicatorGroup> indicatorGroups )
+ public void setIndicatorGroups( List<IndicatorGroup> indicatorGroups )
{
this.indicatorGroups = indicatorGroups;
}
@@ -359,12 +359,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "indicatorGroupSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "indicatorGroupSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<IndicatorGroupSet> getIndicatorGroupSets()
+ public List<IndicatorGroupSet> getIndicatorGroupSets()
{
return indicatorGroupSets;
}
- public void setIndicatorGroupSets( Set<IndicatorGroupSet> indicatorGroupSets )
+ public void setIndicatorGroupSets( List<IndicatorGroupSet> indicatorGroupSets )
{
this.indicatorGroupSets = indicatorGroupSets;
}
@@ -372,12 +372,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "indicatorTypes", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "indicatorType", namespace = Dxf2Namespace.NAMESPACE )
- public Set<IndicatorType> getIndicatorTypes()
+ public List<IndicatorType> getIndicatorTypes()
{
return indicatorTypes;
}
- public void setIndicatorTypes( Set<IndicatorType> indicatorTypes )
+ public void setIndicatorTypes( List<IndicatorType> indicatorTypes )
{
this.indicatorTypes = indicatorTypes;
}
@@ -385,12 +385,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "organisationUnits", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "organisationUnit", namespace = Dxf2Namespace.NAMESPACE )
- public Set<OrganisationUnit> getOrganisationUnits()
+ public List<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
}
- public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
+ public void setOrganisationUnits( List<OrganisationUnit> organisationUnits )
{
this.organisationUnits = organisationUnits;
}
@@ -398,12 +398,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "organisationUnitGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "organisationUnitGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<OrganisationUnitGroup> getOrganisationUnitGroups()
+ public List<OrganisationUnitGroup> getOrganisationUnitGroups()
{
return organisationUnitGroups;
}
- public void setOrganisationUnitGroups( Set<OrganisationUnitGroup> organisationUnitGroups )
+ public void setOrganisationUnitGroups( List<OrganisationUnitGroup> organisationUnitGroups )
{
this.organisationUnitGroups = organisationUnitGroups;
}
@@ -411,12 +411,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "organisationUnitGroupSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "organisationUnitGroupSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<OrganisationUnitGroupSet> getOrganisationUnitGroupSets()
+ public List<OrganisationUnitGroupSet> getOrganisationUnitGroupSets()
{
return organisationUnitGroupSets;
}
- public void setOrganisationUnitGroupSets( Set<OrganisationUnitGroupSet> organisationUnitGroupSets )
+ public void setOrganisationUnitGroupSets( List<OrganisationUnitGroupSet> organisationUnitGroupSets )
{
this.organisationUnitGroupSets = organisationUnitGroupSets;
}
@@ -424,12 +424,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "organisationUnitLevels", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "organisationUnitLevel", namespace = Dxf2Namespace.NAMESPACE )
- public Set<OrganisationUnitLevel> getOrganisationUnitLevels()
+ public List<OrganisationUnitLevel> getOrganisationUnitLevels()
{
return organisationUnitLevels;
}
- public void setOrganisationUnitLevels( Set<OrganisationUnitLevel> organisationUnitLevels )
+ public void setOrganisationUnitLevels( List<OrganisationUnitLevel> organisationUnitLevels )
{
this.organisationUnitLevels = organisationUnitLevels;
}
@@ -437,12 +437,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "dataSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "dataSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataSet> getDataSets()
+ public List<DataSet> getDataSets()
{
return dataSets;
}
- public void setDataSets( Set<DataSet> dataSets )
+ public void setDataSets( List<DataSet> dataSets )
{
this.dataSets = dataSets;
}
@@ -450,12 +450,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "validationRules", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "validationRule", namespace = Dxf2Namespace.NAMESPACE )
- public Set<ValidationRule> getValidationRules()
+ public List<ValidationRule> getValidationRules()
{
return validationRules;
}
- public void setValidationRules( Set<ValidationRule> validationRules )
+ public void setValidationRules( List<ValidationRule> validationRules )
{
this.validationRules = validationRules;
}
@@ -463,12 +463,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "validationRuleGroups", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "validationRuleGroup", namespace = Dxf2Namespace.NAMESPACE )
- public Set<ValidationRuleGroup> getValidationRuleGroups()
+ public List<ValidationRuleGroup> getValidationRuleGroups()
{
return validationRuleGroups;
}
- public void setValidationRuleGroups( Set<ValidationRuleGroup> validationRuleGroups )
+ public void setValidationRuleGroups( List<ValidationRuleGroup> validationRuleGroups )
{
this.validationRuleGroups = validationRuleGroups;
}
@@ -476,12 +476,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "sqlViews", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "sqlView", namespace = Dxf2Namespace.NAMESPACE )
- public Set<SqlView> getSqlViews()
+ public List<SqlView> getSqlViews()
{
return sqlViews;
}
- public void setSqlViews( Set<SqlView> sqlViews )
+ public void setSqlViews( List<SqlView> sqlViews )
{
this.sqlViews = sqlViews;
}
@@ -489,12 +489,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "charts", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "chart", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Chart> getCharts()
+ public List<Chart> getCharts()
{
return charts;
}
- public void setCharts( Set<Chart> charts )
+ public void setCharts( List<Chart> charts )
{
this.charts = charts;
}
@@ -502,12 +502,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "reports", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "report", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Report> getReports()
+ public List<Report> getReports()
{
return reports;
}
- public void setReports( Set<Report> reports )
+ public void setReports( List<Report> reports )
{
this.reports = reports;
}
@@ -515,12 +515,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "reportTables", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "reportTable", namespace = Dxf2Namespace.NAMESPACE )
- public Set<ReportTable> getReportTables()
+ public List<ReportTable> getReportTables()
{
return reportTables;
}
- public void setReportTables( Set<ReportTable> reportTables )
+ public void setReportTables( List<ReportTable> reportTables )
{
this.reportTables = reportTables;
}
@@ -528,12 +528,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "documents", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "document", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Document> getDocuments()
+ public List<Document> getDocuments()
{
return documents;
}
- public void setDocuments( Set<Document> documents )
+ public void setDocuments( List<Document> documents )
{
this.documents = documents;
}
@@ -541,12 +541,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "constants", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "constant", namespace = Dxf2Namespace.NAMESPACE )
- public Set<Constant> getConstants()
+ public List<Constant> getConstants()
{
return constants;
}
- public void setConstants( Set<Constant> constants )
+ public void setConstants( List<Constant> constants )
{
this.constants = constants;
}
@@ -554,12 +554,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "maps", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "map", namespace = Dxf2Namespace.NAMESPACE )
- public Set<MapView> getMaps()
+ public List<MapView> getMaps()
{
return maps;
}
- public void setMaps( Set<MapView> maps )
+ public void setMaps( List<MapView> maps )
{
this.maps = maps;
}
@@ -567,12 +567,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "mapLegends", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "mapLegend", namespace = Dxf2Namespace.NAMESPACE )
- public Set<MapLegend> getMapLegends()
+ public List<MapLegend> getMapLegends()
{
return mapLegends;
}
- public void setMapLegends( Set<MapLegend> mapLegends )
+ public void setMapLegends( List<MapLegend> mapLegends )
{
this.mapLegends = mapLegends;
}
@@ -580,12 +580,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "mapLegendSets", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "mapLegendSet", namespace = Dxf2Namespace.NAMESPACE )
- public Set<MapLegendSet> getMapLegendSets()
+ public List<MapLegendSet> getMapLegendSets()
{
return mapLegendSets;
}
- public void setMapLegendSets( Set<MapLegendSet> mapLegendSets )
+ public void setMapLegendSets( List<MapLegendSet> mapLegendSets )
{
this.mapLegendSets = mapLegendSets;
}
@@ -593,12 +593,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "mapLayers", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "mapLayer", namespace = Dxf2Namespace.NAMESPACE )
- public Set<MapLayer> getMapLayers()
+ public List<MapLayer> getMapLayers()
{
return mapLayers;
}
- public void setMapLayers( Set<MapLayer> mapLayers )
+ public void setMapLayers( List<MapLayer> mapLayers )
{
this.mapLayers = mapLayers;
}
@@ -606,12 +606,12 @@
@JsonProperty
@JacksonXmlElementWrapper( localName = "dataDictionaries", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "dataDictionary", namespace = Dxf2Namespace.NAMESPACE )
- public Set<DataDictionary> getDataDictionaries()
+ public List<DataDictionary> getDataDictionaries()
{
return dataDictionaries;
}
- public void setDataDictionaries( Set<DataDictionary> dataDictionaries )
+ public void setDataDictionaries( List<DataDictionary> dataDictionaries )
{
this.dataDictionaries = dataDictionaries;
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-04-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-04-03 10:24:37 +0000
@@ -61,7 +61,6 @@
import org.springframework.stereotype.Service;
import java.util.ArrayList;
-import java.util.HashSet;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -143,177 +142,177 @@
if ( exportOptions.isAttributeTypes() )
{
- dxf2.setAttributeTypes( new HashSet<Attribute>( attributeService.getAllAttributes() ) );
+ dxf2.setAttributeTypes( new ArrayList<Attribute>( attributeService.getAllAttributes() ) );
}
if ( exportOptions.isUsers() )
{
- dxf2.setUsers( new HashSet<User>( userService.getAllUsers() ) );
+ dxf2.setUsers( new ArrayList<User>( userService.getAllUsers() ) );
}
if ( exportOptions.isUserAuthorityGroups() )
{
- dxf2.setUserAuthorityGroups( new HashSet<UserAuthorityGroup>( userService.getAllUserAuthorityGroups() ) );
+ dxf2.setUserAuthorityGroups( new ArrayList<UserAuthorityGroup>( userService.getAllUserAuthorityGroups() ) );
}
if ( exportOptions.isUserGroups() )
{
- dxf2.setUserGroups( new HashSet<UserGroup>( userGroupService.getAllUserGroups() ) );
+ dxf2.setUserGroups( new ArrayList<UserGroup>( userGroupService.getAllUserGroups() ) );
}
if ( exportOptions.isConstants() )
{
- dxf2.setConstants( new HashSet<Constant>( constantService.getAllConstants() ) );
+ dxf2.setConstants( new ArrayList<Constant>( constantService.getAllConstants() ) );
}
if ( exportOptions.isConcepts() )
{
- dxf2.setConcepts( new HashSet<Concept>( conceptService.getAllConcepts() ) );
+ dxf2.setConcepts( new ArrayList<Concept>( conceptService.getAllConcepts() ) );
}
if ( exportOptions.isDataElements() )
{
- dxf2.setDataElements( new HashSet<DataElement>( dataElementService.getAllDataElements() ) );
+ dxf2.setDataElements( new ArrayList<DataElement>( dataElementService.getAllDataElements() ) );
}
if ( exportOptions.isOptionSets() )
{
- dxf2.setOptionSets( new HashSet<OptionSet>( optionService.getAllOptionSets() ) );
+ dxf2.setOptionSets( new ArrayList<OptionSet>( optionService.getAllOptionSets() ) );
}
if ( exportOptions.isDataElementGroups() )
{
- dxf2.setDataElementGroups( new HashSet<DataElementGroup>( dataElementService.getAllDataElementGroups() ) );
+ dxf2.setDataElementGroups( new ArrayList<DataElementGroup>( dataElementService.getAllDataElementGroups() ) );
}
if ( exportOptions.isDataElementGroupSets() )
{
- dxf2.setDataElementGroupSets( new HashSet<DataElementGroupSet>( dataElementService.getAllDataElementGroupSets() ) );
+ dxf2.setDataElementGroupSets( new ArrayList<DataElementGroupSet>( dataElementService.getAllDataElementGroupSets() ) );
}
if ( exportOptions.isCategories() )
{
- dxf2.setCategories( new HashSet<DataElementCategory>( dataElementCategoryService.getAllDataElementCategories() ) );
+ dxf2.setCategories( new ArrayList<DataElementCategory>( dataElementCategoryService.getAllDataElementCategories() ) );
}
if ( exportOptions.isCategoryOptions() )
{
- dxf2.setCategoryOptions( new HashSet<DataElementCategoryOption>( dataElementCategoryService.getAllDataElementCategoryOptions() ) );
+ dxf2.setCategoryOptions( new ArrayList<DataElementCategoryOption>( dataElementCategoryService.getAllDataElementCategoryOptions() ) );
}
if ( exportOptions.isCategoryCombos() )
{
- dxf2.setCategoryCombos( new HashSet<DataElementCategoryCombo>( dataElementCategoryService.getAllDataElementCategoryCombos() ) );
+ dxf2.setCategoryCombos( new ArrayList<DataElementCategoryCombo>( dataElementCategoryService.getAllDataElementCategoryCombos() ) );
}
if ( exportOptions.isCategoryOptionCombos() )
{
- dxf2.setCategoryOptionCombos( new HashSet<DataElementCategoryOptionCombo>( dataElementCategoryService.getAllDataElementCategoryOptionCombos() ) );
+ dxf2.setCategoryOptionCombos( new ArrayList<DataElementCategoryOptionCombo>( dataElementCategoryService.getAllDataElementCategoryOptionCombos() ) );
}
if ( exportOptions.isIndicators() )
{
- dxf2.setIndicators( new HashSet<Indicator>( indicatorService.getAllIndicators() ) );
+ dxf2.setIndicators( new ArrayList<Indicator>( indicatorService.getAllIndicators() ) );
}
if ( exportOptions.isIndicatorGroups() )
{
- dxf2.setIndicatorGroups( new HashSet<IndicatorGroup>( indicatorService.getAllIndicatorGroups() ) );
+ dxf2.setIndicatorGroups( new ArrayList<IndicatorGroup>( indicatorService.getAllIndicatorGroups() ) );
}
if ( exportOptions.isIndicatorGroupSets() )
{
- dxf2.setIndicatorGroupSets( new HashSet<IndicatorGroupSet>( indicatorService.getAllIndicatorGroupSets() ) );
+ dxf2.setIndicatorGroupSets( new ArrayList<IndicatorGroupSet>( indicatorService.getAllIndicatorGroupSets() ) );
}
if ( exportOptions.isIndicatorTypes() )
{
- dxf2.setIndicatorTypes( new HashSet<IndicatorType>( indicatorService.getAllIndicatorTypes() ) );
+ dxf2.setIndicatorTypes( new ArrayList<IndicatorType>( indicatorService.getAllIndicatorTypes() ) );
}
if ( exportOptions.isOrganisationUnits() )
{
- dxf2.setOrganisationUnits( new HashSet<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() ) );
+ dxf2.setOrganisationUnits( new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() ) );
}
if ( exportOptions.isOrganisationUnitLevels() )
{
- dxf2.setOrganisationUnitLevels( new HashSet<OrganisationUnitLevel>( organisationUnitService.getOrganisationUnitLevels() ) );
+ dxf2.setOrganisationUnitLevels( new ArrayList<OrganisationUnitLevel>( organisationUnitService.getOrganisationUnitLevels() ) );
}
if ( exportOptions.isOrganisationUnitGroups() )
{
- dxf2.setOrganisationUnitGroups( new HashSet<OrganisationUnitGroup>( organisationUnitGroupService.getAllOrganisationUnitGroups() ) );
+ dxf2.setOrganisationUnitGroups( new ArrayList<OrganisationUnitGroup>( organisationUnitGroupService.getAllOrganisationUnitGroups() ) );
}
if ( exportOptions.isOrganisationUnitGroupSets() )
{
- dxf2.setOrganisationUnitGroupSets( new HashSet<OrganisationUnitGroupSet>( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ) );
+ dxf2.setOrganisationUnitGroupSets( new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ) );
}
if ( exportOptions.isDataSets() )
{
- dxf2.setDataSets( new HashSet<DataSet>( dataSetService.getAllDataSets() ) );
+ dxf2.setDataSets( new ArrayList<DataSet>( dataSetService.getAllDataSets() ) );
}
if ( exportOptions.isValidationRules() )
{
- dxf2.setValidationRules( new HashSet<ValidationRule>( validationRuleService.getAllValidationRules() ) );
+ dxf2.setValidationRules( new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() ) );
}
if ( exportOptions.isValidationRuleGroups() )
{
- dxf2.setValidationRuleGroups( new HashSet<ValidationRuleGroup>( validationRuleService.getAllValidationRuleGroups() ) );
+ dxf2.setValidationRuleGroups( new ArrayList<ValidationRuleGroup>( validationRuleService.getAllValidationRuleGroups() ) );
}
if ( exportOptions.isSqlViews() )
{
- dxf2.setSqlViews( new HashSet<SqlView>( sqlViewService.getAllSqlViews() ) );
+ dxf2.setSqlViews( new ArrayList<SqlView>( sqlViewService.getAllSqlViews() ) );
}
if ( exportOptions.isDocuments() )
{
- dxf2.setDocuments( new HashSet<Document>( documentService.getAllDocuments() ) );
+ dxf2.setDocuments( new ArrayList<Document>( documentService.getAllDocuments() ) );
}
if ( exportOptions.isReportTables() )
{
- dxf2.setReportTables( new HashSet<ReportTable>( reportTableService.getAllReportTables() ) );
+ dxf2.setReportTables( new ArrayList<ReportTable>( reportTableService.getAllReportTables() ) );
}
if ( exportOptions.isReports() )
{
- dxf2.setReports( new HashSet<Report>( reportService.getAllReports() ) );
+ dxf2.setReports( new ArrayList<Report>( reportService.getAllReports() ) );
}
if ( exportOptions.isCharts() )
{
- dxf2.setCharts( new HashSet<Chart>( chartService.getAllCharts() ) );
+ dxf2.setCharts( new ArrayList<Chart>( chartService.getAllCharts() ) );
}
if ( exportOptions.isMaps() )
{
- dxf2.setMaps( new HashSet<MapView>( mappingService.getAllMapViews() ) );
+ dxf2.setMaps( new ArrayList<MapView>( mappingService.getAllMapViews() ) );
}
if ( exportOptions.isMapLegends() )
{
- dxf2.setMapLegends( new HashSet<MapLegend>( mappingService.getAllMapLegends() ) );
+ dxf2.setMapLegends( new ArrayList<MapLegend>( mappingService.getAllMapLegends() ) );
}
if ( exportOptions.isMapLegendSets() )
{
- dxf2.setMapLegendSets( new HashSet<MapLegendSet>( mappingService.getAllMapLegendSets() ) );
+ dxf2.setMapLegendSets( new ArrayList<MapLegendSet>( mappingService.getAllMapLegendSets() ) );
}
if ( exportOptions.isMapLayers() )
{
- dxf2.setMapLayers( new HashSet<MapLayer>( mappingService.getAllMapLayers() ) );
+ dxf2.setMapLayers( new ArrayList<MapLayer>( mappingService.getAllMapLayers() ) );
}
if ( exportOptions.isDataDictionaries() )
{
- dxf2.setDataDictionaries( new HashSet<DataDictionary>( dataDictionaryService.getAllDataDictionaries() ) );
+ dxf2.setDataDictionaries( new ArrayList<DataDictionary>( dataDictionaryService.getAllDataDictionaries() ) );
}
return dxf2;
=== 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-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-03 10:24:37 +0000
@@ -27,36 +27,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.attribute.AttributeService;
-import org.hisp.dhis.chart.ChartService;
import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.concept.ConceptService;
-import org.hisp.dhis.constant.Constant;
-import org.hisp.dhis.constant.ConstantService;
-import org.hisp.dhis.datadictionary.DataDictionaryService;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
-import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.document.DocumentService;
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.indicator.IndicatorService;
-import org.hisp.dhis.mapping.MappingService;
-import org.hisp.dhis.option.OptionService;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.report.ReportService;
-import org.hisp.dhis.reporttable.ReportTableService;
-import org.hisp.dhis.sqlview.SqlViewService;
-import org.hisp.dhis.user.UserGroupService;
-import org.hisp.dhis.user.UserService;
-import org.hisp.dhis.validation.ValidationRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -124,15 +104,54 @@
private DocumentService documentService;
@Autowired
- private ConstantService constantService;
-
- @Autowired
private MappingService mappingService;
@Autowired
private DataDictionaryService dataDictionaryService;
*/
+ @Autowired
+ private Set<Importer> importerClasses = new HashSet<Importer>();
+
+ private Importer findImporterClass( Collection<? extends IdentifiableObject> clazzes )
+ {
+ if ( clazzes.size() > 0 )
+ {
+ IdentifiableObject identifiableObject = clazzes.iterator().next();
+
+ return findImporterClass( identifiableObject.getClass() );
+ }
+
+ return null;
+ }
+
+ private Importer findImporterClass( Class<?> clazz )
+ {
+ for ( Importer i : importerClasses )
+ {
+ if ( i.canHandle( clazz ) )
+ {
+ return i;
+ }
+ }
+
+ return null;
+ }
+
+ private void doImport( Collection<? extends IdentifiableObject> objects, ImportOptions importOptions, ImportSummary importSummary )
+ {
+ Importer importer = findImporterClass( objects );
+
+ if ( importer != null )
+ {
+ List<ImportConflict> conflicts = importer.importCollection( objects, importOptions );
+ ImportCount count = importer.getImportCount();
+
+ importSummary.getConflicts().addAll( conflicts );
+ importSummary.getCounts().add( count );
+ }
+ }
+
//-------------------------------------------------------------------------------------------------------
// ImportService Implementation
//-------------------------------------------------------------------------------------------------------
@@ -146,6 +165,12 @@
@Override
public ImportSummary importDxf2WithImportOptions( DXF2 dxf2, ImportOptions importOptions )
{
- return new ImportSummary();
+ 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 );
+
+ return importSummary;
}
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportStrategy.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportStrategy.java 2012-04-02 17:23:48 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportStrategy.java 2012-04-03 10:24:37 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java 2012-04-03 10:24:37 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.dxf2.metadata;
+
+/*
+ * 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.hisp.dhis.dxf2.importsummary.ImportConflict;
+import org.hisp.dhis.dxf2.importsummary.ImportCount;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface Importer<T>
+{
+ ImportConflict importObject( T object, ImportOptions options );
+
+ List<ImportConflict> importCollection( Collection<T> objects, ImportOptions options );
+
+ ImportCount getImportCount();
+
+ boolean canHandle( Class<?> clazz );
+}
=== added directory 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers'
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/AbstractImporter.java 2012-04-03 10:24:37 +0000
@@ -0,0 +1,180 @@
+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.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dxf2.importsummary.ImportConflict;
+import org.hisp.dhis.dxf2.importsummary.ImportCount;
+import org.hisp.dhis.dxf2.metadata.IdScheme;
+import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.dxf2.metadata.Importer;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public abstract class AbstractImporter<T extends IdentifiableObject>
+ implements Importer<T>
+{
+ @Autowired
+ private IdentifiableObjectManager manager;
+
+ protected int imports;
+
+ protected int updates;
+
+ protected int ignores;
+
+ protected abstract void newObject( T object );
+
+ protected abstract void updatedObject( T object, T oldObject );
+
+ protected abstract String getObjectName();
+
+ @Override
+ public List<ImportConflict> importCollection( Collection<T> objects, ImportOptions options )
+ {
+ imports = 0;
+ updates = 0;
+ ignores = 0;
+
+ List<ImportConflict> conflicts = new ArrayList<ImportConflict>();
+
+ for ( T object : objects )
+ {
+ ImportConflict importConflict = importObject( object, options );
+
+ if ( importConflict != null )
+ {
+ conflicts.add( importConflict );
+ }
+ }
+
+ return conflicts;
+ }
+
+ @Override
+ public ImportConflict importObject( T object, ImportOptions options )
+ {
+ Map<String, T> map = getIdMap( (Class) object.getClass(), options.getIdScheme() );
+ String identifier = getIdentifier( object, options.getIdScheme() );
+ T oldObject = map.get( identifier );
+
+ if ( options.getImportStrategy().isNewStrategy() )
+ {
+ if ( oldObject != null )
+ {
+ ignores++;
+ return new ImportConflict( object.getClass().getName(), "Strategy is new, but identifier '" + identifier + "' already exists." );
+ }
+
+ imports++;
+ newObject( object );
+ }
+ else if ( options.getImportStrategy().isUpdatesStrategy() )
+ {
+ if ( oldObject == null )
+ {
+ ignores++;
+ return new ImportConflict( object.getClass().getName(), "Strategy is updates, but identifier '" + identifier + "' does not exist." );
+ }
+
+ updates++;
+ updatedObject( object, oldObject );
+ }
+ else if ( options.getImportStrategy().isNewAndUpdatesStrategy() )
+ {
+ if ( oldObject != null )
+ {
+ updates++;
+ updatedObject( object, oldObject );
+ }
+ else
+ {
+ imports++;
+ newObject( object );
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ImportCount getImportCount()
+ {
+ ImportCount importCount = new ImportCount( getObjectName() );
+
+ importCount.setImports( imports );
+ importCount.setUpdates( updates );
+ importCount.setIgnores( ignores );
+
+ return importCount;
+ }
+
+ protected Map<String, T> getIdMap( Class<T> clazz, IdScheme scheme )
+ {
+ if ( scheme.isUidScheme() )
+ {
+ return manager.getIdMap( clazz, IdentifiableObject.IdentifiableProperty.UID );
+ }
+ else if ( scheme.isNameScheme() )
+ {
+ return manager.getIdMap( clazz, IdentifiableObject.IdentifiableProperty.NAME );
+ }
+ else if ( scheme.isCodeScheme() )
+ {
+ return manager.getIdMap( clazz, IdentifiableObject.IdentifiableProperty.CODE );
+ }
+
+ return null;
+ }
+
+ protected String getIdentifier( T object, IdScheme scheme )
+ {
+ if ( scheme.isUidScheme() )
+ {
+ return object.getUid();
+ }
+ else if ( scheme.isNameScheme() )
+ {
+ return object.getName();
+ }
+ else if ( scheme.isCodeScheme() )
+ {
+ return object.getCode();
+ }
+
+ return null;
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/ConstantImporter.java 2012-04-03 10:24:37 +0000
@@ -0,0 +1,67 @@
+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>
+{
+ protected static final Log LOG = LogFactory.getLog( ConstantImporter.class );
+
+ @Override
+ protected void newObject( Constant constant )
+ {
+ LOG.info( "NEW OBJECT: " + constant );
+ }
+
+ @Override
+ protected void updatedObject( Constant constant, Constant oldConstant )
+ {
+ LOG.info( "UPDATED OBJECT: " + constant + ", OLD OBJECT: " + oldConstant );
+ }
+
+ @Override
+ protected String getObjectName()
+ {
+ return this.getClass().getName();
+ }
+
+ @Override
+ public boolean canHandle( Class<?> clazz )
+ {
+ return Constant.class.equals( clazz );
+ }
+}