7 |
7 |
import java.net.URISyntaxException;
|
8 |
8 |
import java.net.URLDecoder;
|
9 |
9 |
import java.util.Iterator;
|
|
10 |
import java.util.Set;
|
10 |
11 |
|
11 |
12 |
import com.fasterxml.jackson.core.JsonEncoding;
|
12 |
13 |
import com.fasterxml.jackson.core.JsonFactory;
|
13 |
14 |
import com.fasterxml.jackson.core.JsonGenerator;
|
14 |
15 |
import com.google.common.base.Joiner;
|
15 |
16 |
import com.google.common.collect.Iterators;
|
|
17 |
import com.google.common.collect.Sets;
|
16 |
18 |
import eu.dnetlib.parthenos.CRM;
|
|
19 |
import eu.dnetlib.parthenos.CRMdig;
|
17 |
20 |
import eu.dnetlib.parthenos.CRMpe;
|
18 |
21 |
import eu.dnetlib.parthenos.jrr.ParthenosRegistryResource;
|
19 |
22 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
|
... | ... | |
21 |
24 |
import org.apache.commons.lang3.StringUtils;
|
22 |
25 |
import org.apache.commons.logging.Log;
|
23 |
26 |
import org.apache.commons.logging.LogFactory;
|
|
27 |
import org.apache.jena.rdf.model.RDFNode;
|
24 |
28 |
import org.apache.jena.rdf.model.Resource;
|
25 |
29 |
import org.apache.jena.rdf.model.StmtIterator;
|
26 |
30 |
import org.apache.jena.vocabulary.RDF;
|
... | ... | |
72 |
76 |
//resource not yet registered
|
73 |
77 |
String catGroup = ensureGroup(group);
|
74 |
78 |
String json;
|
|
79 |
//base types are {Project, Service, Actors, Datasets, Software, Physical Collections, ??Standards??} i.e. {PE35_Project, PE1_Service, E39_Actor, PE18_Dataset, D14_Software, E78_Collection, ??E29_Design_or_Procedure??)
|
75 |
80 |
switch (type.getLocalName()) {
|
76 |
|
case "E7_Activity":
|
77 |
|
json = getJsonForActivity(resource, resCatName, catGroup);
|
|
81 |
case "PE35_Project":
|
|
82 |
json = getJsonForProject(resource, resCatName, catGroup);
|
78 |
83 |
break;
|
|
84 |
case "PE1_Service":
|
|
85 |
json = getJsonForService(resource, resCatName, catGroup);
|
|
86 |
break;
|
|
87 |
// case "E7_Activity":
|
|
88 |
// json = getJsonForActivity(resource, resCatName, catGroup);
|
|
89 |
// break;
|
79 |
90 |
case "E29_Design_or_Procedure":
|
80 |
91 |
json = getJsonForDesignProcedure(resource, resCatName, catGroup);
|
81 |
92 |
break;
|
82 |
93 |
case "E39_Actor":
|
83 |
94 |
json = getJsonForActor(resource, resCatName, catGroup);
|
84 |
95 |
break;
|
85 |
|
case "E70_Thing":
|
86 |
|
json = getJsonForThing(resource, resCatName, catGroup);
|
|
96 |
case "PE18_Dataset":
|
|
97 |
json = getJsonForDataset(resource, resCatName, catGroup);
|
87 |
98 |
break;
|
|
99 |
case "D14_Software":
|
|
100 |
json = getJsonForSoftware(resource, resCatName, catGroup);
|
|
101 |
break;
|
|
102 |
case "E78_Collection":
|
|
103 |
json = getJsonForCollection(resource, resCatName, catGroup);
|
|
104 |
break;
|
|
105 |
// case "E70_Thing":
|
|
106 |
// json = getJsonForThing(resource, resCatName, catGroup);
|
|
107 |
// break;
|
88 |
108 |
default:
|
89 |
109 |
throw new IllegalArgumentException(String.format("Type " + type.getLocalName() + " not supported"));
|
90 |
110 |
}
|
... | ... | |
125 |
145 |
return n;
|
126 |
146 |
}
|
127 |
147 |
|
128 |
|
// /**
|
129 |
|
// * Ensure that providers referred in the Resource are available as "groups" in the registry.
|
130 |
|
// * @param res Resource
|
131 |
|
// */
|
132 |
|
// protected void ensureGroups(final Resource res) throws ParthenosPublisherException, IOException, URISyntaxException {
|
133 |
|
// log.debug("Ensuring groups exist");
|
134 |
|
// if(res.hasProperty(CRMpe.PP2_provided_by) || res.hasProperty(CRMpe.PP25_has_maintaining_RI)) {
|
135 |
|
// Iterator<String> providerNames = resourceReader.getProviderNames(res);
|
136 |
|
// while (providerNames.hasNext()) {
|
137 |
|
// String name = providerNames.next();
|
138 |
|
// if (StringUtils.isNotBlank(name)) {
|
139 |
|
// String groupName = getNameForCatalogue(name);
|
140 |
|
// if (!catalogueAPIClient.groupExist(groupName)) {
|
141 |
|
// String groupJson = String.format(groupTemplate, groupName, groupName, name);
|
142 |
|
// catalogueAPIClient.registerGroup(groupJson, groupName);
|
143 |
|
// log.info("NEW GROUP REGISTERED: " + groupName);
|
144 |
|
// }
|
145 |
|
// }
|
146 |
|
// }
|
147 |
|
// }
|
148 |
|
// else{
|
149 |
|
// log.debug("Resource "+res.getURI()+" without PP2_provided_by: no groups to register");
|
150 |
|
// }
|
151 |
|
// }
|
152 |
148 |
|
153 |
149 |
protected String ensureGroup(final String group) throws ParthenosPublisherException, IOException, URISyntaxException {
|
154 |
150 |
log.debug("Ensuring group exist: "+group);
|
... | ... | |
164 |
160 |
return null;
|
165 |
161 |
}
|
166 |
162 |
|
167 |
|
protected String getJsonForActivity(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
|
163 |
protected String getJsonForProject(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
168 |
164 |
JsonFactory jsonFactory = new JsonFactory();
|
169 |
165 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
170 |
166 |
BufferedOutputStream bos = new BufferedOutputStream(out);
|
... | ... | |
176 |
172 |
//jg.writeStringField("maintainer_email", Joiner.on(", ").join(resourceReader.getMaintainerContacts(res)));
|
177 |
173 |
|
178 |
174 |
jg.writeArrayFieldStart("extras");
|
179 |
|
addExtra(jg, "system:type", CRM.E7_Activity.getLocalName());
|
|
175 |
//system:type must be one among {Project, Service, Actors, Datasets, Software, Physical Collections, ??Standards??} i.e. {PE35_Project, PE1_Service, E39_Actor, PE18_Dataset, D14_Software, E78_Collection, ??E29_Design_or_Procedure??)
|
|
176 |
addExtra(jg, "system:type", CRMpe.PE35_Project.getLocalName());
|
180 |
177 |
//specific class
|
181 |
178 |
addExtra(jg, "instance of", resourceReader.findSpecificType(res, CRM.E7_Activity).getLocalName());
|
182 |
179 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL))
|
183 |
180 |
addExtra(jg, "Parthenos URL", res.getURI());
|
184 |
181 |
else addExtra(jg, "URL", res.getURI());
|
185 |
|
//for Services
|
186 |
|
if(res.hasProperty(RDF.type, CRMpe.PE1_Service)) {
|
187 |
|
addExtra(jg, "competence", Joiner.on(", ").join(resourceReader.getCompetences(res)));
|
188 |
|
addExtra(jg, "activity type", Joiner.on(", ").join(resourceReader.getActivityTypes(res)));
|
189 |
|
//condition of use (Rights)
|
190 |
|
addExtra(jg, "condition of use", resourceReader.getConditionOfUse(res));
|
191 |
|
addExtra(jg, "contact points", Joiner.on(", ").join(Iterators.concat(resourceReader.getResourceDirectContactPointsURI(res), resourceReader.getProviderContactPoints(res))));
|
192 |
|
addExtra(jg, "provided by", Joiner.on(", ").join(resourceReader.getProviderUris(res)));
|
193 |
|
addExtra(jg, "online access point", Joiner.on(", ").join(resourceReader.getAccessPoints(res)));
|
194 |
|
addExtra(jg, "protocol", Joiner.on(", ").join(resourceReader.getProtocols(res)));
|
195 |
|
addExtra(jg, "delivers on request", Joiner.on(", ").join(resourceReader.getDeliversOnRequest(res)));
|
196 |
|
addExtra(jg, "runs on request", Joiner.on(", ").join(resourceReader.getRunsOnRequest(res)));
|
197 |
|
addExtra(jg, "hosts", Joiner.on(", ").join(resourceReader.getHostedStuff(res)));
|
198 |
|
addExtra(jg, "curates", Joiner.on(", ").join(resourceReader.getCuratedObjects(res)));
|
199 |
|
addExtra(jg, "declared begin/end of operation", Joiner.on(", ").join(resourceReader.getDeclarativeTimes(res)));
|
200 |
|
addExtra(jg, "availability", resourceReader.getAvailability(res));
|
201 |
|
addExtra(jg, "uses curation plan", Joiner.on(", ").join(resourceReader.getCurationPlans(res)));
|
202 |
|
//TODO: where to get it?
|
203 |
|
//addExtra(jg, "last confirmation", "");
|
204 |
|
//TODO: where to get it?
|
205 |
|
//addExtra(jg, "date of registration", "");
|
206 |
|
}
|
207 |
|
//for Projects
|
208 |
|
if(res.hasProperty(RDF.type, CRMpe.PE35_Project)) {
|
209 |
|
addExtra(jg, "started on", resourceReader.getStartTime(res));
|
210 |
|
addExtra(jg, "maintaining team", Joiner.on(", ").join(resourceReader.getMaintainerUrls(res)));
|
211 |
|
addExtra(jg, "offers", Joiner.on(", ").join(resourceReader.getOfferedServiceUrls(res)));
|
212 |
|
}
|
|
182 |
addIdentifiers(res, jg);
|
|
183 |
|
|
184 |
addExtra(jg, "started on", resourceReader.getStartTime(res));
|
|
185 |
addExtra(jg, "maintaining team", Joiner.on(", ").join(resourceReader.getMaintainerUrls(res)));
|
|
186 |
addExtra(jg, "offers", Joiner.on(", ").join(resourceReader.getOfferedServiceUrls(res)));
|
|
187 |
|
213 |
188 |
jg.writeEndArray(); //end extras
|
214 |
189 |
|
215 |
190 |
jg.writeEndObject();
|
... | ... | |
217 |
192 |
return out.toString("UTF-8");
|
218 |
193 |
}
|
219 |
194 |
|
|
195 |
protected String getJsonForService(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
|
196 |
JsonFactory jsonFactory = new JsonFactory();
|
|
197 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
198 |
BufferedOutputStream bos = new BufferedOutputStream(out);
|
|
199 |
JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
|
|
200 |
jg.writeStartObject();
|
|
201 |
writeCommonFields(jg, res, resNameForCatalogue, catGroup);
|
|
202 |
jg.writeStringField("maintainer", Joiner.on(", ").join(resourceReader.getMaintainersForManagementSection(res)));
|
|
203 |
//TODO: it should be better to identify email contacts rather than generic contact labels of maintainer
|
|
204 |
//jg.writeStringField("maintainer_email", Joiner.on(", ").join(resourceReader.getMaintainerContacts(res)));
|
|
205 |
|
|
206 |
jg.writeArrayFieldStart("extras");
|
|
207 |
//system:type must be one among {Project, Service, Actors, Datasets, Software, Physical Collections, ??Standards??} i.e. {PE35_Project, PE1_Service, E39_Actor, PE18_Dataset, D14_Software, E78_Collection, ??E29_Design_or_Procedure??)
|
|
208 |
addExtra(jg, "system:type", CRMpe.PE1_Service.getLocalName());
|
|
209 |
//specific class
|
|
210 |
addExtra(jg, "instance of", resourceReader.findSpecificType(res, CRM.E7_Activity).getLocalName());
|
|
211 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL))
|
|
212 |
addExtra(jg, "Parthenos URL", res.getURI());
|
|
213 |
else addExtra(jg, "URL", res.getURI());
|
|
214 |
addIdentifiers(res, jg);
|
|
215 |
addExtra(jg, "competence", Joiner.on(", ").join(resourceReader.getCompetences(res)));
|
|
216 |
addExtra(jg, "activity type", Joiner.on(", ").join(resourceReader.getActivityTypes(res)));
|
|
217 |
//condition of use (Rights)
|
|
218 |
addExtra(jg, "condition of use", resourceReader.getConditionOfUse(res));
|
|
219 |
addExtra(jg, "contact points", Joiner.on(", ").join(Iterators.concat(resourceReader.getResourceDirectContactPointsURI(res), resourceReader.getProviderContactPoints(res))));
|
|
220 |
addExtra(jg, "provided by", Joiner.on(", ").join(resourceReader.getProviderUris(res)));
|
|
221 |
addExtra(jg, "online access point", Joiner.on(", ").join(resourceReader.getAccessPoints(res)));
|
|
222 |
addExtra(jg, "protocol", Joiner.on(", ").join(resourceReader.getProtocols(res)));
|
|
223 |
addExtra(jg, "delivers on request", Joiner.on(", ").join(resourceReader.getDeliversOnRequest(res)));
|
|
224 |
addExtra(jg, "runs on request", Joiner.on(", ").join(resourceReader.getRunsOnRequest(res)));
|
|
225 |
addExtra(jg, "hosts", Joiner.on(", ").join(resourceReader.getHostedStuff(res)));
|
|
226 |
addExtra(jg, "curates", Joiner.on(", ").join(resourceReader.getCuratedObjects(res)));
|
|
227 |
addExtra(jg, "declared begin/end of operation", Joiner.on(", ").join(resourceReader.getDeclarativeTimes(res)));
|
|
228 |
addExtra(jg, "availability", resourceReader.getAvailability(res));
|
|
229 |
addExtra(jg, "uses curation plan", Joiner.on(", ").join(resourceReader.getCurationPlans(res)));
|
|
230 |
addExtra(jg, "time of service", Joiner.on(", ").join(resourceReader.getDeclarativeTimes(res)));
|
|
231 |
//TODO: where to get it?
|
|
232 |
//addExtra(jg, "last confirmation", "");
|
|
233 |
//TODO: where to get it?
|
|
234 |
//addExtra(jg, "date of registration", "");
|
|
235 |
|
|
236 |
jg.writeEndArray(); //end extras
|
|
237 |
|
|
238 |
jg.writeEndObject();
|
|
239 |
jg.close();
|
|
240 |
return out.toString("UTF-8");
|
|
241 |
}
|
|
242 |
|
220 |
243 |
protected String getJsonForActor(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
221 |
244 |
JsonFactory jsonFactory = new JsonFactory();
|
222 |
245 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
... | ... | |
232 |
255 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL))
|
233 |
256 |
addExtra(jg, "Parthenos URL", res.getURI());
|
234 |
257 |
else addExtra(jg, "URL", res.getURI());
|
|
258 |
addIdentifiers(res, jg);
|
235 |
259 |
addExtra(jg, "has member", Joiner.on(", ").join(resourceReader.getMemberUrls(res)));
|
236 |
260 |
addExtra(jg, "is member of", Joiner.on(", ").join(resourceReader.isMemberOf(res)));
|
237 |
261 |
addExtra(jg, "provides", Joiner.on(", ").join(resourceReader.getProvidedServiceUrls(res)));
|
238 |
|
//contact points
|
239 |
|
//addExtra(jg, "has contact point", Joiner.on(", ").join(resourceReader.getResourceDirectContactPointsURI(res)));
|
240 |
262 |
String contactPoints = "";
|
241 |
263 |
StmtIterator it = res.listProperties(CRM.P76_has_contact_point);
|
242 |
264 |
while(it.hasNext()) {
|
... | ... | |
261 |
283 |
return out.toString("UTF-8");
|
262 |
284 |
}
|
263 |
285 |
|
264 |
|
protected String getJsonForThing(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
|
286 |
protected String getJsonForDataset(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
265 |
287 |
JsonFactory jsonFactory = new JsonFactory();
|
266 |
288 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
267 |
289 |
BufferedOutputStream bos = new BufferedOutputStream(out);
|
... | ... | |
270 |
292 |
writeCommonFields(jg, res, resNameForCatalogue, catGroup);
|
271 |
293 |
|
272 |
294 |
jg.writeArrayFieldStart("extras");
|
273 |
|
addExtra(jg, "system:type", CRM.E70_Thing.getLocalName());
|
|
295 |
addExtra(jg, "system:type", CRMpe.PE18_Dataset.getLocalName());
|
274 |
296 |
//specific class
|
275 |
297 |
addExtra(jg, "instance of", resourceReader.findSpecificType(res, CRM.E70_Thing).getLocalName());
|
276 |
298 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL)) {
|
277 |
299 |
addExtra(jg, "Parthenos URL", res.getURI());
|
278 |
300 |
}
|
279 |
301 |
else addExtra(jg, "URL", res.getURI());
|
|
302 |
addIdentifiers(res, jg);
|
280 |
303 |
addExtra(jg, "has type", Joiner.on(", ").join(resourceReader.getHasTypeLabels(res)));
|
281 |
304 |
addExtra(jg, "is part of", Joiner.on(", ").join(resourceReader.getIsPartOfUrls(res)));
|
282 |
305 |
addExtra(jg, "has part", Joiner.on(", ").join(resourceReader.getHasPartUrls(res)));
|
283 |
306 |
addExtra(jg, "curated by", Joiner.on(", ").join(resourceReader.getCuratorUrls(res)));
|
284 |
|
//addExtra(jg, "curation plan", Joiner.on(", ").join(resourceReader.getCurationPlans(res)));
|
|
307 |
addExtra(jg, "curation plan", Joiner.on(", ").join(resourceReader.getResourceCuratorCurationPlans(res)));
|
285 |
308 |
addExtra(jg, "hosted by", Joiner.on(", ").join(resourceReader.getHostedBys(res)));
|
286 |
309 |
addExtra(jg, "encoding type", Joiner.on(", ").join(resourceReader.getEncodings(res)));
|
287 |
310 |
addExtra(jg, "creator", Joiner.on(", ").join(resourceReader.getCreatorsURIs(res)));
|
|
311 |
addExtra(jg, "created with software", Joiner.on(", ").join(resourceReader.getUsedSoftware(res)));
|
288 |
312 |
addExtra(jg, "subject", Joiner.on(", ").join(resourceReader.getSubjects(res)));
|
289 |
313 |
addExtra(jg, "temporal coverage", Joiner.on(", ").join(resourceReader.getTemporalCoverages(res)));
|
290 |
314 |
addExtra(jg, "spatial coverage", Joiner.on(", ").join(resourceReader.getSpatialCoverages(res)));
|
... | ... | |
292 |
316 |
addExtra(jg, "used by", Joiner.on(", ").join(resourceReader.getUsedBy(res)));
|
293 |
317 |
addExtra(jg, "languages", Joiner.on(", ").join(resourceReader.getLanguages(res)));
|
294 |
318 |
|
295 |
|
if(res.hasProperty(RDF.type, CRMpe.PE18_Dataset)){
|
296 |
|
addExtra(jg, "has metadata", Joiner.on(", ").join(resourceReader.getMetadata(res)));
|
297 |
|
addExtra(jg, "is metadata for", Joiner.on(", ").join(resourceReader.getDescribedDataset(res)));
|
298 |
|
addExtra(jg, "has snapshot", Joiner.on(", ").join(resourceReader.getSnapshots(res)));
|
299 |
|
addExtra(jg, "is snapshot of", Joiner.on(", ").join(resourceReader.getIsSnapshotOfs(res)));
|
|
319 |
addExtra(jg, "has metadata", Joiner.on(", ").join(resourceReader.getMetadata(res)));
|
|
320 |
addExtra(jg, "is metadata for", Joiner.on(", ").join(resourceReader.getDescribedDataset(res)));
|
|
321 |
addExtra(jg, "has snapshot", Joiner.on(", ").join(resourceReader.getSnapshots(res)));
|
|
322 |
addExtra(jg, "is snapshot of", Joiner.on(", ").join(resourceReader.getIsSnapshotOfs(res)));
|
|
323 |
|
|
324 |
|
|
325 |
jg.writeEndArray();
|
|
326 |
|
|
327 |
jg.writeEndObject();
|
|
328 |
jg.close();
|
|
329 |
return out.toString("UTF-8");
|
|
330 |
}
|
|
331 |
|
|
332 |
protected String getJsonForSoftware(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
|
333 |
JsonFactory jsonFactory = new JsonFactory();
|
|
334 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
335 |
BufferedOutputStream bos = new BufferedOutputStream(out);
|
|
336 |
JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
|
|
337 |
jg.writeStartObject();
|
|
338 |
writeCommonFields(jg, res, resNameForCatalogue, catGroup);
|
|
339 |
|
|
340 |
jg.writeArrayFieldStart("extras");
|
|
341 |
addExtra(jg, "system:type", CRMdig.D14_Software.getLocalName());
|
|
342 |
//specific class
|
|
343 |
addExtra(jg, "instance of", resourceReader.findSpecificType(res, CRM.E70_Thing).getLocalName());
|
|
344 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL)) {
|
|
345 |
addExtra(jg, "Parthenos URL", res.getURI());
|
300 |
346 |
}
|
|
347 |
else addExtra(jg, "URL", res.getURI());
|
|
348 |
addIdentifiers(res, jg);
|
|
349 |
addExtra(jg, "subject", Joiner.on(", ").join(resourceReader.getSubjects(res)));
|
|
350 |
addExtra(jg, "has type", Joiner.on(", ").join(resourceReader.getHasTypeLabels(res)));
|
|
351 |
addExtra(jg, "hosted by", Joiner.on(", ").join(resourceReader.getHostedBys(res)));
|
|
352 |
addExtra(jg, "curated by", Joiner.on(", ").join(resourceReader.getCuratorUrls(res)));
|
|
353 |
addExtra(jg, "has snapshot", Joiner.on(", ").join(resourceReader.getSnapshots(res)));
|
|
354 |
addExtra(jg, "is snapshot of", Joiner.on(", ").join(resourceReader.getIsSnapshotOfs(res)));
|
|
355 |
addExtra(jg, "is part of", Joiner.on(", ").join(resourceReader.getIsPartOfUrls(res)));
|
|
356 |
addExtra(jg, "has part", Joiner.on(", ").join(resourceReader.getHasPartUrls(res)));
|
|
357 |
addExtra(jg, "has release", Joiner.on(", ").join(resourceReader.getHasReleases(res)));
|
|
358 |
addExtra(jg, "is release of", Joiner.on(", ").join(resourceReader.getIsReleaseOfs(res)));
|
|
359 |
addExtra(jg, "used by", Joiner.on(", ").join(resourceReader.getUsedBy(res)));
|
|
360 |
addExtra(jg, "creation time", resourceReader.getFirstCreationTime(res));
|
301 |
361 |
|
302 |
362 |
jg.writeEndArray();
|
303 |
363 |
|
... | ... | |
306 |
366 |
return out.toString("UTF-8");
|
307 |
367 |
}
|
308 |
368 |
|
|
369 |
protected String getJsonForCollection(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
|
370 |
JsonFactory jsonFactory = new JsonFactory();
|
|
371 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
372 |
BufferedOutputStream bos = new BufferedOutputStream(out);
|
|
373 |
JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
|
|
374 |
jg.writeStartObject();
|
|
375 |
writeCommonFields(jg, res, resNameForCatalogue, catGroup);
|
|
376 |
|
|
377 |
jg.writeArrayFieldStart("extras");
|
|
378 |
addExtra(jg, "system:type", CRM.E78_Collection.getLocalName());
|
|
379 |
//specific class
|
|
380 |
addExtra(jg, "instance of", resourceReader.findSpecificType(res, CRM.E70_Thing).getLocalName());
|
|
381 |
if (res.getURI().startsWith(PARTHENOS_BASE_URL)) {
|
|
382 |
addExtra(jg, "Parthenos URL", res.getURI());
|
|
383 |
}
|
|
384 |
else addExtra(jg, "URL", res.getURI());
|
|
385 |
addIdentifiers(res, jg);
|
|
386 |
addExtra(jg, "has type", Joiner.on(", ").join(resourceReader.getHasTypeLabels(res)));
|
|
387 |
addExtra(jg, "subject", Joiner.on(", ").join(resourceReader.getSubjects(res)));
|
|
388 |
addExtra(jg, "temporal coverage", Joiner.on(", ").join(resourceReader.getTemporalCoverages(res)));
|
|
389 |
addExtra(jg, "spatial coverage", Joiner.on(", ").join(resourceReader.getSpatialCoverages(res)));
|
|
390 |
addExtra(jg, "has part", Joiner.on(", ").join(resourceReader.getHasPartUrls(res)));
|
|
391 |
addExtra(jg, "hosted by", Joiner.on(", ").join(resourceReader.getHostedBys(res)));
|
|
392 |
addExtra(jg, "curated by", Joiner.on(", ").join(resourceReader.getCuratorUrls(res)));
|
|
393 |
addExtra(jg, "creator", Joiner.on(", ").join(resourceReader.getCreatorsURIs(res)));
|
|
394 |
addExtra(jg, "languages", Joiner.on(", ").join(resourceReader.getLanguages(res)));
|
|
395 |
|
|
396 |
jg.writeEndArray();
|
|
397 |
|
|
398 |
jg.writeEndObject();
|
|
399 |
jg.close();
|
|
400 |
return out.toString("UTF-8");
|
|
401 |
}
|
|
402 |
|
|
403 |
|
309 |
404 |
protected String getJsonForDesignProcedure(final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
310 |
405 |
JsonFactory jsonFactory = new JsonFactory();
|
311 |
406 |
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
... | ... | |
322 |
417 |
addExtra(jg, "Parthenos URL", res.getURI());
|
323 |
418 |
}
|
324 |
419 |
else addExtra(jg, "URL", res.getURI());
|
|
420 |
addIdentifiers(res, jg);
|
325 |
421 |
addExtra(jg, "used by", Joiner.on(", ").join(resourceReader.getUsedBy(res)));
|
326 |
422 |
//TODO: add additional metadata for E29_Design_or_Procedure, if any
|
327 |
423 |
jg.writeEndArray();
|
... | ... | |
331 |
427 |
return out.toString("UTF-8");
|
332 |
428 |
}
|
333 |
429 |
|
|
430 |
protected void addIdentifiers(final Resource res, final JsonGenerator jg ) throws IOException {
|
|
431 |
/*
|
|
432 |
<${subjectURL}> crm:P1_is_identified_by ?IDRes .
|
|
433 |
?IDRes a crm:E42_Identifier .
|
|
434 |
?IDRes rdfs:label ?ID_label .
|
|
435 |
*/
|
|
436 |
StmtIterator it = res.listProperties(CRM.P1_is_identified_by);
|
|
437 |
Set<String> ids = Sets.newHashSet();
|
|
438 |
while(it.hasNext()){
|
|
439 |
RDFNode obj = it.next().getObject();
|
|
440 |
if(obj.isLiteral()) ids.add(obj.asLiteral().getLexicalForm());
|
|
441 |
else {
|
|
442 |
Resource id = (Resource) obj;
|
|
443 |
if (id.hasProperty(RDF.type, CRM.E42_Identifier)) {
|
|
444 |
ids.add(resourceReader.getLabel(id));
|
|
445 |
}
|
|
446 |
}
|
|
447 |
}
|
|
448 |
addExtra(jg, "ID", String.join(",", ids));
|
|
449 |
}
|
|
450 |
|
334 |
451 |
protected void addExtra(final JsonGenerator jg, final String key, final String value) throws IOException {
|
335 |
452 |
if(StringUtils.isNotBlank(value)) {
|
336 |
453 |
jg.writeStartObject();
|
... | ... | |
340 |
457 |
}
|
341 |
458 |
}
|
342 |
459 |
|
|
460 |
|
|
461 |
|
343 |
462 |
protected void writeCommonFields(final JsonGenerator jg, final Resource res, final String resNameForCatalogue, final String catGroup) throws IOException {
|
344 |
463 |
//end of URI
|
345 |
464 |
jg.writeStringField("name", resNameForCatalogue);
|
According to george's feedback, base types to be considered for the JRR are {Project, Service, Actors, Datasets, Software, Physical Collections, Standards} i.e. {PE35_Project, PE1_Service, E39_Actor, PE18_Dataset, D14_Software, E78_Collection, E29_Design_or_Procedure).
Updated mappings for system:type, adding IDs and other minor changes