Revision 48139
Added by Alessia Bardi over 6 years ago
ResultEntry.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.openaireplus.api.objects; |
2 | 2 |
|
3 | 3 |
import java.text.SimpleDateFormat; |
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Date; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.List; |
|
8 |
import java.util.Map; |
|
4 |
import java.util.*; |
|
9 | 5 |
import java.util.concurrent.TimeUnit; |
10 | 6 |
|
11 |
//import io.swagger.annotations.ApiModelProperty; |
|
7 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
8 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
9 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
10 |
import eu.dnetlib.miscutils.functional.hash.Hashing; |
|
11 |
import eu.dnetlib.msro.openaireplus.api.OpenAIRESubmitterUtils; |
|
12 |
import eu.dnetlib.msro.rmi.MSROException; |
|
13 |
import io.swagger.annotations.ApiModelProperty; |
|
12 | 14 |
import org.apache.commons.lang.StringUtils; |
13 | 15 |
import org.apache.commons.logging.Log; |
14 | 16 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
16 | 18 |
import org.apache.velocity.tools.generic.EscapeTool; |
17 | 19 |
import org.springframework.ui.velocity.VelocityEngineUtils; |
18 | 20 |
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
20 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
21 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
22 |
import eu.dnetlib.miscutils.functional.hash.Hashing; |
|
23 |
import eu.dnetlib.msro.openaireplus.api.OpenAIRESubmitterUtils; |
|
24 |
|
|
25 | 21 |
/** |
26 | 22 |
* Created by michele on 02/12/15. |
27 | 23 |
*/ |
28 | 24 |
public class ResultEntry { |
29 | 25 |
|
26 |
private String openaireId; |
|
30 | 27 |
private String originalId; |
31 | 28 |
private String title; |
32 | 29 |
private List<String> authors = new ArrayList<String>(); |
... | ... | |
56 | 53 |
|
57 | 54 |
private static final Log log = LogFactory.getLog(ResultEntry.class); |
58 | 55 |
|
59 |
public ResultEntry() {} |
|
56 |
public ResultEntry() { |
|
57 |
} |
|
60 | 58 |
|
61 |
// @ApiModelProperty(required = true) |
|
59 |
public String getOpenaireId() { |
|
60 |
return openaireId; |
|
61 |
} |
|
62 |
|
|
63 |
public void setOpenaireId(String openaireId) { |
|
64 |
this.openaireId = openaireId; |
|
65 |
} |
|
66 |
|
|
62 | 67 |
public String getOriginalId() { |
63 | 68 |
return originalId; |
64 | 69 |
} |
... | ... | |
67 | 72 |
this.originalId = originalId; |
68 | 73 |
} |
69 | 74 |
|
70 |
// @ApiModelProperty(required = true)
|
|
75 |
@ApiModelProperty(required = true) |
|
71 | 76 |
public String getTitle() { |
72 | 77 |
return title; |
73 | 78 |
} |
... | ... | |
76 | 81 |
this.title = title; |
77 | 82 |
} |
78 | 83 |
|
79 |
|
|
80 | 84 |
public List<String> getAuthors() { |
81 | 85 |
return authors; |
82 | 86 |
} |
... | ... | |
101 | 105 |
this.description = description; |
102 | 106 |
} |
103 | 107 |
|
104 |
// @ApiModelProperty(value="ISO Alpha-3 code. E.g. 'eng', 'ita'")
|
|
108 |
@ApiModelProperty(value = "ISO Alpha-3 code. E.g. 'eng', 'ita'")
|
|
105 | 109 |
public String getLanguage() { |
106 | 110 |
return language; |
107 | 111 |
} |
... | ... | |
118 | 122 |
this.pids = pids; |
119 | 123 |
} |
120 | 124 |
|
121 |
// @ApiModelProperty(required = true, allowableValues = "OPEN, CLOSED, RESTRICTED, EMBARGO, UNKNOWN, OTHER")
|
|
125 |
@ApiModelProperty(required = true, allowableValues = "OPEN, CLOSED, RESTRICTED, EMBARGO, UNKNOWN, OTHER") |
|
122 | 126 |
public String getLicenseCode() { |
123 | 127 |
return licenseCode; |
124 | 128 |
} |
... | ... | |
127 | 131 |
this.licenseCode = licenseCode; |
128 | 132 |
} |
129 | 133 |
|
130 |
// @ApiModelProperty(required = true, value="Use 001 for articles, 021 for datasets. See: http://api.openaire.eu/vocabularies/dnet:publication_resource.")
|
|
134 |
@ApiModelProperty(required = true, value = "Use 001 for articles, 021 for datasets. See: http://api.openaire.eu/vocabularies/dnet:publication_resource.")
|
|
131 | 135 |
public String getResourceType() { |
132 | 136 |
return resourceType; |
133 | 137 |
} |
... | ... | |
136 | 140 |
this.resourceType = resourceType; |
137 | 141 |
} |
138 | 142 |
|
139 |
// @ApiModelProperty(required = true)
|
|
143 |
@ApiModelProperty(required = true) |
|
140 | 144 |
public String getUrl() { |
141 | 145 |
return url; |
142 | 146 |
} |
... | ... | |
145 | 149 |
this.url = url; |
146 | 150 |
} |
147 | 151 |
|
148 |
// @ApiModelProperty(required = true, value="Use opendoar___::2659 for Zenodo Publications; re3data_____::r3d100010468 for Zenodo datasets; infrastruct::openaire for OpenAIRE portal.")
|
|
152 |
@ApiModelProperty(required = true, value = "Use opendoar___::2659 for Zenodo Publications; re3data_____::r3d100010468 for Zenodo datasets; infrastruct::openaire for OpenAIRE portal.")
|
|
149 | 153 |
public String getCollectedFromId() { |
150 | 154 |
return collectedFromId; |
151 | 155 |
} |
... | ... | |
162 | 166 |
this.hostedById = hostedById; |
163 | 167 |
} |
164 | 168 |
|
165 |
// @ApiModelProperty(value="E.g. fet, egi::classification::natsc::math::pure, egi::projects::EMI")
|
|
169 |
@ApiModelProperty(value = "E.g. fet, egi::classification::natsc::math::pure, egi::projects::EMI")
|
|
166 | 170 |
public List<String> getContexts() { |
167 | 171 |
return contexts; |
168 | 172 |
} |
... | ... | |
170 | 174 |
public void setContexts(final List<String> contexts) { |
171 | 175 |
this.contexts = contexts; |
172 | 176 |
} |
173 |
// @ApiModelProperty(value="E.g. info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus") |
|
177 |
|
|
178 |
@ApiModelProperty(value = "E.g. info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus") |
|
174 | 179 |
public List<String> getLinksToProjects() { |
175 | 180 |
return linksToProjects; |
176 | 181 |
} |
... | ... | |
179 | 184 |
this.linksToProjects = linksToProjects; |
180 | 185 |
} |
181 | 186 |
|
182 |
// @ApiModelProperty(allowableValues = "publication, dataset")
|
|
187 |
@ApiModelProperty(allowableValues = "publication, dataset") |
|
183 | 188 |
public String getType() { |
184 | 189 |
return type; |
185 | 190 |
} |
... | ... | |
200 | 205 |
final ISLookUpService lookupService, |
201 | 206 |
final String oafSchemaLocation) throws Exception { |
202 | 207 |
|
208 |
if (StringUtils.isBlank(getOriginalId()) && StringUtils.isBlank(getOpenaireId())) { |
|
209 |
throw new MSROException("One of the following fields is required: originalId or openaireId"); |
|
210 |
} |
|
211 |
if (StringUtils.isBlank(getTitle())) { throw new MSROException("A required field is missing: title"); } |
|
212 |
if (StringUtils.isBlank(getUrl())) { throw new MSROException("A required field is missing: url"); } |
|
213 |
if (StringUtils.isBlank(getLicenseCode())) { throw new MSROException("A required field is missing: licenseCode"); } |
|
214 |
if (StringUtils.isBlank(getResourceType())) { throw new MSROException("A required field is missing: resourceType"); } |
|
215 |
if (StringUtils.isBlank(getCollectedFromId())) { throw new MSROException("A required field is missing: collectedFromId"); } |
|
216 |
if (StringUtils.isBlank(getType())) { throw new MSROException("A required field is missing: type"); } |
|
217 |
|
|
203 | 218 |
final DatasourceEntry collectedFromEntry = getDatasourceInfo(collectedFromId, lookupService); |
204 | 219 |
final DatasourceEntry hostedByEntry = getDatasourceInfo(hostedById, lookupService); |
205 | 220 |
|
206 |
final String objId = calculateObjId(originalId, collectedFromEntry); |
|
221 |
if (StringUtils.isBlank(openaireId)) { |
|
222 |
setOpenaireId(calculateOpenaireId(originalId, collectedFromEntry)); |
|
223 |
} |
|
207 | 224 |
|
225 |
if (!openaireId.matches("^\\w{12}::\\w{32}$")) { |
|
226 |
throw new MSROException("Invalid openaireId: " + openaireId + " - regex ^\\w{12}::\\w{32}$ not matched"); |
|
227 |
} |
|
228 |
|
|
208 | 229 |
final Map<String, Object> model = new HashMap<String, Object>(); |
209 | 230 |
model.put("esc", new EscapeTool()); |
210 | 231 |
model.put("util", new OpenAIRESubmitterUtils()); |
211 | 232 |
model.put("pub", this); |
212 |
model.put("objIdentifier", objId);
|
|
233 |
model.put("objIdentifier", getOpenaireId());
|
|
213 | 234 |
model.put("oafSchemaLocation", oafSchemaLocation); |
214 | 235 |
model.put("resultTypes", getVocabulary("dnet:result_typologies", lookupService)); |
215 | 236 |
model.put("licenses", getVocabulary("dnet:access_modes", lookupService)); |
... | ... | |
224 | 245 |
return VelocityEngineUtils.mergeTemplateIntoString(ve, "/eu/dnetlib/msro/openaireplus/api/indexRecord.xml.vm", "UTF-8", model); |
225 | 246 |
} |
226 | 247 |
|
227 |
public static String calculateObjId(final String originalId, final DatasourceEntry collectedFromEntry) {
|
|
248 |
private static String calculateOpenaireId(final String originalId, final DatasourceEntry collectedFromEntry) {
|
|
228 | 249 |
return collectedFromEntry.getPrefix() + "::" + Hashing.md5(originalId); |
229 | 250 |
} |
230 | 251 |
|
231 |
public static String calculateObjId(final String originalId, final String collectedFromId, final ISLookUpService lookupService) throws ISLookUpException { |
|
232 |
return calculateObjId(originalId, getDatasourceInfo(collectedFromId, lookupService)); |
|
252 |
public static String calculateOpenaireId(final String originalId, final String collectedFromId, final ISLookUpService lookupService) |
|
253 |
throws ISLookUpException { |
|
254 |
return calculateOpenaireId(originalId, getDatasourceInfo(collectedFromId, lookupService)); |
|
233 | 255 |
} |
234 | 256 |
|
235 | 257 |
private synchronized static DatasourceEntry getDatasourceInfo(final String dsId, final ISLookUpService lookupService) throws ISLookUpException { |
... | ... | |
294 | 316 |
return cached_contexts; |
295 | 317 |
} |
296 | 318 |
|
297 |
} |
|
319 |
@Override |
|
320 |
public String toString() { |
|
321 |
return StringUtils.isNotBlank(openaireId) ? openaireId : originalId; |
|
322 |
} |
|
323 |
} |
Also available in: Unified diff
integrated (hopefully) all required changes from dnet40