dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33694
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17249: Minor
------------------------------------------------------------
revno: 17249
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-23 19:08:13 +0200
message:
Minor
modified:
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-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 16:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-10-23 17:08:13 +0000
@@ -134,6 +134,10 @@
@Autowired
private InputUtils inputUtils;
+ // -------------------------------------------------------------------------
+ // Get
+ // -------------------------------------------------------------------------
+
@RequestMapping( method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
public void getApprovalState(
@RequestParam String ds,
@@ -280,6 +284,10 @@
permissions.isMayApprove(), permissions.isMayUnapprove(), permissions.isMayAccept(),
permissions.isMayUnaccept() );
}
+
+ // -------------------------------------------------------------------------
+ // Post
+ // -------------------------------------------------------------------------
@PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@RequestMapping( method = RequestMethod.POST )
@@ -434,6 +442,159 @@
}
}
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
+ @RequestMapping( value = ACCEPTANCES_PATH, method = RequestMethod.POST )
+ public void acceptApproval(
+ @RequestParam String ds,
+ @RequestParam String pe,
+ @RequestParam String ou,
+ @RequestParam( required = false ) String cog, HttpServletResponse response )
+ {
+ log.info( "POST " + RESOURCE_PATH + ACCEPTANCES_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+ + (cog == null ? "" : ("&cog=" + cog)) );
+
+ DataSet dataSet = dataSetService.getDataSet( ds );
+
+ if ( dataSet == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal data set identifier: " + ds );
+ return;
+ }
+
+ Period period = PeriodType.getPeriodFromIsoString( pe );
+
+ if ( period == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal period identifier: " + pe );
+ return;
+ }
+
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( ou );
+
+ if ( organisationUnit == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
+ return;
+ }
+
+ Set<CategoryOptionGroup> categoryOptionGroups = null;
+ Set<DataElementCategoryOption> categoryOptions = null;
+
+ if ( cog != null )
+ {
+ categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+ if ( categoryOptionGroups == null || categoryOptionGroups.isEmpty() )
+ {
+ return;
+ }
+
+ categoryOptions = getCommonOptions( categoryOptionGroups );
+ }
+
+ DataApprovalLevel dataApprovalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( organisationUnit, categoryOptionGroups );
+
+ if ( dataApprovalLevel == null )
+ {
+ ContextUtils.conflictResponse( response, "Approval level not found." );
+ return;
+ }
+
+ User user = currentUserService.getCurrentUser();
+
+ List<DataApproval> dataApprovalList = makeDataApprovalList( dataApprovalLevel, dataSet,
+ period, organisationUnit, categoryOptions, false, new Date(), user );
+
+ try
+ {
+ dataApprovalService.acceptData( dataApprovalList );
+ }
+ catch ( DataApprovalException ex )
+ {
+ ContextUtils.conflictResponse( response, ex.getClass().getName() );
+ }
+ }
+
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
+ @RequestMapping( method = RequestMethod.POST, value = MULTIPLE_ACCEPTANCES_RESOURCE_PATH )
+ public void acceptApprovalMultiple( @RequestBody DataApprovalStateRequests dataApprovalStateRequests,
+ HttpServletResponse response )
+ {
+ List<DataApproval> dataApprovalList = new ArrayList<>();
+
+ for ( DataApprovalStateRequest dataApprovalStateRequest : dataApprovalStateRequests )
+ {
+ DataSet dataSet = dataSetService.getDataSet( dataApprovalStateRequest.getDs() );
+
+ if ( dataSet == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal data set identifier: " + dataApprovalStateRequest.getDs() );
+ return;
+ }
+
+ Period period = PeriodType.getPeriodFromIsoString( dataApprovalStateRequest.getPe() );
+
+ if ( period == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal period identifier: " + dataApprovalStateRequest.getPe() );
+ return;
+ }
+
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(
+ dataApprovalStateRequest.getOu() );
+
+ if ( organisationUnit == null )
+ {
+ ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + dataApprovalStateRequest.getOu() );
+ return;
+ }
+
+ Set<CategoryOptionGroup> categoryOptionGroups = null;
+ Set<DataElementCategoryOption> categoryOptions = null;
+
+ if ( dataApprovalStateRequest.getCog() != null )
+ {
+ categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, dataApprovalStateRequest.getCog() );
+
+ if ( categoryOptionGroups == null || categoryOptionGroups.isEmpty() )
+ {
+ return;
+ }
+
+ categoryOptions = getCommonOptions( categoryOptionGroups );
+ }
+
+ DataApprovalLevel dataApprovalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( organisationUnit, categoryOptionGroups );
+
+ if ( dataApprovalLevel == null )
+ {
+ ContextUtils.conflictResponse( response, "Approval level not found." );
+ return;
+ }
+
+ User user = dataApprovalStateRequest.getAb() == null ?
+ currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername( dataApprovalStateRequest.getAb() ).getUser();
+
+ Date approvalDate = (dataApprovalStateRequest.getAd() == null) ? new Date() : dataApprovalStateRequest.getAd();
+
+ dataApprovalList.addAll( makeDataApprovalList( dataApprovalLevel, dataSet,
+ period, organisationUnit, categoryOptions, false, approvalDate, user ) );
+ }
+
+ try
+ {
+ dataApprovalService.acceptData( dataApprovalList );
+ }
+ catch ( DataApprovalException ex )
+ {
+ ContextUtils.conflictResponse( response, ex.getClass().getName() );
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Delete
+ // -------------------------------------------------------------------------
+
@PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@RequestMapping( method = RequestMethod.DELETE )
public void removeApproval(
@@ -514,155 +675,6 @@
}
@PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
- @RequestMapping( value = ACCEPTANCES_PATH, method = RequestMethod.POST )
- public void acceptApproval(
- @RequestParam String ds,
- @RequestParam String pe,
- @RequestParam String ou,
- @RequestParam( required = false ) String cog, HttpServletResponse response )
- {
- log.info( "POST " + RESOURCE_PATH + ACCEPTANCES_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
- + (cog == null ? "" : ("&cog=" + cog)) );
-
- DataSet dataSet = dataSetService.getDataSet( ds );
-
- if ( dataSet == null )
- {
- ContextUtils.conflictResponse( response, "Illegal data set identifier: " + ds );
- return;
- }
-
- Period period = PeriodType.getPeriodFromIsoString( pe );
-
- if ( period == null )
- {
- ContextUtils.conflictResponse( response, "Illegal period identifier: " + pe );
- return;
- }
-
- OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( ou );
-
- if ( organisationUnit == null )
- {
- ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + ou );
- return;
- }
-
- Set<CategoryOptionGroup> categoryOptionGroups = null;
- Set<DataElementCategoryOption> categoryOptions = null;
-
- if ( cog != null )
- {
- categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
-
- if ( categoryOptionGroups == null || categoryOptionGroups.isEmpty() )
- {
- return;
- }
-
- categoryOptions = getCommonOptions( categoryOptionGroups );
- }
-
- DataApprovalLevel dataApprovalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( organisationUnit, categoryOptionGroups );
-
- if ( dataApprovalLevel == null )
- {
- ContextUtils.conflictResponse( response, "Approval level not found." );
- return;
- }
-
- User user = currentUserService.getCurrentUser();
-
- List<DataApproval> dataApprovalList = makeDataApprovalList( dataApprovalLevel, dataSet,
- period, organisationUnit, categoryOptions, false, new Date(), user );
-
- try
- {
- dataApprovalService.acceptData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
- }
-
- @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
- @RequestMapping( method = RequestMethod.POST, value = MULTIPLE_ACCEPTANCES_RESOURCE_PATH )
- public void acceptApprovalMultiple( @RequestBody DataApprovalStateRequests dataApprovalStateRequests,
- HttpServletResponse response )
- {
- List<DataApproval> dataApprovalList = new ArrayList<>();
-
- for ( DataApprovalStateRequest dataApprovalStateRequest : dataApprovalStateRequests )
- {
- DataSet dataSet = dataSetService.getDataSet( dataApprovalStateRequest.getDs() );
-
- if ( dataSet == null )
- {
- ContextUtils.conflictResponse( response, "Illegal data set identifier: " + dataApprovalStateRequest.getDs() );
- return;
- }
-
- Period period = PeriodType.getPeriodFromIsoString( dataApprovalStateRequest.getPe() );
-
- if ( period == null )
- {
- ContextUtils.conflictResponse( response, "Illegal period identifier: " + dataApprovalStateRequest.getPe() );
- return;
- }
-
- OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(
- dataApprovalStateRequest.getOu() );
-
- if ( organisationUnit == null )
- {
- ContextUtils.conflictResponse( response, "Illegal organisation unit identifier: " + dataApprovalStateRequest.getOu() );
- return;
- }
-
- Set<CategoryOptionGroup> categoryOptionGroups = null;
- Set<DataElementCategoryOption> categoryOptions = null;
-
- if ( dataApprovalStateRequest.getCog() != null )
- {
- categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, dataApprovalStateRequest.getCog() );
-
- if ( categoryOptionGroups == null || categoryOptionGroups.isEmpty() )
- {
- return;
- }
-
- categoryOptions = getCommonOptions( categoryOptionGroups );
- }
-
- DataApprovalLevel dataApprovalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( organisationUnit, categoryOptionGroups );
-
- if ( dataApprovalLevel == null )
- {
- ContextUtils.conflictResponse( response, "Approval level not found." );
- return;
- }
-
- User user = dataApprovalStateRequest.getAb() == null ?
- currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername( dataApprovalStateRequest.getAb() ).getUser();
-
- Date approvalDate = (dataApprovalStateRequest.getAd() == null) ? new Date() : dataApprovalStateRequest.getAd();
-
- dataApprovalList.addAll( makeDataApprovalList( dataApprovalLevel, dataSet,
- period, organisationUnit, categoryOptions, false, approvalDate, user ) );
- }
-
- try
- {
- dataApprovalService.acceptData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
- }
-
- @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
@RequestMapping( value = ACCEPTANCES_PATH, method = RequestMethod.DELETE )
public void unacceptApproval(
@RequestParam String ds,