Project

General

Profile

« Previous | Next » 

Revision 51479

Removed deprecated classes

View differences:

modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueClient.java
1
package eu.dnetlib.parthenos.catalogue;
2

  
3
import java.io.IOException;
4

  
5
import eu.dnetlib.parthenos.jrr.JRRClient;
6
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
7
import eu.dnetlib.parthenos.publisher.SaxonHelper;
8

  
9
/**
10
 * Created by Alessia Bardi on 21/11/2017.
11
 *
12
 * @author Alessia Bardi
13
 */
14
@Deprecated
15
public class CatalogueClient extends JRRClient{
16

  
17
	private CatalogueRegistrator catalogueRegistrator;
18

  
19
	@Override
20
	protected void doRegister(final String recordRDF, final String objIdentifier) throws IOException, ParthenosPublisherException {
21
		//this.catalogueRegistrator.register(recordRDF, objIdentifier);
22
	}
23

  
24
	public CatalogueClient(final SaxonHelper saxonHelper, final CatalogueRegistrator catalogueRegistrator ) throws ParthenosPublisherException {
25
		super(saxonHelper);
26
		this.catalogueRegistrator = catalogueRegistrator;
27
	}
28

  
29
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueClientFactory.java
1
package eu.dnetlib.parthenos.catalogue;
2

  
3
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
4
import eu.dnetlib.parthenos.publisher.SaxonHelper;
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.stereotype.Component;
10

  
11
/**
12
 * Created by Alessia Bardi on 26/09/2017.
13
 *
14
 * @author Alessia Bardi
15
 */
16
@Component
17
@Deprecated
18
public class CatalogueClientFactory {
19

  
20
	private static final Log log = LogFactory.getLog(CatalogueClientFactory.class);
21

  
22
	@Value("${gcube.catalogue.baseurl}")
23
	private String baseURL;
24
	@Value("${gcube.registry.application.token}")
25
	private String gcubeToken;
26
	@Autowired
27
	private SaxonHelper saxonHelper;
28
	@Autowired
29
	private CatalogueRegistrator catalogueRegistrator;
30

  
31

  
32

  
33
	public CatalogueClient getCatalogueClient() throws ParthenosPublisherException {
34
		log.debug("Creating CatalogueClient");
35
		return new CatalogueClient(saxonHelper, catalogueRegistrator);
36
	}
37

  
38
	public String getBaseURL() {
39
		return baseURL;
40
	}
41

  
42
	public void setBaseURL(final String baseURL) {
43
		this.baseURL = baseURL;
44
	}
45

  
46
	public String getGcubeToken() {
47
		return gcubeToken;
48
	}
49

  
50
	public void setGcubeToken(final String gcubeToken) {
51
		this.gcubeToken = gcubeToken;
52
	}
53

  
54
	public SaxonHelper getSaxonHelper() {
55
		return saxonHelper;
56
	}
57

  
58
	public void setSaxonHelper(final SaxonHelper saxonHelper) {
59
		this.saxonHelper = saxonHelper;
60
	}
61
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueAPIClient.java
42 42
	private RestTemplate jrrRestTemplate;
43 43

  
44 44
	public ParthenosRegistryResource getRegistered(final String resCatName) throws ParthenosPublisherException {
45
		log.debug(String.format("Catalogue --> Checking if %s exists", resCatName));
45
		log.debug(String.format("Catalogue --> Checking if item %s exists", resCatName));
46 46
		HttpEntity<String> entity = new HttpEntity<String>(getHeaders());
47 47
		try {
48 48
			URI uri = new URIBuilder(getBaseURL()+showItemPath).addParameter("gcube-token", getApplicationToken()).addParameter("id", resCatName).build();
......
70 70
	 * @throws ParthenosPublisherException
71 71
	 */
72 72
	public String doRegister(final String json, final String resCatName) throws URISyntaxException, IOException {
73
		log.debug(String.format("Catalogue --> Registering %s : %s", resCatName, json));
73
		log.debug(String.format("Catalogue --> Registering item %s : %s", resCatName, json));
74 74
		HttpEntity<String> entity = new HttpEntity<String>(json, getHeaders());
75 75
		URI uri = new URIBuilder(getBaseURL() + createItemPath).addParameter("gcube-token", getApplicationToken()).build();
76 76
		ResponseEntity<String> res = jrrRestTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
......
91 91
	}
92 92

  
93 93
	public boolean groupExist(final String groupName) throws ParthenosPublisherException {
94
		log.debug(String.format("Catalogue --> Checking if %s exists", groupName));
95
		HttpEntity<String> entity = new HttpEntity<String>(getHeaders());
94
		log.debug(String.format("Catalogue --> Checking if group %s exists", groupName));
95
		HttpEntity<String> entity = new HttpEntity<>(getHeaders());
96 96
		try {
97 97
			URI uri = new URIBuilder(getBaseURL()+showGroupPath).addParameter("gcube-token", getApplicationToken()).addParameter("id", groupName).build();
98 98
			ResponseEntity<String> res = jrrRestTemplate.<String>exchange(uri, HttpMethod.GET, entity, String.class);
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RegistryClientFactory.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
4
import eu.dnetlib.parthenos.publisher.SaxonHelper;
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.stereotype.Component;
10

  
11
/**
12
 * Created by Alessia Bardi on 26/09/2017.
13
 *
14
 * @author Alessia Bardi
15
 */
16
@Component
17
@Deprecated
18
public class RegistryClientFactory {
19

  
20
	private static final Log log = LogFactory.getLog(RegistryClientFactory.class);
21

  
22
	@Value("${gcube.registry.uri.base.default}")
23
	private String defaultBaseURI;
24

  
25
	@Autowired
26
	private SaxonHelper saxonHelper;
27
	@Autowired
28
	private GCubeResourceRegistrator gCubeResourceRegistrator;
29

  
30
	public RegistryClient getRegistryClient() throws ParthenosPublisherException {
31
		log.debug("Creating RegistryClient");
32
		return new RegistryClient(getSaxonHelper(), defaultBaseURI, getgCubeResourceRegistrator());
33
	}
34

  
35
	public SaxonHelper getSaxonHelper() {
36
		return saxonHelper;
37
	}
38

  
39
	public void setSaxonHelper(final SaxonHelper saxonHelper) {
40
		this.saxonHelper = saxonHelper;
41
	}
42

  
43
	public String getDefaultBaseURI() {
44
		return defaultBaseURI;
45
	}
46

  
47
	public void setDefaultBaseURI(final String defaultBaseURI) {
48
		this.defaultBaseURI = defaultBaseURI;
49
	}
50

  
51
	public GCubeResourceRegistrator getgCubeResourceRegistrator() {
52
		return gCubeResourceRegistrator;
53
	}
54

  
55
	public void setgCubeResourceRegistrator(final GCubeResourceRegistrator gCubeResourceRegistrator) {
56
		this.gCubeResourceRegistrator = gCubeResourceRegistrator;
57
	}
58
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RegistryClient.java
1
package eu.dnetlib.parthenos.registry;
2

  
3
import java.io.IOException;
4

  
5
import eu.dnetlib.parthenos.jrr.JRRClient;
6
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
7
import eu.dnetlib.parthenos.publisher.SaxonHelper;
8
import net.sf.saxon.s9api.SaxonApiException;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
12
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
13
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
14
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
15

  
16
/**
17
 * Created by Alessia Bardi on 26/09/2017.
18
 *
19
 * @author Alessia Bardi
20
 */
21
@Deprecated
22
public class RegistryClient extends JRRClient{
23

  
24
	private static final Log log = LogFactory.getLog(RegistryClient.class);
25

  
26
	private GCubeResourceRegistrator gCubeResourceRegistrator;
27
	private ResourceRegistryPublisher resourceRegistryPublisher;
28
	private ResourceRegistryClient resourceRegistryClient;
29
	private String defaultBaseURI;
30

  
31
	protected RegistryClient(final SaxonHelper saxonHelper,
32
			final String defaultBaseURI,
33
			final GCubeResourceRegistrator gCubeResourceRegistrator)
34
			throws ParthenosPublisherException {
35
		super(saxonHelper);
36
		this.defaultBaseURI = defaultBaseURI;
37
		this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
38
		this.resourceRegistryClient = ResourceRegistryClientFactory.create();
39
		this.gCubeResourceRegistrator = gCubeResourceRegistrator;
40
		try {
41
			prepareXpathSelectors();
42
		} catch (SaxonApiException e) {
43
			throw new ParthenosPublisherException(e);
44
		}
45
	}
46

  
47
	public int unregister(final String datasourceInterface) {
48
		return gCubeResourceRegistrator.unregister(datasourceInterface);
49
	}
50

  
51
	public void doRegister(final String recordRDF, final String objIdentifier) throws ParthenosPublisherException, IOException {
52
		//gCubeResourceRegistrator.register(recordRDF, objIdentifier);
53
	}
54

  
55
	public void dropRegistry() throws ParthenosPublisherException {
56
		//TODO ask Luca to implement a method or instruction to do so
57
		log.fatal("dropRegistry not yet implemented");
58
	}
59

  
60

  
61
	public void setDefaultBaseURI(final String defaultBaseURI) {
62
		this.defaultBaseURI = defaultBaseURI;
63
	}
64

  
65
	public String getDefaultBaseURI() {
66
		return defaultBaseURI;
67
	}
68

  
69
	public GCubeResourceRegistrator getgCubeResourceRegistrator() {
70
		return gCubeResourceRegistrator;
71
	}
72

  
73
	public void setgCubeResourceRegistrator(final GCubeResourceRegistrator gCubeResourceRegistrator) {
74
		this.gCubeResourceRegistrator = gCubeResourceRegistrator;
75
	}
76

  
77
	public ResourceRegistryPublisher getResourceRegistryPublisher() {
78
		return resourceRegistryPublisher;
79
	}
80

  
81
	public void setResourceRegistryPublisher(final ResourceRegistryPublisher resourceRegistryPublisher) {
82
		this.resourceRegistryPublisher = resourceRegistryPublisher;
83
	}
84

  
85
	public ResourceRegistryClient getResourceRegistryClient() {
86
		return resourceRegistryClient;
87
	}
88

  
89
	public void setResourceRegistryClient(final ResourceRegistryClient resourceRegistryClient) {
90
		this.resourceRegistryClient = resourceRegistryClient;
91
	}
92

  
93

  
94
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/jrr/JRRClient.java
1
package eu.dnetlib.parthenos.jrr;
2

  
3
import java.io.IOException;
4
import java.util.Map;
5

  
6
import com.google.common.collect.Maps;
7
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
8
import eu.dnetlib.parthenos.publisher.SaxonHelper;
9
import eu.dnetlib.parthenos.registry.RegistryClient;
10
import net.sf.saxon.s9api.SaxonApiException;
11
import net.sf.saxon.s9api.Serializer;
12
import net.sf.saxon.s9api.XPathSelector;
13
import org.apache.commons.lang3.StringUtils;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16

  
17
/**
18
 * Created by Alessia Bardi on 21/11/2017.
19
 *
20
 * @author Alessia Bardi
21
 */
22
@Deprecated
23
public abstract class JRRClient {
24

  
25
	private static final Log log = LogFactory.getLog(RegistryClient.class);
26

  
27
	public static final String OAI_NAMESPACE_URI = "http://www.openarchives.org/OAI/2.0/";
28
	public static final String DRI_NAMESPACE_URI = "http://www.driver-repository.eu/namespace/dri";
29
	public static final String RDF_NAMESPACE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
30

  
31
	private SaxonHelper saxonHelper;
32
	private XPathSelector xpathSelectorObjIdentifier;
33
	private XPathSelector xpathSelectorRDF;
34

  
35
	protected JRRClient(final SaxonHelper saxonHelper) throws ParthenosPublisherException {
36
		this.saxonHelper = saxonHelper;
37
		try {
38
			prepareXpathSelectors();
39
		} catch (SaxonApiException e) {
40
			throw new ParthenosPublisherException(e);
41
		}
42
	}
43

  
44
	public void register(final String record) throws ParthenosPublisherException {
45
		try {
46
			if (StringUtils.isBlank(record)) {
47
				log.warn("Got empty record -- skipping");
48
				return;
49
			}
50
			String objIdentifier = getObjIdentifier(record);
51
			if (StringUtils.isBlank(objIdentifier)) {
52
				log.warn("Got record with no objIdentifier -- skipping");
53
				return;
54
			}
55
			String recordRDF = getRDFBlock(record);
56
			doRegister(recordRDF, objIdentifier);
57
		} catch (Throwable e) {
58
			log.error(e.getMessage());
59
			throw new ParthenosPublisherException(e);
60
		}
61
	}
62

  
63
	protected abstract void doRegister(final String recordRDF, final String objIdentifier) throws IOException, ParthenosPublisherException;
64

  
65

  
66
	protected void prepareXpathSelectors() throws SaxonApiException {
67
		Map<String, String> namespaces = Maps.newHashMap();
68
		namespaces.put("oai", OAI_NAMESPACE_URI);
69
		namespaces.put("dri", DRI_NAMESPACE_URI);
70
		namespaces.put("rdf", RDF_NAMESPACE_URI);
71
		xpathSelectorObjIdentifier = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:objIdentifier/text()", namespaces);
72
		xpathSelectorRDF = this.saxonHelper.help().prepareXPathSelector("//oai:metadata/rdf:RDF", namespaces);
73
	}
74

  
75
	protected String extractFromRecord(final String record, final XPathSelector xPathSelector) {
76
		try {
77
			return this.saxonHelper.help().setSerializerProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes").setSerializerProperty(Serializer.Property.ENCODING, "UTF-8").evaluateSingleAsString(record, xPathSelector);
78
		} catch (SaxonApiException e) {
79
			throw new RuntimeException("Cannot extract content ", e);
80
		}
81
	}
82

  
83
	protected String getObjIdentifier(final String record){
84
		return extractFromRecord(record, xpathSelectorObjIdentifier);
85
	}
86

  
87
	protected String getRDFBlock(final String record){
88
		return extractFromRecord(record, xpathSelectorRDF);
89
	}
90

  
91

  
92
	public void setSaxonHelper(final SaxonHelper saxonHelper) {
93
		this.saxonHelper = saxonHelper;
94
	}
95
	public SaxonHelper getSaxonHelper() {
96
		return saxonHelper;
97
	}
98

  
99
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherHelper.java
3 3
import java.io.IOException;
4 4
import java.net.URISyntaxException;
5 5

  
6
import eu.dnetlib.parthenos.catalogue.CatalogueClientFactory;
7 6
import eu.dnetlib.parthenos.jrr.JRRPublisher;
8
import eu.dnetlib.parthenos.registry.RegistryClient;
9
import eu.dnetlib.parthenos.registry.RegistryClientFactory;
10 7
import eu.dnetlib.parthenos.virtuoso.VirtuosoClient;
11 8
import eu.dnetlib.parthenos.virtuoso.VirtuosoClientFactory;
12 9
import org.apache.commons.logging.Log;
......
14 11
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
15 12
import org.springframework.beans.factory.annotation.Autowired;
16 13
import org.springframework.stereotype.Component;
14
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
17 15

  
18 16
/**
19 17
 * Created by Alessia Bardi on 11/08/2017.
......
32 30
	@Autowired
33 31
	private VirtuosoClientFactory virtuosoClientFactory;
34 32
	@Autowired
35
	private RegistryClientFactory registryClientFactory;
36
	@Autowired
37
	private CatalogueClientFactory catalogueClientFactory;
38
	@Autowired
39 33
	private JRRPublisher jrrPublisher;
40 34

  
41 35
	public void publish(final String record, final ParthenosTargets target) throws ParthenosPublisherException {
......
82 76
		//Note that this method might not be a good idea if we want to keep the uuid and only update the facets/rels
83 77
		//maybe it is worth to implement the incremental in the ResourceRegistrator. We slow down things, but it may be worthy...
84 78
		log.debug("Unpublishing from registry "+datasourceInterface);
85
		RegistryClient registryClient = this.registryClientFactory.getRegistryClient();
86
		return registryClient.unregister(datasourceInterface);
79
		//TODO: implement me
80
		throw new NotImplementedException();
87 81
	}
88 82

  
89 83
	private long unpublishVirtuoso(final String datasourceInterface) throws ParthenosPublisherException {
......
96 90

  
97 91
	public void dropRegistry() throws ParthenosPublisherException {
98 92
		log.debug("Dropping JRR");
99
		RegistryClient registryClient = this.registryClientFactory.getRegistryClient();
100
		registryClient.dropRegistry();
93
		//TODO: implement me
94
		throw new NotImplementedException();
101 95
	}
102 96

  
103 97

  

Also available in: Unified diff