dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29024
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14589: Remove optionCombos, add option groups to DataApprovalController
------------------------------------------------------------
revno: 14589
committer: Jim Grace <jimgrace@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-01 13:04:30 -0400
message:
Remove optionCombos, add option groups to DataApprovalController
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/InputUtils.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java 2014-03-30 04:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java 2014-04-01 17:04:30 +0000
@@ -32,6 +32,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletResponse;
@@ -41,7 +42,7 @@
import org.hisp.dhis.api.utils.InputUtils;
import org.hisp.dhis.dataapproval.*;
import org.hisp.dhis.dataelement.CategoryOptionGroup;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -89,9 +90,6 @@
private OrganisationUnitService organisationUnitService;
@Autowired
- private DataElementCategoryService categoryService;
-
- @Autowired
private CurrentUserService currentUserService;
@Autowired
@@ -102,7 +100,7 @@
@RequestParam String ds,
@RequestParam String pe,
@RequestParam String ou,
- @RequestParam( required = false ) String cc,
+ @RequestParam( required = false ) Set<String> cog,
@RequestParam( required = false ) String cp, HttpServletResponse response ) throws IOException
{
log.info( "getApprovalState called." );
@@ -130,15 +128,22 @@
ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
return;
}
-
- DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
-
- if ( attributeOptionCombo == null )
- {
- return;
- }
-
- DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, attributeOptionCombo );
+
+ Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroups( response, cog );
+
+ if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+ {
+ return;
+ }
+
+ Set<DataElementCategoryOption> categoryOptions = inputUtils.getAttributeOptions( response, cp );
+
+ if ( categoryOptions != null && categoryOptions.isEmpty() )
+ {
+ return;
+ }
+
+ DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, categoryOptions );
Map<String, Object> approvalState = new HashMap<String, Object>();
approvalState.put( APPROVAL_STATE, permissions.getDataApprovalStatus().getDataApprovalState().toString() );
@@ -156,8 +161,7 @@
@RequestParam String ds,
@RequestParam String pe,
@RequestParam String ou,
- @RequestParam( required = false ) String cc,
- @RequestParam( required = false ) String cp, HttpServletResponse response )
+ @RequestParam( required = false ) String cog, HttpServletResponse response )
{
log.info( "saveApproval called." );
@@ -184,15 +188,15 @@
ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
return;
}
-
- DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
-
- if ( attributeOptionCombo == null )
+
+ Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+ if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
{
return;
}
-
- DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, attributeOptionCombo );
+
+ DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
if ( !DataApprovalState.UNAPPROVED_READY.equals( permissions.getDataApprovalStatus().getDataApprovalState() ) )
{
@@ -202,16 +206,16 @@
if ( !permissions.isMayApprove() )
{
- ContextUtils.conflictResponse( response, "Current user is not authorized to approve for organisation unit: " + ou );
+ ContextUtils.conflictResponse( response, "Current user is not authorized to approve for "
+ + approvalParameters( dataSet, period, organisationUnit, categoryOptionGroups ) );
return;
}
User user = currentUserService.getCurrentUser();
- //TODO: FIX. We need to know what CategoryOptionGroup if any was selected, to use when constructing the data approval object.
- CategoryOptionGroup attributeOptionGroup = null;
+ CategoryOptionGroup categoryOptionGroup = categoryOptionGroups == null ? null : (CategoryOptionGroup) categoryOptionGroups.toArray() [0];
- DataApproval approval = new DataApproval( dataSet, period, organisationUnit, attributeOptionGroup, false, new Date(), user );
+ DataApproval approval = new DataApproval( dataSet, period, organisationUnit, categoryOptionGroup, false, new Date(), user );
dataApprovalService.addDataApproval( approval );
}
@@ -223,8 +227,7 @@
@RequestParam String ds,
@RequestParam String pe,
@RequestParam String ou,
- @RequestParam( required = false ) String cc,
- @RequestParam( required = false ) String cp, HttpServletResponse response )
+ @RequestParam( required = false ) String cog, HttpServletResponse response )
{
log.info( "removeApproval called." );
@@ -251,15 +254,15 @@
ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
return;
}
-
- DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
-
- if ( attributeOptionCombo == null )
+
+ Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+ if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
{
return;
}
- DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, attributeOptionCombo );
+ DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
if ( !DataApprovalState.APPROVED_HERE.equals( permissions.getDataApprovalStatus().getDataApprovalState() ) )
{
@@ -270,7 +273,7 @@
if ( !permissions.isMayUnapprove() )
{
ContextUtils.conflictResponse( response, "Current user is not authorized to unapprove for "
- + approvalParameters( dataSet, period, organisationUnit, attributeOptionCombo ) );
+ + approvalParameters( dataSet, period, organisationUnit, categoryOptionGroups ) );
return;
}
@@ -283,8 +286,7 @@
@RequestParam String ds,
@RequestParam String pe,
@RequestParam String ou,
- @RequestParam( required = false ) String cc,
- @RequestParam( required = false ) String cp, HttpServletResponse response )
+ @RequestParam( required = false ) String cog, HttpServletResponse response )
{
log.info( "acceptApproval called." );
@@ -312,14 +314,14 @@
return;
}
- DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
+ Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
- if ( attributeOptionCombo == null )
+ if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
{
return;
}
- DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, attributeOptionCombo );
+ DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
if ( !DataApprovalState.APPROVED_HERE.equals( permissions.getDataApprovalStatus().getDataApprovalState() ) )
{
@@ -330,7 +332,7 @@
if ( !permissions.isMayAccept() )
{
ContextUtils.conflictResponse( response, "Current user is not authorized to accept approval for "
- + approvalParameters( dataSet, period, organisationUnit, attributeOptionCombo ) );
+ + approvalParameters( dataSet, period, organisationUnit, categoryOptionGroups ) );
return;
}
@@ -344,8 +346,7 @@
@RequestParam String ds,
@RequestParam String pe,
@RequestParam String ou,
- @RequestParam( required = false ) String cc,
- @RequestParam( required = false ) String cp, HttpServletResponse response )
+ @RequestParam( required = false ) String cog, HttpServletResponse response )
{
log.info( "unacceptApproval called." );
@@ -373,14 +374,14 @@
return;
}
- DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo( response, cc, cp );
+ Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
- if ( attributeOptionCombo == null )
+ if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
{
return;
}
- DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, attributeOptionCombo );
+ DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
if ( !DataApprovalState.ACCEPTED_HERE.equals( permissions.getDataApprovalStatus().getDataApprovalState() ) )
{
@@ -391,7 +392,7 @@
if ( !permissions.isMayUnaccept() )
{
ContextUtils.conflictResponse( response, "Current user is not authorized to unaccept approval for "
- + approvalParameters( dataSet, period, organisationUnit, attributeOptionCombo ) );
+ + approvalParameters( dataSet, period, organisationUnit, categoryOptionGroups ) );
return;
}
@@ -402,11 +403,11 @@
// Supportive methods
// -------------------------------------------------------------------------
- private String approvalParameters( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo )
+ private String approvalParameters( DataSet dataSet, Period period, OrganisationUnit organisationUnit, Set<CategoryOptionGroup> categoryOptionGroups )
{
return "dataSet " + dataSet.getName()
+ ", period " + period.getName()
+ ", org unit " + organisationUnit.getName()
- + ", attributeOptionCombo " + ( attributeOptionCombo == null ? "null" : attributeOptionCombo.getName() );
+ + ", categoryOptionGroup " + ( categoryOptionGroups == null ? "null" : ( (CategoryOptionGroup) categoryOptionGroups.toArray() [0] ).getName() );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/InputUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/InputUtils.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/InputUtils.java 2014-04-01 17:04:30 +0000
@@ -34,6 +34,7 @@
import javax.servlet.http.HttpServletResponse;
+import org.hisp.dhis.dataelement.CategoryOptionGroup;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -126,4 +127,95 @@
return attributeOptionCombo;
}
+
+ /**
+ * Validates and retrieves a single category option group. 409 conflict as
+ * status code along with a textual message will be set on the response in
+ * case of invalid input.
+ *
+ * @param response the servlet response.
+ * @param cog the category option group query string.
+ * @return the set of category option groups, null if the input was
+ * missing or an empty set if the input was invalid.
+ */
+ public Set<CategoryOptionGroup> getAttributeOptionGroup( HttpServletResponse response, String cog )
+ {
+ Set<String> groups = new HashSet<String>();
+
+ groups.add(cog);
+
+ return getAttributeOptionGroups( response, groups );
+ }
+
+ /**
+ * Validates and retrieves a set of category option groups. 409 conflict as
+ * status code along with a textual message will be set on the response in
+ * case of invalid input.
+ *
+ * @param response the servlet response.
+ * @param cog the category option group query string set.
+ * @return the set of category option groups, null if the input was
+ * missing or an empty set if the input was invalid.
+ */
+ public Set<CategoryOptionGroup> getAttributeOptionGroups( HttpServletResponse response, Set<String> cog )
+ {
+ Set<CategoryOptionGroup> groups = null;
+
+ if ( cog != null )
+ {
+ groups = new HashSet<CategoryOptionGroup>();
+
+ for ( String id : cog )
+ {
+ CategoryOptionGroup categoryOptionGroup = categoryService.getCategoryOptionGroup( id );
+
+ if ( categoryOptionGroup == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal category option group identifier: " + cog );
+ return null;
+ }
+
+ groups.add( categoryOptionGroup );
+ }
+ }
+
+ return groups;
+ }
+
+ /**
+ * Validates and retrieves a set of category options. 409 conflict as
+ * status code along with a textual message will be set on the response in
+ * case of invalid input.
+ *
+ * @param response the servlet response.
+ * @param cp the category option query string.
+ * @return the set of category option groups, null if the input was
+ * missing or an empty set if the input was invalid.
+ */
+ public Set<DataElementCategoryOption> getAttributeOptions( HttpServletResponse response, String cp )
+ {
+ Set<DataElementCategoryOption> options = null;
+
+ if ( cp != null )
+ {
+ List<String> opts = ContextUtils.getQueryParamValues( cp );
+
+ options = new HashSet<DataElementCategoryOption>();
+
+ for ( String id : opts )
+ {
+ DataElementCategoryOption categoryOption = categoryService.getDataElementCategoryOption( id );
+
+ if ( categoryOption == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal category option identifier: " + id );
+ return null;
+ }
+
+ options.add( categoryOption );
+ }
+ }
+
+ return options;
+ }
}