dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41771
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21308: wip, change IdSchemes to use new class IdScheme(property, attribute)
------------------------------------------------------------
revno: 21308
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-12-04 12:41:43 +0700
message:
wip, change IdSchemes to use new class IdScheme(property, attribute)
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/IdSchemes.java
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.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/common/IdentifiableObjectUtils.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/gml/DefaultGmlImportService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/CategoryOptionComboAclCallable.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/IdentifiableObjectCallable.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/PeriodCallable.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java 2015-12-04 05:41:43 +0000
@@ -0,0 +1,164 @@
+package org.hisp.dhis.common;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.base.MoreObjects;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class IdScheme
+{
+ public static final IdScheme NULL = new IdScheme( null );
+ public static final IdScheme ID = new IdScheme( IdentifiableProperty.ID );
+ public static final IdScheme UID = new IdScheme( IdentifiableProperty.UID );
+ public static final IdScheme UUID = new IdScheme( IdentifiableProperty.UUID );
+ public static final IdScheme CODE = new IdScheme( IdentifiableProperty.CODE );
+ public static final IdScheme NAME = new IdScheme( IdentifiableProperty.NAME );
+
+ private IdentifiableProperty identifiableProperty;
+
+ private String attribute;
+
+ public static IdScheme from( IdScheme idScheme )
+ {
+ if ( idScheme == null )
+ {
+ return IdScheme.NULL;
+ }
+
+ return idScheme;
+ }
+
+ public static IdScheme from( String scheme )
+ {
+ if ( scheme == null )
+ {
+ return IdScheme.NULL;
+ }
+
+ if ( IdScheme.isAttribute( scheme ) )
+ {
+ return new IdScheme( IdentifiableProperty.ATTRIBUTE, scheme.substring( 10 ) );
+ }
+
+ return IdScheme.from( IdentifiableProperty.valueOf( scheme.toUpperCase() ) );
+ }
+
+ public static IdScheme from( IdentifiableProperty property )
+ {
+ if ( property == null )
+ {
+ return IdScheme.NULL;
+ }
+
+ switch ( property )
+ {
+ case ID:
+ return IdScheme.ID;
+ case UID:
+ return IdScheme.UID;
+ case UUID:
+ return IdScheme.UUID;
+ case CODE:
+ return IdScheme.CODE;
+ case NAME:
+ return IdScheme.NAME;
+ }
+
+ return new IdScheme( property );
+ }
+
+ private IdScheme( IdentifiableProperty identifiableProperty )
+ {
+ this.identifiableProperty = identifiableProperty;
+ }
+
+ private IdScheme( IdentifiableProperty identifiableProperty, String attribute )
+ {
+ this.identifiableProperty = identifiableProperty;
+ this.attribute = attribute;
+ }
+
+ public IdentifiableProperty getIdentifiableProperty()
+ {
+ return identifiableProperty;
+ }
+
+ public void setIdentifiableProperty( IdentifiableProperty identifiableProperty )
+ {
+ this.identifiableProperty = identifiableProperty;
+ }
+
+ public String getAttribute()
+ {
+ return attribute;
+ }
+
+ public void setAttribute( String attribute )
+ {
+ this.attribute = attribute;
+ }
+
+ public boolean is( IdentifiableProperty identifiableProperty )
+ {
+ return this.identifiableProperty == identifiableProperty;
+ }
+
+ public boolean isNull()
+ {
+ return null == this.identifiableProperty;
+ }
+
+ public boolean isNotNull()
+ {
+ return !isNull();
+ }
+
+ public boolean isAttribute()
+ {
+ return IdentifiableProperty.ATTRIBUTE == identifiableProperty && !StringUtils.isEmpty( attribute );
+ }
+
+
+ public static boolean isAttribute( String str )
+ {
+ return !StringUtils.isEmpty( str ) && str.toUpperCase().startsWith( "ATTRIBUTE:" ) && str.length() == 21;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MoreObjects.toStringHelper( this )
+ .add( "identifiableProperty", identifiableProperty )
+ .add( "attribute", attribute )
+ .toString();
+ }
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java 2015-12-04 05:41:43 +0000
@@ -0,0 +1,173 @@
+package org.hisp.dhis.common;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class IdSchemes
+{
+ private IdScheme idScheme;
+
+ private IdScheme dataElementIdScheme = IdScheme.UID;
+
+ private IdScheme categoryOptionComboIdScheme = IdScheme.UID;
+
+ private IdScheme orgUnitIdScheme = IdScheme.UID;
+
+ private IdScheme programIdScheme = IdScheme.UID;
+
+ private IdScheme programStageIdScheme = IdScheme.UID;
+
+ public IdSchemes()
+ {
+ }
+
+ public IdScheme getScheme( IdScheme idScheme )
+ {
+ return IdScheme.from( this.idScheme != null ? this.idScheme : idScheme );
+ }
+
+ public IdScheme getIdScheme()
+ {
+ return IdScheme.from( idScheme );
+ }
+
+ public IdSchemes setIdScheme( String idScheme )
+ {
+ this.idScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public IdScheme getDataElementIdScheme()
+ {
+ return getScheme( dataElementIdScheme );
+ }
+
+ public IdSchemes setDataElementIdScheme( String idScheme )
+ {
+ this.dataElementIdScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public IdScheme getCategoryOptionComboIdScheme()
+ {
+ return getScheme( categoryOptionComboIdScheme );
+ }
+
+ public IdSchemes setCategoryOptionComboIdScheme( String idScheme )
+ {
+ this.categoryOptionComboIdScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public IdScheme getOrgUnitIdScheme()
+ {
+ return getScheme( orgUnitIdScheme );
+ }
+
+ public IdSchemes setOrgUnitIdScheme( String idScheme )
+ {
+ this.orgUnitIdScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public IdScheme getProgramIdScheme()
+ {
+ return getScheme( programIdScheme );
+ }
+
+ public IdSchemes setProgramIdScheme( String idScheme )
+ {
+ this.programIdScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public IdScheme getProgramStageIdScheme()
+ {
+ return getScheme( programStageIdScheme );
+ }
+
+ public IdSchemes setProgramStageIdScheme( String idScheme )
+ {
+ this.programStageIdScheme = IdScheme.from( idScheme );
+ return this;
+ }
+
+ public static String getValue( String uid, String code, IdentifiableProperty identifiableProperty )
+ {
+ return getValue( uid, code, IdScheme.from( identifiableProperty ) );
+ }
+
+ public static String getValue( String uid, String code, IdScheme idScheme )
+ {
+ boolean isId = idScheme.is( IdentifiableProperty.ID ) || idScheme.is( IdentifiableProperty.UID );
+ return isId ? uid : code;
+ }
+
+ public static String getValue( IdentifiableObject identifiableObject, IdentifiableProperty identifiableProperty )
+ {
+ return getValue( identifiableObject, IdScheme.from( identifiableProperty ) );
+ }
+
+ public static String getValue( IdentifiableObject identifiableObject, IdScheme idScheme )
+ {
+ boolean isId = idScheme.is( IdentifiableProperty.ID ) || idScheme.is( IdentifiableProperty.UID );
+
+ if ( isId )
+ {
+ return identifiableObject.getUid();
+ }
+ else if ( idScheme.is( IdentifiableProperty.CODE ) )
+ {
+ return identifiableObject.getCode();
+ }
+ else if ( idScheme.is( IdentifiableProperty.CODE ) )
+ {
+ return identifiableObject.getName();
+ }
+
+ return null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MoreObjects.toStringHelper( this )
+ .add( "idScheme", idScheme )
+ .add( "dataElementIdScheme", dataElementIdScheme )
+ .add( "categoryOptionComboIdScheme", categoryOptionComboIdScheme )
+ .add( "orgUnitIdScheme", orgUnitIdScheme )
+ .add( "programIdScheme", programIdScheme )
+ .add( "programStageIdScheme", programStageIdScheme )
+ .toString();
+ }
+}
=== 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 2015-12-03 04:18:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-12-04 05:41:43 +0000
@@ -115,8 +115,12 @@
<T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property );
+ <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdScheme idScheme );
+
<T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdentifiableProperty property );
+ <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdScheme idScheme );
+
<T extends NameableObject> Map<String, T> getIdMap( Class<T> clazz, NameableProperty property );
<T extends NameableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, NameableProperty property );
@@ -127,7 +131,7 @@
<T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String value );
- <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String aid, String value );
+ <T extends IdentifiableObject> T getObject( Class<T> clazz, IdScheme idScheme, String value );
IdentifiableObject getObject( String uid, String simpleClassName );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-11-26 19:28:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-12-04 05:41:43 +0000
@@ -28,6 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.StringUtils;
+import org.hisp.dhis.calendar.Calendar;
+import org.hisp.dhis.calendar.DateTimeUnit;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -39,19 +51,6 @@
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.commons.lang3.StringUtils;
-import org.hisp.dhis.calendar.Calendar;
-import org.hisp.dhis.calendar.DateTimeUnit;
-import org.hisp.dhis.dataelement.DataElementCategory;
-import org.hisp.dhis.dataelement.DataElementCategoryCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryOption;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
/**
* @author Lars Helge Overland
*/
@@ -62,9 +61,9 @@
private static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" );
public static final Map<String, String> CLASS_ALIAS = ImmutableMap.<String, String>builder().
- put( "CategoryOption", DataElementCategoryOption.class.getSimpleName() ).
- put( "Category", DataElementCategory.class.getSimpleName() ).
- put( "CategoryCombo", DataElementCategoryCombo.class.getSimpleName()).build();
+ put( "CategoryOption", DataElementCategoryOption.class.getSimpleName() ).
+ put( "Category", DataElementCategory.class.getSimpleName() ).
+ put( "CategoryCombo", DataElementCategoryCombo.class.getSimpleName() ).build();
/**
* Joins the names of the IdentifiableObjects in the given list and separates
@@ -258,14 +257,14 @@
}
/**
- * Returns a mapping between the uid and the display name of the given
+ * Returns a mapping between the uid and the display name of the given
* identifiable objects.
*
* @param objects the identifiable objects.
* @return mapping between the uid and the display name of the given objects.
*/
public static Map<String, String> getUidNameMap( Collection<? extends IdentifiableObject> objects )
- {
+ {
return objects.stream().collect( Collectors.toMap( IdentifiableObject::getUid, IdentifiableObject::getDisplayName ) );
}
@@ -283,16 +282,17 @@
/**
* Returns a map of identifiable properties and objects.
- *
- * @param objects the objects.
- * @param property the identifiable property.
+ *
+ * @param objects the objects.
+ * @param idScheme the id scheme to use.
* @return a map.
*/
@SuppressWarnings( "unchecked" )
- public static <T extends IdentifiableObject> Map<String, T> getMap( List<T> objects, IdentifiableProperty property )
+ public static <T extends IdentifiableObject> Map<String, T> getMap( List<T> objects, IdScheme idScheme )
{
Map<String, T> map = new HashMap<>();
-
+ IdentifiableProperty property = idScheme.getIdentifiableProperty();
+
for ( T object : objects )
{
if ( IdentifiableProperty.ID.equals( property ) )
@@ -333,7 +333,7 @@
}
}
}
-
+
return map;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-12-03 19:01:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-12-04 05:41:43 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.user.UserCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
@@ -677,9 +678,15 @@
}
@Override
- @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property )
{
+ return getIdMap( clazz, IdScheme.from( property ) );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdScheme idScheme )
+ {
Map<String, T> map = new HashMap<>();
GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
@@ -691,13 +698,19 @@
List<T> objects = store.getAll();
- return IdentifiableObjectUtils.getMap( objects, property );
+ return IdentifiableObjectUtils.getMap( objects, idScheme );
}
@Override
- @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdentifiableProperty property )
{
+ return getIdMapNoAcl( clazz, IdScheme.from( property ) );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdScheme idScheme )
+ {
Map<String, T> map = new HashMap<>();
GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
@@ -709,7 +722,7 @@
List<T> objects = store.getAllNoAcl();
- return IdentifiableObjectUtils.getMap( objects, property );
+ return IdentifiableObjectUtils.getMap( objects, idScheme );
}
@Override
@@ -804,52 +817,52 @@
@Override
public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String value )
{
- return getObject( clazz, property, null, value );
+ return getObject( clazz, IdScheme.from( property ), value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String aid, String value )
+ public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdScheme idScheme, String value )
{
GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
Attribute attribute = null;
- if ( aid != null )
+ if ( idScheme.isAttribute() )
{
- attribute = get( Attribute.class, aid );
+ attribute = get( Attribute.class, idScheme.getAttribute() );
}
- if ( value != null )
+ if ( !StringUtils.isEmpty( value ) )
{
- if ( IdentifiableProperty.UID == property )
+ if ( idScheme.isNull() || idScheme.is( IdentifiableProperty.UID ) )
{
return store.getByUid( value );
}
- else if ( IdentifiableProperty.CODE == property )
+ if ( idScheme.is( IdentifiableProperty.CODE ) )
{
return store.getByCode( value );
}
- else if ( IdentifiableProperty.NAME == property )
+ if ( idScheme.is( IdentifiableProperty.NAME ) )
{
return store.getByName( value );
}
- else if ( IdentifiableProperty.ATTRIBUTE == property )
+ if ( idScheme.is( IdentifiableProperty.ATTRIBUTE ) )
{
return store.getByAttributeValue( attribute, value );
}
- else if ( property == null || IdentifiableProperty.ID == property )
+ else if ( idScheme.is( IdentifiableProperty.ID ) )
{
if ( Integer.valueOf( value ) > 0 )
{
return store.get( Integer.valueOf( value ) );
}
}
- else if ( IdentifiableProperty.UUID.equals( property ) && OrganisationUnit.class.isAssignableFrom( clazz ) )
+ else if ( idScheme.is( IdentifiableProperty.UUID ) && OrganisationUnit.class.isAssignableFrom( clazz ) )
{
return (T) organisationUnitService.getOrganisationUnitByUuid( value );
}
- throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property );
+ throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + idScheme );
}
return null;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java 2015-12-03 07:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java 2015-12-04 05:41:43 +0000
@@ -205,7 +205,7 @@
dxfWriter.writeStartElement( "dataValueSet" );
dxfWriter.writeDefaultNamespace( "http://dhis2.org/schema/dxf/2.0" );
- IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme();
+ IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme().getIdentifiableProperty();
Map<String, String> groupAttributes = adxReader.readAttributes();
@@ -288,7 +288,7 @@
throw new AdxException( AdxDataService.VALUE + " attribute is required on 'dataValue'" );
}
- IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme();
+ IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme().getIdentifiableProperty();
DataElement dataElement = identifiableObjectManager.getObject( DataElement.class, dataElementIdScheme, dvAttributes.get( AdxDataService.DATAELEMENT ) );
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/IdSchemes.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/IdSchemes.java 2015-12-03 07:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/IdSchemes.java 1970-01-01 00:00:00 +0000
@@ -1,262 +0,0 @@
-package org.hisp.dhis.dxf2.common;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.base.MoreObjects;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableProperty;
-import org.springframework.util.StringUtils;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class IdSchemes
-{
- private IdentifiableProperty idScheme = IdentifiableProperty.UID;
-
- private String idSchemeAttribute;
-
- private IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
-
- private String dataElementIdSchemeAttribute;
-
- private IdentifiableProperty categoryOptionComboIdScheme = IdentifiableProperty.UID;
-
- private String categoryOptionComboIdSchemeAttribute;
-
- private IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
-
- private String orgUnitIdSchemeAttribute;
-
- private IdentifiableProperty programIdScheme = IdentifiableProperty.UID;
-
- private String programIdSchemeAttribute;
-
- private IdentifiableProperty programStageIdScheme = IdentifiableProperty.UID;
-
- private String programStageIdSchemeAttribute;
-
- public IdSchemes()
- {
- }
-
- public IdentifiableProperty getScheme( IdentifiableProperty identifiableProperty )
- {
- return idScheme != null ? idScheme : identifiableProperty;
- }
-
- public IdentifiableProperty getIdScheme()
- {
- return idScheme;
- }
-
- public String getIdSchemeAttribute()
- {
- return idSchemeAttribute;
- }
-
- public IdSchemes setIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.idScheme = IdentifiableProperty.ATTRIBUTE;
- this.idSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.idScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public IdentifiableProperty getDataElementIdScheme()
- {
- return getScheme( dataElementIdScheme );
- }
-
- public String getDataElementIdSchemeAttribute()
- {
- return dataElementIdSchemeAttribute;
- }
-
- public IdSchemes setDataElementIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.dataElementIdScheme = IdentifiableProperty.ATTRIBUTE;
- this.dataElementIdSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.dataElementIdScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public IdentifiableProperty getCategoryOptionComboIdScheme()
- {
- return getScheme( categoryOptionComboIdScheme );
- }
-
- public String getCategoryOptionComboIdSchemeAttribute()
- {
- return categoryOptionComboIdSchemeAttribute;
- }
-
- public IdSchemes setCategoryOptionComboIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.categoryOptionComboIdScheme = IdentifiableProperty.ATTRIBUTE;
- this.categoryOptionComboIdSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.categoryOptionComboIdScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public IdentifiableProperty getOrgUnitIdScheme()
- {
- return getScheme( orgUnitIdScheme );
- }
-
- public String getOrgUnitIdSchemeAttribute()
- {
- return orgUnitIdSchemeAttribute;
- }
-
- public IdSchemes setOrgUnitIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.orgUnitIdScheme = IdentifiableProperty.ATTRIBUTE;
- this.orgUnitIdSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.orgUnitIdScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public IdentifiableProperty getProgramIdScheme()
- {
- return getScheme( programIdScheme );
- }
-
- public String getProgramIdSchemeAttribute()
- {
- return programIdSchemeAttribute;
- }
-
- public IdSchemes setProgramIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.programIdScheme = IdentifiableProperty.ATTRIBUTE;
- this.programIdSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.programIdScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public IdentifiableProperty getProgramStageIdScheme()
- {
- return getScheme( programStageIdScheme );
- }
-
- public String getProgramStageIdSchemeAttribute()
- {
- return programStageIdSchemeAttribute;
- }
-
- public IdSchemes setProgramStageIdScheme( String idScheme )
- {
- if ( isAttribute( idScheme ) )
- {
- this.programStageIdScheme = IdentifiableProperty.ATTRIBUTE;
- this.programStageIdSchemeAttribute = idScheme.substring( 10 );
- return this;
- }
-
- this.programStageIdScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );
- return this;
- }
-
- public static String getValue( String uid, String code, IdentifiableProperty identifiableProperty )
- {
- boolean idScheme = IdentifiableProperty.ID.equals( identifiableProperty ) || IdentifiableProperty.UID.equals( identifiableProperty );
- return idScheme ? uid : code;
- }
-
-
- public static String getValue( IdentifiableObject identifiableObject, IdentifiableProperty identifiableProperty )
- {
- boolean idScheme = IdentifiableProperty.ID.equals( identifiableProperty ) || IdentifiableProperty.UID.equals( identifiableProperty );
-
- if ( idScheme )
- {
- return identifiableObject.getUid();
- }
- else if ( IdentifiableProperty.CODE.equals( identifiableProperty ) )
- {
- return identifiableObject.getCode();
- }
- else if ( IdentifiableProperty.NAME.equals( identifiableProperty ) )
- {
- return identifiableObject.getName();
- }
-
- return null;
- }
-
- public static boolean isAttribute( String str )
- {
- return !StringUtils.isEmpty( str ) && str.toUpperCase().startsWith( "ATTRIBUTE:" ) && str.length() == 21;
- }
-
- @Override
- public String toString()
- {
- return MoreObjects.toStringHelper( this )
- .add( "idScheme", idScheme )
- .add( "idSchemeAttribute", idSchemeAttribute )
- .add( "dataElementIdScheme", dataElementIdScheme )
- .add( "dataElementIdSchemeAttribute", dataElementIdSchemeAttribute )
- .add( "categoryOptionComboIdScheme", categoryOptionComboIdScheme )
- .add( "categoryOptionComboIdSchemeAttribute", categoryOptionComboIdSchemeAttribute )
- .add( "orgUnitIdScheme", orgUnitIdScheme )
- .add( "orgUnitIdSchemeAttribute", orgUnitIdSchemeAttribute )
- .add( "programIdScheme", programIdScheme )
- .add( "programIdSchemeAttribute", programIdSchemeAttribute )
- .add( "programStageIdScheme", programStageIdScheme )
- .add( "programStageIdSchemeAttribute", programStageIdSchemeAttribute )
- .toString();
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java 2015-12-03 07:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java 2015-12-04 05:41:43 +0000
@@ -29,6 +29,7 @@
*/
import com.google.common.base.MoreObjects;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.common.MergeStrategy;
import org.hisp.dhis.importexport.ImportStrategy;
@@ -173,73 +174,43 @@
public ImportOptions setProgramStageIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setProgramStageIdScheme( idScheme );
return this;
}
public ImportOptions setProgramIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setProgramIdScheme( idScheme );
return this;
}
public ImportOptions setOrgUnitIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setOrgUnitIdScheme( idScheme );
return this;
}
public ImportOptions setCategoryOptionComboIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setCategoryOptionComboIdScheme( idScheme );
return this;
}
public ImportOptions setDataElementIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setDataElementIdScheme( idScheme );
return this;
}
public ImportOptions setIdScheme( String idScheme )
{
- if ( this.idSchemes == null )
- {
- this.idSchemes = new IdSchemes();
- }
-
idSchemes.setIdScheme( idScheme );
return this;
}
public void setIdSchemes( IdSchemes idSchemes )
{
- this.idSchemes = idSchemes;
+ this.idSchemes = idSchemes == null ? new IdSchemes() : idSchemes;
}
public ImportOptions setDryRun( boolean dryRun )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-09-23 17:15:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-12-04 05:41:43 +0000
@@ -33,7 +33,7 @@
import java.util.Set;
import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2015-07-08 09:56:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2015-12-04 05:41:43 +0000
@@ -31,7 +31,7 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.common.ImportOptions;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.scheduling.TaskId;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java 2015-09-13 21:54:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java 2015-12-04 05:41:43 +0000
@@ -32,7 +32,7 @@
import java.io.Writer;
import java.util.Date;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-12-03 12:13:03 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-12-04 05:41:43 +0000
@@ -36,6 +36,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdScheme;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.IdentifiableProperty;
import org.hisp.dhis.common.IllegalQueryException;
@@ -49,7 +51,6 @@
import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.dxf2.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
@@ -549,15 +550,15 @@
log.info( "Import options: " + importOptions );
- IdentifiableProperty dvSetIdScheme = dataValueSet.getIdSchemeProperty();
- IdentifiableProperty dvSetDataElementIdScheme = dataValueSet.getDataElementIdSchemeProperty();
- IdentifiableProperty dvSetOrgUnitIdScheme = dataValueSet.getOrgUnitIdSchemeProperty();
+ IdScheme dvSetIdScheme = IdScheme.from( dataValueSet.getIdSchemeProperty() );
+ IdScheme dvSetDataElementIdScheme = IdScheme.from( dataValueSet.getDataElementIdSchemeProperty() );
+ IdScheme dvSetOrgUnitIdScheme = IdScheme.from( dataValueSet.getOrgUnitIdSchemeProperty() );
log.info( "Data value set scheme: " + dvSetIdScheme + ", data element scheme: " + dvSetDataElementIdScheme + ", org unit scheme: " + dvSetOrgUnitIdScheme );
- IdentifiableProperty idScheme = dvSetIdScheme != null ? dvSetIdScheme : importOptions.getIdSchemes().getIdScheme();
- IdentifiableProperty dataElementIdScheme = dvSetDataElementIdScheme != null ? dvSetDataElementIdScheme : importOptions.getIdSchemes().getDataElementIdScheme();
- IdentifiableProperty orgUnitIdScheme = dvSetOrgUnitIdScheme != null ? dvSetOrgUnitIdScheme : importOptions.getIdSchemes().getOrgUnitIdScheme();
+ IdScheme idScheme = dvSetIdScheme.isNotNull() ? dvSetIdScheme : importOptions.getIdSchemes().getIdScheme();
+ IdScheme dataElementIdScheme = dvSetDataElementIdScheme.isNotNull() ? dvSetDataElementIdScheme : importOptions.getIdSchemes().getDataElementIdScheme();
+ IdScheme orgUnitIdScheme = dvSetOrgUnitIdScheme.isNotNull() ? dvSetOrgUnitIdScheme : importOptions.getIdSchemes().getOrgUnitIdScheme();
log.info( "Scheme: " + idScheme + ", data element scheme: " + dataElementIdScheme + ", org unit scheme: " + orgUnitIdScheme );
@@ -605,10 +606,8 @@
identifiableObjectManager, DataElement.class, dataElementIdScheme, null );
IdentifiableObjectCallable<OrganisationUnit> orgUnitCallable = new IdentifiableObjectCallable<>(
identifiableObjectManager, OrganisationUnit.class, orgUnitIdScheme, trimToNull( dataValueSet.getOrgUnit() ) );
- IdentifiableObjectCallable<DataElementCategoryOptionCombo> optionComboCallable = new CategoryOptionComboAclCallable(
- categoryService, idScheme, null );
- IdentifiableObjectCallable<Period> periodCallable = new PeriodCallable(
- periodService, null, trimToNull( dataValueSet.getPeriod() ) );
+ IdentifiableObjectCallable<DataElementCategoryOptionCombo> optionComboCallable = new CategoryOptionComboAclCallable( categoryService, idScheme, null );
+ IdentifiableObjectCallable<Period> periodCallable = new PeriodCallable( periodService, null, trimToNull( dataValueSet.getPeriod() ) );
//----------------------------------------------------------------------
// Get outer meta-data
@@ -980,10 +979,10 @@
summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) );
}
- private Map<String, OrganisationUnit> getOrgUnitMap( IdentifiableProperty orgUnitIdScheme )
+ private Map<String, OrganisationUnit> getOrgUnitMap( IdScheme idScheme )
{
- return UUID.equals( orgUnitIdScheme ) ?
+ return idScheme.is( UUID ) ?
organisationUnitService.getUuidOrganisationUnitMap() :
- identifiableObjectManager.getIdMap( OrganisationUnit.class, orgUnitIdScheme );
+ identifiableObjectManager.getIdMap( OrganisationUnit.class, idScheme );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-11-12 16:04:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-12-04 05:41:43 +0000
@@ -49,7 +49,7 @@
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.datavalue.DataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.PeriodType;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-12-03 07:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-12-04 05:41:43 +0000
@@ -34,7 +34,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
+import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.common.IdScheme;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.IdentifiableProperty;
import org.hisp.dhis.common.IllegalQueryException;
@@ -48,7 +51,6 @@
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dbms.DbmsManager;
-import org.hisp.dhis.dxf2.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus;
import org.hisp.dhis.dxf2.events.report.EventRow;
@@ -1271,7 +1273,7 @@
}
}
- private OrganisationUnit getOrganisationUnit( IdentifiableProperty scheme, String value )
+ private OrganisationUnit getOrganisationUnit( IdScheme idScheme, String value )
{
OrganisationUnit organisationUnit = null;
@@ -1285,15 +1287,15 @@
return organisationUnitCache.get( value );
}
- if ( IdentifiableProperty.UUID.equals( scheme ) )
+ if ( idScheme.is( IdentifiableProperty.UUID ) )
{
organisationUnit = organisationUnitService.getOrganisationUnitByUuid( value );
}
- else if ( IdentifiableProperty.CODE.equals( scheme ) )
+ else if ( idScheme.is( IdentifiableProperty.CODE ) )
{
organisationUnit = organisationUnitService.getOrganisationUnitByCode( value );
}
- else if ( IdentifiableProperty.NAME.equals( scheme ) )
+ else if ( idScheme.is( IdentifiableProperty.NAME ) )
{
List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName( value );
@@ -1302,6 +1304,11 @@
organisationUnit = organisationUnitByName.get( 0 );
}
}
+ else if ( idScheme.is( IdentifiableProperty.ATTRIBUTE ) )
+ {
+ Attribute attribute = manager.get( Attribute.class, idScheme.getAttribute() );
+ organisationUnit = manager.getByAttributeValue( OrganisationUnit.class, attribute, value );
+ }
else
{
organisationUnit = organisationUnitService.getOrganisationUnit( value );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java 2015-10-01 10:05:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java 2015-12-04 05:41:43 +0000
@@ -32,7 +32,7 @@
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-11-02 03:24:16 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-12-04 05:41:43 +0000
@@ -30,7 +30,7 @@
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.events.report.EventRows;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-11-20 12:41:11 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-12-04 05:41:43 +0000
@@ -32,9 +32,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.util.SqlHelper;
-import org.hisp.dhis.dxf2.common.IdSchemes;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus;
import org.hisp.dhis.dxf2.events.report.EventRow;
import org.hisp.dhis.dxf2.events.trackedentity.Attribute;
@@ -124,8 +124,8 @@
event.setDueDate( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_duedate" ) ) );
event.setEventDate( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_executiondate" ) ) );
event.setCreated( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_created" ) ) );
- event.setLastUpdated( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_lastupdated" ) ) );
-
+ event.setLastUpdated( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_lastupdated" ) ) );
+
event.setCompletedUser( rowSet.getString( "psi_completeduser" ) );
event.setCompletedDate( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_completeddate" ) ) );
@@ -388,8 +388,8 @@
{
sql += hlp.whereAnd() + " psi.lastupdated > '" + DateUtils.getLongDateString( params.getLastUpdated() ) + "' ";
}
-
- if( params.getCategoryOptionCombo() != null )
+
+ if ( params.getCategoryOptionCombo() != null )
{
sql += hlp.whereAnd() + " psi.attributeoptioncomboid = " + params.getCategoryOptionCombo().getId() + " ";
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/gml/DefaultGmlImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/gml/DefaultGmlImportService.java 2015-11-15 20:02:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/gml/DefaultGmlImportService.java 2015-12-04 05:41:43 +0000
@@ -28,25 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xerces.impl.io.MalformedByteSequenceException;
+import org.hisp.dhis.common.IdScheme;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.common.IdentifiableProperty;
@@ -67,9 +57,18 @@
import org.springframework.web.util.HtmlUtils;
import org.xml.sax.SAXParseException;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Maps;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
* Import geospatial data from GML documents and merge into OrganisationUnits.
@@ -264,7 +263,7 @@
for ( OrganisationUnit orgUnit : sourceList ) // Identifier Matching priority: uid, code, name
{
// Only matches if UID is actually in DB as an empty UID on input will be replaced by auto-generated value
-
+
if ( !Strings.isNullOrEmpty( orgUnit.getUid() ) && idObjectManager.exists( OrganisationUnit.class, orgUnit.getUid() ) )
{
uidMap.put( orgUnit.getUid(), orgUnit );
@@ -283,8 +282,7 @@
private Map<String, OrganisationUnit> getMatchingPersistedOrgUnits( Collection<String> identifiers, final IdentifiableProperty property )
{
List<OrganisationUnit> orgUnits = idObjectManager.getObjects( OrganisationUnit.class, property, identifiers );
-
- return IdentifiableObjectUtils.getMap( orgUnits, property );
+ return IdentifiableObjectUtils.getMap( orgUnits, IdScheme.from( property ) );
}
private void mergeNonGeoData( OrganisationUnit source, OrganisationUnit target )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java 2015-10-06 18:35:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java 2015-12-04 05:41:43 +0000
@@ -38,7 +38,7 @@
import org.hisp.dhis.configuration.Configuration;
import org.hisp.dhis.configuration.ConfigurationService;
import org.hisp.dhis.datavalue.DataValueService;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportSummaryResponseExtractor;
import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2015-12-03 07:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2015-12-04 05:41:43 +0000
@@ -30,6 +30,7 @@
import com.google.common.collect.Sets;
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategory;
@@ -43,7 +44,6 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.dxf2.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/CategoryOptionComboAclCallable.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/CategoryOptionComboAclCallable.java 2015-05-28 20:17:44 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/CategoryOptionComboAclCallable.java 2015-12-04 05:41:43 +0000
@@ -28,12 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.concurrent.ExecutionException;
-
-import org.hisp.dhis.common.IdentifiableProperty;
+import org.hisp.dhis.common.IdScheme;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
+import java.util.concurrent.ExecutionException;
+
/**
* @author Lars Helge Overland
*/
@@ -41,10 +41,10 @@
extends IdentifiableObjectCallable<DataElementCategoryOptionCombo>
{
private DataElementCategoryService categoryService;
-
- public CategoryOptionComboAclCallable( DataElementCategoryService categoryService, IdentifiableProperty property, String id )
+
+ public CategoryOptionComboAclCallable( DataElementCategoryService categoryService, IdScheme idScheme, String id )
{
- super( null, DataElementCategoryOptionCombo.class, property, id );
+ super( null, DataElementCategoryOptionCombo.class, idScheme, id );
this.categoryService = categoryService;
}
@@ -52,7 +52,7 @@
public DataElementCategoryOptionCombo call()
throws ExecutionException
{
- return categoryService.getDataElementCategoryOptionComboAcl( property, id );
+ return categoryService.getDataElementCategoryOptionComboAcl( idScheme.getIdentifiableProperty(), id );
}
@Override
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/IdentifiableObjectCallable.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/IdentifiableObjectCallable.java 2015-05-28 20:17:44 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/IdentifiableObjectCallable.java 2015-12-04 05:41:43 +0000
@@ -28,13 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.IdScheme;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
+
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.IdentifiableProperty;
-
/**
* @author Lars Helge Overland
*/
@@ -43,9 +43,9 @@
{
protected IdentifiableObjectManager manager;
protected Class<T> clazz;
- protected IdentifiableProperty property;
+ protected IdScheme idScheme = IdScheme.UID;
protected String id;
-
+
public IdentifiableObjectCallable( IdentifiableObjectManager manager, Class<T> clazz, String id )
{
this.manager = manager;
@@ -53,28 +53,21 @@
this.id = id;
}
- public IdentifiableObjectCallable( IdentifiableObjectManager manager, Class<T> clazz, IdentifiableProperty property, String id )
+ public IdentifiableObjectCallable( IdentifiableObjectManager manager, Class<T> clazz, IdScheme idScheme, String id )
{
this.manager = manager;
this.clazz = clazz;
- this.property = property;
+ this.idScheme = idScheme;
this.id = id;
}
-
+
@Override
public T call()
throws ExecutionException
{
- if ( property == null )
- {
- return manager.get( clazz, id );
- }
- else
- {
- return manager.getObject( clazz, property, id );
- }
+ return manager.getObject( clazz, idScheme, id );
}
-
+
public IdentifiableObjectCallable<T> setId( String id )
{
this.id = id;
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/PeriodCallable.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/PeriodCallable.java 2015-05-29 15:24:03 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/callable/PeriodCallable.java 2015-12-04 05:41:43 +0000
@@ -28,12 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.concurrent.ExecutionException;
-
-import org.hisp.dhis.common.IdentifiableProperty;
+import org.hisp.dhis.common.IdScheme;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
+import java.util.concurrent.ExecutionException;
+
/**
* @author Lars Helge Overland
*/
@@ -41,20 +41,20 @@
extends IdentifiableObjectCallable<Period>
{
private PeriodService periodService;
-
- public PeriodCallable( PeriodService periodService, IdentifiableProperty property, String id )
+
+ public PeriodCallable( PeriodService periodService, IdScheme idScheme, String id )
{
- super( null, Period.class, property, id );
+ super( null, Period.class, idScheme, id );
this.periodService = periodService;
}
-
+
@Override
public Period call()
throws ExecutionException
{
return periodService.reloadIsoPeriod( id );
}
-
+
@Override
public PeriodCallable setId( String id )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2015-11-02 18:56:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2015-12-04 05:41:43 +0000
@@ -30,7 +30,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.datavalueset.DataExportParams;
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-11-17 17:01:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-12-04 05:41:43 +0000
@@ -34,7 +34,7 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.events.event.DataValue;
import org.hisp.dhis.dxf2.events.event.Event;
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2015-12-03 02:06:56 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2015-12-04 05:41:43 +0000
@@ -4,7 +4,7 @@
import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.common.IdentifiableProperty;
-import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.datavalueset.DataExportParams;
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
import org.hisp.dhis.oust.manager.SelectionTreeManager;