Project

General

Profile

« Previous | Next » 

Revision 55561

Removed dep to gcube registry and ignore integration tests

View differences:

modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistratorIntegrationTest.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.UUID;
6

  
7
import eu.dnetlib.parthenos.CRM;
8
import eu.dnetlib.parthenos.CRMdig;
9
import eu.dnetlib.parthenos.CRMpe;
10
import org.apache.commons.io.IOUtils;
11
import org.apache.jena.ontology.OntModel;
12
import org.apache.jena.ontology.OntModelSpec;
13
import org.apache.jena.rdf.model.InfModel;
14
import org.apache.jena.rdf.model.ModelFactory;
15
import org.apache.jena.rdf.model.ResIterator;
16
import org.apache.jena.rdf.model.Resource;
17
import org.apache.jena.vocabulary.RDF;
18
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
19
import org.junit.Before;
20
import org.junit.Ignore;
21
import org.junit.Test;
22
import org.junit.runner.RunWith;
23
import org.springframework.beans.factory.annotation.Autowired;
24
import org.springframework.boot.test.context.SpringBootTest;
25
import org.springframework.core.io.ClassPathResource;
26
import org.springframework.test.context.TestPropertySource;
27
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
28

  
29
/**
30
 * Created by Alessia Bardi on 28/09/2017.
31
 *
32
 * //TODO: Avoid loading remote resources (see setup())
33
 *
34
 * @author Alessia Bardi
35
 */
36
@Ignore
37
@RunWith(SpringJUnit4ClassRunner.class)
38
@SpringBootTest
39
@TestPropertySource(
40
		locations = "classpath:application-integrationtest.properties")
41
public class GCubeResourceRegistratorIntegrationTest {
42

  
43
	private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
44
	private String test = "eu/dnetlib/parthenos/registry/test.rdf";
45

  
46
	@Autowired
47
	private GCubeResourceRegistrator reg;
48
	private OntModel baseModel;
49

  
50

  
51

  
52
	@Before
53
	public void setup() throws ResourceRegistryException {
54
		baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
55
		baseModel.read(CRMpe.RDFS_URL);
56
		baseModel.read(CRM.RDFS_URL);
57
		baseModel.read(CRMdig.RDFS_URL);
58
	}
59

  
60
	@Test
61
	public void testRegistration() throws Exception{
62
		String resource = getString(nakalaService);
63
		InfModel model = loadBaseModel();
64
		model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
65
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
66
		if (subjects.hasNext()) {
67
			Resource subject = subjects.nextResource();
68
			UUID uuid = UUID.randomUUID();
69
			System.out.println("Registering for uuid "+ uuid.toString());
70
			reg.register(subject, uuid.toString(), CRM.E7_Activity);
71
			reg.deleteResourcebyUUID(CRMpe.PE1_Service, uuid);
72
		}
73
	}
74

  
75
	//@Test
76
	//public void delete() throws ResourceRegistryException {
77
	//	reg.deleteResourcebyUUID(UUID.fromString("2adce5d8-66fe-41d6-9d4d-6ecd26faa8c3"));
78
	//}
79

  
80

  
81

  
82

  
83
	private String getString(final String classpath) {
84
		try {
85
			final ClassPathResource resource = new ClassPathResource(classpath);
86
			return IOUtils.toString(resource.getInputStream(), "UTF-8");
87
		}catch(IOException e){
88
			return null;
89
		}
90
	}
91

  
92
	private static InputStream getStream(final String classpath) throws IOException {
93
		return new ClassPathResource(classpath).getInputStream();
94
	}
95

  
96
	protected InfModel loadBaseModel() {
97
		return ModelFactory.createRDFSModel(baseModel);
98
	}
99

  
100
}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/registry/FacetWriterTest.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.StringWriter;
6

  
7
import com.fasterxml.jackson.core.JsonFactory;
8
import com.fasterxml.jackson.core.JsonGenerator;
9
import eu.dnetlib.parthenos.CRM;
10
import eu.dnetlib.parthenos.CRMdig;
11
import eu.dnetlib.parthenos.CRMpe;
12
import eu.dnetlib.parthenos.rdf.ResourceReader;
13
import org.apache.jena.ontology.OntModelSpec;
14
import org.apache.jena.rdf.model.InfModel;
15
import org.apache.jena.rdf.model.ModelFactory;
16
import org.apache.jena.rdf.model.ResIterator;
17
import org.apache.jena.rdf.model.Resource;
18
import org.apache.jena.vocabulary.RDF;
19
import org.junit.Assert;
20
import org.junit.Before;
21
import org.junit.Test;
22
import org.junit.runner.RunWith;
23
import org.junit.runners.JUnit4;
24
import org.springframework.core.io.ClassPathResource;
25

  
26
/**
27
 * Created by Alessia Bardi on 02/10/2017.
28
 *
29
 * @author Alessia Bardi
30
 */
31
@RunWith(JUnit4.class)
32
public class FacetWriterTest {
33

  
34
	private FacetWriter facetWriter;
35
	private ResourceReader rr;
36
	private static String baseURI = "http://parthenos.d4science.org/CRMext/CRMpe.rdfs/";
37

  
38
	@Before
39
	public void setup(){
40
		facetWriter = new FacetWriter();
41
		rr = new ResourceReader();
42
		facetWriter.setResourceReader(rr);
43
	}
44
	/**
45
	 *
46
	 * Method: writeIdentifierFacet(final JsonGenerator jg, final String identifier)
47
	 *
48
	 */
49
	@Test
50
	public void testWriteIdentifierFacet() throws Exception {
51
		JsonFactory jsonFactory = new JsonFactory();
52
		StringWriter sw = new StringWriter();
53
		JsonGenerator jg = jsonFactory.createGenerator(sw);
54
		facetWriter.writeIdentifierFacet(jg, "thisIsAnIDentifier");
55
		jg.close();
56
		System.out.println(sw.toString());
57
		Assert.assertEquals("{\"@class\":\"isIdentifiedBy\",\"target\":{\"@class\":\"IdentifierFacet\",\"value\":\"thisIsAnIDentifier\",\"type\":\"URI\"}}", sw.toString());
58
	}
59

  
60

  
61
	/**
62
	 *
63
	 * Method: writeContactReferenceFacet(final JsonGenerator jg, final Resource resource)
64
	 *
65
	 */
66
	@Test
67
	public void testWriteContactReferenceFacet() throws Exception {
68
		JsonFactory jsonFactory = new JsonFactory();
69
		StringWriter sw = new StringWriter();
70
		JsonGenerator jg = jsonFactory.createGenerator(sw);
71
		InfModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
72
		model.read(CRMpe.RDFS_URL);
73
		model.read(CRM.RDFS_URL);
74
		model.read(CRMdig.RDFS_URL);
75
		model.read(getStream("eu/dnetlib/parthenos/registry/test.rdf"), baseURI);
76
		model = ModelFactory.createRDFSModel(model);
77
		ResIterator iter = model.listResourcesWithProperty(RDF.type, CRMpe.PE1_Service);
78
		if(iter.hasNext()){
79
			Resource r = iter.nextResource();
80
			System.out.println("Found service "+r.getURI());
81
			facetWriter.writeContactReferenceFacet(jg, r);
82
			jg.close();
83
			System.out.println(sw.toString());
84
		}
85
		else {
86
			System.out.println("Could not find any service");
87
			throw new Exception("I was expecting some PE1_Service or subclass instances!");
88
		}
89
	}
90

  
91

  
92
	private InputStream getStream(final String classpath) throws IOException {
93
		return new ClassPathResource(classpath).getInputStream();
94
	}
95

  
96
}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/registry/RelWriterTest.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4

  
5
import com.fasterxml.jackson.core.JsonFactory;
6
import org.junit.Test;
7
import org.junit.runner.RunWith;
8
import org.junit.runners.JUnit4;
9

  
10
/**
11
 * Created by Alessia Bardi on 06/10/2017.
12
 *
13
 * @author Alessia Bardi
14
 */
