~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/DefaultCompleteDataSetRegistrationService.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 All rights reserved.
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met: *
 
7
 * Redistributions of source code must retain the above copyright notice, this
 
8
 * list of conditions and the following disclaimer. * Redistributions in binary
 
9
 * form must reproduce the above copyright notice, this list of conditions and
 
10
 * the following disclaimer in the documentation and/or other materials provided
 
11
 * with the distribution. * Neither the name of the HISP project nor the names
 
12
 * of its contributors may be used to endorse or promote products derived from
 
13
 * this software without specific prior written permission. THIS SOFTWARE IS
 
14
 * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 
15
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
16
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
17
 * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
18
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
19
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
20
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
21
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
23
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
24
 */
 
25
 
 
26
import java.util.Collection;
 
27
import java.util.Date;
 
28
 
 
29
import org.apache.commons.collections.CollectionUtils;
 
30
import org.hisp.dhis.period.Period;
 
31
import org.hisp.dhis.source.Source;
 
32
 
 
33
/**
 
34
 * @author Lars Helge Overland
 
35
 * @version $Id$
 
36
 */
 
37
public class DefaultCompleteDataSetRegistrationService
 
38
    implements CompleteDataSetRegistrationService
 
39
{
 
40
    // -------------------------------------------------------------------------
 
41
    // Dependencies
 
42
    // -------------------------------------------------------------------------
 
43
 
 
44
    private CompleteDataSetRegistrationStore completeDataSetRegistrationStore;
 
45
 
 
46
    public void setCompleteDataSetRegistrationStore( CompleteDataSetRegistrationStore completeDataSetRegistrationStore )
 
47
    {
 
48
        this.completeDataSetRegistrationStore = completeDataSetRegistrationStore;
 
49
    }
 
50
    
 
51
    // -------------------------------------------------------------------------
 
52
    // CompleteDataSetRegistrationService
 
53
    // -------------------------------------------------------------------------
 
54
 
 
55
    public void saveCompleteDataSetRegistration( CompleteDataSetRegistration registration )
 
56
    {
 
57
        completeDataSetRegistrationStore.saveCompleteDataSetRegistration( registration );
 
58
    }
 
59
    public void deleteCompleteDataSetRegistration( CompleteDataSetRegistration registration )
 
60
    {
 
61
        completeDataSetRegistrationStore.deleteCompleteDataSetRegistration( registration );
 
62
    }
 
63
 
 
64
    public CompleteDataSetRegistration getCompleteDataSetRegistration( DataSet dataSet, Period period, Source source )
 
65
    {
 
66
        return completeDataSetRegistrationStore.getCompleteDataSetRegistration( dataSet, period, source );
 
67
    }
 
68
    
 
69
    public Collection<CompleteDataSetRegistration> getAllCompleteDataSetRegistrations()
 
70
    {
 
71
        return completeDataSetRegistrationStore.getAllCompleteDataSetRegistrations();
 
72
    }    
 
73
 
 
74
    public Collection<CompleteDataSetRegistration> getCompleteDataSetRegistrations( 
 
75
        Collection<DataSet> dataSets, Collection<? extends Source> sources, Collection<Period> periods )
 
76
    {
 
77
        return completeDataSetRegistrationStore.getCompleteDataSetRegistrations( dataSets, sources, periods );
 
78
    }    
 
79
 
 
80
    @SuppressWarnings( "unchecked" )
 
81
    public int getCompleteDataSetRegistrationsForDataSet( DataSet dataSet, Collection<? extends Source> sources, Period period )
 
82
    {
 
83
        Collection<? extends Source> intersectingSources = CollectionUtils.intersection( sources, dataSet.getSources() );
 
84
        
 
85
        if ( intersectingSources == null || intersectingSources.size() == 0 )
 
86
        {
 
87
            return 0;
 
88
        }        
 
89
        
 
90
        return completeDataSetRegistrationStore.getCompleteDataSetRegistrations( dataSet, intersectingSources, period ).size();
 
91
    }
 
92
    
 
93
    @SuppressWarnings( "unchecked" )
 
94
    public int getCompleteDataSetRegistrationsForDataSet( DataSet dataSet, Collection<? extends Source> sources, Period period, Date deadline )
 
95
    {
 
96
        Collection<? extends Source> intersectingSources = CollectionUtils.intersection( sources, dataSet.getSources() );
 
97
        
 
98
        if ( intersectingSources == null || intersectingSources.size() == 0 )
 
99
        {
 
100
            return 0;
 
101
        }
 
102
        
 
103
        return completeDataSetRegistrationStore.getCompleteDataSetRegistrations( dataSet, intersectingSources, period, deadline ).size();
 
104
    }
 
105
    
 
106
    public void deleteCompleteDataSetRegistrations( DataSet dataSet )
 
107
    {
 
108
        completeDataSetRegistrationStore.deleteCompleteDataSetRegistrations( dataSet );
 
109
    }
 
110
}