1
|
package eu.dnetlib.msro.openaireplus.api;
|
2
|
|
3
|
import java.io.StringWriter;
|
4
|
import java.util.ArrayList;
|
5
|
import java.util.HashMap;
|
6
|
import java.util.List;
|
7
|
import java.util.Map;
|
8
|
|
9
|
import com.google.common.base.Function;
|
10
|
import com.google.common.collect.Lists;
|
11
|
import eu.dnetlib.miscutils.functional.hash.Hashing;
|
12
|
import org.apache.commons.lang.StringUtils;
|
13
|
|
14
|
/**
|
15
|
* Created by michele on 15/01/16.
|
16
|
*/
|
17
|
public class OpenAIRESubmitterUtils {
|
18
|
|
19
|
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(OpenAIRESubmitterUtils.class);
|
20
|
|
21
|
public Map<String, String> calculateProjectInfo(final String link) {
|
22
|
final Map<String, String> info = new HashMap<String, String>();
|
23
|
final String[] arr = link.split("/");
|
24
|
// info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble
|
25
|
|
26
|
if (arr.length > 4) {
|
27
|
final String acronym = arr.length > 7 ? arr[7] : "";
|
28
|
final String title = arr.length > 6 ? StringUtils.isNotBlank(arr[6]) ? arr[6] : acronym : "";
|
29
|
final String jurisdiction = arr.length > 5 ? arr[5] : "";
|
30
|
final String funderId = calculateFunderId(arr[2], arr[3]);
|
31
|
info.put("id", calculateProjectId(arr[2], arr[3], arr[4]));
|
32
|
info.put("funderShortName", arr[2]);
|
33
|
info.put("fundingName", arr[3]);
|
34
|
info.put("code", arr[4]);
|
35
|
info.put("jurisdiction", jurisdiction);
|
36
|
info.put("title", title);
|
37
|
info.put("acronym", acronym);
|
38
|
info.put("funderId", funderId);
|
39
|
info.put("funderName", calculateFunderName(arr[2]));
|
40
|
info.put("fundingId", funderId + "::" + arr[3]);
|
41
|
}
|
42
|
return info;
|
43
|
}
|
44
|
|
45
|
protected String calculateFunderPrefix(final String funderShortName, final String funding){
|
46
|
switch(funderShortName.toLowerCase()){
|
47
|
case "conicyt":
|
48
|
return "conicytf____::";
|
49
|
case "ec":
|
50
|
if (funding.equalsIgnoreCase("fp7")) {
|
51
|
return "corda_______::";
|
52
|
} else {
|
53
|
return "corda__h2020::";
|
54
|
}
|
55
|
case "hrzz":
|
56
|
case "mzos":
|
57
|
return "irb_hr______::";
|
58
|
case "tara":
|
59
|
return "taraexp_____::";
|
60
|
case "tubitak":
|
61
|
return "tubitakf____::";
|
62
|
default:
|
63
|
String prefix = funderShortName.toLowerCase();
|
64
|
//ensure we have 12 chars
|
65
|
while(prefix.length() < 12) prefix += "_";
|
66
|
return prefix +"::";
|
67
|
}
|
68
|
}
|
69
|
|
70
|
protected String calculateProjectId(final String funderShortName, final String funding, final String code) {
|
71
|
final String suffix = Hashing.md5(code);
|
72
|
final String funderPrefix = calculateFunderPrefix(funderShortName, funding);
|
73
|
return funderPrefix + suffix;
|
74
|
}
|
75
|
|
76
|
protected String calculateFunderId(final String funderShortName, final String funding) {
|
77
|
switch (funderShortName.toLowerCase()) {
|
78
|
case "ec":
|
79
|
return "ec__________::EC";
|
80
|
default:
|
81
|
String prefix = calculateFunderPrefix(funderShortName, funding);
|
82
|
return prefix + funderShortName.toUpperCase();
|
83
|
}
|
84
|
}
|
85
|
|
86
|
|
87
|
protected String calculateFunderName(final String funderShortName) {
|
88
|
|
89
|
switch (funderShortName.toLowerCase()) {
|
90
|
case "aff":
|
91
|
return "Suomen Akatemia";
|
92
|
case "arc":
|
93
|
return "Australian Research Council (ARC)";
|
94
|
case "conicyt":
|
95
|
return "Comisión Nacional de Investigación Científica y Tecnológica";
|
96
|
case "ec":
|
97
|
return "European Commission";
|
98
|
case "fct":
|
99
|
return "Fundação para a Ciência e a Tecnologia, I.P.";
|
100
|
case "fwf":
|
101
|
return "Austrian Science Fund (FWF)";
|
102
|
case "hrzz":
|
103
|
return "Croatian Science Foundation (CSF)";
|
104
|
case "mestd":
|
105
|
return "Ministry of Education, Science and Technological Development of Republic of Serbia";
|
106
|
case "mzos":
|
107
|
return "Ministry of Science, Education and Sports of the Republic of Croatia (MSES)";
|
108
|
case "nhmrc":
|
109
|
return "National Health and Medical Research Council (NHMRC)";
|
110
|
case "nih":
|
111
|
return "National Institutes of Health";
|
112
|
case "nsf":
|
113
|
return "National Science Foundation";
|
114
|
case "nwo":
|
115
|
return "Netherlands Organisation for Scientific Research (NWO)";
|
116
|
case "rcuk":
|
117
|
return "Research Council UK";
|
118
|
case "sfi":
|
119
|
return "Science Foundation Ireland";
|
120
|
case "sgov":
|
121
|
return "Gobierno de España";
|
122
|
case "snsf":
|
123
|
return "Swiss National Science Foundation";
|
124
|
case "tara":
|
125
|
return "Tara Expeditions Foundation";
|
126
|
case "tubitak":
|
127
|
return "Türkiye Bilimsel ve Teknolojik Araştırma Kurumu";
|
128
|
case "wt":
|
129
|
return "Wellcome Trust";
|
130
|
default:
|
131
|
log.error("Funder short name '"+funderShortName+"' not managed");
|
132
|
return "";
|
133
|
}
|
134
|
}
|
135
|
|
136
|
public List<ContextInfo> processContexts(final List<String> list) {
|
137
|
return Lists.newArrayList(Lists.transform(list, new Function<String, ContextInfo>() {
|
138
|
|
139
|
@Override
|
140
|
public ContextInfo apply(final String s) {
|
141
|
return createContextInfo(s.split("::"), 0);
|
142
|
}
|
143
|
|
144
|
private ContextInfo createContextInfo(final String[] arr, final int pos) {
|
145
|
final StringWriter id = new StringWriter();
|
146
|
id.write(arr[0]);
|
147
|
for (int i = 0; i < pos; i++) {
|
148
|
id.write("::");
|
149
|
id.write(arr[i + 1]);
|
150
|
}
|
151
|
final String elem = (pos == 0) ? "context" : (pos == 1) ? "category" : "concept";
|
152
|
final ContextInfo info = new ContextInfo(elem, id.toString());
|
153
|
if ((pos + 1) < arr.length) {
|
154
|
info.getChildren().add(createContextInfo(arr, pos + 1));
|
155
|
}
|
156
|
return info;
|
157
|
}
|
158
|
}));
|
159
|
|
160
|
}
|
161
|
|
162
|
public class ContextInfo {
|
163
|
|
164
|
private String elem;
|
165
|
private String id;
|
166
|
private List<ContextInfo> children = new ArrayList<ContextInfo>();
|
167
|
|
168
|
public ContextInfo(final String elem,
|
169
|
final String id) {
|
170
|
this.elem = elem;
|
171
|
this.id = id;
|
172
|
}
|
173
|
|
174
|
public String getElem() {
|
175
|
return elem;
|
176
|
}
|
177
|
|
178
|
public void setElem(final String elem) {
|
179
|
this.elem = elem;
|
180
|
}
|
181
|
|
182
|
public String getId() {
|
183
|
return id;
|
184
|
}
|
185
|
|
186
|
public void setId(final String id) {
|
187
|
this.id = id;
|
188
|
}
|
189
|
|
190
|
public List<ContextInfo> getChildren() {
|
191
|
return children;
|
192
|
}
|
193
|
|
194
|
public void setChildren(final List<ContextInfo> children) {
|
195
|
this.children = children;
|
196
|
}
|
197
|
|
198
|
public boolean isRoot() {
|
199
|
return elem.equals("context");
|
200
|
}
|
201
|
}
|
202
|
}
|