PageRenderTime 58ms CodeModel.GetById 34ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/mock/DummyData.java

http://sigma-h.googlecode.com/
Java | 253 lines | 174 code | 61 blank | 18 comment | 6 complexity | a17f7174ef777c0a4755dd0de3862264 MD5 | raw file
  1/*
  2 * All Sigmah code is released under the GNU General Public License v3
  3 * See COPYRIGHT.txt and LICENSE.txt.
  4 */
  5
  6package org.sigmah.client.mock;
  7
  8import org.sigmah.shared.command.result.*;
  9import org.sigmah.shared.dto.*;
 10import org.sigmah.shared.map.BaseMap;
 11import org.sigmah.shared.map.LocalBaseMap;
 12
 13import java.util.ArrayList;
 14import java.util.HashMap;
 15import java.util.List;
 16import java.util.Map;
 17
 18public class DummyData {
 19
 20
 21    public static final AdminEntityDTO Beni = new AdminEntityDTO(2, 101, 100, "Beni", new BoundingBoxDTO(0, 0, 25, 25));
 22    public static final AdminEntityDTO Masisi = new AdminEntityDTO(2, 102, 100, "Masisi", new BoundingBoxDTO(0, 25, 25, 50));
 23    public static final AdminEntityDTO NordKivu = new AdminEntityDTO(1, 100, "Nord Kivu", new BoundingBoxDTO(0, 0, 100, 100));
 24    public static final AdminEntityDTO SudKivu = new AdminEntityDTO(1, 200, "Sud Kivu", new BoundingBoxDTO(0, 0, -100, -100));
 25    public static final AdminEntityDTO Watalina = new AdminEntityDTO(3, 1011, Beni.getParentId(), "Watalinga");
 26
 27    /**
 28     *
 29     * @return A schema with one program "PEAR" with two activities (ids=91,92)
 30     */
 31	public static SchemaDTO PEAR() {
 32
 33        CountryDTO country = new CountryDTO(1, "RDC");
 34        country.setBounds(new BoundingBoxDTO(0, 0, 300, 300));
 35        country.getAdminLevels().add(new AdminLevelDTO(1, "Province"));
 36        country.getAdminLevels().add(new AdminLevelDTO(2, 1, "Territoire"));
 37        country.getAdminLevels().add(new AdminLevelDTO(3, 2, "Secteur"));
 38        country.getLocationTypes().add(new LocationTypeDTO(1, "Localite"));
 39        country.getLocationTypes().add(new LocationTypeDTO(2, "Ecole"));
 40
 41        UserDatabaseDTO pear = new UserDatabaseDTO(1, "PEAR");
 42        pear.setFullName("Program of Expanded Assistance to Refugees");
 43        pear.setEditAllAllowed(false);
 44        pear.setEditAllowed(true);
 45        pear.setManageUsersAllowed(true);
 46        pear.setManageAllUsersAllowed(false);
 47        pear.setDesignAllowed(true);
 48        pear.setMyPartnerId(88);
 49        pear.setCountry(country);
 50
 51        pear.getPartners().add(new PartnerDTO(88, "NRC"));
 52
 53        ActivityDTO nfiDistro = new ActivityDTO(91, "NFI Distributions");
 54        nfiDistro.setDatabase(pear);
 55        nfiDistro.setLocationTypeId(1);
 56        pear.getActivities().add(nfiDistro);
 57
 58        ActivityDTO schoolRehab = new ActivityDTO(92, "School Rehab");
 59        schoolRehab.setDatabase(pear);
 60        schoolRehab.setLocationTypeId(2);
 61        pear.getActivities().add(schoolRehab);
 62
 63        AttributeGroupDTO rehabType = new AttributeGroupDTO(71);
 64        rehabType.setName("Rehab type");
 65        rehabType.setMultipleAllowed(false);
 66        schoolRehab.getAttributeGroups().add(rehabType);
 67        
 68        AttributeDTO minor = new AttributeDTO(711, "Minor");
 69        rehabType.getAttributes().add(minor);
 70
 71        AttributeDTO major = new AttributeDTO(712, "Major");
 72        rehabType.getAttributes().add(major);
 73
 74
 75        final SchemaDTO schema = new SchemaDTO();
 76        schema.getDatabases().add(pear);
 77        return schema;
 78	}
 79
 80    public static UserResult RRM_Users() {
 81        List<UserPermissionDTO> users = new ArrayList<UserPermissionDTO>();
 82
 83        UserPermissionDTO typhaine = new UserPermissionDTO();
 84        typhaine.setName("typhaine");
 85        typhaine.setEmail("typhaine@sol.net");
 86        typhaine.setAllowView(true);
 87        typhaine.setAllowManageUsers(true);
 88        typhaine.setAllowManageAllUsers(false);
 89
 90        users.add(typhaine);
 91
 92        return new UserResult(users);
 93    }
 94
 95    /**
 96     *
 97     * @return A schema with two programs, "PEAR" and "RRM" where "PEAR" has
 98     * no activities and "RRM" has one activity.
 99     */
100    public static SchemaDTO EmptyPEARandRRM() {
101        SchemaDTO schema = new SchemaDTO();
102        schema.getDatabases().add(new UserDatabaseDTO(1, "PEAR"));
103
104        UserDatabaseDTO rrm = new UserDatabaseDTO(2, "RRM");
105        rrm.getActivities().add(new ActivityDTO(1, "NFI Distribution"));
106
107        schema.getDatabases().add(rrm);
108
109        return schema;
110    }
111
112    /**
113     *
114     * @return A map of two NFI Distribution sites (activityId=91) sites indexed by id
115     * Site ids = 4, 5
116     */
117    public static Map<Integer, SiteDTO> PEAR_Sites() {
118
119        final SiteDTO fargo = new SiteDTO(4);
120        fargo.setActivityId(91);
121        fargo.setPartner(new PartnerDTO(88, "NRC"));
122        fargo.setLocationName("Fargo");
123        fargo.setAdminEntity(3, Watalina);
124        fargo.setAdminEntity(2, Beni);
125        fargo.setAdminEntity(1, NordKivu);
126
127      
128        SiteDTO boise = new SiteDTO(5);
129        boise.setActivityId(91);
130        boise.setPartner(new PartnerDTO(89, "AVSI"));
131        boise.setLocationName("Boise Idahao");
132
133
134        Map<Integer, SiteDTO> sites = new HashMap<Integer, SiteDTO>();
135        sites.put(4, fargo);
136        sites.put(5, boise);
137
138        return sites;
139    }
140
141    public static SiteResult PEAR_Sites_Many_Results(int count) {
142        List<SiteDTO> sites = new ArrayList<SiteDTO>();
143        for(int i=0;i!=count;++i) {
144            SiteDTO fargo = new SiteDTO(i);
145            fargo.setActivityId(91);
146            fargo.setPartner(new PartnerDTO(88, "NRC"));
147            fargo.setLocationName("Fargo");
148            fargo.setAdminEntity(3, Watalina);
149            fargo.setAdminEntity(2, Beni);
150            fargo.setAdminEntity(1, NordKivu);
151            sites.add(fargo);
152        }
153        return new SiteResult(sites);
154    }
155
156    public static SiteResult PEAR_Sites_Result() {
157        return new SiteResult(new ArrayList<SiteDTO>(PEAR_Sites().values()));
158    }
159    
160    public static ListResult<AdminEntityDTO> getProvinces() {
161        List<AdminEntityDTO> list = new ArrayList<AdminEntityDTO>();
162        list.add(NordKivu);
163        list.add(SudKivu);
164
165        return new AdminEntityResult(list);
166    }
167
168    public static ListResult<AdminEntityDTO> getTerritoires(int provinceId) {
169
170        List<AdminEntityDTO> list = new ArrayList<AdminEntityDTO>();
171
172        if(provinceId == 100) {
173            list.add(Beni);
174            list.add(Masisi);
175        } else if(provinceId == 200) {
176            list.add(new AdminEntityDTO(2, 202, 200, "Shabunda"));
177            list.add(new AdminEntityDTO(2, 201, 200, "Walungu"));
178        }
179
180        return new AdminEntityResult(list);
181    }
182
183    public static SchemaDTO PEARPlus() {
184
185        CountryDTO country = new CountryDTO(1, "RDC");
186        country.getAdminLevels().add(new AdminLevelDTO(1, "Province") );
187        country.getAdminLevels().add(new AdminLevelDTO(2, 1, "Zone de Sante"));
188        country.getAdminLevels().add(new AdminLevelDTO(3, 2, "Aire de Sante"));
189
190        LocationTypeDTO aireSante = new LocationTypeDTO(1, "Aire de Sante");
191        aireSante.setBoundAdminLevelId(3);
192        country.getLocationTypes().add(aireSante);
193
194        SchemaDTO schema = new SchemaDTO();
195        UserDatabaseDTO pearPlus = new UserDatabaseDTO(1, "PEAR Plus");
196        pearPlus.setCountry(country);
197        pearPlus.setEditAllAllowed(true);
198        pearPlus.setEditAllowed(true);
199        
200        schema.getDatabases().add(pearPlus);
201
202        ActivityDTO activity = new ActivityDTO(11, "Reunificiation des Enfants");
203        activity.setDatabase(pearPlus);
204        activity.setLocationTypeId(1);
205        activity.setReportingFrequency(ActivityDTO.REPORT_MONTHLY);
206        pearPlus.getActivities().add(activity);
207
208        return schema;
209    }
210
211    public static AdminEntityResult PEARPlus_Provinces() {
212        List<AdminEntityDTO> list = new ArrayList<AdminEntityDTO>();
213        list.add(new AdminEntityDTO(1, 1, "Ituri"));
214        return new AdminEntityResult(list);
215    }
216
217    public static AdminEntityResult PEARPlus_ZS() {
218        List<AdminEntityDTO> list = new ArrayList<AdminEntityDTO>();
219        list.add(new AdminEntityDTO(2, 11, 1, "Banana"));
220        list.add(new AdminEntityDTO(2, 12, 1, "Drodo"));
221        return new AdminEntityResult(list);
222    }
223
224    public static AdminEntityResult PEARPlus_AS() {
225        List<AdminEntityDTO> list = new ArrayList<AdminEntityDTO>();
226        list.add(new AdminEntityDTO(3, 111, 11, "Logo"));
227        list.add(new AdminEntityDTO(3, 112, 11, "Ndikpa"));
228        list.add(new AdminEntityDTO(3, 113, 11, "Zengo"));
229        return new AdminEntityResult(list);
230    }
231
232
233
234
235    public static BaseMapResult BaseMaps() {
236
237        BaseMap map = new LocalBaseMap();
238        map.setName("Administrative Map");
239        map.setCopyright("Foobar");
240        map.setId("admin");
241        map.setMinZoom(0);
242        map.setMaxZoom(16);
243
244        List<BaseMap> maps = new ArrayList<BaseMap>();
245        maps.add(map);
246
247        return new BaseMapResult(maps);
248        
249    }
250
251
252
253}