Project

General

Profile

« Previous | Next » 

Revision 52248

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

View differences:

modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/catalogue/CatalogueRegistratorTest.java
66 66
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
67 67
		while (subjects.hasNext()) {
68 68
			Resource subject = subjects.nextResource();
69
			String json = reg.getJsonForActivity(subject, "testCatName", "testGroup");
69
			String json = reg.getJsonForService(subject, "testCatName", "testGroup");
70 70
			System.out.println(json);
71 71
		}
72 72
	}
......
78 78
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
79 79
		while (subjects.hasNext()) {
80 80
			Resource subject = subjects.nextResource();
81
			String json = reg.getJsonForActivity(subject, "testCatName", "testGroup");
81
			String json = reg.getJsonForService(subject, "testCatName", "testGroup");
82 82
			System.out.println(json);
83 83
		}
84 84
	}
......
102 102
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRMpe.PE35_Project);
103 103
		while (subjects.hasNext()) {
104 104
			Resource subject = subjects.nextResource();
105
			String json = reg.getJsonForActivity(subject, "testProjectName", "testGroup");
105
			String json = reg.getJsonForProject(subject, "testProjectName", "testGroup");
106 106
			System.out.println(json);
107 107
		}
108 108
	}
......
114 114
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRMpe.PE18_Dataset);
115 115
		while (subjects.hasNext()) {
116 116
			Resource subject = subjects.nextResource();
117
			String json = reg.getJsonForThing(subject, "testDatasetName", "testGroup");
117
			String json = reg.getJsonForDataset(subject, "testDatasetName", "testGroup");
118 118
			System.out.println(json);
119 119
		}
120 120
	}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistratorIntegrationTest.java
17 17
import org.apache.jena.vocabulary.RDF;
18 18
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
19 19
import org.junit.Before;
20
import org.junit.Ignore;
20 21
import org.junit.Test;
21 22
import org.junit.runner.RunWith;
22 23
import org.springframework.beans.factory.annotation.Autowired;
......
32 33
 *
33 34
 * @author Alessia Bardi
34 35
 */
35
//@Ignore
36
@Ignore
36 37
@RunWith(SpringJUnit4ClassRunner.class)
37 38
@SpringBootTest
38 39
@TestPropertySource(
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoTest.java
155 155
		graph.clear();
156 156
	}
157 157

  
158
	@Ignore
158 159
	@Test
159 160
	public void testDescribeRemote() {
160 161
		String resURI = "http://hdl.handle.net/11858/00-203C-0000-0029-F5E8-C";
modules/dnet-parthenos-publisher/trunk/test/main/resources/application-integrationtest.properties
1
#virtuoso.sparqlurl = http://localhost:8890/sparql
2
#virtuoso.connectionstring = jdbc:virtuoso://localhost:1111
3
#virtuoso.pwd = dba
1
virtuoso.sparqlurl = http://localhost:8890/sparql
2
virtuoso.connectionstring = jdbc:virtuoso://localhost:1111
3
virtuoso.pwd = dba
4
virtuoso.usr = dba
5

  
6
#virtuoso.sparqlurl = https://virtuoso.parthenos.d4science.org/sparql
7
#virtuoso.connectionstring = jdbc:virtuoso://virtuoso.parthenos.d4science.org:1111
8
#virtuoso.pwd = d93ab92c7b3bfa1
4 9
#virtuoso.usr = dba
5 10

  
6
virtuoso.sparqlurl = https://virtuoso.parthenos.d4science.org/sparql
7
virtuoso.connectionstring = jdbc:virtuoso://virtuoso.parthenos.d4science.org:1111
8
virtuoso.pwd = d93ab92c7b3bfa1
9
virtuoso.usr = dba
10

  
11 11
virtuoso.uri.base.default =  http://parthenos.d4science.org/handle/
12 12

  
13 13
#gcube.registry.baseurl = https://registry-parthenos.d4science.org/resource-registry/
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueRegistrator.java
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);
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/rdf/ResourceReader.java
38 38
	private Property usedByProperty = ResourceFactory.createProperty("","usedby");
39 39
	//sparql template for datasets include <creator> field that is generated from the creation event
40 40
	private Property creatorProperty = ResourceFactory.createProperty("","creator");
41
	//sparql template for software include <creationtime> field that is generated from the creation event
42
	private Property creationtimeProperty = ResourceFactory.createProperty("","creationtime");
41 43

  
42 44

  
43 45
	public String getTitle(final Resource resource) {
......
50 52
		return getLabel(resource);
51 53
	}
52 54

  
53
	public Iterator<String> getDescriptions(final Resource resource) {
54
		StmtIterator it = resource.listProperties(CRM.P3_has_note);
55
		return Iterators.transform(it, f -> f.getString().replace("'", "\'"));
56
	}
57

  
58 55
	public String getLabel(final Resource resource) {
59 56
		if(resource == null) return "";
60 57
		if (resource.hasProperty(RDFS.label)) {
......
62 59
		} else return "";
63 60
	}
64 61

  
62
	public Iterator<String> getDescriptions(final Resource resource) {
63
		StmtIterator it = resource.listProperties(CRM.P3_has_note);
64
		return Iterators.transform(it, f -> f.getString().replace("'", "\'"));
65
	}
66

  
67

  
65 68
	//NOTE: based on the sparql templates competency is a string, in the model it is a PE36_Competency_Type
66 69
	public Iterator<String> getCompetences(final Resource resource) {
67 70
		StmtIterator it = resource.listProperties(CRMpe.PP45_has_competency);
......
206 209
//		return Iterators.concat(it32, it11, it12, it13);
207 210
	}
