~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.dataset;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 */
 
29
 
 
30
import java.util.ArrayList;
 
31
import java.util.Collection;
 
32
import java.util.HashSet;
 
33
import java.util.List;
 
34
import java.util.Set;
 
35
 
 
36
import org.hisp.dhis.source.Source;
 
37
 
 
38
/**
 
39
 * @author Lars Helge Overland
 
40
 * @version $Id: DefaultDataSetService.java 6255 2008-11-10 16:01:24Z larshelg $
 
41
 */
 
42
public class DefaultDataSetService
 
43
    implements DataSetService
 
44
{
 
45
    // -------------------------------------------------------------------------
 
46
    // Dependencies
 
47
    // -------------------------------------------------------------------------
 
48
 
 
49
    private DataSetStore dataSetStore;
 
50
 
 
51
    public void setDataSetStore( DataSetStore dataSetStore )
 
52
    {
 
53
        this.dataSetStore = dataSetStore;
 
54
    }
 
55
    
 
56
    private DataEntryFormService dataEntryFormService;
 
57
 
 
58
    public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
 
59
    {
 
60
        this.dataEntryFormService = dataEntryFormService;
 
61
    }
 
62
 
 
63
    // -------------------------------------------------------------------------
 
64
    // DataSet
 
65
    // -------------------------------------------------------------------------
 
66
 
 
67
    public int addDataSet( DataSet dataSet )
 
68
    {
 
69
        return dataSetStore.addDataSet( dataSet );
 
70
    }
 
71
 
 
72
    public void updateDataSet( DataSet dataSet )
 
73
    {
 
74
        dataSetStore.updateDataSet( dataSet );
 
75
    }
 
76
 
 
77
    public void deleteDataSet( DataSet dataSet )
 
78
    {
 
79
        dataSetStore.deleteDataSet( dataSet );
 
80
    }
 
81
 
 
82
    public DataSet getDataSet( int id )
 
83
    {
 
84
        return dataSetStore.getDataSet( id );
 
85
    }
 
86
 
 
87
    public DataSet getDataSetByName( String name )
 
88
    {
 
89
        return dataSetStore.getDataSetByName( name );
 
90
    }
 
91
 
 
92
    public DataSet getDataSetByShortName( String shortName )
 
93
    {
 
94
        return dataSetStore.getDataSetByShortName( shortName );
 
95
    }
 
96
    
 
97
    public DataSet getDataSetByCode( String code )
 
98
    {
 
99
        return dataSetStore.getDataSetByCode( code );
 
100
    }
 
101
 
 
102
    public Collection<DataSet> getDataSetsBySource( Source source )
 
103
    {
 
104
        return dataSetStore.getDataSetsBySource( source );
 
105
    }
 
106
 
 
107
    public Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources )
 
108
    {
 
109
        Set<DataSet> dataSets = new HashSet<DataSet>();
 
110
        
 
111
        for ( Source source : sources )
 
112
        {
 
113
            dataSets.addAll( dataSetStore.getDataSetsBySource( source ) );
 
114
        }
 
115
        
 
116
        return dataSets;
 
117
    }
 
118
    
 
119
    public int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<? extends Source> sources )
 
120
    {
 
121
        int count = 0;
 
122
        
 
123
        for ( Source source : sources )
 
124
        {
 
125
            if ( dataSet.getSources().contains( source ) )
 
126
            {
 
127
                count++;
 
128
            }
 
129
        }
 
130
        
 
131
        return count;
 
132
    }
 
133
    
 
134
    public Collection<DataSet> getAllDataSets()
 
135
    {
 
136
        return dataSetStore.getAllDataSets();
 
137
    }
 
138
    
 
139
    public Collection<DataSet> getDataSets( Collection<Integer> identifiers )
 
140
    {
 
141
        Collection<DataSet> objects = new ArrayList<DataSet>();
 
142
        
 
143
        for ( Integer id : identifiers )
 
144
        {
 
145
            objects.add( getDataSet( id ) );
 
146
        }
 
147
        
 
148
        return objects;
 
149
    }
 
150
 
 
151
    public List<DataSet> getAvailableDataSets()
 
152
    {
 
153
        List<DataSet> availableDataSetList = new ArrayList<DataSet>();
 
154
        List<DataSet> dataSetList = new ArrayList<DataSet>( getAllDataSets() );
 
155
 
 
156
        for ( DataSet dataSet : dataSetList )
 
157
        {            
 
158
            DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryFormByDataSet( dataSet );
 
159
            
 
160
            if ( dataEntryForm == null )
 
161
            {
 
162
                availableDataSetList.add( dataSet );
 
163
            }
 
164
        }
 
165
 
 
166
        return availableDataSetList;
 
167
    }
 
168
 
 
169
    public List<DataSet> getAssignedDataSets()
 
170
    {
 
171
        List<DataSet> assignedDataSetList = new ArrayList<DataSet>();
 
172
        List<DataSet> dataSetList = new ArrayList<DataSet>( getAllDataSets() );
 
173
 
 
174
        for ( DataSet dataSet : dataSetList )
 
175
        {
 
176
            DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryFormByDataSet( dataSet );
 
177
            
 
178
            if ( dataEntryForm != null )
 
179
            {
 
180
                assignedDataSetList.add( dataSet );
 
181
            }
 
182
        }
 
183
 
 
184
        return assignedDataSetList;
 
185
    }
 
186
    
 
187
    // -------------------------------------------------------------------------
 
188
    // FrequencyOverrideAssociation
 
189
    // -------------------------------------------------------------------------
 
190
 
 
191
    public void addFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
 
192
    {
 
193
        dataSetStore.addFrequencyOverrideAssociation( frequencyOverrideAssociation );
 
194
    }
 
195
 
 
196
    public void updateFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
 
197
    {
 
198
        dataSetStore.updateFrequencyOverrideAssociation( frequencyOverrideAssociation );
 
199
    }
 
200
 
 
201
    public void removeFrequencyOverrideAssociation( FrequencyOverrideAssociation frequencyOverrideAssociation )
 
202
    {
 
203
        dataSetStore.removeFrequencyOverrideAssociation( frequencyOverrideAssociation );
 
204
    }
 
205
 
 
206
    public FrequencyOverrideAssociation getFrequencyOverrideAssociation( DataSet dataSet, Source source )
 
207
    {
 
208
        return dataSetStore.getFrequencyOverrideAssociation( dataSet, source );
 
209
    }
 
210
 
 
211
    public Collection<FrequencyOverrideAssociation> getFrequencyOverrideAssociationsByDataSet( DataSet dataSet )
 
212
    {
 
213
        return dataSetStore.getFrequencyOverrideAssociationsByDataSet( dataSet );
 
214
    }
 
215
 
 
216
    public Collection<FrequencyOverrideAssociation> getFrequencyOverrideAssociationsBySource( Source source )
 
217
    {
 
218
        return dataSetStore.getFrequencyOverrideAssociationsBySource( source );
 
219
    }
 
220
}