dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33746
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17287: Approvals. Changed approvals/acceptances resources.
------------------------------------------------------------
revno: 17287
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-10-25 23:58:41 +0200
message:
Approvals. Changed approvals/acceptances resources.
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approval.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approvals.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseMetaDataCollectionObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.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/common/BaseMetaDataCollectionObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseMetaDataCollectionObject.java 2014-10-25 10:06:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseMetaDataCollectionObject.java 2014-10-25 21:58:41 +0000
@@ -95,40 +95,6 @@
protected List<DataElementCategoryOptionCombo> categoryOptionCombos = new ArrayList<>();
// -------------------------------------------------------------------------
- // Logic
- // -------------------------------------------------------------------------
-
- public boolean hasIndicators()
- {
- return indicators != null && !indicators.isEmpty();
- }
-
- public boolean hasDataElements()
- {
- return dataElements != null && !dataElements.isEmpty();
- }
-
- public boolean hasDataSets()
- {
- return dataSets != null && !dataSets.isEmpty();
- }
-
- public boolean hasOrganisationUnits()
- {
- return organisationUnits != null && !organisationUnits.isEmpty();
- }
-
- public boolean hasPeriods()
- {
- return periods != null && !periods.isEmpty();
- }
-
- public boolean hasCategoryOptionCombos()
- {
- return categoryOptionCombos != null && !categoryOptionCombos.isEmpty();
- }
-
- // -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-10-25 20:49:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-10-25 21:58:41 +0000
@@ -28,17 +28,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.dataelement.CategoryOptionGroup;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.user.User;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* @author Jim Grace
*/
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-10-25 20:49:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-10-25 21:58:41 +0000
@@ -36,12 +36,7 @@
import java.util.Map;
import java.util.Set;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
import org.apache.commons.collections.CollectionUtils;
-import org.hisp.dhis.dataelement.CategoryOptionGroup;
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -56,6 +51,10 @@
import org.hisp.dhis.user.UserService;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
/**
* @author Jim Grace
*/
=== 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-25 21:36:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-10-25 21:58:41 +0000
@@ -29,7 +29,6 @@
*/
import static com.google.common.collect.Lists.newArrayList;
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
import java.io.IOException;
import java.util.ArrayList;
@@ -45,7 +44,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.common.BaseMetaDataCollectionObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.view.BasicView;
import org.hisp.dhis.dataapproval.DataApproval;
@@ -74,6 +72,8 @@
import org.hisp.dhis.user.UserService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.InputUtils;
+import org.hisp.dhis.webapi.webdomain.approval.Approval;
+import org.hisp.dhis.webapi.webdomain.approval.Approvals;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -126,7 +126,7 @@
private PeriodService periodService;
@Autowired
- private DataElementCategoryService dataElementCategoryService;
+ private DataElementCategoryService categoryService;
@Autowired
private InputUtils inputUtils;
@@ -347,27 +347,27 @@
}
@RequestMapping( value = APPROVALS_PATH + "/approvals", method = RequestMethod.POST )
- public void saveApprovalBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+ public void saveApprovalBatch( @RequestBody Approvals approvals,
HttpServletRequest request, HttpServletResponse response )
{
- if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+ if ( approvals.getDs() == null || approvals.getDs().isEmpty() || approvals.getPe() == null || approvals.getPe().isEmpty() )
{
- ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
+ ContextUtils.conflictResponse( response, "Approval must have data sets and periods" );
}
- dataApprovalService.approveData( getDataApprovalList( dataApproval ) );
+ dataApprovalService.approveData( getDataApprovalList( approvals ) );
}
@RequestMapping( value = APPROVALS_PATH + "/unapprovals", method = RequestMethod.POST )
- public void removeApprovalBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+ public void removeApprovalBatch( @RequestBody Approvals approvals,
HttpServletRequest request, HttpServletResponse response )
{
- if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+ if ( approvals.getDs() == null || approvals.getDs().isEmpty() || approvals.getPe() == null || approvals.getPe().isEmpty() )
{
- ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
+ ContextUtils.conflictResponse( response, "Approval must have data sets and periods" );
}
- dataApprovalService.unapproveData( getDataApprovalList( dataApproval ) );
+ dataApprovalService.unapproveData( getDataApprovalList( approvals ) );
}
@PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@@ -479,27 +479,27 @@
}
@RequestMapping( value = ACCEPTANCES_PATH + "/acceptances", method = RequestMethod.POST )
- public void saveAcceptanceBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+ public void saveAcceptanceBatch( @RequestBody Approvals approvals,
HttpServletRequest request, HttpServletResponse response )
{
- if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+ if ( approvals.getDs() == null || approvals.getDs().isEmpty() || approvals.getPe() == null || approvals.getPe().isEmpty() )
{
- ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
+ ContextUtils.conflictResponse( response, "Approval must have data sets and periods" );
}
- dataApprovalService.acceptData( getDataApprovalList( dataApproval ) );
+ dataApprovalService.acceptData( getDataApprovalList( approvals ) );
}
@RequestMapping( value = ACCEPTANCES_PATH + "/unacceptances", method = RequestMethod.POST )
- public void removeAcceptancesBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+ public void removeAcceptancesBatch( @RequestBody Approvals approvals,
HttpServletRequest request, HttpServletResponse response )
{
- if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+ if ( approvals.getDs() == null || approvals.getDs().isEmpty() || approvals.getPe() == null || approvals.getPe().isEmpty() )
{
- ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
+ ContextUtils.conflictResponse( response, "Approval must have data sets and periods" );
}
- dataApprovalService.unacceptData( getDataApprovalList( dataApproval ) );
+ dataApprovalService.unacceptData( getDataApprovalList( approvals ) );
}
@PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
@@ -672,7 +672,7 @@
{
List<DataApproval> approvals = new ArrayList<>();
- DataElementCategoryOptionCombo combo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
+ DataElementCategoryOptionCombo combo = categoryService.getDefaultDataElementCategoryOptionCombo();
period = periodService.reloadPeriod( period );
approvals.add( new DataApproval( dataApprovalLevel, dataSet, period, organisationUnit, combo, accepted, created, creator ) );
@@ -680,19 +680,15 @@
return approvals;
}
- private List<DataApproval> getDataApprovalList( BaseMetaDataCollectionObject dataApproval )
+ private List<DataApproval> getDataApprovalList( Approvals approvals )
{
- List<DataSet> dataSets = objectManager.getByUid( DataSet.class, getUids( dataApproval.getDataSets() ) );
- List<Period> periods = PeriodType.getPeriodsFromIsoStrings( getUids( dataApproval.getPeriods() ) );
- List<DataElementCategoryOptionCombo> optionCombos = objectManager.getByUid( DataElementCategoryOptionCombo.class, getUids( dataApproval.getCategoryOptionCombos() ) );
+ List<DataSet> dataSets = objectManager.getByUid( DataSet.class, approvals.getDs() );
+ List<Period> periods = PeriodType.getPeriodsFromIsoStrings( approvals.getPe() );
User user = currentUserService.getCurrentUser();
- OrganisationUnit unit = user.getOrganisationUnit(); //TODO
- DataApprovalLevel approvalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( unit );
-
Date date = new Date();
- List<DataApproval> approvals = new ArrayList<>();
+ List<DataApproval> list = new ArrayList<>();
for ( DataSet dataSet : dataSets )
{
@@ -700,17 +696,21 @@
for ( Period period : periods )
{
- for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+ for ( Approval approval : approvals.getApprovals() )
{
+ OrganisationUnit unit = organisationUnitService.getOrganisationUnit( approval.getOu() );
+ DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( approval.getAoc() );
+ DataApprovalLevel approvalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( unit );
+
if ( dataSetOptionCombos != null && dataSetOptionCombos.contains( optionCombo ) )
{
- DataApproval approval = new DataApproval( approvalLevel, dataSet, period, unit, optionCombo, false, date, user );
- approvals.add( approval );
+ DataApproval dataApproval = new DataApproval( approvalLevel, dataSet, period, unit, optionCombo, false, date, user );
+ list.add( dataApproval );
}
}
}
}
- return approvals;
+ return list;
}
}
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approval.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approval.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approval.java 2014-10-25 21:58:41 +0000
@@ -0,0 +1,71 @@
+package org.hisp.dhis.webapi.webdomain.approval;
+
+/*
+ * Copyright (c) 2004-2014, 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.
+ */
+
+import org.hisp.dhis.common.DxfNamespaces;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+@JacksonXmlRootElement( localName = "approval", namespace = DxfNamespaces.DXF_2_0 )
+public class Approval
+{
+ private String ou;
+
+ private String aoc;
+
+ public Approval()
+ {
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getOu()
+ {
+ return ou;
+ }
+
+ public void setOu( String ou )
+ {
+ this.ou = ou;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getAoc()
+ {
+ return aoc;
+ }
+
+ public void setAoc( String aoc )
+ {
+ this.aoc = aoc;
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approvals.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approvals.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/approval/Approvals.java 2014-10-25 21:58:41 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.webapi.webdomain.approval;
+
+/*
+ * Copyright (c) 2004-2014, 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hisp.dhis.common.DxfNamespaces;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+@JacksonXmlRootElement( localName = "approvals", namespace = DxfNamespaces.DXF_2_0 )
+public class Approvals
+{
+ private List<String> ds = new ArrayList<>();
+
+ private List<String> pe = new ArrayList<>();
+
+ private List<Approval> approvals = new ArrayList<>();
+
+ public Approvals()
+ {
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public List<String> getDs()
+ {
+ return ds;
+ }
+
+ public void setDs( List<String> ds )
+ {
+ this.ds = ds;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public List<String> getPe()
+ {
+ return pe;
+ }
+
+ public void setPe( List<String> pe )
+ {
+ this.pe = pe;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public List<Approval> getApprovals()
+ {
+ return approvals;
+ }
+
+ public void setApprovals( List<Approval> approvals )
+ {
+ this.approvals = approvals;
+ }
+}