dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28531
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14250: support update of TrackedEntityAttribute/TrackedEntityAttributeGroup through web-api
------------------------------------------------------------
revno: 14250
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-17 14:26:23 +0100
message:
support update of TrackedEntityAttribute/TrackedEntityAttributeGroup through web-api
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeGroup.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeGroupController.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/trackedentity/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java 2014-03-17 13:15:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java 2014-03-17 13:26:23 +0000
@@ -36,6 +36,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.WithoutOrganisationUnitsView;
import org.hisp.dhis.period.PeriodType;
@@ -403,4 +404,35 @@
return age;
}
+
+ @Override
+ public void mergeWith( IdentifiableObject other )
+ {
+ super.mergeWith( other );
+
+ if ( other.getClass().isInstance( this ) )
+ {
+ TrackedEntityAttribute trackedEntityAttribute = (TrackedEntityAttribute) other;
+
+ description = trackedEntityAttribute.getDescription();
+ valueType = trackedEntityAttribute.getValueType();
+ mandatory = trackedEntityAttribute.isMandatory();
+ inherit = trackedEntityAttribute.getInherit();
+ groupBy = trackedEntityAttribute.getGroupBy();
+ attributeGroup = trackedEntityAttribute.getAttributeGroup();
+
+ attributeOptions.clear();
+ attributeOptions.addAll( trackedEntityAttribute.getAttributeOptions() );
+
+ expression = trackedEntityAttribute.getExpression();
+ displayOnVisitSchedule = trackedEntityAttribute.getDisplayOnVisitSchedule();
+ sortOrderInVisitSchedule = trackedEntityAttribute.getSortOrderInVisitSchedule();
+ displayInListNoProgram = trackedEntityAttribute.getDisplayInListNoProgram();
+ sortOrderInListNoProgram = trackedEntityAttribute.getSortOrderInListNoProgram();
+ unique = trackedEntityAttribute.getUnique();
+ orgunitScope = trackedEntityAttribute.getOrgunitScope();
+ programScope = trackedEntityAttribute.getProgramScope();
+ periodType = trackedEntityAttribute.getPeriodType();
+ }
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeGroup.java 2014-03-17 13:15:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeGroup.java 2014-03-17 13:26:23 +0000
@@ -36,6 +36,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
@@ -109,4 +110,20 @@
{
this.sortOrder = sortOrder;
}
+
+ @Override
+ public void mergeWith( IdentifiableObject other )
+ {
+ super.mergeWith( other );
+
+ if ( other.getClass().isInstance( this ) )
+ {
+ TrackedEntityAttributeGroup trackedEntityAttributeGroup = (TrackedEntityAttributeGroup) other;
+
+ description = trackedEntityAttributeGroup.getDescription();
+
+ attributes.clear();
+ attributes.addAll( trackedEntityAttributeGroup.getAttributes() );
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeController.java 2014-03-17 13:17:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeController.java 2014-03-17 13:26:23 +0000
@@ -41,7 +41,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
-import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -144,14 +143,38 @@
@ResponseStatus( value = HttpStatus.NO_CONTENT )
public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
{
- throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+ TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute( uid );
+
+ if ( trackedEntityAttribute == null )
+ {
+ ContextUtils.conflictResponse( response, "TrackedEntityAttribute does not exist: " + uid );
+ return;
+ }
+
+ TrackedEntityAttribute newTrackedEntityAttribute = JacksonUtils.fromXml( input, TrackedEntityAttribute.class );
+ newTrackedEntityAttribute.setUid( trackedEntityAttribute.getUid() );
+ trackedEntityAttribute.mergeWith( newTrackedEntityAttribute );
+
+ trackedEntityAttributeService.updateTrackedEntityAttribute( trackedEntityAttribute );
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@ResponseStatus( value = HttpStatus.NO_CONTENT )
public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
{
- throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+ TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute( uid );
+
+ if ( trackedEntityAttribute == null )
+ {
+ ContextUtils.conflictResponse( response, "TrackedEntityAttribute does not exist: " + uid );
+ return;
+ }
+
+ TrackedEntityAttribute newTrackedEntityAttribute = JacksonUtils.fromJson( input, TrackedEntityAttribute.class );
+ newTrackedEntityAttribute.setUid( trackedEntityAttribute.getUid() );
+ trackedEntityAttribute.mergeWith( newTrackedEntityAttribute );
+
+ trackedEntityAttributeService.updateTrackedEntityAttribute( trackedEntityAttribute );
}
//--------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeGroupController.java 2014-03-17 13:17:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityAttributeGroupController.java 2014-03-17 13:26:23 +0000
@@ -36,7 +36,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
-import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -90,14 +89,38 @@
@ResponseStatus( value = HttpStatus.NO_CONTENT )
public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
{
- throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+ TrackedEntityAttributeGroup trackedEntityAttributeGroup = trackedEntityAttributeGroupService.getTrackedEntityAttributeGroup( uid );
+
+ if ( trackedEntityAttributeGroup == null )
+ {
+ ContextUtils.conflictResponse( response, "TrackedEntityAttributeGroup does not exist: " + uid );
+ return;
+ }
+
+ TrackedEntityAttributeGroup newTrackedEntityAttributeGroup = JacksonUtils.fromXml( input, TrackedEntityAttributeGroup.class );
+ newTrackedEntityAttributeGroup.setUid( trackedEntityAttributeGroup.getUid() );
+ trackedEntityAttributeGroup.mergeWith( newTrackedEntityAttributeGroup );
+
+ trackedEntityAttributeGroupService.updateTrackedEntityAttributeGroup( trackedEntityAttributeGroup );
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@ResponseStatus( value = HttpStatus.NO_CONTENT )
public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
{
- throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+ TrackedEntityAttributeGroup trackedEntityAttributeGroup = trackedEntityAttributeGroupService.getTrackedEntityAttributeGroup( uid );
+
+ if ( trackedEntityAttributeGroup == null )
+ {
+ ContextUtils.conflictResponse( response, "TrackedEntityAttributeGroup does not exist: " + uid );
+ return;
+ }
+
+ TrackedEntityAttributeGroup newTrackedEntityAttributeGroup = JacksonUtils.fromJson( input, TrackedEntityAttributeGroup.class );
+ newTrackedEntityAttributeGroup.setUid( trackedEntityAttributeGroup.getUid() );
+ trackedEntityAttributeGroup.mergeWith( newTrackedEntityAttributeGroup );
+
+ trackedEntityAttributeGroupService.updateTrackedEntityAttributeGroup( trackedEntityAttributeGroup );
}
//--------------------------------------------------------------------------