15
@RunWith(JUnit4.class)
16
public class RelWriterTest {
17

  
18
	private RelWriter relWriter = new RelWriter();
19

  
20
	@Test
21
	public void test() throws IOException {
22
		String rel = relWriter.writeRelationship(new JsonFactory(), "theType", "uuid1", "typeSource", "uuid2", "typeTarget");
23
		System.out.println(rel);
24
	}
25
}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistratorTest.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.List;
6

  
7
import com.fasterxml.jackson.core.JsonFactory;
8
import eu.dnetlib.parthenos.CRM;
9
import eu.dnetlib.parthenos.CRMdig;
10
import eu.dnetlib.parthenos.CRMpe;
11
import eu.dnetlib.parthenos.jrr.ParthenosRegistryRel;
12
import eu.dnetlib.parthenos.jrr.ParthenosRegistryResource;
13
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
14
import eu.dnetlib.parthenos.rdf.ResourceReader;
15
import org.apache.commons.io.IOUtils;
16
import org.apache.commons.lang3.StringUtils;
17
import org.apache.jena.ontology.OntModel;
18
import org.apache.jena.ontology.OntModelSpec;
19
import org.apache.jena.rdf.model.*;
20
import org.apache.jena.vocabulary.RDF;
21
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
22
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
23
import org.junit.Before;
24
import org.junit.Ignore;
25
import org.junit.Test;
26
import org.junit.runner.RunWith;
27
import org.junit.runners.JUnit4;
28
import org.mockito.Mockito;
29
import org.springframework.core.io.ClassPathResource;
30

  
31
import static org.junit.Assert.assertEquals;
32

  
33
/**
34
 * Created by Alessia Bardi on 28/09/2017.
35
 *
36
 * //TODO: Avoid loading remote resources (see setup())
37
 *
38
 * @author Alessia Bardi
39
 */
40
@Ignore
41
@RunWith(JUnit4.class)
42
public class GCubeResourceRegistratorTest {
43

  
44
	private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
45
	private String test = "eu/dnetlib/parthenos/registry/test.rdf";
46

  
47
	private GCubeResourceRegistrator reg;
48
	private OntModel baseModel;
49

  
50
	private ResourceRegistryClient regClient = Mockito.mock(ResourceRegistryClient.class);
51

  
52

  
53
	@Before
54
	public void setup() throws ResourceRegistryException {
55
		reg = new GCubeResourceRegistrator();
56
		FacetWriter facetWriter = new FacetWriter();
57
		facetWriter.setResourceReader(new ResourceReader());
58
		reg.setFacetWriter(facetWriter);
59
		reg.setResourceReader(new ResourceReader());
60
		baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
61
		baseModel.read(CRMpe.RDFS_URL);
62
		baseModel.read(CRM.RDFS_URL);
63
		baseModel.read(CRMdig.RDFS_URL);
64
		Mockito.when(regClient.query(Mockito.anyString(), Mockito.anyInt(), Mockito.anyString())).thenReturn(null);
65
		reg.setResourceRegistryClient(regClient);
66
	}
67

  
68
	@Test
69
	public void testProcessService() throws Exception{
70
		String resource = getString(nakalaService);
71
		InfModel model = loadBaseModel();
72
		model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
73
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
74
		while (subjects.hasNext()) {
75
			Resource subject = subjects.nextResource();
76
			ParthenosRegistryResource prr = reg.processService(subject, new JsonFactory(), "FAKEUUID");
77
			System.out.println(prr.getJson());
78
			final List<ParthenosRegistryRel> resourceRels = reg.getResourceRels(subject, prr);
79
			for(ParthenosRegistryRel r : resourceRels){
80
				System.out.println(r.getJson());
81
			}
82
		}
83
	}
84

  
85

  
86
	@Test
87
	public void testLoadBaseModel() {
88
		//let's snapshot to a normal model to write all statements
89
		Model snapshot = ModelFactory.createDefaultModel();
90
		snapshot.add(baseModel);
91
	}
92

  
93
	@Test
94
	public void testLoadRDFFileWithModel() throws IOException {
95
		//let's snapshot to a normal model to write all statements
96
		Model snapshot = ModelFactory.createDefaultModel();
97
		snapshot.add(baseModel);
98
		snapshot.write(System.out);
99
	}
100

  
101

  
102
	@Test
103
	public void testRules() throws IOException {
104
		StmtIterator it = baseModel.listStatements(new SimpleSelector(ResourceFactory.createResource("uuid:AAAH"), RDF.type, (Resource) null));
105
		while(it.hasNext()){
106
			System.out.println(it.nextStatement().toString());
107
		}
108
		Resource classHS = ResourceFactory.createResource(CRMpe.NS+"PE1_Service");
109
		StmtIterator it2 = baseModel.listStatements(classHS, RDF.type, (Resource) null);
110
		while(it2.hasNext()){
111
			System.out.println(it2.nextStatement().toString());
112
		}
113
	}
114

  
115
	@Test
116
	public void testAmbiguousSpecificType() throws IOException {
117
		Resource res = baseModel.getResource("uuid:AAAH");
118
		Resource specificType = reg.getResourceReader().findSpecificType(res, CRMpe.PE1_Service);
119
		System.out.println(specificType.getURI());
120
		assertEquals(CRMpe.PE1_Service.getURI(), specificType.getURI());
121
	}
122

  
123
	@Test
124
	public void testDashes() throws IOException {
125
		System.out.println(StringUtils.remove(CRMpe.NS+"PE1_Service-HOLA", "-"));
126
	}
127

  
128
	@Test
129
	public void testJsonGeneration1() throws IOException, ResourceRegistryException, ParthenosPublisherException {
130
		testJsonGeneration(test);
131
	}
132

  
133
	@Test
134
	public void testJsonGeneration2() throws IOException, ResourceRegistryException, ParthenosPublisherException {
135
		//testJsonGeneration(recordPath);
136
	}
137

  
138
	@Test
139
	public void testJsonGeneration3() throws IOException, ResourceRegistryException, ParthenosPublisherException {
140
		testJsonGeneration(nakalaService);
141
	}
142

  
143
	private void testJsonGeneration(final String recordClasspath) throws IOException, ResourceRegistryException,
144
			ParthenosPublisherException {
145
		try {
146
			//reg.register(getString(recordClasspath), objIdentifier);
147
		}catch(NullPointerException npe){
148
			//ok: it is because of the registryPublisher
149
		}
150
	}
151

  
152
	private String getString(final String classpath) {
153
		try {
154
			final ClassPathResource resource = new ClassPathResource(classpath);
155
			return IOUtils.toString(resource.getInputStream(), "UTF-8");
156
		}catch(IOException e){
157
			return null;
158
		}
159
	}
160

  
161
	private static InputStream getStream(final String classpath) throws IOException {
162
		return new ClassPathResource(classpath).getInputStream();
163
	}
164

  
165
	protected InfModel loadBaseModel() {
166
		return ModelFactory.createRDFSModel(baseModel);
167
	}
168

  
169
}
modules/dnet-parthenos-publisher/trunk/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ParthenosRegistryPublisherSetter.java
1
package org.gcube.informationsystem.resourceregistry.publisher;
2

  
3
/**
4
 * Created by Alessia Bardi on 26/09/2017.
5
 *
6
 * @author Alessia Bardi
7
 */
8
public class ParthenosRegistryPublisherSetter {
9

  
10
	public static void forceToURL(String url) {
11
		ResourceRegistryPublisherFactory.forceToURL(url);
12
	}
13

  
14
}
modules/dnet-parthenos-publisher/trunk/src/main/java/org/gcube/informationsystem/resourceregistry/client/ParthenosRegistryClientSetter.java
1
package org.gcube.informationsystem.resourceregistry.client;
2

  
3
/**
4
 * Created by Alessia Bardi on 26/09/2017.
5
 *
6
 * @author Alessia Bardi
7
 */
