dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26745
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13220: added store method to count mapDashboardItems, mapInterpretations, allows for proper deletion of ...
------------------------------------------------------------
revno: 13220
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-13 12:44:41 +0100
message:
added store method to count mapDashboardItems, mapInterpretations, allows for proper deletion of Map (where its allowed)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.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/dashboard/DashboardItemStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java 2013-12-13 11:08:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java 2013-12-13 11:44:41 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.mapping.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -36,4 +37,5 @@
public interface DashboardItemStore
extends GenericIdentifiableObjectStore<DashboardItem>
{
+ int countMapDashboardItems( Map map );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java 2013-09-16 17:07:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java 2013-12-13 11:44:41 +0000
@@ -1,10 +1,12 @@
package org.hisp.dhis.dashboard;
+import org.hisp.dhis.interpretation.Interpretation;
+import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.user.User;
+
import java.util.List;
import java.util.Set;
-import org.hisp.dhis.user.User;
-
/*
* Copyright (c) 2004-2013, University of Oslo
* All rights reserved.
@@ -42,24 +44,26 @@
final String ID = DashboardService.class.getName();
DashboardSearchResult search( String query );
-
+
DashboardSearchResult search( String query, Set<String> maxTypes );
-
+
boolean addItemContent( String dashboardUid, String type, String contentUid );
-
+
void mergeDashboard( Dashboard dashboard );
-
+
void mergeDashboardItem( DashboardItem item );
-
+
int saveDashboard( Dashboard dashboard );
-
+
void updateDashboard( Dashboard dashboard );
-
+
void deleteDashboard( Dashboard dashboard );
-
+
Dashboard getDashboard( int id );
-
+
Dashboard getDashboard( String uid );
-
+
List<Dashboard> getByUser( User user );
+
+ int countMapDashboardItems( Map map );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java 2013-12-01 15:05:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java 2013-12-13 11:44:41 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.mapping.Map;
+
import java.util.Date;
import java.util.List;
@@ -57,4 +59,6 @@
void updateCurrentUserLastChecked();
long getNewInterpretationCount();
+
+ int countMapInterpretations( Map map );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java 2013-10-08 17:16:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java 2013-12-13 11:44:41 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.mapping.Map;
/**
* @author Lars Helge Overland
@@ -36,4 +37,5 @@
public interface InterpretationStore
extends GenericIdentifiableObjectStore<Interpretation>
{
+ int countMapInterpretations( Map map );
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java 2013-12-13 11:08:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java 2013-12-13 11:44:41 +0000
@@ -49,6 +49,6 @@
@Override
public String allowDeleteMap( Map map )
{
- return ERROR;
+ return dashboardService.countMapDashboardItems( map ) == 0 ? null : ERROR;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java 2013-12-13 11:08:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java 2013-12-13 11:44:41 +0000
@@ -28,9 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hibernate.Query;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.dashboard.DashboardItem;
import org.hisp.dhis.dashboard.DashboardItemStore;
+import org.hisp.dhis.mapping.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -38,4 +40,12 @@
public class HibernateDashboardItemStore extends HibernateIdentifiableObjectStore<DashboardItem>
implements DashboardItemStore
{
+ @Override
+ public int countMapDashboardItems( Map map )
+ {
+ Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where c.map=:map" );
+ query.setEntity( "map", map );
+
+ return ((Long) query.uniqueResult()).intValue();
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2013-12-13 11:08:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2013-12-13 11:44:41 +0000
@@ -37,6 +37,7 @@
import org.hisp.dhis.dashboard.DashboardSearchResult;
import org.hisp.dhis.dashboard.DashboardService;
import org.hisp.dhis.document.Document;
+import org.hisp.dhis.interpretation.Interpretation;
import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.patientreport.PatientTabularReport;
import org.hisp.dhis.report.Report;
@@ -268,6 +269,13 @@
{
return dashboardStore.getByUser( user );
}
+
+ @Override
+ public int countMapDashboardItems( Map map )
+ {
+ return dashboardItemStore.countMapDashboardItems( map );
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java 2013-10-08 17:16:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java 2013-12-13 11:44:41 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.system.deletion.DeletionHandler;
import org.hisp.dhis.user.User;
import org.springframework.beans.factory.annotation.Autowired;
@@ -62,4 +63,10 @@
}
}
}
+
+ @Override
+ public String allowDeleteMap( Map map )
+ {
+ return interpretationService.countMapInterpretations( map ) == 0 ? null : ERROR;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java 2013-10-08 17:16:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java 2013-12-13 11:44:41 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.interpretation.Interpretation;
import org.hisp.dhis.interpretation.InterpretationStore;
+import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.user.User;
import java.util.List;
@@ -42,7 +43,7 @@
public class HibernateInterpretationStore
extends HibernateIdentifiableObjectStore<Interpretation> implements InterpretationStore
{
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public List<Interpretation> getInterpretations( User user )
{
String hql = "select distinct i from Interpretation i left join i.comments c " +
@@ -67,4 +68,13 @@
return query.list();
}
+
+ @Override
+ public int countMapInterpretations( Map map )
+ {
+ Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where c.map=:map" );
+ query.setEntity( "map", map );
+
+ return ((Long) query.uniqueResult()).intValue();
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java 2013-12-01 15:05:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java 2013-12-13 11:44:41 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.interpretation.InterpretationComment;
import org.hisp.dhis.interpretation.InterpretationService;
import org.hisp.dhis.interpretation.InterpretationStore;
+import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
@@ -192,4 +193,10 @@
return count;
}
+
+ @Override
+ public int countMapInterpretations( Map map )
+ {
+ return interpretationStore.countMapInterpretations( map );
+ }
}