dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33697
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17252: Approval, added resource for getting approvals by category option combo
------------------------------------------------------------
revno: 17252
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-23 21:09:36 +0200
message:
Approval, added resource for getting approvals by category option combo
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.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/dataapproval/DataApprovalLevel.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java 2014-10-03 22:13:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevel.java 2014-10-23 19:09:36 +0000
@@ -30,6 +30,7 @@
import java.util.Date;
+import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.view.DetailedView;
@@ -38,6 +39,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -188,6 +190,7 @@
}
@JsonProperty
+ @JsonSerialize( as = BaseDimensionalObject.class )
@JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public CategoryOptionGroupSet getCategoryOptionGroupSet()
@@ -200,6 +203,9 @@
this.categoryOptionGroupSet = categoryOptionGroupSet;
}
+ @JsonProperty
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getOrgUnitLevelName()
{
return orgUnitLevelName;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-10-23 18:31:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-10-23 19:09:36 +0000
@@ -34,9 +34,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
@@ -267,6 +269,47 @@
createdDate, createdByUsername, status.getPermissions() );
}
+ @RequestMapping( method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON, value = "/categoryOptionCombos" )
+ public void getApprovalByCategoryOptionCombos(
+ @RequestParam Set<String> ds,
+ @RequestParam String pe,
+ HttpServletResponse response ) throws IOException
+ {
+ Set<DataSet> dataSets = new HashSet<>( manager.getByUid( DataSet.class, ds ) );
+
+ Period period = PeriodType.getPeriodFromIsoString( pe );
+
+ if ( period == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal period identifier: " + pe );
+ return;
+ }
+
+ List<DataApprovalStatus> statusList = dataApprovalService.getUserDataApprovalsAndPermissions( dataSets, period );
+
+ List<Map<String, Object>> list = new ArrayList<>();
+
+ for ( DataApprovalStatus status : statusList )
+ {
+ Map<String, Object> item = new HashMap<String, Object>();
+
+ DataApproval approval = status.getDataApproval();
+
+ if ( approval != null )
+ {
+ item.put( "id", approval.getAttributeOptionCombo().getUid() );
+ item.put( "level", status.getDataApprovalLevel() );
+ item.put( "ou", approval.getOrganisationUnit().getUid() );
+ item.put( "accepted", approval.isAccepted() );
+ item.put( "permissions", status.getPermissions() );
+
+ list.add( item );
+ }
+ }
+
+ JacksonUtils.toXml( response.getOutputStream(), list );
+ }
+
// -------------------------------------------------------------------------
// Post
// -------------------------------------------------------------------------