dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43074
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21900: minor object bundle fixes
------------------------------------------------------------
revno: 21900
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-02-08 14:21:53 +0700
message:
minor object bundle fixes
added:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleException.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/degAUidRef.json
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundle.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-02-04 08:01:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-02-08 07:21:53 +0000
@@ -44,6 +44,12 @@
}
@Override
+ public void validate( ObjectBundle bundle )
+ {
+
+ }
+
+ @Override
public void commit( ObjectBundle bundle )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundle.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundle.java 2016-02-04 08:01:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundle.java 2016-02-08 07:21:53 +0000
@@ -28,9 +28,91 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.preheat.Preheat;
+import org.hisp.dhis.preheat.PreheatIdentifier;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public class ObjectBundle
{
+ private ObjectBundleMode objectBundleMode = ObjectBundleMode.COMMIT;
+
+ private PreheatIdentifier preheatIdentifier = PreheatIdentifier.UID;
+
+ private Preheat preheat = new Preheat();
+
+ private Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objects = new HashMap<>();
+
+ public ObjectBundle()
+ {
+ }
+
+ public ObjectBundleMode getObjectBundleMode()
+ {
+ return objectBundleMode;
+ }
+
+ public void setObjectBundleMode( ObjectBundleMode objectBundleMode )
+ {
+ this.objectBundleMode = objectBundleMode;
+ }
+
+ public PreheatIdentifier getPreheatIdentifier()
+ {
+ return preheatIdentifier;
+ }
+
+ public void setPreheatIdentifier( PreheatIdentifier preheatIdentifier )
+ {
+ this.preheatIdentifier = preheatIdentifier;
+ }
+
+ public Preheat getPreheat()
+ {
+ return preheat;
+ }
+
+ public void setPreheat( Preheat preheat )
+ {
+ this.preheat = preheat;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> void addObject( T object )
+ {
+ if ( object == null )
+ {
+ return;
+ }
+
+ if ( !objects.containsKey( object.getClass() ) )
+ {
+ objects.put( object.getClass(), new ArrayList<>() );
+ }
+
+ objects.get( object.getClass() ).add( object );
+ preheat.put( preheatIdentifier, object );
+ }
+
+ public <T extends IdentifiableObject> void addObjects( List<T> objects )
+ {
+ objects.forEach( this::addObject );
+ }
+
+ public Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> getObjects()
+ {
+ return objects;
+ }
+
+ public void setObjects( Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objects )
+ {
+ this.objects = objects;
+ }
}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleException.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleException.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleException.java 2016-02-08 07:21:53 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.dxf2.metadata2.objectbundle;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ObjectBundleException
+ extends RuntimeException
+{
+ public ObjectBundleException( String message )
+ {
+ super( message );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleParams.java 2016-02-04 08:01:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleParams.java 2016-02-08 07:21:53 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.preheat.PreheatIdentifier;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -35,6 +37,8 @@
{
private ObjectBundleMode objectBundleMode;
+ private PreheatIdentifier preheatIdentifier;
+
public ObjectBundleParams()
{
}
@@ -49,4 +53,15 @@
this.objectBundleMode = objectBundleMode;
return this;
}
+
+ public PreheatIdentifier getPreheatIdentifier()
+ {
+ return preheatIdentifier;
+ }
+
+ public ObjectBundleParams setPreheatIdentifier( PreheatIdentifier preheatIdentifier )
+ {
+ this.preheatIdentifier = preheatIdentifier;
+ return this;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java 2016-02-04 08:01:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java 2016-02-08 07:21:53 +0000
@@ -42,6 +42,13 @@
ObjectBundle create( ObjectBundleParams params );
/**
+ * Validate object bundle
+ *
+ * @param bundle Bundle to validate
+ */
+ void validate( ObjectBundle bundle );
+
+ /**
* Commits objects from bundle into persistence store if bundle mode COMMIT is enabled.
*
* @param bundle ObjectBundle to commit.
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-02-04 08:01:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-02-08 07:21:53 +0000
@@ -29,10 +29,14 @@
*/
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.preheat.PreheatIdentifier;
+import org.hisp.dhis.render.RenderService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -43,6 +47,15 @@
@Autowired
private ObjectBundleService objectBundleService;
+ @Autowired
+ private RenderService _renderService;
+
+ @Override
+ protected void setUpTest() throws Exception
+ {
+ renderService = _renderService;
+ }
+
@Test
public void testCreateObjectBundle()
{
@@ -51,4 +64,17 @@
assertNotNull( bundle );
}
+
+ @Test
+ public void testObjectBundleShouldAddToObjectAndPreheat()
+ {
+ ObjectBundleParams params = new ObjectBundleParams();
+ ObjectBundle bundle = objectBundleService.create( params );
+
+ DataElementGroup dataElementGroup = fromJson( "dxf2/degAUidRef.json", DataElementGroup.class );
+ bundle.addObject( dataElementGroup );
+
+ assertTrue( bundle.getObjects().get( DataElementGroup.class ).contains( dataElementGroup ) );
+ assertTrue( bundle.getPreheat().containsKey( PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid() ) );
+ }
}
\ No newline at end of file
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/degAUidRef.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/degAUidRef.json 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/degAUidRef.json 2016-02-08 07:21:53 +0000
@@ -0,0 +1,17 @@
+{
+ "name": "DataElementGroupA",
+ "user": {
+ "id": "userabcdefA"
+ },
+ "dataElements": [
+ {
+ "id": "deabcdefghA"
+ },
+ {
+ "id": "deabcdefghB"
+ },
+ {
+ "id": "deabcdefghC"
+ }
+ ]
+}
\ No newline at end of file