Project

General

Profile

« Previous | Next » 

Revision 49453

Log and exceptions

View differences:

GCubeResourceRegistrator.java
69 69
	public void init() throws Exception {
70 70
		ParthenosRegistryClientSetter.forceToURL(getRegistryBaseURL());
71 71
		ParthenosRegistryPublisherSetter.forceToURL(getRegistryBaseURL());
72
		log.info("Registry URL forced to "+getRegistryBaseURL());
73
		if(StringUtils.isNotBlank(getApplicationToken())) {
72
		log.info("Registry URL forced to " + getRegistryBaseURL());
73
		if (StringUtils.isNotBlank(getApplicationToken())) {
74 74
			GCubeResourceRegistrator.setContext(getApplicationToken());
75 75
			log.info("GCube Context set");
76
		}
77
		else{
76
		} else {
78 77
			log.fatal("GCube context cannot be configured without a value in gcube.registry.application.token");
79 78
		}
80 79
		this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
......
88 87
	protected static String getCurrentScope(String token) throws Exception {
89 88
		AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
90 89
		String context = authorizationEntry.getContext();
91
		log.info("Context of token "+token+" is: "+context);
90
		log.info("Context of token " + token + " is: " + context);
92 91
		return context;
93 92
	}
94 93

  
......
97 96
		ScopeProvider.instance.set(getCurrentScope(token));
98 97
	}
99 98

  
100

  
101

  
102
	public int unregister(final String datasourceApi){
99
	public int unregister(final String datasourceApi) {
103 100
		//TODO: implement me
104 101
		return -1;
105 102
	}
......
109 106
	 *
110 107
	 * @param rdfRecord RDF record in RDF/XML PLAIN format
111 108
	 */
112
	public void register(final String rdfRecord, final String objIdentifier) throws IOException, ResourceRegistryException, ParthenosPublisherException {
109
	public void register(final String rdfRecord, final String objIdentifier) throws ParthenosPublisherException, IOException {
110
		log.info("Processing record " + objIdentifier + " for registration on JRR");
113 111
		if (StringUtils.isBlank(rdfRecord)) {
114
			log.warn("Got empty record "+objIdentifier);
112
			log.warn("Got empty record " + objIdentifier);
115 113
		} else {
116 114
			InfModel model = loadBaseModel();
117 115
			model.read(IOUtils.toInputStream(rdfRecord, "UTF-8"), CRMpe.NS);
......
120 118
			Set<String> uriProcessed = Sets.newHashSet();
121 119
			/* Maps URI to ParthenosRegistryResource (with uuids) */
122 120
			Map<String, ParthenosRegistryResource> idMap = Maps.newHashMap();
123

  
121
			try {
124 122
			/* Resource */
125
			int registeredServices = processServices(model, uriProcessed, jsonFactory, idMap);
126
			int registeredDigitalObjects = processDigitalObjects(model, uriProcessed, jsonFactory, idMap);
127
			int registeredActors = processActors(model, uriProcessed, jsonFactory, idMap);
128
			int registeredProjects = processProjects(model, uriProcessed, jsonFactory, idMap);
123
				int registeredServices = processServices(model, uriProcessed, jsonFactory, idMap);
124
				int registeredDigitalObjects = processDigitalObjects(model, uriProcessed, jsonFactory, idMap);
125
				int registeredActors = processActors(model, uriProcessed, jsonFactory, idMap);
126
				int registeredProjects = processProjects(model, uriProcessed, jsonFactory, idMap);
129 127

  
130
			int total = registeredActors+registeredDigitalObjects+registeredProjects+registeredServices;
131
			log.debug(String.format("Registered %d resources from record with objIdentifier %s", total, objIdentifier));
128
				int total = registeredActors + registeredDigitalObjects + registeredProjects + registeredServices;
129
				log.info(String.format("Registered %d resources from record with objIdentifier %s", total, objIdentifier));
132 130

  
133 131
			/* Relationships */
134
			int relTotal = 0;
135
			for(String uri : uriProcessed){
136
				relTotal += processRelationships(model, uri, idMap);
132
				int relTotal = 0;
133
				for (String uri : uriProcessed) {
134
					relTotal += processRelationships(model, uri, idMap);
135
				}
136
				log.info(String.format("Registered %d relationships from record with objIdentifier %s", relTotal, objIdentifier));
137
			} catch (Throwable e) {
138
				String msg = "Registration of " + objIdentifier + " could not be completed correctly";
139
				log.error(msg, e);
140
				throw new ParthenosPublisherException(msg, e);
137 141
			}
138
			log.debug(String.format("Registered %d relationships from record with objIdentifier %s", relTotal, objIdentifier));
139 142
		}
140 143
	}
141 144

  
......
146 149
		JsonFactory jsonFactory = new JsonFactory();
147 150
		int relCount = 0;
148 151

  
149
		if(subject.hasProperty(RDF.type, CRMpe.PE1_Service)){
152
		if (subject.hasProperty(RDF.type, CRMpe.PE1_Service)) {
150 153
			StmtIterator itOfferedBy = subject.listProperties(CRMpe.PP1i_is_currently_offered_by);
151
			while(itOfferedBy.hasNext()){
154
			while (itOfferedBy.hasNext()) {
152 155
				Resource project = itOfferedBy.nextStatement().getResource();
153 156
				ParthenosRegistryResource source = idMap.get(uri);
154 157
				ParthenosRegistryResource projectRes = idMap.get(project.getURI());
155
				String relJson = relWriter.writeRelationship(jsonFactory, "PP1_currently_offers", projectRes.getUuid(), projectRes.getRegistryType(), source.getUuid(), source.getRegistryType());
158
				String relJson = relWriter
159
						.writeRelationship(jsonFactory, "PP1_currently_offers", projectRes.getUuid(), projectRes.getRegistryType(), source.getUuid(),
160
								source.getRegistryType());
156 161
				this.resourceRegistryPublisher.createIsRelatedTo("PP1_currently_offers", relJson);
157 162
				relCount++;
158 163
			}
159 164
			StmtIterator itProvidedBy = subject.listProperties(CRMpe.PP2_provided_by);
160
			while(itProvidedBy.hasNext()){
165
			while (itProvidedBy.hasNext()) {
161 166
				Resource provider = itProvidedBy.nextStatement().getResource();
162 167
				ParthenosRegistryResource prr = idMap.get(uri);
163 168
				ParthenosRegistryResource providerRes = idMap.get(provider.getURI());
164
				String relJson = relWriter.writeRelationship(jsonFactory, "PP2_provided_by", prr.getUuid(), prr.getRegistryType(), providerRes.getUuid(), providerRes.getRegistryType());
169
				String relJson = relWriter.writeRelationship(jsonFactory, "PP2_provided_by", prr.getUuid(), prr.getRegistryType(), providerRes.getUuid(),
170
						providerRes.getRegistryType());
165 171
				this.resourceRegistryPublisher.createIsRelatedTo("PP2_provided_by", relJson);
166 172
				relCount++;
167 173
				//TODO: IsRelatedTo the contact person of the provider. Interpret '"Follow path of service ‘Provided by’ and switch E39 for E21: E21- >p76->E51""
......
183 189
			relCount += registerRelationship(CRMpe.PP15_delivers_on_request, subject, idMap, jsonFactory);
184 190
			relCount += registerRelationship(CRMpe.PP46_brokers_access_to, subject, idMap, jsonFactory);
185 191
		}
186
		if(subject.hasProperty(RDF.type, CRMpe.PE18_Dataset)){
192
		if (subject.hasProperty(RDF.type, CRMpe.PE18_Dataset)) {
187 193
			StmtIterator itPartOf = subject.listProperties(CRMpe.PP23i_is_dataset_part_of);
188
			while(itPartOf.hasNext()){
194
			while (itPartOf.hasNext()) {
189 195
				Resource obj = itPartOf.nextStatement().getResource();
190 196
				ParthenosRegistryResource prr = idMap.get(uri);
191 197
				ParthenosRegistryResource objres = idMap.get(obj.getURI());
192
				String relJson = relWriter.writeRelationship(jsonFactory, "PP23_has_dataset_part", objres.getUuid(), objres.getRegistryType(), prr.getUuid(), prr.getRegistryType());
198
				String relJson = relWriter.writeRelationship(jsonFactory, "PP23_has_dataset_part", objres.getUuid(), objres.getRegistryType(), prr.getUuid(),
199
						prr.getRegistryType());
193 200
				this.resourceRegistryPublisher.createIsRelatedTo("PP23_has_dataset_part", relJson);
194 201
				relCount++;
195 202
			}
196 203
			//TODO: this is in the registry model but I am not sure what's going to happen...
197 204
			StmtIterator itIsAbout = subject.listProperties(CRM.P129_is_about);
198
			while(itIsAbout.hasNext()){
205
			while (itIsAbout.hasNext()) {
199 206
				Resource obj = itIsAbout.nextStatement().getResource();
200
				if(obj.hasProperty(RDF.type, CRM.E55_Type)) {
207
				if (obj.hasProperty(RDF.type, CRM.E55_Type)) {
201 208
					ParthenosRegistryResource prr = idMap.get(uri);
202 209
					ParthenosRegistryResource objres = idMap.get(obj.getURI());
203
					String relJson = relWriter.writeRelationship(jsonFactory, "P129_is_about", prr.getUuid(), prr.getRegistryType(), objres.getUuid(), objres.getRegistryType());
210
					String relJson = relWriter
211
							.writeRelationship(jsonFactory, "P129_is_about", prr.getUuid(), prr.getRegistryType(), objres.getUuid(), objres.getRegistryType());
204 212
					this.resourceRegistryPublisher.createIsRelatedTo("P129_is_about", relJson);
205 213
					relCount++;
206 214
				}
207 215
			}
208 216
		}
209
		if(subject.hasProperty(RDF.type, CRMpe.PE19_Persistent_Digital_Object)){
217
		if (subject.hasProperty(RDF.type, CRMpe.PE19_Persistent_Digital_Object)) {
210 218
			relCount += registerRelationship(CRMpe.PP16_has_persistent_digital_object_part, subject, idMap, jsonFactory);
211 219
		}
212
		if(subject.hasProperty(RDF.type, CRMpe.PE20_Volatile_Digital_Object)){
220
		if (subject.hasProperty(RDF.type, CRMpe.PE20_Volatile_Digital_Object)) {
213 221
			relCount += registerRelationship(CRMpe.PP17_has_snapshot, subject, idMap, jsonFactory);
214 222
			relCount += registerRelationship(CRMpe.PP18_has_digital_object_part, subject, idMap, jsonFactory);
215 223
		}
216
		if(subject.hasProperty(RDF.type, CRMpe.PE21_Persistent_Software)){
224
		if (subject.hasProperty(RDF.type, CRMpe.PE21_Persistent_Software)) {
217 225
			relCount += registerRelationship(CRMpe.PP19_has_persistent_software_part, subject, idMap, jsonFactory);
218 226
		}
219
		if(subject.hasProperty(RDF.type, CRMpe.PE22_Persistent_Dataset)){
227
		if (subject.hasProperty(RDF.type, CRMpe.PE22_Persistent_Dataset)) {
220 228
			relCount += registerRelationship(CRMpe.PP20_has_persistent_dataset_part, subject, idMap, jsonFactory);
221 229
			relCount += registerRelationship(CRMpe.PP39_is_metadata_for, subject, idMap, jsonFactory);
222 230
		}
223
		if(subject.hasProperty(RDF.type, CRMpe.PE23_Volatile_Software)){
231
		if (subject.hasProperty(RDF.type, CRMpe.PE23_Volatile_Software)) {
224 232
			relCount += registerRelationship(CRMpe.PP21_has_software_part, subject, idMap, jsonFactory);
225 233
			relCount += registerRelationship(CRMpe.PP22_has_release, subject, idMap, jsonFactory);
226 234
		}
227
		if(subject.hasProperty(RDF.type, CRMpe.PE24_Volatile_Dataset)){
235
		if (subject.hasProperty(RDF.type, CRMpe.PE24_Volatile_Dataset)) {
228 236
			relCount += registerRelationship(CRMpe.PP23_has_dataset_part, subject, idMap, jsonFactory);
229 237
			relCount += registerRelationship(CRMpe.PP24_has_dataset_snapshot, subject, idMap, jsonFactory);
230 238
			relCount += registerRelationship(CRMpe.PP41_is_index_of, subject, idMap, jsonFactory);
231 239
		}
232
		if(subject.hasProperty(RDF.type, CRMpe.PE26_RI_Project)){
240
		if (subject.hasProperty(RDF.type, CRMpe.PE26_RI_Project)) {
233 241
			relCount += registerRelationship(CRMpe.PP25_has_maintaining_RI, subject, idMap, jsonFactory);
234 242
		}
235
		if(subject.hasProperty(RDF.type, CRMpe.PE35_Project)){
236
			relCount += registerRelationship(CRMpe.PP43_supported_project_activity,  subject, idMap, jsonFactory);
243
		if (subject.hasProperty(RDF.type, CRMpe.PE35_Project)) {
244
			relCount += registerRelationship(CRMpe.PP43_supported_project_activity, subject, idMap, jsonFactory);
237 245
			relCount += registerRelationship(CRMpe.PP44_has_maintaining_team, subject, idMap, jsonFactory);
238 246
		}
239 247
		log.debug(String.format("Registered %d relationships for uri %s, uuid %s", relCount, uri, uuid));
240 248
		return relCount;
241 249
	}
242 250

  
243
	protected int registerRelationship(final Property rel, final Resource subject, final Map<String,ParthenosRegistryResource> idMap, final JsonFactory jsonFactory)
251
	protected int registerRelationship(final Property rel,
252
			final Resource subject,
253
			final Map<String, ParthenosRegistryResource> idMap,
254
			final JsonFactory jsonFactory)
244 255
			throws IOException, ResourceRegistryException, ParthenosPublisherException {
245 256
		int relCount = 0;
246 257
		StmtIterator it = subject.listProperties(rel);
247
		while(it.hasNext()){
258
		while (it.hasNext()) {
248 259
			Resource obj = it.nextStatement().getResource();
249
			if(obj == null) throw new ParthenosPublisherException(String.format("No target resource available for %s --> %s", subject.getURI(), rel.getURI()));
260
			if (obj == null) throw new ParthenosPublisherException(String.format("No target resource available for %s --> %s", subject.getURI(), rel.getURI()));
250 261
			ParthenosRegistryResource source = idMap.get(subject.getURI());
251 262
			ParthenosRegistryResource target = idMap.get(obj.getURI());
252
			String relJson = relWriter.writeRelationship(jsonFactory, rel.getLocalName(), source.getUuid(), source.getRegistryType(), target.getUuid(), target.getRegistryType());
263
			String relJson = relWriter
264
					.writeRelationship(jsonFactory, rel.getLocalName(), source.getUuid(), source.getRegistryType(), target.getUuid(), target.getRegistryType());
253 265
			this.resourceRegistryPublisher.createIsRelatedTo(rel.getLocalName(), relJson);
254 266
			relCount++;
255 267
		}
256 268
		return relCount;
257 269
	}
258 270

  
259

  
260 271
	protected InfModel loadBaseModel() {
261 272
		return ModelFactory.createRDFSModel(baseModel);
262 273
	}
263 274

  
264
	protected int processServices(final InfModel model, final Set<String> uriProcessed, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
275
	protected int processServices(final InfModel model,
276
			final Set<String> uriProcessed,
277
			final JsonFactory jsonFactory,
278
			final Map<String, ParthenosRegistryResource> idMap)
265 279
			throws IOException, ResourceRegistryException {
266 280
		log.debug("Processing services");
267 281
		int count = 0;
......
288 302

  
289 303
	}
290 304

  
291
	private ParthenosRegistryResource processService(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap) throws IOException {
305
	private ParthenosRegistryResource processService(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
306
			throws IOException {
292 307
		log.debug("Processing " + res.getURI());
293 308

  
294 309
		StringWriter sw = new StringWriter();
......
325 340
	 * @param idMap     map of the already assigned UUID
326 341
	 * @return the uuid of the resource
327 342
	 */
328
	protected String writeCommon(final Resource resource, final String className, final JsonGenerator jg, final Map<String, ParthenosRegistryResource> idMap) throws IOException {
343
	protected String writeCommon(final Resource resource, final String className, final JsonGenerator jg, final Map<String, ParthenosRegistryResource> idMap)
344
			throws IOException {
329 345
		String uuid;
330 346
		if (idMap.containsKey(resource.getURI())) {
331 347
			uuid = idMap.get(resource.getURI()).getUuid();
......
352 368
		facetWriter.writeInfoFacet(jg, res);
353 369
	}
354 370

  
355
	protected int processDigitalObjects(final InfModel model, final Set<String> uriProcessed, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
371
	protected int processDigitalObjects(final InfModel model,
372
			final Set<String> uriProcessed,
373
			final JsonFactory jsonFactory,
374
			final Map<String, ParthenosRegistryResource> idMap)
356 375
			throws IOException, ResourceRegistryException {
357 376
		log.debug("Processing digital objects (include dataset and software)");
358 377
		int count = 0;
......
376 395
		return count;
377 396
	}
378 397

  
379
	protected ParthenosRegistryResource processDigitalObject(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
398
	protected ParthenosRegistryResource processDigitalObject(final Resource res,
399
			final JsonFactory jsonFactory,
400
			final Map<String, ParthenosRegistryResource> idMap)
380 401
			throws IOException {
381 402
		log.debug("Processing " + res.getURI());
382 403
		String specificType = findSpecificType(res, CRMdig.D1_Digital_Object).getLocalName();
......
400 421
		return new ParthenosRegistryResource().setUuid(uuid).setType(specificType).setJson(json);
401 422
	}
402 423

  
403
	protected int processActors(final InfModel model, Set<String> uriProcessed, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
424
	protected int processActors(final InfModel model,
425
			Set<String> uriProcessed,
426
			final JsonFactory jsonFactory,
427
			final Map<String, ParthenosRegistryResource> idMap)
404 428
			throws IOException {
405 429
		log.debug("Processing actors");
406 430
		int count = 0;
......
424 448
		return count;
425 449
	}
426 450

  
427
	protected ParthenosRegistryResource processActor(final Resource r, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap) throws IOException {
451
	protected ParthenosRegistryResource processActor(final Resource r, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
452
			throws IOException {
428 453
		log.debug("Processing " + r.getURI());
429 454
		String specificType = findSpecificType(r, CRM.E39_Actor).getLocalName();
430 455
		StringWriter sw = new StringWriter();
......
446 471
		return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid);
447 472
	}
448 473

  
449
	protected int processProjects(final InfModel model, Set<String> uriProcessed, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
474
	protected int processProjects(final InfModel model,
475
			Set<String> uriProcessed,
476
			final JsonFactory jsonFactory,
477
			final Map<String, ParthenosRegistryResource> idMap)
450 478
			throws IOException, ResourceRegistryException {
451 479
		log.debug("Processing projects");
452 480
		int count = 0;
......
470 498
		return count;
471 499
	}
472 500

  
473
	protected ParthenosRegistryResource processProject(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap) throws IOException {
501
	protected ParthenosRegistryResource processProject(final Resource res, final JsonFactory jsonFactory, final Map<String, ParthenosRegistryResource> idMap)
502
			throws IOException {
474 503
		log.debug("Processing " + res.getURI());
475 504
		String specificType = findSpecificType(res, CRMpe.PE35_Project).getLocalName();
476 505
		StringWriter sw = new StringWriter();

Also available in: Unified diff