← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13219: added dashboarditemstore

 

------------------------------------------------------------
revno: 13219
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-13 12:08:00 +0100
message:
  added dashboarditemstore
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.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/
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapDeletionHandler.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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.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-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java	2013-12-13 11:08:00 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.dashboard;
+
+/*
+ * Copyright (c) 2004-2013, 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.GenericIdentifiableObjectStore;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface DashboardItemStore
+    extends GenericIdentifiableObjectStore<DashboardItem>
+{
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapDeletionHandler.java	2013-09-16 17:07:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapDeletionHandler.java	2013-12-13 11:08:00 +0000
@@ -28,11 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Iterator;
-
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.hisp.dhis.user.User;
 
+import java.util.Iterator;
+
 /**
  * @author Lars Helge Overland
  */
@@ -55,7 +55,7 @@
     {
         return Map.class.getSimpleName();
     }
-    
+
     @Override
     public void deleteUser( User user )
     {
@@ -68,7 +68,7 @@
             }
         }
     }
-    
+
     @Override
     public void deleteMap( Map map )
     {
@@ -80,5 +80,5 @@
             views.remove();
             mappingService.deleteMapView( view );
         }
-    }    
+    }
 }

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java	2013-12-13 11:08:00 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.dashboard;
+
+/*
+ * Copyright (c) 2004-2013, 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.mapping.Map;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DashboardItemDeletionHandler extends DeletionHandler
+{
+    @Autowired
+    private DashboardService dashboardService;
+
+    @Override
+    protected String getClassName()
+    {
+        return DashboardItem.class.getSimpleName();
+    }
+
+    @Override
+    public String allowDeleteMap( Map map )
+    {
+        return ERROR;
+    }
+}

=== added directory 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate'
=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java	2013-12-13 11:08:00 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.dashboard.hibernate;
+
+/*
+ * Copyright (c) 2004-2013, 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.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.dashboard.DashboardItem;
+import org.hisp.dhis.dashboard.DashboardItemStore;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class HibernateDashboardItemStore extends HibernateIdentifiableObjectStore<DashboardItem>
+    implements DashboardItemStore
+{
+}

=== 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-09-24 11:21:38 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-12-13 11:08:00 +0000
@@ -28,26 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_CHART;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MAP;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_PATIENT_TABULAR_REPORTS;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORTS;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLE;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLES;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_RESOURCES;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_USERS;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MESSAGES;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.dashboard.Dashboard;
 import org.hisp.dhis.dashboard.DashboardItem;
+import org.hisp.dhis.dashboard.DashboardItemStore;
 import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
 import org.hisp.dhis.document.Document;
@@ -59,9 +45,16 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+import static org.hisp.dhis.dashboard.DashboardItem.*;
+
 /**
  * Note: The remove associations methods must be altered if caching is introduced.
- * 
+ *
  * @author Lars Helge Overland
  */
 @Transactional
