Revision 49490
Added by Alessia Bardi over 6 years ago
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistrator.java | ||
---|---|---|
123 | 123 |
int registeredDigitalObjects = processDigitalObjects(model, uriProcessed, jsonFactory, idMap); |
124 | 124 |
int registeredActors = processActors(model, uriProcessed, jsonFactory, idMap); |
125 | 125 |
int registeredProjects = processProjects(model, uriProcessed, jsonFactory, idMap); |
126 |
int registeredTypes = processTypes(model, uriProcessed, jsonFactory, idMap); |
|
126 | 127 |
|
127 |
int total = registeredActors + registeredDigitalObjects + registeredProjects + registeredServices; |
|
128 |
int total = registeredActors + registeredDigitalObjects + registeredProjects + registeredServices+registeredTypes;
|
|
128 | 129 |
log.info(String.format("Registered %d resources from record with objIdentifier %s", total, objIdentifier)); |
129 | 130 |
|
130 | 131 |
/* Relationships */ |
... | ... | |
330 | 331 |
return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid); |
331 | 332 |
} |
332 | 333 |
|
334 |
protected int processTypes(final InfModel model, |
|
335 |
final Set<String> uriProcessed, |
|
336 |
final JsonFactory jsonFactory, |
|
337 |
final Map<String, ParthenosRegistryResource> idMap) |
|
338 |
throws IOException, ResourceRegistryException { |
|
339 |
log.debug("Processing types"); |
|
340 |
int count = 0; |
|
341 |
int total = 0; |
|
342 |
ResIterator iter = model.listResourcesWithProperty(RDF.type, CRM.E55_Type); |
|
343 |
while (iter.hasNext()) { |
|
344 |
total++; |
|
345 |
Resource res = iter.nextResource(); |
|
346 |
String resourceURI = res.getURI(); |
|
347 |
if (!uriProcessed.contains(resourceURI)) { |
|
348 |
ParthenosRegistryResource prr = processType(res, jsonFactory, idMap); |
|
349 |
//TODO: if something goes wrong we stop the registration but we are not rolling back the one that may have succeeded before. |
|
350 |
//Let's decide if this is ok or if we must be smarter than this |
|
351 |
this.resourceRegistryPublisher.createResource(prr.getRegistryType(), prr.getJson()); |
|
352 |
uriProcessed.add(resourceURI); |
|
353 |
idMap.put(resourceURI, prr); |
|
354 |
count++; |
|
355 |
} else { |
|
356 |
log.debug(resourceURI + " already processed, now skipping it"); |
|
357 |
} |
|
358 |
} |
|
359 |
log.debug(String.format("Registered %d/%d types", count, total)); |
|
360 |
return count; |
|
361 |
|
|
362 |
} |
|
363 |
|
|
364 |
private ParthenosRegistryResource processType(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap) |
|
365 |
throws IOException { |
|
366 |
log.debug("Processing " + res.getURI()); |
|
367 |
|
|
368 |
StringWriter sw = new StringWriter(); |
|
369 |
JsonGenerator jg = jsonFactory.createGenerator(sw); |
|
370 |
jg.writeStartObject(); |
|
371 |
String specificType = findSpecificType(res, CRM.E55_Type).getLocalName(); |
|
372 |
String uuid = writeCommon(res, specificType, jg, idMap); |
|
373 |
//******THE FACETS *******// |
|
374 |
jg.writeArrayFieldStart("consistsOf"); |
|
375 |
writeCommonFacets(res, jg); |
|
376 |
jg.writeEndArray(); |
|
377 |
jg.writeEndObject(); |
|
378 |
jg.close(); |
|
379 |
String json = sw.toString(); |
|
380 |
log.debug(json); |
|
381 |
return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid); |
|
382 |
} |
|
383 |
|
|
384 |
|
|
333 | 385 |
/** |
334 | 386 |
* Write the common properties: header, class for all resources |
335 | 387 |
* |
Also available in: Unified diff
Process E55_Types