dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12736
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3977: Improved deletion handlers
------------------------------------------------------------
revno: 3977
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-06-22 08:57:50 +0200
message:
Improved deletion handlers
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementDeletionHandler.java 2011-06-21 15:01:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -95,4 +95,16 @@
}
}
}
+
+ @Override
+ public void deleteDataElementGroup( DataElementGroup group )
+ {
+ for ( DataElement dataElement : dataElementService.getAllDataElements() )
+ {
+ if ( dataElement.getGroups().remove( dataElement ) )
+ {
+ dataElementService.updateDataElement( dataElement );
+ }
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java 2011-05-28 11:57:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DataSetDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -28,6 +28,7 @@
*/
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.deletion.DeletionHandler;
@@ -72,6 +73,18 @@
}
@Override
+ public void deleteIndicator( Indicator indicator )
+ {
+ for ( DataSet dataSet : dataSetService.getAllDataSets() )
+ {
+ if ( dataSet.getIndicators().remove( indicator ) )
+ {
+ dataSetService.updateDataSet( dataSet );
+ }
+ }
+ }
+
+ @Override
public void deleteSection( Section section )
{
for ( DataSet dataSet : dataSetService.getAllDataSets() )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2011-06-01 08:39:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -93,6 +93,18 @@
}
}
}
+
+ @Override
+ public void deleteIndicatorGroup( IndicatorGroup group )
+ {
+ for ( Indicator indicator : indicatorService.getAllIndicators() )
+ {
+ if ( indicator.getGroups().remove( group ) )
+ {
+ indicatorService.updateIndicator( indicator );
+ }
+ }
+ }
@Override
public boolean allowDeleteDataElement( DataElement dataElement )
@@ -115,5 +127,5 @@
}
return true;
- }
+ }
}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -0,0 +1,96 @@
+package org.hisp.dhis.organisationunit;
+
+/*
+ * Copyright (c) 2004-2010, 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.dataset.DataSet;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.user.User;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class OrganisationUnitDeletionHandler
+ extends DeletionHandler
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DeletionHandler implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String getClassName()
+ {
+ return OrganisationUnit.class.getSimpleName();
+ }
+
+ @Override
+ public void deleteDataSet( DataSet dataSet )
+ {
+ for ( OrganisationUnit unit : organisationUnitService.getAllOrganisationUnits() )
+ {
+ if ( unit.getDataSets().remove( dataSet ) )
+ {
+ organisationUnitService.updateOrganisationUnit( unit );
+ }
+ }
+ }
+
+ @Override
+ public void deleteUser( User user )
+ {
+ for ( OrganisationUnit unit : organisationUnitService.getAllOrganisationUnits() )
+ {
+ if ( unit.getUsers().remove( user ) )
+ {
+ organisationUnitService.updateOrganisationUnit( unit );
+ }
+ }
+ }
+
+ @Override
+ public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
+ {
+ for ( OrganisationUnit unit : organisationUnitService.getAllOrganisationUnits() )
+ {
+ if ( unit.getGroups().remove( group ) )
+ {
+ organisationUnitService.updateOrganisationUnit( unit );
+ }
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java 2011-06-13 14:03:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -27,8 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
-
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.deletion.DeletionHandler;
@@ -75,21 +73,20 @@
@Override
public boolean allowDeleteUserAuthorityGroup( UserAuthorityGroup authorityGroup )
{
- Collection<UserCredentials> userCredentials = userService.getAllUserCredentials();
-
- for( UserCredentials uc : userCredentials )
+ for ( UserCredentials credentials : userService.getAllUserCredentials() )
{
- if( uc != null && uc.getUserAuthorityGroups() != null )
+ if ( credentials != null && credentials.getUserAuthorityGroups() != null )
{
- for( UserAuthorityGroup role : uc.getUserAuthorityGroups())
+ for ( UserAuthorityGroup role : credentials.getUserAuthorityGroups())
{
- if( role.getId() == authorityGroup.getId())
+ if ( role.equals( authorityGroup ) )
{
return false;
}
}
}
}
+
return true;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-06-13 14:03:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-06-22 06:57:50 +0000
@@ -1153,6 +1153,12 @@
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
+ <bean id="org.hisp.dhis.organisationunit.OrganisationUnitDeletionHandler"
+ class="org.hisp.dhis.organisationunit.OrganisationUnitDeletionHandler">
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ </bean>
+
<bean id="org.hisp.dhis.organisationunit.OrganisationUnitGroupDeletionHandler"
class="org.hisp.dhis.organisationunit.OrganisationUnitGroupDeletionHandler">
<property name="organisationUnitGroupService"
@@ -1229,6 +1235,7 @@
<ref local="org.hisp.dhis.validation.ValidationRuleGroupDeletionHandler" />
<ref local="org.hisp.dhis.datavalue.DataValueDeletionHandler" />
<ref local="org.hisp.dhis.datavalue.DataValueAuditDeletionHandler" />
+ <ref local="org.hisp.dhis.organisationunit.OrganisationUnitDeletionHandler" />
<ref local="org.hisp.dhis.organisationunit.OrganisationUnitGroupDeletionHandler" />
<ref local="org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDeletionHandler" />
<ref local="org.hisp.dhis.user.UserDeletionHandler" />
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2011-06-22 06:57:50 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.system.deletion.DeletionHandler;
@@ -80,5 +81,17 @@
mappingService.updateMapLegendSet( legendSet );
}
}
- }
+ }
+
+ @Override
+ public void deleteDataElement( DataElement dataElement )
+ {
+ for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() )
+ {
+ if ( legendSet.getDataElements().remove( dataElement ) )
+ {
+ mappingService.updateMapLegendSet( legendSet );
+ }
+ }
+ }
}