8
public class ParthenosRegistryClientSetter {
9

  
10
	public static void forceToURL(String url) {
11
		ResourceRegistryClientFactory.forceToURL(url);
12
	}
13

  
14
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RelWriter.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.BufferedOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6

  
7
import com.fasterxml.jackson.core.JsonEncoding;
8
import com.fasterxml.jackson.core.JsonFactory;
9
import com.fasterxml.jackson.core.JsonGenerator;
10
import org.springframework.stereotype.Component;
11

  
12
/**
13
 * Created by Alessia Bardi on 02/10/2017.
14
 *
15
 * @author Alessia Bardi
16
 */
17
@Component
18
public class RelWriter {
19

  
20
	protected String writeRelationship(final JsonFactory jsonFactory, final String relType, final String sourceUUID, final String sourceType, final String targetUUID, final String targetType)
21
			throws IOException {
22
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
23
		BufferedOutputStream bos = new BufferedOutputStream(out);
24
		JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
25
		jg.writeStartObject();
26
		jg.writeStringField("@class", relType);
27
		jg.writeObjectFieldStart("source");
28
		jg.writeObjectFieldStart("header");
29
		jg.writeStringField("uuid", sourceUUID);
30
		jg.writeEndObject();
31
		jg.writeStringField("@class", sourceType);
32
		jg.writeEndObject();
33
		jg.writeObjectFieldStart("target");
34
		jg.writeObjectFieldStart("header");
35
		jg.writeStringField("uuid", targetUUID);
36
		jg.writeEndObject();
37
		jg.writeStringField("@class", targetType);
38
		jg.writeEndObject();
39
		jg.close();
40
		return out.toString("UTF-8");
41
	}
42
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/FacetWriter.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4

  
5
import com.fasterxml.jackson.core.JsonGenerator;
6
import com.google.common.base.Joiner;
7
import eu.dnetlib.parthenos.CRM;
8
import eu.dnetlib.parthenos.CRMpe;
9
import eu.dnetlib.parthenos.rdf.ResourceReader;
10
import org.apache.commons.lang3.StringUtils;
11
import org.apache.jena.rdf.model.RDFNode;
12
import org.apache.jena.rdf.model.Resource;
13
import org.apache.jena.rdf.model.StmtIterator;
14
import org.apache.jena.vocabulary.RDF;
15
import org.gcube.resourcemanagement.model.reference.entity.facet.IdentifierFacet.IdentificationType;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Component;
18

  
19
/**
20
 * Created by Alessia Bardi on 02/10/2017.
21
 *
22
 * @author Alessia Bardi
23
 */
24
@Component
25
public class FacetWriter {
26

  
27
	@Autowired
28
	private ResourceReader resourceReader;
29

  
30
	//final IdentificationType type
31
	public void writeP1Facet(final JsonGenerator jg, final String value) throws IOException {
32
		jg.writeStartObject();
33
		jg.writeStringField("@class", "P1_is_identified_by");
34
		jg.writeObjectFieldStart("target");
35
		jg.writeStringField("@class", "SimpleFacet");
36
		jg.writeStringField("value", value);
37
		jg.writeEndObject();
38
		jg.writeEndObject();
39
	}
40

  
41
	public void writeIdentifierFacet(final JsonGenerator jg, final String identifier) throws IOException {
42
		jg.writeStartObject();
43
		jg.writeStringField("@class", "isIdentifiedBy");
44
		jg.writeObjectFieldStart("target");
45
		jg.writeStringField("@class", "IdentifierFacet");
46
		jg.writeStringField("value", identifier);
47
		jg.writeStringField("type", IdentificationType.URI.name());
48
		jg.writeEndObject();
49
		jg.writeEndObject();
50
	}
51

  
52
	public void writeP1Facets(final JsonGenerator jg, final Resource res) throws IOException {
53
		if(res.hasProperty(CRM.P1_is_identified_by)){
54
			StmtIterator idRelsIt = res.listProperties(CRM.P1_is_identified_by);
55
			while(idRelsIt.hasNext()){
56
				RDFNode obj = idRelsIt.nextStatement().getObject();
57
				String value = "";
58
				if(obj.isLiteral()){
59
					value = obj.asLiteral().getLexicalForm();
60
				}
61
				else if(obj.isResource()) {
62
					value = resourceReader.getLabel(obj.asResource());
63
				}
64
				if(StringUtils.isNotBlank(value)) writeP1Facet(jg, value);
65
			}
66
		}
67
	}
68

  
69
	public void writeInfoFacet(final JsonGenerator jg, final Resource res) throws IOException {
70
		jg.writeStartObject();
71
		jg.writeStringField("@class", "consistsOf");
72
		jg.writeObjectFieldStart("target");
73
		jg.writeStringField("@class", "PE_Info_Facet");
74
		jg.writeStringField("title", resourceReader.getTitle(res));
75
		jg.writeStringField("description", Joiner.on(",").join(resourceReader.getDescriptions(res)));
76
		//new object comp + field value + schema="noSchema"
77
		String competence = Joiner.on(',').join(resourceReader.getCompetences(res));
78
		if(StringUtils.isNotBlank(competence)) {
79
			writeValueSchema(jg, "competence", competence, "noSchema");
80
		}
81
		//TODO: uncomment this when George adds the rel to the model
82
		//String availability = getAvailabilityFromRDFResource(res);
83
//		if(StringUtils.isNotBlank(availability)) {
84
//			writeValueSchema(jg, "availability", availability, "noSchema");
85
//		}
86
		jg.writeEndObject();
87
		jg.writeEndObject();
88
	}
89

  
90
	protected void writeValueSchema(final JsonGenerator jg, final String fieldName, final String value, final String schema) throws IOException {
91
		jg.writeObjectFieldStart(fieldName);
92
		jg.writeStringField("value", value);
93
		jg.writeStringField("schema", schema);
94
		jg.writeEndObject();
95
	}
96

  
97
	public void writeEventFacet(final JsonGenerator jg) {
98
		//TODO: implement me. get begin/end of operation from PP42_has_declarative_time
99
	}
100

  
101
	public void writeRightsFacet(final JsonGenerator jg, final Resource res) throws IOException {
102
		//TODO: implement me. E30_Right facet extends from licenseFacet but it is not correct (textUrl is mandatory, we can't use it in Parthenos)
103
	}
104

  
105
	public void writeContactReferenceFacet(final JsonGenerator jg, final Resource actor) throws IOException {
106
		if (actor != null) {
107
			String appellation = resourceReader.getTitle(actor);
108
			String description = Joiner.on(',').join(resourceReader.getDescriptions(actor));
109
			String legalAddress = "";
110
			String email = "";
111
			String website = "";
112
			String address = "";
113
			String phoneNumber = "";
114
			//more contact point per provider
115
			StmtIterator contactPointsStm = actor.listProperties(CRM.P76_has_contact_point);
116
			while (contactPointsStm.hasNext()) {
117
				Resource cp = contactPointsStm.nextStatement().getResource();
118
				//contact points can bean E45_Address or E51_Contact_Point
119
				if ((cp.hasProperty(RDF.type, CRM.E45_Address) || cp.hasProperty(RDF.type, CRM.E51_Contact_Point)) && cp.hasProperty(CRM.P2_has_type)) {
120
					Resource addressType = cp.getPropertyResourceValue(CRM.P2_has_type);
121
					String info = resourceReader.getLabel(cp);
122
					String addressTypeLabel = resourceReader.getLabel(addressType);
123
					switch (addressTypeLabel.toLowerCase()) {
124
					case "email":
125
						email = info;
126
						break;
127
					case "legal address":
128
						legalAddress = info;
129
						break;
130
					case "address":
131
						address = info;
132
						break;
133
					case "phone":
134
						phoneNumber = info;
135
						break;
136
					case "web":
137
						website = info;
138
						break;
139
					}
140
				}
141
			}
142
			jg.writeStartObject();
143
			jg.writeStringField("@class", "consistsOf");
144
			jg.writeObjectFieldStart("target");
145
			jg.writeStringField("@class", "PE_Contact_Reference_Facet");
146
			jg.writeStringField("appellation", appellation);
147
			jg.writeStringField("description", description);
148
			jg.writeStringField("legalAddress", legalAddress);
149
			if(StringUtils.isNotBlank(email)) jg.writeStringField("email", email);
150
			jg.writeStringField("website", website);
151
			jg.writeStringField("address", address);
152
			jg.writeStringField("phoneNumber", phoneNumber);
153
			jg.writeEndObject();
154
			jg.writeEndObject();
155
		}
156
	}
157

  
158
	public void writeDesignatedAccessPointFacet(final JsonGenerator jg, final Resource resource) throws IOException {
159
		//PP28_has_designated_access_point
160
		StmtIterator apStms = resource.listProperties(CRMpe.PP28_has_designated_access_point);
161
		while (apStms.hasNext()) {
162
			String entryName = resourceReader.getLabel(resource);
163
			//(mandatory)
164
			String endpoint = "";
165
			String protocol = "";
166
			String description = Joiner.on(',').join(resourceReader.getDescriptions(resource));
167
			//TODO: authorization is a ValueSchema, I do not understand how to use it and how to map it
168
			String authorization = "";
169
			Resource ap = apStms.next().getResource();
170
			endpoint = ap.getURI();
171
			//TODO: where to get protocol and authorization?
172
			jg.writeStartObject();
173
			jg.writeStringField("@class", "consistsOf");
174
			jg.writeObjectFieldStart("target");
175
			jg.writeStringField("@class", "PE29_Access_Point");
176
			jg.writeStringField("entryName", entryName);
177
			jg.writeStringField("description", description);
178
			jg.writeStringField("endpoint", endpoint);
179
			jg.writeStringField("protocol", protocol);
180
			//TODO: authorization is a ValueSchema, I do not understand how to use it and how to map it
181
			//jg.writeStringField("authorization", authorization);
182
			jg.writeEndObject();
183
			jg.writeEndObject();
184
		}
185

  
186
	}
187

  
188
	public void writeTemporalCoverageFacet(final JsonGenerator jg, final Resource resource) {
189
		//TODO: CoverageFacet wants a value and a mandatory schema. Can't be applied to Parthenos.
190
	}
191

  
192
	public ResourceReader getResourceReader() {
193
		return resourceReader;
194
	}
195

  
196
	public void setResourceReader(final ResourceReader resourceReader) {
197
		this.resourceReader = resourceReader;
198
	}
199
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistrator.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.BufferedOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.UUID;
9
import javax.annotation.PostConstruct;
10

  
11
import com.fasterxml.jackson.core.JsonEncoding;
12
import com.fasterxml.jackson.core.JsonFactory;
13
import com.fasterxml.jackson.core.JsonGenerator;
14
import com.google.common.collect.Lists;
15
import com.google.common.collect.Maps;
16
import eu.dnetlib.parthenos.CRM;
17
import eu.dnetlib.parthenos.CRMdig;
18
import eu.dnetlib.parthenos.CRMpe;
19
import eu.dnetlib.parthenos.jrr.ParthenosRegistryRel;
20
import eu.dnetlib.parthenos.jrr.ParthenosRegistryResource;
21
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
22
import eu.dnetlib.parthenos.rdf.ResourceReader;
23
import org.apache.commons.lang3.StringUtils;
24
import org.apache.commons.logging.Log;
25
import org.apache.commons.logging.LogFactory;
26
import org.apache.jena.rdf.model.Property;
27
import org.apache.jena.rdf.model.Resource;
28
import org.apache.jena.rdf.model.StmtIterator;
29
import org.apache.jena.vocabulary.RDF;
30
import org.gcube.common.authorization.client.Constants;
31
import org.gcube.common.authorization.library.AuthorizationEntry;
32
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
33
import org.gcube.common.scope.api.ScopeProvider;
34
import org.gcube.informationsystem.model.reference.relation.IsIdentifiedBy;
35
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
36
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
37
import org.gcube.informationsystem.resourceregistry.client.ParthenosRegistryClientSetter;
38
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
39
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
40
import org.gcube.informationsystem.resourceregistry.publisher.ParthenosRegistryPublisherSetter;
41
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
42
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
43
import org.gcube.resourcemanagement.model.reference.entity.facet.IdentifierFacet;
44
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.beans.factory.annotation.Value;
46
import org.springframework.stereotype.Component;
47

  
48
/**
49
 * Created by Alessia Bardi on 26/09/2017.
50
 *
51
 * TODO: when the mappings have a definitive URI generation policy then we need to be able to "upsert" (Luca will prepare new method for me).
52
 * When generating relationships, it could be the case that the linked entity was generated from another file, so we have to ask
53
 * the registry if it already exists a resource with a given URI. We cannot do it now because different entities with the same fake UUID are
54
 * generated by the mappings, now. See also https://support.d4science.org/issues/9820#change-56673
55
 *
56
 * @author Alessia Bardi
57
 */
58
@Component
59
public class GCubeResourceRegistrator {
60

  
61
	private static final Log log = LogFactory.getLog(GCubeResourceRegistrator.class);
62

  
63
	@Value("${gcube.registry.baseurl}")
64
	private String registryBaseURL;
65
	@Value("${gcube.registry.application.token}")
66
	private String applicationToken;
67

  
68
	@Autowired
69
	private FacetWriter facetWriter;
70
	@Autowired
71
	private RelWriter relWriter;
72
	@Autowired
73
	private ResourceReader resourceReader;
74

  
75
	private ResourceRegistryPublisher resourceRegistryPublisher;
76
	private ResourceRegistryClient resourceRegistryClient;
77

  
78

  
79
	@PostConstruct
80
	public void init() throws Exception {
81
		ParthenosRegistryClientSetter.forceToURL(getRegistryBaseURL());
82
		ParthenosRegistryPublisherSetter.forceToURL(getRegistryBaseURL());
83
		log.info("Registry URL forced to " + getRegistryBaseURL());
84
		if (StringUtils.isNotBlank(getApplicationToken())) {
85
			GCubeResourceRegistrator.setContext(getApplicationToken());
86
			log.info("GCube Context set");
87
		} else {
88
			log.fatal("GCube context cannot be configured without a value in gcube.registry.application.token");
89
		}
90
		this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
91
		this.resourceRegistryClient = ResourceRegistryClientFactory.create();
92
	}
93

  
94
	protected static String getCurrentScope(String token) throws Exception {
95
		AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
96
		String context = authorizationEntry.getContext();
97
		log.info("Context of token " + token + " is: " + context);
98
		return context;
99
	}
100

  
101
	protected static void setContext(String token) throws Exception {
102
		SecurityTokenProvider.instance.set(token);
103
		ScopeProvider.instance.set(getCurrentScope(token));
104
	}
105

  
106
	public int unregister(final String datasourceApi) {
107
		//TODO: implement me
108
		return -1;
109
	}
110

  
111
	protected boolean deleteResourcebyUUID(final Resource resourceType, final UUID uuid) throws ResourceRegistryException {
112
		//return resourceRegistryPublisher.deleteResource(uuid);
113
		throw new UnsupportedOperationException();
114
	}
115

  
116
	/**
117
	 *
118
	 * @param rdfResource
119
	 * @param uuid
120
	 * @param type
121
	 * @throws IOException
122
	 * @throws ResourceRegistryException
123
	 * @throws ParthenosPublisherException
124
	 *
125
	 */
126
	public void register(final Resource rdfResource, final String uuid, final Resource type) throws IOException, ResourceRegistryException, ParthenosPublisherException {
127
		String resURI = rdfResource.getURI();
128
		log.debug("Processing resource " + resURI + " for registration on JRR");
129
		JsonFactory jsonFactory = new JsonFactory();
130
		ParthenosRegistryResource prr = null;
131
		List<ParthenosRegistryRel> rels;
132
		switch(type.getLocalName()){
133
		case "E7_Activity":
134
			if(rdfResource.hasProperty(RDF.type, CRMpe.PE1_Service)) {
135
				prr = processService(rdfResource, jsonFactory, uuid);
136
			}
137
			else{
138
				if(rdfResource.hasProperty(RDF.type, CRMpe.PE35_Project)){
139
					prr = processProject(rdfResource, jsonFactory, uuid);
140
				}
141
			}
142
			break;
143
		case "E55_Type":
144
			if(rdfResource.hasProperty(RDF.type, CRMpe.PE36_Competency_Type)) {
145
				prr = processBasicResource(rdfResource, CRMpe.PE36_Competency_Type, jsonFactory, uuid);
146
			}
147
			else{
148
				if(rdfResource.hasProperty(RDF.type, CRMpe.PE37_Protocol_Type))
149
					prr = processBasicResource(rdfResource, CRMpe.PE37_Protocol_Type, jsonFactory, uuid);
150
			}
151
			//TODO: need other E55_Types?
152
			break;
153
		case "E70_Thing":
154
			if(rdfResource.hasProperty(RDF.type, CRMdig.D1_Digital_Object)) {
155
				prr = processDigitalObject(rdfResource, jsonFactory, uuid);
156
			}
157
			//TODO: include PE32_Curated_Thing and E19_PhysicalObject?
158
			break;
159
		case "E39_Actor":
160
			prr = processActor(rdfResource, jsonFactory, uuid);
161
			break;
162
		case "E29_Design_or_Procedure":
163
			prr = processBasicResource(rdfResource, CRM.E29_Design_or_Procedure, jsonFactory, uuid);
164
			break;
165
		default:
166
			throw new IllegalArgumentException(String.format("Type "+type.getLocalName()+" not supported"));
167
		}
168
		if(prr != null) {
169
			this.resourceRegistryPublisher.createResource(prr.getJson());
170
			rels = getResourceRels(rdfResource, prr);
171
			int registeredRels = 0;
172
			for(ParthenosRegistryRel r : rels){
173
				//TODO: handle exception
174
				String res = this.resourceRegistryPublisher.createIsRelatedTo(r.getJson());
175
				//TODO: handle negative response
176
				if(StringUtils.isNotBlank(res)) registeredRels++;
177
			}
178
			log.debug(String.format("Registered %d/%d relationships for uri %s, uuid %s", registeredRels, rels.size(), resURI, uuid));
179
		}
180
		else{
181
			log.warn("Could not register on registry: "+resURI);
182
		}
183

  
184
	}
185

  
186

  
187
	protected ParthenosRegistryResource processService(final Resource res, final JsonFactory jsonFactory, final String uuid) throws IOException {
188
		//ensure we are not registering generic PE1_Service because the class is abstract and the registry complaints.
189
		//We only want specific types of services.
190
		if (res.hasProperty(RDF.type, CRMpe.PE8_E_Service)
191
				|| res.hasProperty(RDF.type, CRMpe.PE2_Hosting_Service)
192
				|| res.hasProperty(RDF.type, CRMpe.PE3_Curating_Service)) {
193
			final ByteArrayOutputStream out = new ByteArrayOutputStream();
194
			BufferedOutputStream bos = new BufferedOutputStream(out);
195
			JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
196
			jg.writeStartObject();
197
			//it should never happen to get PE1_Service as a specific type -- it happened in Parthenos top level entities
198
			String specificType = resourceReader.findSpecificType(res, CRMpe.PE1_Service).getLocalName();
199
			writeCommon(res, specificType, jg, uuid);
200
			//******THE FACETS *******//
201
			jg.writeArrayFieldStart("consistsOf");
202
			//list of facets
203
			writeCommonFacets(res, jg);
204
			facetWriter.writeEventFacet(jg);
205
			facetWriter.writeRightsFacet(jg, res);
206
			if (res.hasProperty(CRMpe.PP2_provided_by)) {
207
				//TODO: shouldn't this be a rel to an actor?
208
				Resource provider = res.getPropertyResourceValue(CRMpe.PP2_provided_by);
209
				facetWriter.writeContactReferenceFacet(jg, provider);
210
			}
211
			facetWriter.writeDesignatedAccessPointFacet(jg, res);
212
			jg.writeEndArray();
213
			jg.writeEndObject();
214
			jg.close();
215
			String json = out.toString("UTF-8");
216
			log.debug(json);
217
			return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid);
218

  
219
		}
220
		else{
221
			log.warn(String.format("Skipping resource: %s It is not an instance of a specific service"));
222
			return null;
223
		}
224
	}
225

  
226
	protected ParthenosRegistryResource processProject(final Resource res, final JsonFactory jsonFactory, final String uuid) throws IOException {
227
		String specificType = resourceReader.findSpecificType(res, CRMpe.PE35_Project).getLocalName();
228
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
229
		BufferedOutputStream bos = new BufferedOutputStream(out);
230
		JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
231
		jg.writeStartObject();
232

  
233
		writeCommon(res, specificType, jg, uuid);
234
		jg.writeArrayFieldStart("consistsOf");
235
		writeCommonFacets(res, jg);
236

  
237
		jg.writeEndArray();
238
		jg.writeEndObject();
239
		jg.close();
240
		String json = out.toString("UTF-8");
241
		log.debug(json);
242
		return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid);
243
	}
244

  
245
	protected ParthenosRegistryResource processActor(final Resource res, final JsonFactory jsonFactory, final String uuid) throws IOException {
246
		String specificType = resourceReader.findSpecificType(res, CRM.E39_Actor).getLocalName();
247
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
248
		BufferedOutputStream bos = new BufferedOutputStream(out);
249
		JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
250
		jg.writeStartObject();
251

  
252
		writeCommon(res, specificType, jg, uuid);
253
		//******THE FACETS *******//
254
		jg.writeArrayFieldStart("consistsOf");
255
		//list of facets
256
		writeCommonFacets(res, jg);
257
		facetWriter.writeContactReferenceFacet(jg, res);
258

  
259
		jg.writeEndArray();
260
		jg.writeEndObject();
261
		jg.close();
262
		String json = out.toString("UTF-8");
263
		log.debug(json);
264
		return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid);
265
	}
266

  
267
	protected ParthenosRegistryResource processDigitalObject(final Resource res, final JsonFactory jsonFactory, final String uuid) throws IOException {
268
		String specificType = resourceReader.findSpecificType(res, CRMdig.D1_Digital_Object).getLocalName();
269
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
270
		BufferedOutputStream bos = new BufferedOutputStream(out);
271
		JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
272
		jg.writeStartObject();
273

  
274
		writeCommon(res, specificType, jg, uuid);
275
		//******THE FACETS *******//
276
		jg.writeArrayFieldStart("consistsOf");
277
		//list of facets
278
		writeCommonFacets(res, jg);
279
		facetWriter.writeTemporalCoverageFacet(jg, res);
280
		facetWriter.writeRightsFacet(jg, res);
281

  
282
		jg.writeEndArray();
283
		jg.writeEndObject();
284
		jg.close();
285
		String json = out.toString("UTF-8");
286
		log.debug(json);
287
		return new ParthenosRegistryResource().setUuid(uuid).setType(specificType).setJson(json);
288
	}
289

  
290
	protected ParthenosRegistryResource processBasicResource(final Resource res, final Resource basicType, final JsonFactory jsonFactory, final String uuid) throws IOException {
291
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
292
		BufferedOutputStream bos = new BufferedOutputStream(out);
293
		JsonGenerator jg = jsonFactory.createGenerator(bos, JsonEncoding.UTF8);
294
		jg.writeStartObject();
295
		String specificType = resourceReader.findSpecificType(res, basicType).getLocalName();
296
		writeCommon(res, specificType, jg, uuid);
297
		//******THE FACETS *******//
298
		jg.writeArrayFieldStart("consistsOf");
299
		writeCommonFacets(res, jg);
300
		jg.writeEndArray();
301
		jg.writeEndObject();
302
		jg.close();
303
		String json = out.toString("UTF-8");
304
		log.debug(json);
305
		return new ParthenosRegistryResource().setJson(json).setType(specificType).setUuid(uuid);
306
	}
307

  
308
	protected List<ParthenosRegistryRel> getResourceRels(final Resource resource, final ParthenosRegistryResource prr) throws IOException, ResourceRegistryException,
309
			InvalidQueryException, ParthenosPublisherException {
310
		JsonFactory jsonFactory = new JsonFactory();
311
		List<ParthenosRegistryRel> jsonRels = Lists.newArrayList();
312

  
313
		if(resource.hasProperty(RDF.type, CRMpe.PE1_Service)) {
314
			jsonRels.addAll(getRels(resource, prr, CRM.P129_is_about, jsonFactory));
315
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP2_provided_by, jsonFactory));
316
			//TODO: IsRelatedTo the contact person of the provider. Interpret '"Follow path of service ‘Provided by’ and switch E39 for E21: E21- >p76->E51"
317
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP45_has_competency, jsonFactory));
318
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP4_hosts_object, jsonFactory));
319
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP31_uses_curation_plan, jsonFactory));
320
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP32_curates, jsonFactory));
321
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP6_hosts_digital_object, jsonFactory));
322
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP7_hosts_software_object, jsonFactory));
323
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP8_hosts_dataset, jsonFactory));
324
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP29_uses_access_protocol, jsonFactory));
325
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP47_has_protocol_type, jsonFactory));
326
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP46_brokers_access_to, jsonFactory));
327
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP11_curates_volatile_digital_object, jsonFactory));
328
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP12_curates_volatile_software, jsonFactory));
329
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP13_curates_volatile_dataset, jsonFactory));
330
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP15_delivers_on_request, jsonFactory));
331
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP45_has_competency, jsonFactory));
332
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP1i_is_currently_offered_by, CRMpe.PP1_currently_offers, jsonFactory));
333
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP46i_has_access_brokered_by, CRMpe.PP46_brokers_access_to, jsonFactory));
334
		}
