Project

General

Profile

« Previous | Next » 

Revision 46147

Branch for migration to Saxon-HE

View differences:

modules/dnet-core-services/branches/saxonHE/src/test/resources/eu/dnetlib/enabling/resultset/push/ResultSetDescriptorFactoryTest-context.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4
	xmlns:p="http://www.springframework.org/schema/p"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
7

  
8
	<bean id="resultSetDescriptorPrototype" class="eu.dnetlib.enabling.resultset.push.ResultSetDescriptor"
9
		p:rangeLength="200" scope="prototype" />
10

  
11
	<bean id="resultSetDescriptorFactory" class="eu.dnetlib.springutils.beans.factory.PrototypeFactory">
12
		<lookup-method name="newInstance" bean="resultSetDescriptorPrototype" />
13
	</bean>
14
</beans>
modules/dnet-core-services/branches/saxonHE/src/test/resources/eu/dnetlib/enabling/resultset/test.xsl
1
<xsl:stylesheet version="1.0"
2
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
	<xsl:template match="first">
4
		<second><xsl:value-of select="."/></second>
5
	</xsl:template>
6
</xsl:stylesheet>
modules/dnet-core-services/branches/saxonHE/src/test/resources/log4j.properties
1
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
2

  
3
log4j.rootLogger=WARN, CONSOLE
4
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
5
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
6
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
7

  
8
log4j.logger.eu.dnetlib=INFO
9
log4j.logger.eu.dnetlib.enabling.is.sn=INFO
10
#log4j.logger.org.apache.cxf.interceptor=FATAL
11
log4j.logger.org.apache.cxf.ws.addressing.ContextUtils=FATAL
12
log4j.logger.eu.dnetlib.enabling.tools.AbstractBaseService=INFO
13
log4j.logger.eu.dnetlib.enabling.inspector=DEBUG
14
log4j.logger.eu.dnetlib.xml.database.LoggingTrigger=FATAL
15
#log4j.logger.eu.dnetlib.enabling.tools.registration=DEBUG
16
log4j.logger.eu.dnetlib.enabling.tools.registration.ServiceRegistrator=INFO
17
log4j.logger.eu.dnetlib.enabling.inspector=FATAL
18
log4j.logger.eu.dnetlib.enabling.resultset=DEBUG
19
log4j.logger.eu.dnetlib.enabling.inspector.SubscriptionController=DEBUG
20
log4j.logger.eu.dnetlib.springutils.stringtemplate.StringTemplateViewResolver=FATAL
21
log4j.logger.eu.dnetlib.enabling.is.sn.SynchronousNotificationSenderImpl=WARN
22

  
23
log4j.logger.eu.dnetlib.enabling.manager.msro.wf.RefreshIndexJob=DEBUG
24
log4j.logger.eu.dnetlib.enabling.ui=DEBUG
25
log4j.logger.eu.dnetlib.enabling.manager.msro.wf.RefreshIndexJob=DEBUG
26

  
27
log4j.logger.org.apache.zookeeper.ClientCnxn=FATAL
28

  
29
log4j.logger.eu.dnetlib.enabling.resultset.push=DEBUG
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/hcm/sn/SubscriptionException.java
1
package eu.dnetlib.enabling.hcm.sn;
2

  
3
public class SubscriptionException extends Exception {
4

  
5
	/**
6
	 *
7
	 */
8
	private static final long serialVersionUID = 3281648062309941192L;
9

  
10
	public SubscriptionException() {
11
		super();
12
	}
13

  
14
	public SubscriptionException(final String message, final Throwable cause) {
15
		super(message, cause);
16
	}
17

  
18
	public SubscriptionException(final String message) {
19
		super(message);
20
	}
21

  
22
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/hcm/sn/HCMSubscriber.java
1
package eu.dnetlib.enabling.hcm.sn;
2

  
3
/**
4
 * This component takes care of subscribing the MSRO service to interesting events.
5
 *
6
 * @author marko
7
 *
8
 */
9
public interface HCMSubscriber {
10

  
11
	void subscribeAll() throws SubscriptionException;
12
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/hcm/sn/HCMSubscriberImpl.java
1
package eu.dnetlib.enabling.hcm.sn;
2

  
3
import java.util.List;
4
import javax.annotation.PostConstruct;
5

  
6
import eu.dnetlib.enabling.actions.SubscriptionAction;
7
import eu.dnetlib.enabling.hcm.HostingContextManagerServiceImpl;
8
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Required;
13

  
14
/**
15
 * This component takes care of subscribing the SubscriptionAction(s) to interesting events.
16
 *
17
 * @author claudio
18
 *
19
 */
20
public class HCMSubscriberImpl implements HCMSubscriber {
21

  
22
	/**
23
	 * logger.
24
	 */
25
	private static final Log log = LogFactory.getLog(HCMSubscriberImpl.class);
26

  
27
	/**
28
	 * service locator.
29
	 */
30
	@Autowired
31
	private UniqueServiceLocator serviceLocator;
32

  
33
	/**
34
	 * hcm
35
	 */
36
	private HostingContextManagerServiceImpl hcm;
37

  
38
	/**
39
	 * subscription actions.
40
	 */
41
	@Autowired(required = false)
42
	private List<SubscriptionAction> actions;
43

  
44
	@PostConstruct
45
	public void printList() {
46
		log.info(getActions());
47
	}
48

  
49
	@Override
50
	public void subscribeAll() throws SubscriptionException {
51
		// final String profileId = this.hcm.getProfileId();
52
		// if (getActions() != null) {
53
		// for (final SubscriptionAction action : getActions()) {
54
		// log.info("dynamically subscribing to " + action.getTopicExpression());
55
		// this.serviceLocator.getService(ISSNService.class).subscribe(profileId, action.getTopicExpression(), 0);
56
		// }
57
		// }
58
	}
59

  
60
	public List<SubscriptionAction> getActions() {
61
		return this.actions;
62
	}
63

  
64
	public void setActions(final List<SubscriptionAction> actions) {
65
		this.actions = actions;
66
	}
67

  
68
	public HostingContextManagerServiceImpl getHcm() {
69
		return this.hcm;
70
	}
71

  
72
	@Required
73
	public void setHcm(final HostingContextManagerServiceImpl hcm) {
74
		this.hcm = hcm;
75
	}
76

  
77
	public UniqueServiceLocator getServiceLocator() {
78
		return this.serviceLocator;
79
	}
80

  
81
	public void setServiceLocator(final UniqueServiceLocator serviceLocator) {
82
		this.serviceLocator = serviceLocator;
83
	}
84

  
85
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/hcm/HostingContextManagerServiceImpl.java
1
package eu.dnetlib.enabling.hcm;
2

  
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5

  
6
import eu.dnetlib.enabling.tools.AbstractBaseService;
7
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
8
import eu.dnetlib.rmi.enabling.HostingContextManagerService;
9

  
10
/**
11
 * CNR HostingContextManagerService implementation. Will conflict with NKUA! yes this is ok.
12
 *
13
 * @author marko
14
 *
15
 */
16
public class HostingContextManagerServiceImpl extends AbstractBaseService implements HostingContextManagerService {
17

  
18
	/**
19
	 * logger.
20
	 */
21
	private static final Log log = LogFactory.getLog(HostingContextManagerServiceImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
22

  
23
	/**
24
	 * notification handler.
25
	 */
26
	private NotificationHandler notificationHandler; // NOPMD
27

  
28
	@Override
29
	public String echo(final String s) {
30
		return s;
31
	}
32

  
33
	@Override
34
	public void notify(final String subscrId, final String topic, final String isId, final String message) {
35
		// if (log.isDebugEnabled()) {
36
		// log.debug("---- service got notification ----");
37
		// log.debug("subscrId: " + subscrId);
38
		// log.debug("topic " + topic);
39
		// log.debug("isId " + isId);
40
		// log.debug("msg: " + message);
41
		// log.debug("____ now processing the notification ____");
42
		// }
43
		// getNotificationHandler().notified(subscrId, topic, isId, message);
44
	}
45

  
46
	/**
47
	 * {@inheritDoc}
48
	 *
49
	 * @see eu.dnetlib.enabling.tools.AbstractBaseService#start()
50
	 */
51
	@Override
52
	public void start() {
53
		log.info("staring hosting context manager");
54
	}
55

  
56
	public NotificationHandler getNotificationHandler() {
57
		return this.notificationHandler;
58
	}
59

  
60
	// @Required
61
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
62
		this.notificationHandler = notificationHandler;
63
	}
64

  
65
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/listener/ResultSetListener.java
1
package eu.dnetlib.enabling.resultset.listener;
2

  
3
import eu.dnetlib.rmi.common.ResultSetException;
4

  
5
/**
6
 * @author michele
7
 *
8
 */
9
public interface ResultSetListener<T> {
10

  
11
	boolean hasNext();
12

  
13
	T next() throws ResultSetException;
14

  
15
	int getCount();
16

  
17
	int getTotal();
18

  
19
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/listener/IterableResultSetListener.java
1
package eu.dnetlib.enabling.resultset.listener;
2

  
3
import java.util.Collection;
4
import java.util.Iterator;
5

  
6
import eu.dnetlib.rmi.common.ResultSetException;
7

  
8
public class IterableResultSetListener<T> implements ResultSetListener<T> {
9

  
10
	private Iterator<T> iter;
11
	private int count;
12
	private int total;
13

  
14
	public IterableResultSetListener(final Iterable<T> iter) {
15
		this(iter.iterator());
16

  
17
		if (iter instanceof Collection) {
18
			this.total = ((Collection<?>) iter).size();
19
		}
20
	}
21

  
22
	public IterableResultSetListener(final Iterator<T> iter) {
23
		this.iter = iter;
24
		this.count = 0;
25
		this.total = -1;
26
	}
27

  
28
	@Override
29
	public boolean hasNext() {
30
		return this.iter.hasNext();
31
	}
32

  
33
	@Override
34
	public T next() throws ResultSetException {
35
		final T res = this.iter.next();
36
		if (res != null) {
37
			this.count++;
38
			return res;
39
		}
40
		throw new ResultSetException("Found a null element in resultset");
41
	}
42

  
43
	@Override
44
	public int getCount() {
45
		return this.count;
46
	}
47

  
48
	@Override
49
	public int getTotal() {
50
		return hasNext() ? this.total : this.count;
51
	}
52

  
53
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/ResultSetInfo.java
1
package eu.dnetlib.enabling.resultset;
2

  
3
import javax.xml.bind.annotation.XmlRootElement;
4

  
5
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
6

  
7
@XmlRootElement
8
public class ResultSetInfo {
9

  
10
	private String id;
11
	private int cursor = -1;
12
	private int total = -1;
13
	private boolean inaccurate = false;
14

  
15
	public ResultSetInfo() {}
16

  
17
	public ResultSetInfo(final String id, final ResultSetListener<?> listener) {
18
		this.id = id;
19
		this.cursor = listener.getCount();
20
		this.total = listener.getTotal();
21
		this.inaccurate = listener.getCount() < 0 || listener.getTotal() < 0 || listener.getTotal() < listener.getCount();
22
	}
23

  
24
	public ResultSetInfo(final String id, final int cursor, final int total, final boolean inaccurate) {
25
		this.id = id;
26
		this.cursor = cursor;
27
		this.total = total;
28
		this.inaccurate = inaccurate;
29
	}
30

  
31
	public String getId() {
32
		return this.id;
33
	}
34

  
35
	public void setId(final String id) {
36
		this.id = id;
37
	}
38

  
39
	public int getTotal() {
40
		return this.total;
41
	}
42

  
43
	public void setTotal(final int total) {
44
		this.total = total;
45
	}
46

  
47
	public int getCursor() {
48
		return this.cursor;
49
	}
50

  
51
	public void setCursor(final int cursor) {
52
		this.cursor = cursor;
53
	}
54

  
55
	public boolean isInaccurate() {
56
		return this.inaccurate;
57
	}
58

  
59
	public void setInaccurate(final boolean inaccurate) {
60
		this.inaccurate = inaccurate;
61
	}
62

  
63
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/factory/ResultSetFactory.java
1
package eu.dnetlib.enabling.resultset.factory;
2

  
3
import java.util.Map;
4
import java.util.function.Function;
5
import java.util.stream.StreamSupport;
6

  
7
import javax.xml.transform.TransformerFactory;
8
import javax.xml.transform.dom.DOMSource;
9

  
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Required;
12
import org.springframework.core.io.Resource;
13

  
14
import eu.dnetlib.enabling.resultset.client.ResultSetClient;
15
import eu.dnetlib.enabling.resultset.listener.IterableResultSetListener;
16
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
17
import eu.dnetlib.enabling.resultset.registry.ResultSetRegistry;
18
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
19
import eu.dnetlib.rmi.common.ResultSet;
20

  
21
public class ResultSetFactory {
22

  
23
	private ResultSetRegistry resultSetRegistry;
24
	private ResultSetClient resultSetClient;
25
	private String baseUrl;
26
	@Autowired
27
	private TransformerFactory saxonTransformerFactory;
28

  
29
	public <T> ResultSet<T> registerResultSet(final ResultSetListener<T> rs) {
30
		final String rsId = this.resultSetRegistry.registerResultSet(rs);
31
		return new ResultSet<T>(rsId, this.baseUrl);
32
	}
33

  
34
	public <T> ResultSet<T> createResultSet(final ResultSetListener<T> listener) {
35
		return registerResultSet(listener);
36
	}
37

  
38
	public <T> ResultSet<T> createResultSet(final Iterable<T> iter) {
39
		return registerResultSet(new IterableResultSetListener<T>(iter));
40
	}
41

  
42
	public <T, K> ResultSet<K> map(final ResultSet<?> rsIn, final Class<T> clazzIn, final Function<T, K> mapper) {
43
		final Iterable<T> iterIn = this.resultSetClient.iter(rsIn, clazzIn);
44
		return createResultSet(() -> StreamSupport.stream(iterIn.spliterator(), false).map(mapper).iterator());
45
	}
46

  
47
	public ResultSet<String> xsltMap(final ResultSet<?> rsIn, final String xslt) {
48
		return map(rsIn, String.class, new ApplyXslt(xslt, saxonTransformerFactory));
49
	}
50

  
51
	public ResultSet<String> xsltMap(final ResultSet<?> rsIn, final String xslt, final Map<String, String> params) {
52
		return map(rsIn, String.class, new ApplyXslt(xslt, null, params, saxonTransformerFactory));
53
	}
54

  
55
	public ResultSet<String> xsltMap(final ResultSet<?> rsIn, final Resource xsltResource) {
56
		return map(rsIn, String.class, new ApplyXslt(xsltResource,saxonTransformerFactory));
57
	}
58

  
59
	public ResultSet<String> xsltMap(final ResultSet<?> rsIn, final Resource xsltResource, final Map<String, String> params) {
60
		return map(rsIn, String.class, new ApplyXslt(xsltResource, params, saxonTransformerFactory));
61
	}
62

  
63
	public ResultSet<String> xsltMap(final ResultSet<?> rsIn, final DOMSource domSource) {
64
		return map(rsIn, String.class, new ApplyXslt(domSource,saxonTransformerFactory));
65
	}
66

  
67
	public ResultSetRegistry getResultSetRegistry() {
68
		return this.resultSetRegistry;
69
	}
70

  
71
	@Required
72
	public void setResultSetRegistry(final ResultSetRegistry resultSetRegistry) {
73
		this.resultSetRegistry = resultSetRegistry;
74
	}
75

  
76
	public String getBaseUrl() {
77
		return this.baseUrl;
78
	}
79

  
80
	@Required
81
	public void setBaseUrl(final String baseUrl) {
82
		this.baseUrl = baseUrl;
83
	}
84

  
85
	public ResultSetClient getResultSetClient() {
86
		return this.resultSetClient;
87
	}
88

  
89
	@Required
90
	public void setResultSetClient(final ResultSetClient resultSetClient) {
91
		this.resultSetClient = resultSetClient;
92
	}
93

  
94
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/registry/ResultSetRegistry.java
1
package eu.dnetlib.enabling.resultset.registry;
2

  
3
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
4
import eu.dnetlib.rmi.common.ResultSetException;
5

  
6
/**
7
 * Instances of ResultSetRegistry manage a set of resultset objects and manage their garbage collection.
8
 *
9
 * @author michele
10
 *
11
 */
12
public interface ResultSetRegistry {
13

  
14
	/**
15
	 * register a resultSetListener
16
	 *
17
	 * @param listener
18
	 *            a resultsetListener object
19
	 * @return the resultset id
20
	 */
21
	String registerResultSet(ResultSetListener<?> listener);
22

  
23
	/**
24
	 * obtain the resultsetListener with the given id.
25
	 *
26
	 * @param rsId
27
	 *            resultset id
28
	 * @return the resultsetListener object matching the rsId or null
29
	 * @throws ResultSetException
30
	 */
31
	<T> ResultSetListener<T> getResultSetById(String rsId) throws ResultSetException;
32

  
33
	/**
34
	 *
35
	 * @param id
36
	 * @return
37
	 */
38
	boolean contains(String id);
39
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/registry/ResultSetRegistryImpl.java
1
package eu.dnetlib.enabling.resultset.registry;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Set;
6
import java.util.UUID;
7
import java.util.stream.Collectors;
8

  
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.springframework.beans.factory.annotation.Required;
12

  
13
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
14
import eu.dnetlib.miscutils.datetime.DateUtils;
15
import eu.dnetlib.rmi.common.ResultSetException;
16

  
17
public class ResultSetRegistryImpl implements ResultSetRegistry {
18

  
19
	private static final String RS_PREFIX = "rs-";
20

  
21
	private long ttl = 600000;
22

  
23
	private static final Log log = LogFactory.getLog(ResultSetRegistry.class);
24

  
25
	private class RsCacheElem {
26

  
27
		private final ResultSetListener<?> listener;
28
		private long lastDate = DateUtils.now();
29

  
30
		public RsCacheElem(final ResultSetListener<?> listener) {
31
			this.listener = listener;
32
		}
33

  
34
		public ResultSetListener<?> getListener() {
35
			this.lastDate = DateUtils.now();
36
			return this.listener;
37
		}
38

  
39
		public boolean isOld(final long now) {
40
			return (now - this.lastDate) > ResultSetRegistryImpl.this.ttl;
41
		}
42
	}
43

  
44
	private final Map<String, RsCacheElem> cache = new HashMap<>();
45

  
46
	@Override
47
	public String registerResultSet(final ResultSetListener<?> listener) {
48
		verifyCache();
49
		final String newId = RS_PREFIX + UUID.randomUUID();
50
		this.cache.put(newId, new RsCacheElem(listener));
51

  
52
		log.debug("New resultset created: " + newId);
53

  
54
		return newId;
55
	}
56

  
57
	private void verifyCache() {
58
		final long now = DateUtils.now();
59
		final Set<String> toDelete = this.cache.entrySet()
60
				.stream()
61
				.filter(e -> e.getValue().isOld(now))
62
				.map(e -> e.getKey())
63
				.collect(Collectors.toSet());
64

  
65
		if (!toDelete.isEmpty()) {
66
			log.debug("The following resultsets are expired: " + toDelete);
67
		}
68

  
69
		toDelete.forEach(this.cache::remove);
70
	}
71

  
72
	@SuppressWarnings("unchecked")
73
	@Override
74
	public <T> ResultSetListener<T> getResultSetById(final String rsId) throws ResultSetException {
75
		final RsCacheElem elem = this.cache.get(rsId);
76
		if (elem != null) {
77
			final ResultSetListener<T> rs = (ResultSetListener<T>) elem.getListener();
78
			if (rs != null) { return rs; }
79
		}
80
		throw new ResultSetException("Missing resultset with id " + rsId);
81
	}
82

  
83
	@Override
84
	public boolean contains(final String rsId) {
85
		return this.cache.get(rsId) != null;
86
	}
87

  
88
	public long getTtl() {
89
		return this.ttl;
90
	}
91

  
92
	@Required
93
	public void setTtl(final long ttl) {
94
		this.ttl = ttl;
95
	}
96

  
97
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/ResultSetResponse.java
1
package eu.dnetlib.enabling.resultset;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import javax.xml.bind.annotation.XmlRootElement;
7

  
8
@XmlRootElement
9
public class ResultSetResponse {
10

  
11
	private int from = 0;
12
	private int to = 0;
13
	private boolean end = false;
14
	private int total = -1;
15
	private List<String> elements = new ArrayList<>();
16

  
17
	public ResultSetResponse() {}
18

  
19
	public ResultSetResponse(final int from, final int to, final boolean end, final int total, final List<String> elements) {
20
		this.from = from;
21
		this.to = to;
22
		this.end = end;
23
		this.total = total;
24
		this.elements = elements;
25
	}
26

  
27
	public int getFrom() {
28
		return this.from;
29
	}
30

  
31
	public void setFrom(final int from) {
32
		this.from = from;
33
	}
34

  
35
	public int getTo() {
36
		return this.to;
37
	}
38

  
39
	public void setTo(final int to) {
40
		this.to = to;
41
	}
42

  
43
	public boolean isEnd() {
44
		return this.end;
45
	}
46

  
47
	public void setEnd(final boolean end) {
48
		this.end = end;
49
	}
50

  
51
	public int getTotal() {
52
		return this.total;
53
	}
54

  
55
	public void setTotal(final int total) {
56
		this.total = total;
57
	}
58

  
59
	public List<String> getElements() {
60
		return this.elements;
61
	}
62

  
63
	public void setElements(final List<String> elements) {
64
		this.elements = elements;
65
	}
66

  
67
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/ResultSetController.java
1
package eu.dnetlib.enabling.resultset;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import com.google.gson.Gson;
7
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
8
import eu.dnetlib.enabling.resultset.registry.ResultSetRegistry;
9
import eu.dnetlib.rmi.common.ResultSetException;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.stereotype.Controller;
12
import org.springframework.web.bind.annotation.PathVariable;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.ResponseBody;
16

  
17
@Controller
18
public class ResultSetController {
19

  
20
	@Autowired
21
	private ResultSetRegistry resultSetRegistry;
22

  
23
	@RequestMapping(value = "/rs/{rsId}/next/{n}", method = RequestMethod.GET)
24
	public @ResponseBody ResultSetResponse getNextResults(@PathVariable(value = "rsId") final String rsId, @PathVariable(value = "n") final int n)
25
			throws ResultSetException {
26
		final ResultSetListener<?> rs = this.resultSetRegistry.getResultSetById(rsId);
27

  
28
		final int start = rs.getCount();
29

  
30
		final List<String> elements = new ArrayList<>();
31

  
32
		final Gson gson = new Gson();
33
		while (rs.hasNext() && elements.size() < n) {
34
			elements.add(gson.toJson(rs.next()));
35
		}
36

  
37
		final int from = start;
38
		final int to = rs.getCount();
39
		final boolean end = !rs.hasNext();
40
		final int total = rs.getTotal();
41

  
42
		return new ResultSetResponse(from, to, end, total, elements);
43
	}
44

  
45
	@RequestMapping(value = "/rs/{rsId}/info", method = RequestMethod.GET)
46
	public @ResponseBody ResultSetInfo getRsInfo(@PathVariable(value = "rsId") final String rsId)
47
			throws ResultSetException {
48
		final ResultSetListener<?> rs = this.resultSetRegistry.getResultSetById(rsId);
49
		return new ResultSetInfo(rsId, rs);
50
	}
51

  
52
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/client/HttpResultSetClientIterator.java
1
package eu.dnetlib.enabling.resultset.client;
2

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

  
7
import com.google.gson.Gson;
8

  
9
import eu.dnetlib.enabling.resultset.ResultSetResponse;
10
import eu.dnetlib.rmi.common.ResultSetException;
11
import org.apache.commons.io.IOUtils;
12
import org.apache.http.HttpStatus;
13
import org.apache.http.client.methods.CloseableHttpResponse;
14
import org.apache.http.client.methods.HttpGet;
15
import org.apache.http.impl.client.CloseableHttpClient;
16
import org.apache.http.impl.client.HttpClients;
17

  
18
public class HttpResultSetClientIterator<T> extends AbstractResultSetClientIterator<T> {
19

  
20
	private static final int PAGE_SIZE = 20;
21

  
22
	private final String id;
23
	private final String baseUrl;
24
	private final Class<T> clazz;
25

  
26
	private final CloseableHttpClient client = HttpClients.createDefault();
27

  
28
	public HttpResultSetClientIterator(final String id, final String baseUrl, final Class<T> clazz) {
29
		super();
30
		this.id = id;
31
		this.baseUrl = baseUrl;
32
		this.clazz = clazz;
33
	}
34

  
35
	@Override
36
	protected List<T> nextPage() throws ResultSetException {
37
		final HttpGet method = new HttpGet(getBaseUrl() + "/" + getId() + "/next/" + PAGE_SIZE);
38

  
39
		try(CloseableHttpResponse httpResponse = client.execute(method)) {
40

  
41
			int statusCode = httpResponse.getStatusLine().getStatusCode();
42
			if (HttpStatus.SC_OK != statusCode) {
43
				throw new ResultSetException("Error " + statusCode + " dowloading url: " + getBaseUrl());
44
			}
45

  
46
			try(InputStream responseBody = httpResponse.getEntity().getContent()) {
47
				final String json = IOUtils.toString(responseBody);
48
				final Gson gson = new Gson();
49
				final ResultSetResponse response = gson.fromJson(json, ResultSetResponse.class);
50
				return response.getElements()
51
						.stream()
52
						.map(s -> gson.fromJson(s, getClazz()))
53
						.collect(Collectors.toList());
54
			}
55
		} catch (Throwable e) {
56
			throw new ResultSetException("Error dowloading url: " + getBaseUrl(), e);
57
		}
58
	}
59

  
60
	public String getId() {
61
		return this.id;
62
	}
63

  
64
	public String getBaseUrl() {
65
		return this.baseUrl;
66
	}
67

  
68
	public Class<T> getClazz() {
69
		return this.clazz;
70
	}
71

  
72
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/client/AbstractResultSetClientIterator.java
1
package eu.dnetlib.enabling.resultset.client;
2

  
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
import java.util.NoSuchElementException;
7
import java.util.Queue;
8

  
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

  
12
import eu.dnetlib.rmi.common.ResultSetException;
13

  
14
public abstract class AbstractResultSetClientIterator<T> implements Iterator<T> {
15

  
16
	private static final Log log = LogFactory.getLog(AbstractResultSetClientIterator.class);
17

  
18
	private final Queue<T> buffer = new LinkedList<T>();
19

  
20
	@Override
21
	public boolean hasNext() {
22
		if (!this.buffer.isEmpty()) { return true; }
23
		try {
24
			return refillBuffer();
25
		} catch (final ResultSetException e) {
26
			log.error("Error refilling resultSet buffer", e);
27
			throw new RuntimeException("Error refilling resultSet buffer", e);
28
		}
29
	}
30

  
31
	@Override
32
	public T next() {
33
		if (!hasNext()) {
34
			log.error("NoSuchElementException");
35
			throw new NoSuchElementException();
36
		}
37
		return this.buffer.poll();
38
	}
39

  
40
	@Override
41
	public void remove() {
42
		throw new RuntimeException("Not implemented");
43
	}
44

  
45
	private boolean refillBuffer() throws ResultSetException {
46
		final List<T> page = nextPage();
47
		if (page == null || page.isEmpty()) { return false; }
48
		this.buffer.addAll(page);
49
		return true;
50
	}
51

  
52
	abstract protected List<T> nextPage() throws ResultSetException;
53

  
54
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/client/ResultSetClient.java
1
package eu.dnetlib.enabling.resultset.client;
2

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

  
6
import org.apache.commons.io.IOUtils;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.apache.http.HttpStatus;
10
import org.apache.http.client.methods.CloseableHttpResponse;
11
import org.apache.http.client.methods.HttpGet;
12
import org.apache.http.impl.client.CloseableHttpClient;
13
import org.apache.http.impl.client.HttpClients;
14
import org.springframework.beans.factory.annotation.Required;
15

  
16
import com.google.gson.Gson;
17

  
18
import eu.dnetlib.enabling.resultset.ResultSetInfo;
19
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
20
import eu.dnetlib.enabling.resultset.registry.ResultSetRegistry;
21
import eu.dnetlib.rmi.common.ResultSet;
22
import eu.dnetlib.rmi.common.ResultSetException;
23

  
24
public class ResultSetClient {
25

  
26
	private ResultSetRegistry resultSetRegistry;
27

  
28
	private static final Log log = LogFactory.getLog(ResultSetClient.class);
29

  
30
	public <T> Iterable<T> iter(final ResultSet<?> resultSet, final Class<T> clazz) {
31
		try {
32
			if (this.resultSetRegistry.contains(resultSet.getId())) {
33
				final ResultSetListener<?> listener = this.resultSetRegistry.getResultSetById(resultSet.getId());
34
				return () -> new LocalResultSetClientIterator<>(listener, clazz);
35
			} else {
36
				return () -> new HttpResultSetClientIterator<>(resultSet.getId(), resultSet.getBaseUrl(), clazz);
37
			}
38
		} catch (final Throwable e) {
39
			log.error("Error accessing resultset: " + resultSet.getId());
40
			throw new RuntimeException(e);
41
		}
42
	}
43

  
44
	public ResultSetInfo info(final ResultSet<?> resultSet) {
45
		try {
46
			if (this.resultSetRegistry.contains(resultSet.getId())) {
47
				final ResultSetListener<?> listener = this.resultSetRegistry.getResultSetById(resultSet.getId());
48
				return new ResultSetInfo(resultSet.getId(), listener);
49
			} else {
50
				return invokeRemoteInfo(resultSet);
51
			}
52
		} catch (final Throwable e) {
53
			log.error("Error accessing resultset: " + resultSet.getId());
54
			throw new RuntimeException(e);
55
		}
56
	}
57

  
58
	private ResultSetInfo invokeRemoteInfo(final ResultSet<?> rs) throws ResultSetException {
59
		final HttpGet method = new HttpGet(rs.getBaseUrl() + "/" + rs.getId() + "/info");
60
		try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
61
			try(CloseableHttpResponse response = httpClient.execute(method)) {
62

  
63
				int statusCode = response.getStatusLine().getStatusCode();
64

  
65
				if (HttpStatus.SC_OK != statusCode) {
66
					throw new ResultSetException("Error " + statusCode + " dowloading url: " + rs.getBaseUrl());
67
				}
68
				try(InputStream responseBody = response.getEntity().getContent()) {
69
					String json = IOUtils.toString(responseBody);
70
					return new Gson().fromJson(json, ResultSetInfo.class);
71
				}
72
			} catch (final Throwable e) {
73
				throw new ResultSetException("Error dowloading url: " + rs.getBaseUrl(), e);
74
			}
75
		} catch (IOException e) {
76
			log.error("Can't close connections gracefully", e);
77
			throw new ResultSetException("Can't close connections gracefully", e);
78
		}
79
	}
80

  
81
	public ResultSetRegistry getResultSetRegistry() {
82
		return this.resultSetRegistry;
83
	}
84

  
85
	@Required
86
	public void setResultSetRegistry(final ResultSetRegistry resultSetRegistry) {
87
		this.resultSetRegistry = resultSetRegistry;
88
	}
89

  
90
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/resultset/client/LocalResultSetClientIterator.java
1
package eu.dnetlib.enabling.resultset.client;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
7
import eu.dnetlib.rmi.common.ResultSetException;
8

  
9
public class LocalResultSetClientIterator<T> extends AbstractResultSetClientIterator<T> {
10

  
11
	private static final int PAGE_SIZE = 20;
12

  
13
	private final ResultSetListener<?> listener;
14
	private final Class<T> clazz;
15

  
16
	public LocalResultSetClientIterator(final ResultSetListener<?> listener, final Class<T> clazz) {
17
		super();
18
		this.listener = listener;
19
		this.clazz = clazz;
20
	}
21

  
22
	@Override
23
	protected List<T> nextPage() throws ResultSetException {
24
		final List<T> res = new ArrayList<>();
25
		for (int i = 0; i < PAGE_SIZE && this.listener.hasNext(); i++) {
26
			res.add(this.clazz.cast(this.listener.next()));
27
		}
28
		return res;
29
	}
30

  
31
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/datasources/IfaceDescToNode.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.util.Map.Entry;
4

  
5
import eu.dnetlib.rmi.datasource.IfaceDesc;
6
import org.dom4j.DocumentHelper;
7
import org.dom4j.Element;
8

  
9
public class IfaceDescToNode {
10

  
11
	public static Element convert(final IfaceDesc iface) throws Exception {
12

  
13
		final Element ifcNode = DocumentHelper.createElement("INTERFACE");
14
		ifcNode.addAttribute("id", iface.getId());
15
		ifcNode.addAttribute("label", iface.getTypology() + " (" + iface.getCompliance() + ")");
16
		ifcNode.addAttribute("compliance", iface.getCompliance());
17
		ifcNode.addAttribute("typology", iface.getTypology());
18
		ifcNode.addAttribute("contentDescription", iface.getContentDescription());
19
		ifcNode.addAttribute("active", Boolean.toString(iface.getActive()));
20
		ifcNode.addAttribute("removable", Boolean.toString(iface.getRemovable()));
21

  
22
		final Element acProtoNode = ifcNode.addElement("ACCESS_PROTOCOL");
23

  
24
		for (Entry<String, String> e : iface.getAccessParams().entrySet()) {
25
			acProtoNode.addAttribute(e.getKey(), e.getValue());
26
		}
27
		acProtoNode.setText(iface.getAccessProtocol());
28

  
29
		ifcNode.addElement("BASE_URL").setText(iface.getBaseUrl());
30
		;
31

  
32
		for (Entry<String, String> e : iface.getExtraFields().entrySet()) {
33
			final Element field = ifcNode.addElement("INTERFACE_EXTRA_FIELD");
34
			field.addAttribute("name", e.getKey());
35
			field.setText(e.getValue());
36
		}
37

  
38
		return ifcNode;
39
	}
40
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/datasources/XmlBrowsableField.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import eu.dnetlib.rmi.datasource.BrowsableField;
4

  
5
public class XmlBrowsableField extends BrowsableField {
6

  
7
	private String xpath;
8
	private String vocabulary;
9

  
10
	public XmlBrowsableField() {
11
		super();
12
	}
13

  
14
	public XmlBrowsableField(final String id, final String label) {
15
		super(id, label);
16
	}
17

  
18
	public XmlBrowsableField(final String id, final String label, final String xpath, final String vocabulary) {
19
		super(id, label);
20
		this.xpath = xpath;
21
		this.vocabulary = vocabulary;
22
	}
23

  
24
	public String getXpath() {
25
		return xpath;
26
	}
27

  
28
	public void setXpath(final String xpath) {
29
		this.xpath = xpath;
30
	}
31

  
32
	public String getVocabulary() {
33
		return vocabulary;
34
	}
35

  
36
	public void setVocabulary(final String vocabulary) {
37
		this.vocabulary = vocabulary;
38
	}
39

  
40
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/datasources/DatasourceManagerServiceImpl.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.util.Date;
4
import java.util.List;
5
import java.util.Map;
6

  
7
import eu.dnetlib.enabling.tools.AbstractBaseService;
8
import eu.dnetlib.rmi.datasource.*;
9
import org.springframework.beans.factory.annotation.Required;
10

  
11
public class DatasourceManagerServiceImpl extends AbstractBaseService implements DatasourceManagerService {
12

  
13
	//private List<XmlBrowsableField> browsableFields;
14

  
15
	private DnetDatasourceManagerCore datasourceManagerCore;
16

  
17
	@Override
18
	public boolean addDatasource(final DatasourceDesc ds) throws DatasourceManagerServiceException {
19
		return datasourceManagerCore.addDatasource(ds);
20
	}
21

  
22
	@Override
23
	public boolean deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
24
		return datasourceManagerCore.deleteDatasource(dsId);
25
	}
26

  
27
	@Override
28
	public DatasourceDesc getDatasource(final String dsId) throws DatasourceManagerServiceException {
29
		return datasourceManagerCore.getDatasource(dsId);
30
	}
31

  
32
	@Override
33
	public List<DatasourceDesc> listAllDatasources() throws DatasourceManagerServiceException {
34
		return listDatasourcesUsingFilter(null, null, null, null);
35
	}
36

  
37
	@Override
38
	public List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance,
39
			final String contentDescription,
40
			final String iisProcessingWorkflow,
41
			final String collectedFrom)
42
			throws DatasourceManagerServiceException {
43

  
44
		return datasourceManagerCore.listDatasourcesUsingFilter(compliance, contentDescription, iisProcessingWorkflow, collectedFrom);
45

  
46
	}
47

  
48
	@Override
49
	public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
50
		return datasourceManagerCore.updateLevelOfCompliance(dsId, ifaceId, level);
51
	}
52

  
53

  
54

  
55
	@Override
56
	public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
57
		return datasourceManagerCore.updateBaseUrl(dsId, ifaceId, baseUrl);
58
	}
59

  
60

  
61

  
62
	@Override
63
	public boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
64
		return datasourceManagerCore.updateActivationStatus(dsId, ifaceId, active);
65
	}
66

  
67

  
68

  
69
	@Override
70
	public boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
71
		return datasourceManagerCore.updateContentDescription(dsId, ifaceId, desc);
72
	}
73

  
74

  
75

  
76
	@Override
77
	public boolean setIisProcessingWorkflow(final String dsId, final String ifaceId, final String wf) throws DatasourceManagerServiceException {
78
		return datasourceManagerCore.setIisProcessingWorkflow(dsId, ifaceId, wf);
79
	}
80

  
81
	@Override
82
	public boolean updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
83
			throws DatasourceManagerServiceException {
84
		return datasourceManagerCore.updateExtraField(dsId, ifaceId, field, value, preserveOriginal);
85
	}
86

  
87

  
88

  
89
	@Override
90
	public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
91
			throws DatasourceManagerServiceException {
92
		return datasourceManagerCore.updateAccessParam(dsId, ifaceId, field, value, preserveOriginal);
93
	}
94

  
95

  
96

  
97
	@Override
98
	public boolean deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
99
		return datasourceManagerCore.deleteAccessParamOrExtraField(dsId, ifaceId, field);
100
	}
101

  
102

  
103

  
104
	@Override
105
	public boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
106
		return datasourceManagerCore.addInterface(dsId, iface);
107
	}
108

  
109
	@Override
110
	public boolean deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
111
		return datasourceManagerCore.deleteInterface(dsId, ifaceId);
112
	}
113

  
114

  
115

  
116
	@Override
117
	public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerServiceException {
118
		return datasourceManagerCore.updateSQL(dsId, sql, delete);
119
	}
120

  
121
	@Override
122
	public Date findNextScheduledExecution(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
123
		return datasourceManagerCore.findNextScheduledExecution(dsId, ifaceId);
124
	}
125

  
126

  
127

  
128
	@Override
129
	public boolean bulkUpdateApiExtraFields(final String repoId, final String ifaceId, final Map<String, String> fields)
130
			throws DatasourceManagerServiceException {
131
		return datasourceManagerCore.bulkUpdateApiExtraFields(repoId, ifaceId, fields);
132

  
133
	}
134

  
135
	@Override
136
	public boolean bulkUpdateApiAccessParams(final String dsId, final String ifaceId, final Map<String, String> params)
137
			throws DatasourceManagerServiceException {
138
		return datasourceManagerCore.bulkUpdateApiAccessParams(dsId, ifaceId, params);
139
	}
140

  
141

  
142

  
143
	@Override
144
	public boolean overrideCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
145
		return datasourceManagerCore.overrideCompliance(dsId, ifaceId, level);
146
	}
147

  
148

  
149

  
150
	@Override
151
	public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
152
		return datasourceManagerCore.listBrowsableFields();
153
	}
154

  
155
	@Override
156
	public List<BrowseTerm> browseField(final String f) throws DatasourceManagerServiceException {
157
		return datasourceManagerCore.browseField(f);
158
	}
159

  
160
	@Override
161
	public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerServiceException {
162
		return datasourceManagerCore.searchInterface(field, value);
163
	}
164

  
165

  
166

  
167
	@Override
168
	public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException {
169
		return datasourceManagerCore.getRepositoryMap();
170
	}
171

  
172
	@Override
173
	public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerServiceException {
174
		return datasourceManagerCore.simpleListDatasourcesByType(type);
175
	}
176

  
177
	public DnetDatasourceManagerCore getDatasourceManagerCore() {
178
		return datasourceManagerCore;
179
	}
180

  
181
	@Required
182
	public void setDatasourceManagerCore(final DnetDatasourceManagerCore datasourceManagerCore) {
183
		this.datasourceManagerCore = datasourceManagerCore;
184
	}
185

  
186

  
187

  
188
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/datasources/DnetDatasourceManagerCore.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.util.Date;
4
import java.util.List;
5
import java.util.Map;
6

  
7
import eu.dnetlib.rmi.datasource.*;
8

  
9
/**
10
 * Created by sandro on 6/29/16.
11
 */
12
public interface DnetDatasourceManagerCore {
13

  
14
	boolean addDatasource(DatasourceDesc datasourceDescription) throws DatasourceManagerServiceException;
15

  
16
	boolean deleteDatasource(final String datasourceIdentifier) throws DatasourceManagerServiceException;
17

  
18
	DatasourceDesc getDatasource(final String datasourceIdentifier) throws DatasourceManagerServiceException;
19

  
20
	List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance, final String contentDescription,
21
			final String iisProcessingWorkflow,
22
			final String collectedFrom) throws DatasourceManagerServiceException;
23

  
24
	boolean deleteInterface(final String dsId, final String ifaceId) throws DatasourceManagerServiceException;
25

  
26
	boolean updateLevelOfCompliance(final String dsId, final String interfaceId, final String level) throws DatasourceManagerServiceException;
27

  
28
	boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException;
29

  
30
	boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException;
31

  
32
	boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException;
33

  
34
	boolean setIisProcessingWorkflow(final String dsId, final String ifaceId, final String wf) throws DatasourceManagerServiceException;
35

  
36
	boolean updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
37
			throws DatasourceManagerServiceException;
38

  
39
	boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
40
			throws DatasourceManagerServiceException;
41

  
42
	boolean deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException;
43

  
44
	boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException;
45

  
46
	List<DatasourceDesc> listAllDatasources() throws DatasourceManagerServiceException;
47

  
48
	boolean overrideCompliance(String dsId, String ifaceId, String level) throws DatasourceManagerServiceException;
49

  
50
	boolean updateSQL(String dsId, String sql, boolean delete) throws DatasourceManagerServiceException;
51

  
52
	Date findNextScheduledExecution(String dsId, String ifaceId) throws DatasourceManagerServiceException;
53

  
54
	boolean bulkUpdateApiExtraFields(String dsId, String ifaceId, Map<String, String> fields) throws DatasourceManagerServiceException;
55

  
56
	boolean bulkUpdateApiAccessParams(String dsId, String ifaceId, Map<String, String> params) throws DatasourceManagerServiceException;
57

  
58
	List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException;
59

  
60
	List<BrowseTerm> browseField(final String field) throws DatasourceManagerServiceException;
61

  
62
	List<SearchInterfacesEntry> searchInterface(final String field, final String value)
63
			throws DatasourceManagerServiceException;
64

  
65
	List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException;
66

  
67
	List<SimpleDatasourceDesc> simpleListDatasourcesByType(String type) throws DatasourceManagerServiceException;
68

  
69
}
modules/dnet-core-services/branches/saxonHE/src/main/java/eu/dnetlib/enabling/datasources/DnetDatasourceManagerCoreImpl.java
1
package eu.dnetlib.enabling.datasources;
2

  
3
import java.io.StringReader;
4
import java.text.ParseException;
5
import java.util.*;
6
import java.util.stream.Collectors;
7

  
8
import com.google.common.collect.Sets;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
10
import eu.dnetlib.rmi.datasource.*;
11
import eu.dnetlib.rmi.enabling.*;
12
import org.antlr.stringtemplate.StringTemplate;
13
import org.apache.commons.io.IOUtils;
14
import org.apache.commons.lang3.StringEscapeUtils;
15
import org.apache.commons.lang3.StringUtils;
16
import org.apache.commons.lang3.math.NumberUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.dom4j.Document;
20
import org.dom4j.Element;
21
import org.dom4j.Node;
22
import org.dom4j.io.SAXReader;
23
import org.quartz.CronExpression;
24
import org.springframework.beans.factory.annotation.Autowired;
25
import org.springframework.beans.factory.annotation.Required;
26
import org.springframework.core.io.ClassPathResource;
27

  
28
/**
29
 * Created by sandro on 6/29/16.
30
 */
31
public class DnetDatasourceManagerCoreImpl implements DnetDatasourceManagerCore {
32

  
33
	private static final Log log = LogFactory.getLog(DnetDatasourceManagerCoreImpl.class);
34

  
35
	private static final String REPOSITORY_RESOURCE_TYPE = "RepositoryServiceResourceType";
36

  
37
	private List<XmlBrowsableField> browsableFields;
38

  
39
	@Autowired
40
	private UniqueServiceLocator serviceLocator;
41

  
42
	private ClassPathResource findReposQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findRepos.xquery.st");
43
	private ClassPathResource browseRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/browseRepoApis.xquery.st");
44
	private ClassPathResource findRepoApisQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findRepoApis.xquery.st");
45
	private ClassPathResource findReposMapQuery = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/findReposMap.xquery");
46
	private ClassPathResource simpleFindReposQueryTmpl = new ClassPathResource("/eu/dnetlib/enabling/datasources/templates/simpleFindRepos.xquery.st");
47

  
48
	@Override
49
	public boolean addDatasource(final DatasourceDesc datasourceDescription) throws DatasourceManagerServiceException {
50
		try {
51
			final String profile = DatasourceDescToProfile.convert(datasourceDescription);
52
			serviceLocator.getService(ISRegistryService.class).registerProfile(profile);
53
			return true;
54
		} catch (Exception e) {
55
			log.error("Error registering profile", e);
56
			throw new DatasourceManagerServiceException("Error registering profile", e);
57
		}
58
	}
59

  
60
	@Override
61
	public boolean deleteDatasource(final String datasourceIdentifier) throws DatasourceManagerServiceException {
62
		return _deleteDatasource(fixDsId(datasourceIdentifier));
63
	}
64

  
65
	@Override
66
	public DatasourceDesc getDatasource(final String datasourceIdentifier) throws DatasourceManagerServiceException {
67
		return _getDatasource(fixDsId(datasourceIdentifier));
68
	}
69

  
70
	@Override
71
	public List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance,
72
			final String contentDescription,
73
			final String iisProcessingWorkflow,
74
			final String collectedFrom) throws DatasourceManagerServiceException {
75
		try {
76
			final StringTemplate st = new StringTemplate();
77
			st.setTemplate(IOUtils.toString(findReposQueryTmpl.getInputStream()));
78

  
79
			final Map<String, String> conds = new HashMap<>();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff