dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42236
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21579: moved methods from ImportUtils => IdObjectUtils, and removed ImportUtils class
------------------------------------------------------------
revno: 21579
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 14:41:40 +0700
message:
moved methods from ImportUtils => IdObjectUtils, and removed ImportUtils class
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportUtils.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2016-01-05 07:41:40 +0000
@@ -336,4 +336,35 @@
return map;
}
+
+ /**
+ * @param object Object to get display name for
+ * @return A usable display name
+ */
+ public static String getDisplayName( Object object )
+ {
+ if ( object == null )
+ {
+ return "[ object is null ]";
+ }
+ else if ( IdentifiableObject.class.isInstance( object ) )
+ {
+ IdentifiableObject identifiableObject = (IdentifiableObject) object;
+
+ if ( identifiableObject.getDisplayName() != null && !identifiableObject.getDisplayName().isEmpty() )
+ {
+ return identifiableObject.getDisplayName();
+ }
+ else if ( identifiableObject.getUid() != null && !identifiableObject.getUid().isEmpty() )
+ {
+ return identifiableObject.getUid();
+ }
+ else if ( identifiableObject.getCode() != null && !identifiableObject.getCode().isEmpty() )
+ {
+ return identifiableObject.getCode();
+ }
+ }
+
+ return object.getClass().getName();
+ }
}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportUtils.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportUtils.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportUtils.java 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-package org.hisp.dhis.dxf2.common;
-
-/*
- * Copyright (c) 2004-2016, 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;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class ImportUtils
-{
- /**
- * @param object Object to get display name for
- * @return A usable display name
- */
- public static String getDisplayName( Object object )
- {
- if ( object == null )
- {
- return "[ object is null ]";
- }
- else if ( IdentifiableObject.class.isInstance( object ) )
- {
- IdentifiableObject identifiableObject = (IdentifiableObject) object;
-
- if ( identifiableObject.getName() != null && identifiableObject.getName().length() > 0 )
- {
- return identifiableObject.getName();
- }
- else if ( identifiableObject.getUid() != null && identifiableObject.getUid().length() > 0 )
- {
- return identifiableObject.getUid();
- }
- else if ( identifiableObject.getCode() != null && identifiableObject.getCode().length() > 0 )
- {
- return identifiableObject.getCode();
- }
- }
-
- return object.getClass().getName();
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2016-01-05 07:41:40 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DataDimensionItem;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.constant.Constant;
import org.hisp.dhis.dashboard.DashboardItem;
@@ -52,7 +53,6 @@
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dxf2.common.ImportOptions;
-import org.hisp.dhis.dxf2.common.ImportUtils;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
import org.hisp.dhis.dxf2.metadata.Importer;
@@ -234,7 +234,7 @@
if ( !aclService.canDelete( user, persistedObject ) )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( persistedObject ), "Permission denied for deletion of object " +
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( persistedObject ), "Permission denied for deletion of object " +
persistedObject.getUid() ) );
log.debug( "Permission denied for deletion of object " + persistedObject.getUid() );
@@ -242,7 +242,7 @@
return false;
}
- log.debug( "Trying to delete object => " + ImportUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass()
+ log.debug( "Trying to delete object => " + IdentifiableObjectUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass()
.getSimpleName() + ")" );
try
@@ -252,7 +252,7 @@
catch ( Exception ex )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( persistedObject ), ex.getMessage() ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( persistedObject ), ex.getMessage() ) );
return false;
}
@@ -274,7 +274,7 @@
if ( !aclService.canCreate( user, object.getClass() ) )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "Permission denied, you are not allowed to create objects of " +
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Permission denied, you are not allowed to create objects of " +
"type " + object.getClass() ) );
log.debug( "Permission denied, you are not allowed to create objects of type " + object.getClass() );
@@ -287,7 +287,7 @@
if ( !validationViolations.isEmpty() )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
return false;
}
@@ -306,7 +306,7 @@
if ( !validationViolations.isEmpty() )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
return false;
}
@@ -322,7 +322,7 @@
if ( userCredentials == null )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "User is missing userCredentials part." ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "User is missing userCredentials part." ) );
return false;
}
@@ -333,7 +333,7 @@
reattachFields( object, fields, user );
- log.debug( "Trying to save new object => " + ImportUtils.getDisplayName( object ) + " (" + object.getClass().getSimpleName() + ")" +
+ log.debug( "Trying to save new object => " + IdentifiableObjectUtils.getDisplayName( object ) + " (" + object.getClass().getSimpleName() + ")" +
"" );
updatePeriodTypes( object );
@@ -391,7 +391,7 @@
if ( !aclService.canUpdate( user, persistedObject ) )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( persistedObject ), "Permission denied for update of object " +
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( persistedObject ), "Permission denied for update of object " +
persistedObject.getUid() ) );
log.debug( "Permission denied for update of object " + persistedObject.getUid() );
@@ -412,7 +412,7 @@
if ( !validationViolations.isEmpty() )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
return false;
}
@@ -423,7 +423,7 @@
if ( !validationViolations.isEmpty() )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
return false;
}
@@ -440,7 +440,7 @@
if ( userCredentials == null )
{
summaryType.getImportConflicts().add(
- new ImportConflict( ImportUtils.getDisplayName( object ), "User is missing userCredentials part." ) );
+ new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "User is missing userCredentials part." ) );
return false;
}
@@ -469,7 +469,7 @@
reattachCollectionFields( persistedObject, collectionFields, user );
- log.debug( "Starting update of object " + ImportUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass()
+ log.debug( "Starting update of object " + IdentifiableObjectUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass()
.getSimpleName() + ")" );
objectBridge.updateObject( persistedObject );
@@ -610,7 +610,7 @@
&& !DashboardItem.class.isInstance( object ) && !Translation.class.isInstance( object )
&& !ProgramStageDataElement.class.isInstance( object ) )
{
- conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty name for object " + object );
+ conflict = new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Empty name for object " + object );
}
if ( NameableObject.class.isInstance( object ) )
@@ -627,7 +627,7 @@
&& !ProgramStageDataElement.class.isAssignableFrom( object.getClass() )
&& !Constant.class.isAssignableFrom( object.getClass() ) )
{
- conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty shortName for object " + object );
+ conflict = new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Empty shortName for object " + object );
}
}
@@ -866,17 +866,17 @@
private ImportConflict reportLookupConflict( IdentifiableObject object )
{
- return new ImportConflict( ImportUtils.getDisplayName( object ), "Object does not exist." );
+ return new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Object does not exist." );
}
private ImportConflict reportMoreThanOneConflict( IdentifiableObject object )
{
- return new ImportConflict( ImportUtils.getDisplayName( object ), "More than one object matches identifiers." );
+ return new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "More than one object matches identifiers." );
}
private ImportConflict reportConflict( IdentifiableObject object )
{
- return new ImportConflict( ImportUtils.getDisplayName( object ), "Object already exists." );
+ return new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), "Object already exists." );
}
public String identifiableObjectToString( Object object )
@@ -913,7 +913,7 @@
log.debug( logMsg );
- ImportConflict importConflict = new ImportConflict( ImportUtils.getDisplayName( object ), logMsg );
+ ImportConflict importConflict = new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), logMsg );
summaryType.getImportConflicts().add( importConflict );
}
@@ -927,7 +927,7 @@
log.debug( logMsg );
- ImportConflict importConflict = new ImportConflict( ImportUtils.getDisplayName( object ), logMsg );
+ ImportConflict importConflict = new ImportConflict( IdentifiableObjectUtils.getDisplayName( object ), logMsg );
summaryType.getImportConflicts().add( importConflict );
}