335
		if(resource.hasProperty(RDF.type, CRMdig.D1_Digital_Object)){
336
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP6i_is_digital_object_hosted_by, CRMpe.PP6_hosts_digital_object, jsonFactory));
337
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP18i_is_digital_object_part_of, CRMpe.PP18_has_digital_object_part, jsonFactory));
338
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP39i_has_metadata, CRMpe.PP39_is_metadata_for, jsonFactory));
339
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP41i_is_indexed_by, CRMpe.PP41_is_index_of, jsonFactory));
340
		}
341
		if(resource.hasProperty(RDF.type, CRMpe.PE18_Dataset)) {
342
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP23i_is_dataset_part_of, CRMpe.PP23_has_dataset_part, jsonFactory));
343
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP8i_is_dataset_hosted_by, CRMpe.PP8_hosts_dataset, jsonFactory));
344
		}
345
		if(resource.hasProperty(RDF.type, CRMdig.D14_Software)) {
346
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP14i_is_run_by, CRMpe.PP14_runs_on_request, jsonFactory));
347
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP15i_is_delivered_by, CRMpe.PP15_delivers_on_request, jsonFactory));
348
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP21i_is_software_part_of, CRMpe.PP21_has_software_part, jsonFactory));
349
			//TODO: is this correct? Service --> uses access protocol --> Software ?
