1
package org.hisp.dhis.dataset;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.ArrayList;
31
import java.util.Collection;
32
import java.util.HashSet;
33
import java.util.List;
36
import org.hisp.dhis.source.Source;
39
* @author Lars Helge Overland
40
* @version $Id: DefaultDataSetService.java 6255 2008-11-10 16:01:24Z larshelg $
42
public class DefaultDataSetService
43
implements DataSetService
45
// -------------------------------------------------------------------------
47
// -------------------------------------------------------------------------
49
private DataSetStore dataSetStore;
51
public void setDataSetStore( DataSetStore dataSetStore )
53
this.dataSetStore = dataSetStore;
56
private DataEntryFormService dataEntryFormService;
58
public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
60
this.dataEntryFormService = dataEntryFormService;
63
// -------------------------------------------------------------------------
65
// -------------------------------------------------------------------------
67
public int addDataSet( DataSet dataSet )
69
return dataSetStore.addDataSet( dataSet );
72
public void updateDataSet( DataSet dataSet )
74
dataSetStore.updateDataSet( dataSet );
77
public void deleteDataSet( DataSet dataSet )
79
dataSetStore.deleteDataSet( dataSet );
82
public DataSet getDataSet( int id )
84
return dataSetStore.getDataSet( id );
87
public DataSet getDataSetByName( String name )
89
return dataSetStore.getDataSetByName( name );
92
public DataSet getDataSetByShortName( String shortName )
94
return dataSetStore.getDataSetByShortName( shortName );
97
public DataSet getDataSetByCode( String code )
99
return dataSetStore.getDataSetByCode( code );
102
public Collection<DataSet> getDataSetsBySource( Source source )
104
return dataSetStore.getDataSetsBySource( source );
107
public Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources )
109
Set<DataSet> dataSets = new HashSet<DataSet>();
111
for ( Source source : sources )
113
dataSets.addAll( dataSetStore.getDataSetsBySource( source ) );
119
public int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<? extends Source> sources )
123
for ( Source source : sources )
125
if ( dataSet.getSources().contains( source ) )
134
public Collection<DataSet> getAllDataSets()
136
return dataSetStore.getAllDataSets();
139
public Collection<DataSet> getDataSets( Collection<Integer> identifiers )
141
Collection<DataSet> objects = new ArrayList<DataSet>();
143
for ( Integer id : identifiers )
145
objects.add( getDataSet( id ) );
151
public List<DataSet> getAvailableDataSets()
153
List<DataSet> availableDataSetList = new ArrayList<DataSet>();
154
List<DataSet> dataSetList = new ArrayList<DataSet>( getAllDataSets() );
156
for ( DataSet dataSet : dataSetList )
158
DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryFormByDataSet( dataSet );
160
if ( dataEntryForm == null )
162
availableDataSetList.add( dataSet );
166
return availableDataSetList;
169
public List<DataSet> getAssignedDataSets()
171
List<DataSet> assignedDataSetList = new ArrayList<DataSet>();
172
List<DataSet> dataSetList = new ArrayList<DataSet>( getAllDataSets() );
174
for ( DataSet dataSet : dataSetList )
176
DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryFormByDataSet( dataSet );
178
if ( dataEntryForm != null )
180
assignedDataSetList.add( dataSet );
184
return assignedDataSetList;
187
// -------------------------------------------------------------------------
188
// FrequencyOverrideAssociation
189
// -------------------------------------------------------------------------
191
public void addFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
193
dataSetStore.addFrequencyOverrideAssociation( frequencyOverrideAssociation );
196
public void updateFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
198
dataSetStore.updateFrequencyOverrideAssociation( frequencyOverrideAssociation );
201
public void removeFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
203
dataSetStore.removeFrequencyOverrideAssociation( frequencyOverrideAssociation );
206
public FrequencyOverrideAssociation getFrequencyOverrideAssociation( DataSet dataSet, Source source )
208
return dataSetStore.getFrequencyOverrideAssociation( dataSet, source );
211
public Collection<FrequencyOverrideAssociation> getFrequencyOverrideAssociationsByDataSet( DataSet dataSet )
213
return dataSetStore.getFrequencyOverrideAssociationsByDataSet( dataSet );
216
public Collection<FrequencyOverrideAssociation> getFrequencyOverrideAssociationsBySource( Source source )
218
return dataSetStore.getFrequencyOverrideAssociationsBySource( source );