@@ -70,13 +63,13 @@
 {
     private static final int HITS_PER_OBJECT = 5;
     private static final int MAX_HITS_PER_OBJECT = 25;
-    
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
     private HibernateIdentifiableObjectStore<Dashboard> dashboardStore;
-    
+
     public void setDashboardStore( HibernateIdentifiableObjectStore<Dashboard> dashboardStore )
     {
         this.dashboardStore = dashboardStore;
@@ -84,7 +77,10 @@
 
     @Autowired
     private IdentifiableObjectManager objectManager;
-    
+
+    @Autowired
+    private DashboardItemStore dashboardItemStore;
+
     // -------------------------------------------------------------------------
     // DashboardService implementation
     // -------------------------------------------------------------------------
@@ -94,12 +90,12 @@
     {
         return search( query, new HashSet<String>() );
     }
-    
+
     @Override
     public DashboardSearchResult search( String query, Set<String> maxTypes )
     {
         DashboardSearchResult result = new DashboardSearchResult();
-        
+
         result.setUsers( objectManager.getBetweenByName( User.class, query, 0, getMax( TYPE_USERS, maxTypes ) ) );
         result.setCharts( objectManager.getBetweenByName( Chart.class, query, 0, getMax( TYPE_CHART, maxTypes ) ) );
         result.setMaps( objectManager.getBetweenByName( Map.class, query, 0, getMax( TYPE_MAP, maxTypes ) ) );
@@ -107,20 +103,20 @@
         result.setReports( objectManager.getBetweenByName( Report.class, query, 0, getMax( TYPE_REPORTS, maxTypes ) ) );
         result.setResources( objectManager.getBetweenByName( Document.class, query, 0, getMax( TYPE_RESOURCES, maxTypes ) ) );
         result.setPatientTabularReports( objectManager.getBetweenByName( PatientTabularReport.class, query, 0, getMax( TYPE_PATIENT_TABULAR_REPORTS, maxTypes ) ) );
-        
+
         return result;
     }
 
     @Override
     public boolean addItemContent( String dashboardUid, String type, String contentUid )
     {
-        Dashboard dashboard = getDashboard( dashboardUid );               
-        
+        Dashboard dashboard = getDashboard( dashboardUid );
+
         if ( dashboard == null )
         {
             return false;
         }
-        
+
         if ( TYPE_CHART.equals( type ) )
         {
             DashboardItem item = new DashboardItem();
@@ -148,9 +144,9 @@
         else // Link item
         {
             DashboardItem availableItem = dashboard.getAvailableItemByType( type );
-            
+
             DashboardItem item = availableItem == null ? new DashboardItem() : availableItem;
-            
+
             if ( TYPE_USERS.equals( type ) )
             {
                 item.getUsers().add( objectManager.get( User.class, contentUid ) );
@@ -171,7 +167,7 @@
             {
                 item.getPatientTabularReports().add( objectManager.get( PatientTabularReport.class, contentUid ) );
             }
-            
+
             if ( availableItem == null )
             {
                 dashboard.getItems().add( 0, item );
@@ -182,12 +178,12 @@
         {
             return false;
         }
-        
+
         updateDashboard( dashboard );
-        
+
         return true;
     }
-    
+
     public void mergeDashboard( Dashboard dashboard )
     {
         if ( dashboard.getItems() != null )
@@ -198,39 +194,39 @@
             }
         }
     }
-    
+
     public void mergeDashboardItem( DashboardItem item )
     {
         if ( item.getChart() != null )
         {
             item.setChart( objectManager.get( Chart.class, item.getChart().getUid() ) );
         }
-        
+
         if ( item.getMap() != null )
         {
             item.setMap( objectManager.get( Map.class, item.getMap().getUid() ) );
         }
-        
+
         if ( item.getReportTable() != null )
         {
             item.setReportTable( objectManager.get( ReportTable.class, item.getReportTable().getUid() ) );
         }
-        
+
         if ( item.getUsers() != null )
         {
             item.setUsers( objectManager.getByUid( User.class, getUids( item.getUsers() ) ) );
         }
-        
+
         if ( item.getReportTables() != null )
         {
             item.setReportTables( objectManager.getByUid( ReportTable.class, getUids( item.getReportTables() ) ) );
         }
-        
+
         if ( item.getReports() != null )
         {
             item.setReports( objectManager.getByUid( Report.class, getUids( item.getReports() ) ) );
         }
-        
+
         if ( item.getResources() != null )
         {
             item.setResources( objectManager.getByUid( Document.class, getUids( item.getResources() ) ) );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-10-16 11:58:17 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-12-13 11:08:00 +0000
@@ -130,6 +130,15 @@
     <property name="dashboardStore" ref="org.hisp.dhis.dashboard.DashboardStore" />
   </bean>
 
+  <bean id="org.hisp.dhis.dashboard.impl.DashboardItemDeletionHandler" class="org.hisp.dhis.dashboard.DashboardItemDeletionHandler">
+  </bean>
+
+  <bean id="org.hisp.dhis.dashboard.DashboardItemStore" class="org.hisp.dhis.dashboard.hibernate.HibernateDashboardItemStore">
+    <property name="clazz" value="org.hisp.dhis.dashboard.DashboardItem" />
+    <property name="sessionFactory" ref="sessionFactory" />
+    <property name="cacheable" value="true" />
+  </bean>
+
   <!-- Organisation Unit Distribution -->
 
   <bean id="org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService"
@@ -215,6 +224,7 @@
           <ref local="org.hisp.dhis.reporttable.ReportTableDeletionHandler" />
           <ref local="org.hisp.dhis.chart.ChartDeletionHandler" />
           <ref local="org.hisp.dhis.interpretation.InterpretationDeletionHandler" />
+          <ref local="org.hisp.dhis.dashboard.impl.DashboardItemDeletionHandler" />
         </list>
       </list>
     </property>

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2013-12-13 11:08:00 +0000
@@ -83,14 +83,14 @@
 
         try
         {
-            Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[] { clazz } );
+            Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[]{ clazz } );
 
             for ( DeletionHandler handler : handlers )
             {
                 currentHandler = handler.getClass().getSimpleName();
 
                 log.debug( "Check if allowed using " + currentHandler + " for class " + className );
-                
+
                 Object allow = allowMethod.invoke( handler, object );
 
                 if ( allow != null )
@@ -127,17 +127,17 @@
 
         try
         {
-            Method deleteMethod = DeletionHandler.class.getMethod( deleteMethodName, new Class[] { clazz } );
+            Method deleteMethod = DeletionHandler.class.getMethod( deleteMethodName, new Class[]{ clazz } );
 
             for ( DeletionHandler handler : handlers )
             {
                 currentHandler = handler.getClass().getSimpleName();
 
                 log.debug( "Deleting object using " + currentHandler + " for class " + className );
-                
+
                 deleteMethod.invoke( handler, object );
             }
-        } 
+        }
         catch ( Exception ex )
         {
             log.error( "Failed to invoke method " + deleteMethodName + " on DeletionHandler '" + currentHandler + "'", ex );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2013-12-13 09:58:21 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2013-12-13 11:08:00 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.concept.Concept;
 import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.dashboard.DashboardItem;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategory;
@@ -728,11 +729,19 @@
 
     public void deleteSqlView( SqlView sqlView )
     {
-
     }
 
     public String allowDeleteSqlView( SqlView sqlView )
     {
         return null;
     }
+
+    public void deleteDashboardItem( DashboardItem dashboardItem )
+    {
+    }
+
+    public String allowDeleteDashboardItem( DashboardItem dashboardItem )
+    {
+        return null;
+    }
 }