350
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP29i_is_access_protocol_used_by, CRMpe.PP29_uses_access_protocol, jsonFactory));
351
		}
352
		if(resource.hasProperty(RDF.type, CRMpe.PE19_Persistent_Digital_Object)) {
353
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP16_has_persistent_digital_object_part, jsonFactory));
354
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP16i_is_persistent_digital_object_part_of, CRMpe.PP16_has_persistent_digital_object_part, jsonFactory));
355
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP17i_is_snapshot_of, CRMpe.PP17_has_snapshot, jsonFactory));
356
		}
357
		if(resource.hasProperty(RDF.type, CRMpe.PE20_Volatile_Digital_Object)) {
358
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP17_has_snapshot, jsonFactory));
359
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP18_has_digital_object_part, jsonFactory));
360
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP11i_is_volatile_digital_object_curated_by, CRMpe.PP11_curates_volatile_digital_object, jsonFactory));
361
		}
362
		if(resource.hasProperty(RDF.type, CRMpe.PE21_Persistent_Software)) {
363
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP19_has_persistent_software_part, jsonFactory));
364
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP19i_is_persistent_software_part_of, CRMpe.PP19_has_persistent_software_part, jsonFactory));
365
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP22i_is_release_of, CRMpe.PP22_has_release, jsonFactory));
366
		}
