dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07698
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2239: Fixed bug <633168> Data Element Groups silently fail to be deleted when members of a group set.
------------------------------------------------------------
revno: 2239
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Sun 2010-09-26 04:09:08 +0700
message:
Fixed bug <633168> Data Element Groups silently fail to be deleted when members of a group set.
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSetDeletionHandler.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/RemoveDataElementGroupAction.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
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSetDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSetDeletionHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSetDeletionHandler.java 2010-09-25 21:09:08 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.dataelement;
+
+/*
+ * 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.system.deletion.DeletionHandler;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class DataElementGroupSetDeletionHandler
+ extends DeletionHandler
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DeletionHandler implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String getClassName()
+ {
+ return DataElementGroupSet.class.getSimpleName();
+ }
+
+ @Override
+ public boolean allowDeleteDataElementGroup( DataElementGroup dataElementGroup )
+ {
+ for ( DataElementGroupSet groupSet : dataElementService.getAllDataElementGroupSets() )
+ {
+ if ( groupSet.getMembers().contains( dataElementGroup ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void deleteDataElementGroup( DataElementGroup dataElementGroup )
+ {
+ for ( DataElementGroupSet groupSet : dataElementService.getAllDataElementGroupSets() )
+ {
+ if ( groupSet.getMembers().remove( dataElementGroup ) )
+ {
+ dataElementService.updateDataElementGroupSet( groupSet );
+ }
+ }
+ }
+}
=== 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 2010-09-23 06:55:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2010-09-25 21:09:08 +0000
@@ -1086,21 +1086,10 @@
<entry key="message" value="" />
</map>
</entry>
- <entry key="title">
- <map>
- <entry key="unique" value="true" />
- <entry key="required" value="true" />
- <entry key="minlength" value="2" />
- <entry key="maxlength" value="160" />
- <entry key="regex" value="''" />
- <entry key="message" value="" />
- </map>
- </entry>
</map>
</property>
</bean>
-
<!-- Startup routine definitions -->
<bean id="org.hisp.dhis.startup.TableAlteror" class="org.hisp.dhis.startup.TableAlteror">
@@ -1358,6 +1347,12 @@
ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
+ <bean id="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler"
+ class="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler">
+ <property name="dataElementService"
+ ref="org.hisp.dhis.dataelement.DataElementService" />
+ </bean>
+
<!-- Security -->
<bean id="org.hisp.dhis.security.PasswordManager"
@@ -1451,6 +1446,8 @@
local="org.hisp.dhis.user.UserSettingDeletionHandler" />
<ref
local="org.hisp.dhis.dataelement.DataElementCategoryDeletionHandler" />
+ <ref
+ local="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler" />
</list>
</list>
</property>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/RemoveDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/RemoveDataElementGroupAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/RemoveDataElementGroupAction.java 2010-09-25 21:09:08 +0000
@@ -27,13 +27,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.DeleteNotAllowedException;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
import com.opensymphony.xwork2.ActionSupport;
/**
* @author Torgeir Lorange Ostby
- * @version $Id: RemoveDataElementGroupAction.java 2869 2007-02-20 14:26:09Z andegje $
+ * @version $Id: RemoveDataElementGroupAction.java 2869 2007-02-20 14:26:09Z
+ * andegje $
*/
public class RemoveDataElementGroupAction
extends ActionSupport
@@ -50,6 +53,17 @@
}
// -------------------------------------------------------------------------
+ // I18n
+ // -------------------------------------------------------------------------
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -61,12 +75,35 @@
}
// -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
public String execute()
{
- dataElementService.deleteDataElementGroup( dataElementService.getDataElementGroup( id ) );
+ try
+ {
+ dataElementService.deleteDataElementGroup( dataElementService.getDataElementGroup( id ) );
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getClassName();
+
+ return ERROR;
+ }
+ }
return SUCCESS;
}