1 |
11e8f060
|
Cherian Mathew
|
package org.bgbm.biovel.drf.utils;
|
2 |
|
|
|
3 |
|
|
import java.util.ArrayList;
|
4 |
|
|
import java.util.Arrays;
|
5 |
|
|
import java.util.HashMap;
|
6 |
|
|
import java.util.Iterator;
|
7 |
|
|
import java.util.List;
|
8 |
|
|
import java.util.Map;
|
9 |
|
|
|
10 |
|
|
import org.bgbm.biovel.drf.checklist.BaseChecklistClient.ChecklistInfo;
|
11 |
|
|
import org.bgbm.biovel.drf.checklist.BgbmEditClient;
|
12 |
|
|
import org.bgbm.biovel.drf.checklist.DRFChecklistException;
|
13 |
|
|
import org.bgbm.biovel.drf.checklist.GBIFBetaBackboneClient;
|
14 |
|
|
import org.bgbm.biovel.drf.checklist.Species2000ColClient;
|
15 |
|
|
|
16 |
|
|
public class ChecklistUtils {
|
17 |
|
|
|
18 |
|
|
public static String generateChecklistInfoList() throws DRFChecklistException {
|
19 |
|
|
String checklistInfoList = "[]";
|
20 |
|
|
List<ChecklistInfo> cilist = new ArrayList<ChecklistInfo>();
|
21 |
|
|
|
22 |
|
|
Species2000ColClient col = new Species2000ColClient();
|
23 |
|
|
cilist.add(col.getChecklistInfo());
|
24 |
|
|
|
25 |
|
|
BgbmEditClient bec = new BgbmEditClient();
|
26 |
|
|
cilist.add(bec.getChecklistInfo());
|
27 |
|
|
|
28 |
|
|
GBIFBetaBackboneClient gbc = new GBIFBetaBackboneClient();
|
29 |
|
|
cilist.add(gbc.getChecklistInfo());
|
30 |
|
|
checklistInfoList = JSONUtils.convertObjectToJson(cilist);
|
31 |
|
|
return checklistInfoList;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
public static List<ChecklistInfo> convertStringToChecklistInfo(List<String> ciStrList) throws DRFChecklistException {
|
35 |
|
|
Map<String,ChecklistInfo> ciMap = new HashMap<String, ChecklistInfo>();
|
36 |
|
|
|
37 |
|
|
Iterator<String> ciItr = ciStrList.iterator();
|
38 |
|
|
while(ciItr.hasNext()) {
|
39 |
|
|
String[] ciStrArray = ciItr.next().split(";",5);
|
40 |
dcd1bb77
|
Cherian Mathew
|
System.out.println("ci array length : " + ciStrArray.length);
|
41 |
11e8f060
|
Cherian Mathew
|
if(ciStrArray.length == 5) {
|
42 |
|
|
String key = ciStrArray[0];
|
43 |
dcd1bb77
|
Cherian Mathew
|
System.out.println("ci key : " + key);
|
44 |
11e8f060
|
Cherian Mathew
|
ChecklistInfo ci = ciMap.get(ciStrArray[0]);
|
45 |
|
|
if(ci == null) {
|
46 |
dcd1bb77
|
Cherian Mathew
|
if(key.equals(Species2000ColClient.ID)) {
|
47 |
ddbcdcf3
|
Cherian Mathew
|
ci = new ChecklistInfo(Species2000ColClient.ID,
|
48 |
|
|
Species2000ColClient.LABEL,
|
49 |
|
|
Species2000ColClient.URL,
|
50 |
|
|
Species2000ColClient.DATA_AGR_URL);
|
51 |
11e8f060
|
Cherian Mathew
|
}
|
52 |
dcd1bb77
|
Cherian Mathew
|
if(key.equals(BgbmEditClient.ID)) {
|
53 |
ddbcdcf3
|
Cherian Mathew
|
ci = new ChecklistInfo(BgbmEditClient.ID,
|
54 |
|
|
BgbmEditClient.LABEL,
|
55 |
|
|
BgbmEditClient.URL,
|
56 |
|
|
BgbmEditClient.DATA_AGR_URL);
|
57 |
11e8f060
|
Cherian Mathew
|
}
|
58 |
dcd1bb77
|
Cherian Mathew
|
if(key.equals(GBIFBetaBackboneClient.ID)) {
|
59 |
ddbcdcf3
|
Cherian Mathew
|
ci = new ChecklistInfo(GBIFBetaBackboneClient.ID,
|
60 |
|
|
GBIFBetaBackboneClient.LABEL,
|
61 |
|
|
GBIFBetaBackboneClient.URL,
|
62 |
|
|
GBIFBetaBackboneClient.DATA_AGR_URL);
|
63 |
11e8f060
|
Cherian Mathew
|
}
|
64 |
|
|
if(ci != null) {
|
65 |
|
|
ciMap.put(key, ci);
|
66 |
dcd1bb77
|
Cherian Mathew
|
System.out.println("put key : " + key);
|
67 |
11e8f060
|
Cherian Mathew
|
ci.addSubChecklist(ChecklistInfo.create(Arrays.copyOfRange(ciStrArray, 1, 5)));
|
68 |
dcd1bb77
|
Cherian Mathew
|
System.out.println("put sub checklist : " + ciStrArray[1]);
|
69 |
|
|
|
70 |
11e8f060
|
Cherian Mathew
|
}
|
71 |
|
|
} else {
|
72 |
|
|
ci.addSubChecklist(ChecklistInfo.create(Arrays.copyOfRange(ciStrArray, 1, 5)));
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
return new ArrayList<ChecklistInfo>(ciMap.values());
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
}
|