367
		if(resource.hasProperty(RDF.type, CRMpe.PE22_Persistent_Dataset)) {
368
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP20_has_persistent_dataset_part, jsonFactory));
369
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP39_is_metadata_for, jsonFactory));
370
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP20i_is_persistent_dataset_part_of, CRMpe.PP20_has_persistent_dataset_part, jsonFactory));
371
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP24i_is_dataset_snapshot_of, CRMpe.PP24_has_dataset_snapshot, jsonFactory));
372
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP40i_is_deprecated_by, CRMpe.PP40_created_successor_of, jsonFactory));
373
		}
374
		if(resource.hasProperty(RDF.type, CRMpe.PE23_Volatile_Software)) {
375
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP21_has_software_part, jsonFactory));
376
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP22_has_release, jsonFactory));
377
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP12i_is_volatile_software_curated_by, CRMpe.PP12_curates_volatile_software, jsonFactory));
378
		}
379
		if(resource.hasProperty(RDF.type, CRMpe.PE24_Volatile_Dataset)) {
380
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP23_has_dataset_part, jsonFactory));
381
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP24_has_dataset_snapshot, jsonFactory));
382
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP41_is_index_of, jsonFactory));
383
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP13i_is_volatile_dataset_curated_by, CRMpe.PP13_curates_volatile_dataset, jsonFactory));
384
		}
385
		if(resource.hasProperty(RDF.type, CRMpe.PE26_RI_Project)) {
386
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP25_has_maintaining_RI, jsonFactory));
387
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP1_currently_offers, jsonFactory));
388
		}
389
		if(resource.hasProperty(RDF.type, CRMpe.PE35_Project)) {
390
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP43_supported_project_activity, jsonFactory));
391
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP44_has_maintaining_team, jsonFactory));
392
		}
393
		if(resource.hasProperty(RDF.type, CRM.E39_Actor)) {
394
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP2i_provides, CRMpe.PP2_provided_by, jsonFactory));
395
		}
396
		if(resource.hasProperty(RDF.type, CRMpe.PE34_Team)) {
397
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP44i_is_maintaining_team_of, CRMpe.PP44_has_maintaining_team, jsonFactory));
398
		}
399
		if(resource.hasProperty(RDF.type, CRM.E70_Thing)) {
400
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP4i_is_object_hosted_by, CRMpe.PP4_hosts_object, jsonFactory));
401
		}
402
		if(resource.hasProperty(RDF.type, CRMpe.PE25_RI_Consortium)) {
403
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP25i_is_maintaining_RI_of, CRMpe.PP25_has_maintaining_RI, jsonFactory));
404
		}
405
		if(resource.hasProperty(RDF.type, CRMpe.PE28_Curation_Plan)) {
406
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP31i_is_curation_plan_used_by, CRMpe.PP31_uses_curation_plan, jsonFactory));
407
		}
408
		if(resource.hasProperty(RDF.type, CRMpe.PE32_Curated_Thing)) {
409
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP32i_is_curated_by, CRMpe.PP32_curates, jsonFactory));
410
		}
411
		if(resource.hasProperty(RDF.type, CRM.E65_Creation)) {
412
			jsonRels.addAll(getRels(resource, prr, CRMpe.PP40_created_successor_of, jsonFactory));
413
		}
414
		if(resource.hasProperty(RDF.type, CRM.E7_Activity)) {
415
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP43i_is_project_activity_supported_by, CRMpe.PP43_supported_project_activity, jsonFactory));
416
		}
417
		if(resource.hasProperty(RDF.type, CRMpe.PE36_Competency_Type)) {
418
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP45i_is_competency_of, CRMpe.PP45_has_competency, jsonFactory));
419
		}
420
		if(resource.hasProperty(RDF.type, CRMpe.PE37_Protocol_Type)) {
421
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP47i_is_protocol_type_of, CRMpe.PP47_has_protocol_type, jsonFactory));
422
		}
423
		if(resource.hasProperty(RDF.type, CRMpe.PE38_Schema)) {
424
			jsonRels.addAll(getInverseRels(resource, prr, CRMpe.PP47i_is_protocol_type_of, CRMpe.PP47_has_protocol_type, jsonFactory));
425
		}
426
		return jsonRels;
427
	}
428

  
429
	protected List<ParthenosRegistryRel> getRels(final Resource subject, final ParthenosRegistryResource subjectPrr, final Property rel, final JsonFactory jsonFactory) throws IOException, InvalidQueryException, ParthenosPublisherException, ResourceRegistryException {
430
		List<ParthenosRegistryRel> rels = Lists.newArrayList();
431
		StmtIterator it = subject.listProperties(rel);
432
		while (it.hasNext()) {
433
			Resource obj = it.nextStatement().getResource();
434
			if (obj == null) throw new ParthenosPublisherException(String.format("No target resource available for %s --> %s", subject.getURI(), rel.getURI()));
435
			ParthenosRegistryResource target = findInRegistry(obj.getURI());
436
			if(target == null){
437
				log.debug(String.format("Rel: %s - %s - %s: target is not yet registered", subject.getURI(), rel.getLocalName(), obj.getURI()));
438
			}
439
			else{
440
				rels.add(getRel(subjectPrr, rel, target, jsonFactory));
441
			}
442
		}
443
		return rels;
444
	}
445

  
446
	protected ParthenosRegistryRel getRel(final ParthenosRegistryResource subjectPrr, final Property rel, final ParthenosRegistryResource targetPrr, final JsonFactory jsonFactory ) throws IOException {
447
		String relJson = relWriter.writeRelationship(jsonFactory, rel.getLocalName(), subjectPrr.getUuid(), subjectPrr.getRegistryType(), targetPrr.getUuid(), targetPrr.getRegistryType());
448
		return new ParthenosRegistryRel().json(relJson).relName(rel.getLocalName());
449
	}
450

  
451
	protected List<ParthenosRegistryRel> getInverseRels(final Resource resource, final ParthenosRegistryResource resourcePRR, final Property rel, final Property inverseRel, final JsonFactory jsonFactory) throws IOException, InvalidQueryException, ResourceRegistryException {
452
		List<ParthenosRegistryRel> rels = Lists.newArrayList();
453
		StmtIterator it = resource.listProperties(rel);
454
		while (it.hasNext()) {
455
			Resource obj = it.nextStatement().getResource();
456
			String objURI = obj.getURI();
457
			ParthenosRegistryResource registryRes = findInRegistry(objURI);
458
			if (registryRes != null) {
459
				rels.add(getRel(registryRes, inverseRel, resourcePRR, jsonFactory));
460
			}
461
		}
462
		return rels;
463
	}
