dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #05883
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1850: Made the import process more robust in situations where an imported CalculatedDataElement is matc...
------------------------------------------------------------
revno: 1850
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Thu 2010-05-13 14:16:45 +0200
message:
Made the import process more robust in situations where an imported CalculatedDataElement is matching with a regular DataElement in the database and vice versa.
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractCalculatedDataElementConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractDataElementConverter.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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractCalculatedDataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractCalculatedDataElementConverter.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractCalculatedDataElementConverter.java 2010-05-13 12:16:45 +0000
@@ -83,7 +83,7 @@
if ( calculated != null )
{
- calculated.getExpression().getExpression(); // Load Expression into memory
+ calculated.getExpression().getExpression(); // Load Expression in session
}
return calculated;
@@ -129,5 +129,18 @@
}
return true;
- }
+ }
+
+ @Override
+ protected boolean ignore( CalculatedDataElement object, CalculatedDataElement match )
+ {
+ boolean ignore = !(object instanceof CalculatedDataElement) && match instanceof CalculatedDataElement;
+
+ if ( ignore )
+ {
+ log.warn( "Data element ignored because it matches with a calculated data element: " + object );
+ }
+
+ return ignore;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractConverter.java 2010-05-12 13:38:28 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractConverter.java 2010-05-13 12:16:45 +0000
@@ -33,6 +33,8 @@
import static org.hisp.dhis.importexport.ImportStrategy.NEW_AND_UPDATES;
import org.amplecode.quick.BatchHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.ImportableObject;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.importexport.GroupMemberType;
@@ -48,6 +50,8 @@
*/
public abstract class AbstractConverter<T extends ImportableObject>
{
+ protected static final Log log = LogFactory.getLog( AbstractConverter.class );
+
protected static final String EMPTY = "";
// -------------------------------------------------------------------------
@@ -105,14 +109,14 @@
{
if ( !params.isPreview() ) // Import object
{
- if ( !isIdentical( object, match ) ) // Skip if identical
+ if ( !isIdentical( object, match ) && !ignore( object, match ) ) // Skip if identical or ignore-able
{
importMatching( object, match );
}
}
else if ( params.isPreview() ) // Preview object. DataValue cannot be match in preview.
{
- ImportObjectStatus status = isIdentical( object, match ) ? MATCH : UPDATE;
+ ImportObjectStatus status = !isIdentical( object, match ) && !ignore( object, match ) ? UPDATE : MATCH;
importObjectService.addImportObject( status, groupMemberType, object, match ); // Set to match if existing, update otherwise
}
@@ -133,6 +137,15 @@
protected abstract boolean isIdentical( T object, T match );
// -------------------------------------------------------------------------
+ // Override-able methods
+ // -------------------------------------------------------------------------
+
+ protected boolean ignore( T object, T match )
+ {
+ return false;
+ }
+
+ // -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractDataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractDataElementConverter.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/converter/AbstractDataElementConverter.java 2010-05-13 12:16:45 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dataelement.CalculatedDataElement;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
@@ -116,4 +117,17 @@
return true;
}
+
+ @Override
+ protected boolean ignore( DataElement object, DataElement match )
+ {
+ boolean ignore = object instanceof CalculatedDataElement && !( match instanceof CalculatedDataElement );
+
+ if ( ignore )
+ {
+ log.warn( "Calculated data element ignored because it matches with a regular data element: " + object );
+ }
+
+ return ignore;
+ }
}