208 211

  
212
	public Iterator<String> getResourceCuratorCurationPlans(final Resource resource) {
213
		//In inference we trust
214
		StmtIterator sit32 = resource.listProperties(CRMpe.PP32i_is_curated_by);
215
		return Iterators.concat(Iterators.transform(sit32, c -> getCurationPlans(c.getResource())));
216
	}
217

  
209 218
	public Iterator<String> getDeliversOnRequest(final Resource resource){
210 219
		StmtIterator sit = resource.listProperties(CRMpe.PP15_delivers_on_request);
211 220
		return Iterators.transform(sit, f -> f.getResource().getURI());
......
328 337
		return "";
329 338
	}
330 339

  
340
	public String getFirstCreationTime(final Resource resource){
341
		StmtIterator it = resource.listProperties(creationtimeProperty);
342
		if(it.hasNext()){
343
			return it.next().getString();
344
		}
345
		return "";
346
	}
347

  
331 348
	public Iterator<String> getMaintainerUrls(final Resource resource){
332 349
		StmtIterator it = resource.listProperties(CRMpe.PP44_has_maintaining_team);
333 350
		return Iterators.transform(it, f -> f.getResource().getURI());
......
366 383
		return Iterators.transform(it, f -> f.getResource().getURI());
367 384
	}
368 385

  
386
	public Iterator<String> getHasReleases(final Resource resource){
387
		StmtIterator it = resource.listProperties(CRMpe.PP22_has_release);
388
		return Iterators.transform(it, f -> f.getResource().getURI());
389
	}
390

  
391
	public Iterator<String> getIsReleaseOfs(final Resource resource){
392
		StmtIterator it = resource.listProperties(CRMpe.PP22i_is_release_of);
393
		return Iterators.transform(it, f -> f.getResource().getURI());
394
	}
395

  
369 396
	public Iterator<String> getUsedSoftware(final Resource resource){
370 397
		StmtIterator it = resource.listProperties(usedSoftwareProperty);
371 398
		return Iterators.transform(it, f -> f.getResource().getURI());
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/jrr/JRRPublisher.java
69 69
	protected void register(final Model model, final String resourceURI, final String datasourceName)
70 70
			throws ParthenosPublisherException, IOException, URISyntaxException, InterruptedException {
71 71
		Resource rdfResource = model.getResource(resourceURI);
72
		if(rdfResource == null){
73
			log.error("UNEXPECTED NULL rdfResource with resourceURI "+resourceURI+". I am skipping it, but you should check!");
74
		}
75
		else {
72
		if (rdfResource == null) {
73
			log.error("UNEXPECTED NULL rdfResource with resourceURI " + resourceURI + ". I am skipping it, but you should check!");
74
		} else {
76 75
			//call the correct register method based on the resource type
77 76
			//we skip everything that is not Software, Actor, Service, Dataset, Curation Plan and Project: other entities are in fact source of metadata for them
77
			////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??)
78 78
			if (rdfResource.hasProperty(RDF.type, CRM.E39_Actor)) registerRDFResource(rdfResource, CRM.E39_Actor, datasourceName);
79 79
			else {
80
				if (rdfResource.hasProperty(RDF.type, CRMdig.D14_Software) || rdfResource.hasProperty(RDF.type, CRMpe.PE18_Dataset))
81
					registerRDFResource(rdfResource, CRM.E70_Thing, datasourceName);
80
				if (rdfResource.hasProperty(RDF.type, CRMpe.PE35_Project)) registerRDFResource(rdfResource, CRMpe.PE35_Project, datasourceName);
82 81
				else {
83
					if (rdfResource.hasProperty(RDF.type, CRMpe.PE1_Service) || rdfResource.hasProperty(RDF.type, CRMpe.PE35_Project))
84
						registerRDFResource(rdfResource, CRM.E7_Activity, datasourceName);
82
					if (rdfResource.hasProperty(RDF.type, CRMpe.PE1_Service)) registerRDFResource(rdfResource, CRMpe.PE1_Service, datasourceName);
85 83
					else {
86
						if (rdfResource.hasProperty(RDF.type, CRMpe.PE28_Curation_Plan)) registerRDFResource(rdfResource, CRM.E29_Design_or_Procedure, datasourceName);
87
						else log.debug("Skipping " + resourceURI + " because of its type");
84
						if (rdfResource.hasProperty(RDF.type, CRMpe.PE18_Dataset)) registerRDFResource(rdfResource, CRMpe.PE18_Dataset, datasourceName);
85
						else {
86
							if (rdfResource.hasProperty(RDF.type, CRMdig.D14_Software)) registerRDFResource(rdfResource, CRMdig.D14_Software, datasourceName);
87
							else {
88
								if (rdfResource.hasProperty(RDF.type, CRM.E78_Collection)) registerRDFResource(rdfResource, CRM.E78_Collection, datasourceName);
89
								else {
90
									if (rdfResource.hasProperty(RDF.type, CRM.E29_Design_or_Procedure)) registerRDFResource(rdfResource, CRM.E29_Design_or_Procedure, datasourceName);
91
									else {
92
										log.debug("Skipping " + resourceURI + " because of its type");
93
									}
94
								}
95
							}
96
						}
88 97
					}
89 98
				}
90 99
			}
91 100
		}
92 101
	}
93 102

  
94

  
95 103
	protected boolean registerRDFResource(final Resource rdfResource, final Resource type, final String catalogueGroup)
96 104
			throws ParthenosPublisherException, IOException, URISyntaxException, InterruptedException {
97 105
		String resURI = rdfResource.getURI();

Also available in: Unified diff