464

  
465
	/**
466
	 * Write the common properties: header, class for all resources
467
	 *
468
	 * @param resource  input Resource.
469
	 * @param className name of the class for the registry
470
	 * @param jg        JsonGenerator to write with.
471
	 * @param uuid      uuid of the resource
472
	 */
473
	protected void writeCommon(final Resource resource, final String className, final JsonGenerator jg, final String uuid)
474
			throws IOException {
475
		jg.writeObjectFieldStart("header");
476
		jg.writeStringField("uuid", uuid);
477
		jg.writeEndObject();
478
		jg.writeStringField("@class", StringUtils.remove(className, '-'));
479
	}
480

  
481
	/**
482
	 * Write the common facets: identifier and info facets
483
	 *
484
	 * @param res
485
	 * @param jg
486
	 */
487
	protected void writeCommonFacets(final Resource res, final JsonGenerator jg) throws IOException {
488
		facetWriter.writeIdentifierFacet(jg, res.getURI());
489
		facetWriter.writeP1Facets(jg, res);
490
		facetWriter.writeInfoFacet(jg, res);
491
	}
492

  
493
	public ParthenosRegistryResource findInRegistry(final String uri) throws ResourceRegistryException {
494
		Map<String, Object> queryMap = Maps.newHashMap();
495
		queryMap.put("value", uri);
496
		List<org.gcube.informationsystem.model.reference.entity.Resource> resources = resourceRegistryClient.getFilteredResources(
497
				org.gcube.informationsystem.model.reference.entity.Resource.class, IsIdentifiedBy.class, IdentifierFacet.class, true, queryMap);
498
		if(resources.isEmpty()) return null;
499
		org.gcube.informationsystem.model.reference.entity.Resource resource = resources.get(0);
500
		if(resources.size() > 1){
501
			log.warn("More than one resource in registry with uri "+uri+" -- considering the first, with uuid: "+resource.getHeader().getUUID());
502
		}
503
		//build PRR from res, need to have type and uuid
504
		//TODO: check the type is what we want
505
		ParthenosRegistryResource prr = new ParthenosRegistryResource().setUuid(resource.getHeader().getUUID().toString()).setType(resource.getClass().getSimpleName());
506
		log.debug(prr.toString());
507
		return prr;
508
	}
509

  
510

  
511
	public FacetWriter getFacetWriter() {
512
		return facetWriter;
513
	}
514

  
515
	public void setFacetWriter(final FacetWriter facetWriter) {
516
		this.facetWriter = facetWriter;
517
	}
518

  
519
	public String getApplicationToken() {
520
		return applicationToken;
521
	}
522

  
523
	public void setApplicationToken(final String applicationToken) {
524
		this.applicationToken = applicationToken;
525
	}
526

  
527
	public String getRegistryBaseURL() {
528
		return registryBaseURL;
529
	}
530

  
531
	public void setRegistryBaseURL(final String registryBaseURL) {
532
		this.registryBaseURL = registryBaseURL;
533
	}
534

  
535
	public RelWriter getRelWriter() {
536
		return relWriter;
537
	}
538

  
539
	public void setRelWriter(final RelWriter relWriter) {
540
		this.relWriter = relWriter;
541
	}
542

  
543
	public ResourceRegistryPublisher getResourceRegistryPublisher() {
544
		return resourceRegistryPublisher;
545
	}
546

  
547
	public void setResourceRegistryPublisher(final ResourceRegistryPublisher resourceRegistryPublisher) {
548
		this.resourceRegistryPublisher = resourceRegistryPublisher;
549
	}
550

  
551
	public ResourceRegistryClient getResourceRegistryClient() {
552
		return resourceRegistryClient;
553
	}
554

  
555
	public void setResourceRegistryClient(final ResourceRegistryClient resourceRegistryClient) {
556
		this.resourceRegistryClient = resourceRegistryClient;
557
	}
558

  
559
	public ResourceReader getResourceReader() {
560
		return resourceReader;
561
	}
562

  
563
	public void setResourceReader(final ResourceReader resourceReader) {
564
		this.resourceReader = resourceReader;
565
	}
566
}
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/catalogue/CatalogueRegistratorIntegrationTest.java
15 15
import org.apache.jena.rdf.model.Resource;
16 16
import org.apache.jena.vocabulary.RDF;
17 17
import org.junit.Before;
18
import org.junit.Ignore;
18 19
import org.junit.Test;
19 20
import org.junit.runner.RunWith;
20 21
import org.springframework.beans.factory.annotation.Autowired;
......
33 34
@SpringBootTest
34 35
@TestPropertySource(
35 36
		locations = "classpath:application-integrationtest.properties")
37
@Ignore
36 38
public class CatalogueRegistratorIntegrationTest {
37 39

  
38 40
	private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
......
65 67
	}
66 68

  
67 69
	@Test
