← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19853: DataSetService, removed unused code

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 19853 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-08-26 09:04:42 +0200
message:
  DataSetService, removed unused code
removed:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/AggregatedDataValueConverter.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.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/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2015-08-26 06:51:40 +0000
@@ -162,12 +162,6 @@
     List<DataSet> getDataSetsBySources( Collection<OrganisationUnit> sources );
 
     /**
-     * Returns the number of Sources among the specified Sources associated with
-     * the specified DataSet.
-     */
-    int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<OrganisationUnit> sources );
-
-    /**
      * Get all DataSets.
      *
      * @return A list containing all DataSets.
@@ -191,52 +185,6 @@
     List<DataSet> getDataSets( Collection<Integer> identifiers );
 
     /**
-     * Get list of available ie. unassigned datasets.
-     *
-     * @return A List containing all avialable DataSets.
-     */
-    List<DataSet> getAvailableDataSets();
-
-    /**
-     * Get list of assigned (ie. which had corresponding dataentryform)
-     * datasets.
-     *
-     * @return A List containing assigned DataSets.
-     */
-    List<DataSet> getAssignedDataSets();
-
-    /**
-     * Get list of assigned (ie. which had corresponding dataentryform) datasets
-     * for specific period type.
-     *
-     * @return A List containing assigned DataSets for specific period type.
-     */
-    List<DataSet> getAssignedDataSetsByPeriodType( PeriodType periodType );
-
-    /**
-     * Searches through the data sets with the corresponding given identifiers.
-     * If the given data element is a member of one of the data sets, that data
-     * sets period type is returned. This implies that if the data element is a
-     * member of more than one data set, which period type being returned is
-     * undefined. If null is passed as the second argument, all data sets will
-     * be searched.
-     *
-     * @param dataElement        the data element to find the period type for.
-     * @param dataSetIdentifiers the data set identifiers to search through.
-     * @return the period type of the given data element.
-     */
-    PeriodType getPeriodType( DataElement dataElement, Collection<Integer> dataSetIdentifiers );
-
-    /**
-     * Returns a distinct collection of data elements associated with the data
-     * sets with the given corresponding data set identifiers.
-     *
-     * @param dataSetIdentifiers the data set identifiers.
-     * @return a distinct list of data elements.
-     */
-    Set<DataElement> getDistinctDataElements( Collection<Integer> dataSetIdentifiers );
-
-    /**
      * Returns a list of data sets with the given uids.
      *
      * @param uids the collection of uids.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2015-06-16 08:40:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2015-08-26 06:51:40 +0000
@@ -37,22 +37,20 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.hisp.dhis.commons.filter.Filter;
+import org.hisp.dhis.commons.filter.FilterUtils;
 import org.hisp.dhis.dataapproval.DataApprovalService;
 import org.hisp.dhis.dataapproval.DataApprovalStatus;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.commons.filter.Filter;
-import org.hisp.dhis.commons.filter.FilterUtils;
 import org.hisp.dhis.user.CurrentUserService;
 import org.joda.time.DateTime;
 import org.springframework.transaction.annotation.Transactional;
@@ -226,22 +224,6 @@
     }
 
     @Override
-    public int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<OrganisationUnit> sources )
-    {
-        int count = 0;
-
-        for ( OrganisationUnit source : sources )
-        {
-            if ( dataSet.getSources().contains( source ) )
-            {
-                count++;
-            }
-        }
-
-        return count;
-    }
-
-    @Override
     public List<DataSet> getAllDataSets()
     {
         return i18n( i18nService, dataSetStore.getAll() );
@@ -269,93 +251,6 @@
     }
 
     @Override
-    public List<DataSet> getAvailableDataSets()
-    {
-        List<DataSet> availableDataSetList = new ArrayList<>();
-        List<DataSet> dataSetList = new ArrayList<>( getAllDataSets() );
-
-        for ( DataSet dataSet : dataSetList )
-        {
-            DataEntryForm dataEntryForm = dataSet.getDataEntryForm();
-
-            if ( dataEntryForm == null )
-            {
-                availableDataSetList.add( dataSet );
-            }
-        }
-
-        return availableDataSetList;
-    }
-
-    @Override
-    public List<DataSet> getAssignedDataSets()
-    {
-        List<DataSet> assignedDataSetList = new ArrayList<>();
-        List<DataSet> dataSetList = new ArrayList<>( getAllDataSets() );
-
-        for ( DataSet dataSet : dataSetList )
-        {
-            DataEntryForm dataEntryForm = dataSet.getDataEntryForm();
-
-            if ( dataEntryForm != null )
-            {
-                assignedDataSetList.add( dataSet );
-            }
-        }
-
-        return assignedDataSetList;
-    }
-
-    @Override
-    public PeriodType getPeriodType( DataElement dataElement, Collection<Integer> dataSetIdentifiers )
-    {
-        List<DataSet> dataSets = getDataSets( dataSetIdentifiers );
-
-        for ( DataSet dataSet : dataSets )
-        {
-            if ( dataSet.getDataElements().contains( dataElement ) )
-            {
-                return dataSet.getPeriodType();
-            }
-        }
-
-        return null;
-    }
-
-    @Override
-    public List<DataSet> getAssignedDataSetsByPeriodType( PeriodType periodType )
-    {
-        List<DataSet> dataSetListByPeriodType = new ArrayList<>( getDataSetsByPeriodType( periodType ) );
-
-        Iterator<DataSet> dataSetIterator = dataSetListByPeriodType.iterator();
-        while ( dataSetIterator.hasNext() )
-        {
-            DataSet dataSet = dataSetIterator.next();
-            if ( dataSet.getSources() == null || dataSet.getSources().size() == 0 )
-            {
-                dataSetIterator.remove();
-            }
-        }
-
-        return dataSetListByPeriodType;
-    }
-
-    @Override
-    public Set<DataElement> getDistinctDataElements( Collection<Integer> dataSetIdentifiers )
-    {
-        List<DataSet> dataSets = getDataSets( dataSetIdentifiers );
-
-        Set<DataElement> dataElements = new HashSet<>();
-
-        for ( DataSet dataSet : dataSets )
-        {
-            dataElements.addAll( dataSet.getDataElements() );
-        }
-
-        return dataElements;
-    }
-
-    @Override
     public List<DataSet> getDataSetsByUid( Collection<String> uids )
     {
         return dataSetStore.getByUid( uids );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2015-06-23 15:59:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2015-08-26 07:01:51 +0000
@@ -140,21 +140,16 @@
     @Override
     public List<TrackedEntityAttribute> getTrackedEntityAttributesWithoutProgram()
     {
-        List<TrackedEntityAttribute> result = attributeStore.getAll();
+        List<TrackedEntityAttribute> result = new ArrayList<>( attributeStore.getAll() );
 
         List<Program> programs = programService.getAllPrograms();
 
-        if ( result != null )
+        for ( Program program : programs )
         {
-            for ( Program program : programs )
-            {
-                result.removeAll( program.getProgramAttributes() );
-            }
-
-            return result;
+            result.removeAll( program.getProgramAttributes() );
         }
 
-        return new ArrayList<>();
+        return result;
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java	2015-08-26 06:51:40 +0000
@@ -209,50 +209,6 @@
     }
 
     @Test
-    public void testGetAvailableDataSets()
-    {
-        DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
-        DataEntryForm dataEntryFormB = new DataEntryForm( "DataEntryForm-B" );
-        
-        DataSet dataSetA = new DataSet( "DataSet-A", periodType );
-        DataSet dataSetB = new DataSet( "DataSet-B", periodType );
-        DataSet dataSetC = new DataSet( "DataSet-C", periodType );
-
-        dataSetA.setDataEntryForm( dataEntryFormA );
-        dataSetB.setDataEntryForm( dataEntryFormB );
-        
-        dataSetService.addDataSet( dataSetA );
-        dataSetService.addDataSet( dataSetB );
-        dataSetService.addDataSet( dataSetC );
-        
-        List<DataSet> dataSets = dataSetService.getAvailableDataSets();
-
-        assertEquals( dataSets.size(), 1 );
-    }
-
-    @Test
-    public void testGetAssignedDataSets()
-    {
-        DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
-        DataEntryForm dataEntryFormB = new DataEntryForm( "DataEntryForm-B" );
-        
-        DataSet dataSetA = new DataSet( "DataSet-A", periodType );
-        DataSet dataSetB = new DataSet( "DataSet-B", periodType );
-        DataSet dataSetC = new DataSet( "DataSet-C", periodType );
-
-        dataSetA.setDataEntryForm( dataEntryFormA );
-        dataSetB.setDataEntryForm( dataEntryFormB );
-        
-        dataSetService.addDataSet( dataSetA );
-        dataSetService.addDataSet( dataSetB );
-        dataSetService.addDataSet( dataSetC );
-        
-        List<DataSet> dataSets = dataSetService.getAssignedDataSets();
-
-        assertEquals( dataSets.size(), 2 );
-    }
-
-    @Test
     public void testGetOperands()
     {
         String html = "<table><tr><td><input id=\"abc-def-val\" style=\"width:4em;text-align:center\" /></td></tr></table>";

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java	2015-08-26 06:45:38 +0000
@@ -269,34 +269,6 @@
         assertTrue( dataSets.contains( dataSetB ) );
     }
 
-    @Test
-    public void testGetSourcesAssociatedWithDataSet()
-    {
-        DataSet dataSetA = createDataSet( 'A', periodType );
-        DataSet dataSetB = createDataSet( 'B', periodType );
-
-        dataSetA.getSources().add( unitA );
-        dataSetA.getSources().add( unitB );
-        dataSetB.getSources().add( unitE );
-
-        dataSetB.getSources().add( unitC );
-        dataSetB.getSources().add( unitD );
-        dataSetB.getSources().add( unitE );
-
-        dataSetService.addDataSet( dataSetA );
-        dataSetService.addDataSet( dataSetB );
-
-        List<OrganisationUnit> sources = new ArrayList<>();
-
-        sources.add( unitA );
-        sources.add( unitB );
-        sources.add( unitC );
-        sources.add( unitD );
-
-        assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetA, sources ) );
-        assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetB, sources ) );
-    }
-
     // -------------------------------------------------------------------------
     // LockException
     // -------------------------------------------------------------------------

=== removed file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/AggregatedDataValueConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/AggregatedDataValueConverter.java	2015-07-03 01:33:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/AggregatedDataValueConverter.java	1970-01-01 00:00:00 +0000
@@ -1,155 +0,0 @@
-package org.hisp.dhis.importexport.dxf.converter;
-
-/*
- * Copyright (c) 2004-2015, 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 static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
-
-import java.util.Collection;
-
-import org.amplecode.staxwax.reader.XMLReader;
-import org.amplecode.staxwax.writer.XMLWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.aggregation.AggregatedDataValue;
-import org.hisp.dhis.aggregation.AggregatedDataValueService;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.importexport.ExportParams;
-import org.hisp.dhis.importexport.ImportParams;
-import org.hisp.dhis.importexport.XMLConverter;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.period.PeriodType;
-
-/**
- * @author Lars Helge Overland
- * @version $Id$
- */
-public class AggregatedDataValueConverter
-    implements XMLConverter
-{
-    private static final Log log = LogFactory.getLog( AggregatedDataValueConverter.class );
-    
-    public static final String COLLECTION_NAME = "dataValues";
-    public static final String ELEMENT_NAME = "dataValue";
-    
-    private static final String FIELD_DATAELEMENT = "dataElement";
-    private static final String FIELD_PERIOD = "period";
-    private static final String FIELD_SOURCE = "source";
-    private static final String FIELD_VALUE = "value";
-    private static final String FIELD_STOREDBY = "storedBy";
-    private static final String FIELD_TIMESTAMP = "timeStamp";
-    private static final String FIELD_COMMENT = "comment";
-    private static final String FIELD_CATEGORY_OPTION_COMBO = "categoryOptionCombo";
-
-    // -------------------------------------------------------------------------
-    // Properties
-    // -------------------------------------------------------------------------
-
-    private AggregatedDataValueService aggregatedDataValueService;
-
-    private DataSetService dataSetService;
-    
-    private PeriodService periodService;
-    
-    // -------------------------------------------------------------------------
-    // Constructor
-    // -------------------------------------------------------------------------
-
-    /**
-     * Constructor for write operations.
-     */
-    public AggregatedDataValueConverter( AggregatedDataValueService aggregatedDataValueService,
-        DataSetService dataSetService,
-        PeriodService periodService )
-    {
-        this.aggregatedDataValueService = aggregatedDataValueService;
-        this.dataSetService = dataSetService;
-        this.periodService = periodService;
-    }
-
-    // -------------------------------------------------------------------------
-    // XMLConverter implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public void write( XMLWriter writer, ExportParams params )
-    {
-        if ( params.isIncludeDataValues() )
-        {
-            Collection<DataElement> dataElements = dataSetService.getDistinctDataElements( params.getDataSets() );
-
-            if ( dataElements.size() > 0 && params.getStartDate() != null && params.getEndDate() != null )
-            {
-                Collection<Period> periods = null;
-
-                Collection<AggregatedDataValue> values = null;
-                
-                writer.openElement( COLLECTION_NAME );
-                
-                for ( final DataElement dataElement : dataElements )
-                {
-                    final PeriodType periodType = dataSetService.getPeriodType( dataElement, params.getDataSets() );
-                    
-                    periods = periodService.getIntersectingPeriodsByPeriodType( periodType, params.getStartDate(), params.getEndDate() );
-                    
-                    log.debug( "Using period type: " + periodType.getName() + " for data element: " + dataElement.getName() );
-                    
-                    values = aggregatedDataValueService.getAggregatedDataValues( dataElement.getId(), 
-                        getIdentifiers( periods ), params.getOrganisationUnits() );
-                    
-                    for ( AggregatedDataValue value : values )
-                    {
-                        writer.openElement( ELEMENT_NAME );
-                        
-                        writer.writeElement( FIELD_DATAELEMENT, String.valueOf( value.getDataElementId() ) );
-                        writer.writeElement( FIELD_PERIOD, String.valueOf( value.getPeriodId() ) );
-                        writer.writeElement( FIELD_SOURCE, String.valueOf( value.getOrganisationUnitId() ) );
-                        writer.writeElement( FIELD_VALUE, String.valueOf( Math.round( value.getValue() ) ) );
-                        writer.writeElement( FIELD_STOREDBY, "" );
-                        writer.writeElement( FIELD_TIMESTAMP, "" );
-                        writer.writeElement( FIELD_COMMENT, "" );
-                        writer.writeElement( FIELD_CATEGORY_OPTION_COMBO, String.valueOf( value.getCategoryOptionComboId() ) );
-                        
-                        writer.closeElement();
-                    }
-                }
-                
-                writer.closeElement();
-            }
-        }
-    }
-    
-    @Override
-    public void read( XMLReader reader, ImportParams params )
-    {
-        // this code should never be called
-	throw new UnsupportedOperationException( "Read operation for AggregatedDataValue not supported" );
-    }
-}