dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17589
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7050: Added lastUpdated param to meta-data exporter, ?lastUpdated=dd/MM/yyyy
------------------------------------------------------------
revno: 7050
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-05-26 18:15:25 +0200
message:
Added lastUpdated param to meta-data exporter, ?lastUpdated=dd/MM/yyyy
modified:
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/Options.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-05-26 14:32:28 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-05-26 16:15:25 +0000
@@ -75,6 +75,8 @@
log.info( "User '" + currentUserService.getCurrentUsername() + "' started export at " + new Date() );
+ Date lastUpdated = options.getDate( "lastUpdated" );
+
for ( Map.Entry<String, Class<?>> entry : ExchangeClasses.getExportMap().entrySet() )
{
if ( !options.isEnabled( entry.getKey() ) )
@@ -85,19 +87,26 @@
@SuppressWarnings( "unchecked" )
Class<? extends IdentifiableObject> idObjectClass = (Class<? extends IdentifiableObject>) entry.getValue();
- Collection<? extends IdentifiableObject> idObjects = manager.getAll( idObjectClass );
+ Collection<? extends IdentifiableObject> idObjects = null;
- if ( idObjects != null )
+ if ( lastUpdated != null )
{
- log.info( "Exporting " + idObjects.size() + " " + StringUtils.capitalize( entry.getKey() ) );
-
- List<? extends IdentifiableObject> idObjectsList = new ArrayList<IdentifiableObject>( idObjects );
- ReflectionUtils.invokeSetterMethod( entry.getKey(), metaData, idObjectsList );
+ idObjects = manager.getByLastUpdated( idObjectClass, lastUpdated );
}
else
{
- log.warn( "Skipping objects of type '" + entry.getValue().getSimpleName() + "'." );
- }
+ idObjects = manager.getAll( idObjectClass );
+ }
+
+ if ( idObjects.isEmpty() )
+ {
+ continue;
+ }
+
+ log.info( "Exporting " + idObjects.size() + " " + StringUtils.capitalize( entry.getKey() ) );
+
+ List<? extends IdentifiableObject> idObjectsList = new ArrayList<IdentifiableObject>( idObjects );
+ ReflectionUtils.invokeSetterMethod( entry.getKey(), metaData, idObjectsList );
}
log.info( "Finished export at " + new Date() );
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2012-05-26 14:32:28 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2012-05-26 16:15:25 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -46,14 +49,31 @@
return DEFAULT_OPTIONS;
}
- private static boolean isTrue( String bool )
- {
- return bool != null && bool.equalsIgnoreCase( "true" );
- }
-
- private static boolean isFalse( String bool )
- {
- return !isTrue( bool );
+ private static Date stringAsDate( String str )
+ {
+ if ( str == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ return new SimpleDateFormat( "dd/MM/yyyy" ).parse( str );
+ } catch ( ParseException ignored )
+ {
+ }
+
+ return null;
+ }
+
+ private static boolean stringAsBoolean( String str )
+ {
+ return str != null && str.equalsIgnoreCase( "true" );
+ }
+
+ private static boolean isTrue( String str )
+ {
+ return stringAsBoolean( str );
}
//--------------------------------------------------------------------------
@@ -79,16 +99,12 @@
public Options( Map<String, String> options )
{
- System.err.println("Options: " + options);
-
this.options = options;
this.assumeTrue = options.get( "assumeTrue" ) == null || options.get( "assumeTrue" ).equalsIgnoreCase( "true" );
}
public Options( Map<String, String> options, boolean assumeTrue )
{
- System.err.println("Options: " + options);
-
this.options = options;
this.assumeTrue = assumeTrue;
}
@@ -109,6 +125,11 @@
return !isEnabled( type );
}
+ public Date getDate( String key )
+ {
+ return stringAsDate( options.get( key ));
+ }
+
//--------------------------------------------------------------------------
// Getters and Setters
//--------------------------------------------------------------------------