68
	public void testError500_1() throws Exception{
70
	public void testError500_1() throws Exception {
69 71
		InfModel model = loadBaseModel();
70 72
		model.read(getStream(error500_1), CRMpe.NS);
71 73
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E29_Design_or_Procedure);
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoClientTest.java
11 11
import org.apache.commons.logging.LogFactory;
12 12
import org.junit.Assert;
13 13
import org.junit.Before;
14
import org.junit.Ignore;
14 15
import org.junit.Test;
15 16
import org.junit.runner.RunWith;
16 17
import org.junit.runners.JUnit4;
......
22 23
 *
23 24
 * @author Alessia Bardi
24 25
 */
25
//@Ignore
26
@Ignore
26 27
@RunWith(JUnit4.class)
27 28
public class VirtuosoClientTest {
28 29

  
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherTest.java
37 37
		classes = ParthenosPublisherApplication.class)
38 38
@AutoConfigureMockMvc
39 39
@TestPropertySource(locations = "classpath:application-integrationtest.properties")
40
//Ignore test because ot requires a running virtuoso server
40
//Ignore test because it requires a running virtuoso server
41 41
@Ignore
42 42
public class ParthenosPublisherTest {
43 43

  
modules/dnet-parthenos-publisher/trunk/test/main/resources/application-integrationtest.properties
17 17
gcube.registry.application.token = ff70d166-dc6b-468e-9a2d-81c91a796a40-843339462
18 18

  
19 19
#gcube.catalogue.baseurl = https://catalogue-ws-t.pre.d4science.org/catalogue-ws/
20
gcube.catalogue.baseurl = https://catalogue-ws.d4science.org/catalogue-ws/
20
#gcube.catalogue.baseurl = https://catalogue-ws.d4science.org/catalogue-ws/
21 21

  
22
gcube.uri.resolver=https://data1-p.d4science.org/parthenos_registry
22
#gcube.uri.resolver=https://data1-p.d4science.org/parthenos_registry
23

  
24
gcube.catalogue.baseurl = https://gcat.d4science.org/gcat/
25
gcube.uri.resolver = https://data.d4science.org/parthenos_registry/
modules/dnet-parthenos-publisher/trunk/dnet-parthenos-publisher.iml
28 28
      <sourceFolder url="file://$MODULE_DIR$/test/main/resources" type="java-test-resource" />
29 29
      <excludeFolder url="file://$MODULE_DIR$/target" />
30 30
    </content>
31
    <orderEntry type="inheritedJdk" />
31
    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
32 32
    <orderEntry type="sourceFolder" forTests="false" />
33 33
    <orderEntry type="library" name="Maven: net.sf.saxon:Saxon-HE:9.5.1-5" level="project" />
34 34
    <orderEntry type="library" name="Maven: virtuoso:jena-driver:3.0" level="project" />
35 35
    <orderEntry type="library" name="Maven: openlink:virtuoso-jdbc:4.0" level="project" />
36
    <orderEntry type="library" name="Maven: org.apache.jena:jena-arq:3.9.0" level="project" />
37
    <orderEntry type="library" name="Maven: org.apache.jena:jena-shaded-guava:3.9.0" level="project" />
38
    <orderEntry type="library" name="Maven: com.github.jsonld-java:jsonld-java:0.12.1" level="project" />
36
    <orderEntry type="library" name="Maven: org.apache.jena:jena-arq:3.11.0" level="project" />
37
    <orderEntry type="library" name="Maven: org.apache.jena:jena-shaded-guava:3.11.0" level="project" />
38
    <orderEntry type="library" name="Maven: com.github.jsonld-java:jsonld-java:0.12.3" level="project" />
39
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9" level="project" />
39 40
    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient-cache:4.5.5" level="project" />
40
    <orderEntry type="library" name="Maven: org.apache.thrift:libthrift:0.10.0" level="project" />
41
    <orderEntry type="library" name="Maven: org.apache.thrift:libthrift:0.12.0" level="project" />
41 42
    <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
42
    <orderEntry type="library" name="Maven: org.apache.jena:jena-core:3.9.0" level="project" />
43
    <orderEntry type="library" name="Maven: org.apache.jena:jena-iri:3.9.0" level="project" />
43
    <orderEntry type="library" name="Maven: org.apache.jena:jena-core:3.11.0" level="project" />
44
    <orderEntry type="library" name="Maven: org.apache.jena:jena-iri:3.11.0" level="project" />
44 45
    <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
45 46
    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
46
    <orderEntry type="library" name="Maven: org.apache.jena:jena-base:3.9.0" level="project" />
47
    <orderEntry type="library" name="Maven: org.apache.jena:jena-base:3.11.0" level="project" />
47 48
    <orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.5" level="project" />
48
    <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.17" level="project" />
49
    <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.18" level="project" />
49 50
    <orderEntry type="library" name="Maven: com.github.andrewoma.dexx:collection:0.7" level="project" />
50
    <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb:3.9.0" level="project" />
51
    <orderEntry type="library" name="Maven: org.apache.jena:jena-rdfconnection:3.9.0" level="project" />
52
    <orderEntry type="library" name="Maven: org.apache.jena:jena-cmds:3.9.0" level="project" />
53
    <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb2:3.9.0" level="project" />
54
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-trans-data:3.9.0" level="project" />
55
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-transaction:3.9.0" level="project" />
56
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-base:3.9.0" level="project" />
57
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-index:3.9.0" level="project" />
51
    <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb:3.11.0" level="project" />
52
    <orderEntry type="library" name="Maven: org.apache.jena:jena-rdfconnection:3.11.0" level="project" />
53
    <orderEntry type="library" name="Maven: org.apache.jena:jena-cmds:3.11.0" level="project" />
54
    <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb2:3.11.0" level="project" />
55
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-trans-data:3.11.0" level="project" />
56
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-transaction:3.11.0" level="project" />
57
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-base:3.11.0" level="project" />
58
    <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-index:3.11.0" level="project" />
58 59
    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
59 60
    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
60 61
    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.5.6.RELEASE" level="project" />
......
97 98
    <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.1.Final" level="project" />
98 99
    <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" />
99 100
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.9" level="project" />
101
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
100 102
    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.10.RELEASE" level="project" />
101 103
    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.10.RELEASE" level="project" />
102 104
    <orderEntry type="library" name="Maven: org.apache.solr:solr-solrj:5.5.5" level="project" />
......
109 111
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.1" level="project" />
110 112
    <orderEntry type="library" name="Maven: org.noggit:noggit:0.6" level="project" />
111 113
    <orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
112
    <orderEntry type="library" name="Maven: org.gcube.information-system:parthenos-entities:1.0.0-SNAPSHOT" level="project" />
113
    <orderEntry type="library" name="Maven: org.gcube.information-system:information-system-model:2.1.0-SNAPSHOT" level="project" />
114
    <orderEntry type="library" name="Maven: org.gcube.resource-management:gcube-model:1.1.0-SNAPSHOT" level="project" />
115
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
116
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9" level="project" />
117
    <orderEntry type="library" name="Maven: org.gcube.information-system:resource-registry-publisher:2.0.1-SNAPSHOT" level="project" />
118
    <orderEntry type="library" name="Maven: org.gcube.common:authorization-client:2.0.3-SNAPSHOT" level="project" />
119
    <orderEntry type="library" name="Maven: org.gcube.common:common-authorization:2.1.3-SNAPSHOT" level="project" />
120
    <orderEntry type="library" name="Maven: org.gcube.core:common-configuration-scanner:1.1.0-SNAPSHOT" level="project" />
121
    <orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.8.10" level="project" />
122
    <orderEntry type="library" name="Maven: org.gcube.resources.discovery:ic-client:1.0.4-4.13.0-162683" level="project" />
123
    <orderEntry type="library" name="Maven: org.gcube.core:common-scope:1.2.0-4.13.0-125717" level="project" />
124
    <orderEntry type="library" name="Maven: org.gcube.core:common-scope-maps:1.0.9-4.13.0-171240" level="project" />
125
    <orderEntry type="library" name="Maven: org.gcube.resources.discovery:discovery-client:1.0.1-4.13.0-125857" level="project" />
126
    <orderEntry type="library" name="Maven: org.gcube.resources:common-gcore-resources:1.3.4-4.13.0-162605" level="project" />
127
    <orderEntry type="library" name="Maven: org.gcube.core:common-gcore-stubs:1.2.2-4.13.0-132342" level="project" />
128
    <orderEntry type="library" name="Maven: org.gcube.information-system:resource-registry-client:2.0.1-SNAPSHOT" level="project" />
129
    <orderEntry type="library" name="Maven: org.gcube.information-system:resource-registry-api:2.0.1-SNAPSHOT" level="project" />
130 114
    <orderEntry type="library" name="Maven: com.google.guava:guava:23.3-jre" level="project" />
131 115
    <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
132 116
    <orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueLicense.java
30 30

  
31 31
	public static CatalogueLicense getCatalogueLicenseFor(final String license){
32 32
		//TODO: get the best from the data we have, if we are able to clean the string, this method wil be much simpler...
33
		//TODO: not specified is not a valid value for the new gcat API and requesting the list of licensing fails, ask Luca.
33 34
		if(StringUtils.isBlank(license)) return NotSpecified;
34 35
		if(license.equalsIgnoreCase("CC") || license.equalsIgnoreCase("Free/ CC") || license.equalsIgnoreCase("Creative Commons CC0 1.0 Universal Public Domain Dedication")) return CC0;
35 36
		if(license.equalsIgnoreCase("CC-BY") || license.equalsIgnoreCase("CC BY")) return CCBY;
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueAPIClient.java
4 4
import java.net.URI;
5 5
import java.net.URISyntaxException;
6 6

  
7
import com.google.common.collect.Lists;
7 8
import eu.dnetlib.parthenos.jrr.ParthenosRegistryResource;
8 9
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
9 10
import org.apache.commons.logging.Log;
......
27 28

  
28 29
	@Value("${gcube.catalogue.baseurl}")
29 30
	private String baseURL;
31
	private final String itemPath = "items/";
30 32
	@Value("${gcube.registry.application.token}")
31 33
	private String applicationToken;
32 34
	@Value("${gcube.uri.resolver}")
33 35
	private String uriResolver;
34 36
	private String resolverBodyTemplate = "{ \"entity_name\": \"%s\" }";
37
	private String purgeBodyTemplate = "{\"id\":\"%s\"}";
35 38

  
36
	private final String createItemPath = "rest/api/items/create";
37
	private final String updateItemPath = "rest/api/items/update";
38
	private final String showItemPath = "rest/api/items/show"; //param id
39
	private final String purgeItemPath = "rest/api/items/purge";
39
	private HttpHeaders headersForResolver;
40
	private HttpHeaders headersForCatalogue;
40 41

  
41
	//private final String showGroupPath = "rest/api/groups/show"; //param id
42
	//private final String createGroupPath = "rest/api/groups/create";
43
	//private final String purgeGroupPath = "rest/api/groups/purge";
44
	private String purgeBodyTemplate = "{\"id\":\"%s\"}";
45

  
46 42
	@Autowired
47
	private RestTemplate jrrRestTemplate;
43
	private RestTemplate restTemplate;
48 44

  
45
	public CatalogueAPIClient(){
46
		headersForResolver = new HttpHeaders();
47
		headersForResolver.setContentType(MediaType.APPLICATION_JSON);
48

  
49
		headersForCatalogue = new HttpHeaders();
50
		headersForCatalogue.setContentType(MediaType.APPLICATION_JSON);
51
		headersForCatalogue.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));
52
		headersForCatalogue.set("gcube-token", getApplicationToken());
53
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff