Project

General

Profile

« Previous | Next » 

Revision 30605

[maven-release-plugin] copy for tag cnr-modular-mdstore-service-3.0.0

View differences:

modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>cnr-modular-mdstore-service</artifactId>
12
	<packaging>jar</packaging>
13
	<version>3.0.0</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>junit</groupId>
20
			<artifactId>junit</artifactId>
21
			<version>${junit.version}</version>
22
			<scope>test</scope>
23
		</dependency>
24
		<dependency>
25
			<groupId>org.springframework</groupId>
26
			<artifactId>spring-test</artifactId>
27
			<version>${spring.version}</version>
28
			<scope>test</scope>
29
		</dependency>
30
		<dependency>
31
			<groupId>org.mockito</groupId>
32
			<artifactId>mockito-core</artifactId>
33
			<version>1.6</version>
34
			<scope>test</scope>
35
		</dependency>
36
		<dependency>
37
			<groupId>eu.dnetlib</groupId>
38
			<artifactId>cnr-test-utils</artifactId>
39
			<version>[1.0.0,2.0.0)</version>
40
			<scope>test</scope>
41
		</dependency>
42
		<dependency>
43
			<groupId>eu.dnetlib</groupId>
44
			<artifactId>cnr-rmi-api</artifactId>
45
			<version>[2.0.0,3.0.0)</version>
46
		</dependency>
47
		<dependency>
48
			<groupId>eu.dnetlib</groupId>
49
			<artifactId>cnr-blackboard-common</artifactId>
50
			<version>[1.0.0,2.0.0)</version>
51
		</dependency>
52
		<dependency>
53
			<groupId>eu.dnetlib</groupId>
54
			<artifactId>cnr-misc-utils</artifactId>
55
			<version>[1.0.0,2.0.0)</version>
56
		</dependency>
57
		<dependency>
58
			<groupId>eu.dnetlib</groupId>
59
			<artifactId>cnr-resultset-service</artifactId>
60
			<version>[1.0.0,2.0.0)</version>
61
		</dependency>
62
		<dependency>
63
			<groupId>eu.dnetlib</groupId>
64
			<artifactId>cnr-resultset-client</artifactId>
65
			<version>[1.0.0,2.0.0)</version>
66
		</dependency>
67
	</dependencies>
68
</project>
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.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:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
7
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8
                                    http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
9
                                    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
10
                                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
11
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
12
                            http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd">
13

  
14
	<!-- beans -->
15
	<bean id="mdStoreService" class="eu.dnetlib.data.mdstore.modular.ModularMDStoreService"
16
		init-method="start" destroy-method="stop" p:notificationHandler-ref="mdstoreNotificationHandler"
17
		p:iterableResultSetFactory-ref="iterableResultSetFactory"
18
		p:feeder-ref="mdstoreFeeder" p:retriever-ref="mdstoreRetriever" />
19

  
20
	<bean id="mdstoreNotificationHandler"
21
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerExecutorNotificationHandler"
22
		p:blackboardExecutor-ref="mdstoreBlackboardExecutor" />
23

  
24
	<bean id="mdstoreBlackboardExecutor"
25
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerActionExecutor"
26
		p:blackboardHandler-ref="blackboardHandler"
27
		p:actionType="eu.dnetlib.data.mdstore.modular.MDStoreActions"
28
		p:incomplete="false">
29
		<property name="actionMap">
30
			<map>
31
				<entry key="CREATE">
32
					<bean class="eu.dnetlib.data.mdstore.modular.CreateAction"
33
						p:profileCreator-ref="mdstoreProfileCreator"
34
						p:dao-ref="${services.mdstore.dao}" />
35
				</entry>
36
				<entry key="DELETE">
37
					<bean class="eu.dnetlib.data.mdstore.modular.DeleteAction"
38
						p:registryLocator-ref="registryLocator" p:dao-ref="${services.mdstore.dao}" />
39
				</entry>
40
				<entry key="FEED">
41
					<bean class="eu.dnetlib.data.mdstore.modular.FeedAction"
42
						p:dao-ref="${services.mdstore.dao}" 
43
						p:feeder-ref="mdstoreFeeder"/>
44
				</entry>
45
			</map>
46
		</property>
47
	</bean>
48

  
49
	<bean id="mdstoreProfileCreator" class="eu.dnetlib.data.mdstore.modular.MDStoreProfileCreator"
50
		p:registryLocator-ref="registryLocator" p:mdstoreDsTemplate-ref="mdstoreDsTemplate"
51
		p:endpoint-ref="mdStoreServiceEndpoint" p:eprBuilder-ref="jaxwsEndpointReferenceBuilder" />
52

  
53
	<bean id="mdstoreDsTemplate"
54
		class="eu.dnetlib.springutils.stringtemplate.StringTemplateFactory"
55
		p:template="classpath:/eu/dnetlib/data/mdstore/modular/mdstoreds-template.xml"
56
		scope="prototype" />
57

  
58
	<bean id="mdstoreFeeder" class="eu.dnetlib.data.mdstore.modular.MDStoreFeeder"
59
		p:dao-ref="${services.mdstore.dao}" p:resultSetClientFactory-ref="mdstoreResultSetClientFactory"
60
		p:syncFeed="${services.mdstore.syncFeed}" p:registryLocator-ref="registryLocator" 
61
		p:transactionManager-ref="${services.mdstore.transaction}"
62
		/>
63

  
64
	<bean id="mdstoreResultSetClientFactory" parent="resultSetClientFactory"
65
		p:pageSize="${services.mdstore.rsfactory.pagesize}" />
66

  
67

  
68
	<bean id="mdstoreRetriever" class="eu.dnetlib.data.mdstore.modular.MDStoreRetriever"
69
		p:dao-ref="${services.mdstore.dao}" p:resultSetFactory-ref="${services.mdstore.rsfactory}" />
70

  
71
	<!-- <bean id="mdstoreRecordParser" class="eu.dnetlib.data.mdstore.modular.SimpleRecordParser" 
72
		/> -->
73
	<bean id="mdstoreRecordParser" 
74
		factory-bean="recordParserFactory" factory-method="newInstance"/>
75
	
76
	<bean id="recordParserFactory" class="eu.dnetlib.data.mdstore.modular.RecordParserFactory"
77
		p:parserType="${services.mdstore.recordParser}" />
78
		
79
	<bean id="bulkRecordMapperFactory" class="eu.dnetlib.data.mdstore.modular.BulkRecordMapperFactory" />
80

  
81
	<!-- endpoints -->
82
	<jaxws:endpoint id="mdStoreServiceEndpoint" implementor="#mdStoreService"
83
		implementorClass="eu.dnetlib.data.mdstore.MDStoreService" address="/mdStore" />
84

  
85
	<template:instance name="serviceRegistrationManager"
86
		t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl"
87
		t:name="mdStoreServiceRegistrationManager" t:service="mdStoreService"
88
		t:endpoint="mdStoreServiceEndpoint" t:jobScheduler="jobScheduler"
89
		t:serviceRegistrator="blackboardServiceRegistrator" />
90
</beans>
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/test/java/eu/dnetlib/enabling/tools/blackboard/SampleCreateAction.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import eu.dnetlib.data.mdstore.modular.MDStoreActions;
4

  
5
public class SampleCreateAction implements BlackboardServerAction<MDStoreActions> {
6

  
7
	@Override
8
	public void execute(BlackboardServerHandler handler, BlackboardJob job) {
9
		handler.done(job);
10
	}
11

  
12
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/DeleteAction.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.beans.factory.annotation.Required;
5

  
6
import eu.dnetlib.data.mdstore.MDStoreServiceException;
7
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
8
import eu.dnetlib.enabling.is.registry.ISRegistryDocumentNotFoundException;
9
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
10
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
11
import eu.dnetlib.enabling.tools.ServiceLocator;
12
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
13
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
14
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
15

  
16
public class DeleteAction extends AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> {
17

  
18
	private ServiceLocator<ISRegistryService> registryLocator;
19

  
20
	@Autowired
21
	private MDStoreTransactionManager transactionManager;
22

  
23
	@Override
24
	public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws ISRegistryDocumentNotFoundException, ISRegistryException {
25
		registryLocator.getService().deleteProfile(job.getParameters().get("id"));
26
		String currentId = job.getParameters().get("id");
27
		try {
28
			transactionManager.dropMDStore(currentId);
29
		} catch (MDStoreServiceException e) {
30
			throw new ISRegistryException("Error deleting mdstore with id " + currentId, e);
31
		}
32
		getDao().deleteMDStore(currentId);
33

  
34
		handler.done(job);
35
	}
36

  
37
	public ServiceLocator<ISRegistryService> getRegistryLocator() {
38
		return registryLocator;
39
	}
40

  
41
	@Required
42
	public void setRegistryLocator(final ServiceLocator<ISRegistryService> registryLocator) {
43
		this.registryLocator = registryLocator;
44
	}
45

  
46
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/test/resources/eu/dnetlib/enabling/tools/blackboard/BlackboardServerActionExecutorTest-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:p="http://www.springframework.org/schema/p"
4
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
5

  
6
	<bean id="blackboardHandler" class="eu.dnetlib.test.utils.MockBeanFactory"
7
		p:clazz="eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler" />
8

  
9
	<bean id="executor"
10
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerActionExecutor"
11
		p:blackboardHandler-ref="blackboardHandler" p:actionType="eu.dnetlib.data.mdstore.modular.MDStoreActions"
12
		p:incomplete="true">
13
		<property name="actionMap">
14
			<map>
15
				<entry key="CREATE">
16
					<bean class="eu.dnetlib.enabling.tools.blackboard.SampleCreateAction" />
17
				</entry>
18
			</map>
19
		</property>
20

  
21
	</bean>
22
</beans>
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/FeedAction.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5
import org.springframework.beans.factory.annotation.Required;
6

  
7
import eu.dnetlib.data.mdstore.MDStoreServiceException;
8
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
9
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
10
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
11

  
12
public class FeedAction extends AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> {
13

  
14
	private static final Log log = LogFactory.getLog(FeedAction.class);
15

  
16
	private MDStoreFeeder feeder;
17

  
18
	@Override
19
	public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
20

  
21
		final String mdId = job.getParameters().get("mdId");
22
		if ((mdId == null) || mdId.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
23

  
24
		final String epr = job.getParameters().get("epr");
25
		if ((epr == null) || epr.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
26

  
27
		String storingType = job.getParameters().get("storingType");
28
		if ((storingType == null) || storingType.isEmpty()) {
29
			storingType = "REFRESH";
30
		}
31

  
32
		feeder.feed(mdId, epr, storingType, true, new FeedDoneCallback() {
33

  
34
			@Override
35
			public void call(final int size) {
36
				job.getParameters().put("total", "" + size);
37
				handler.done(job);
38
			}
39
		}, new FeedFailedCallback() {
40

  
41
			@Override
42
			public void call(final Throwable e) {
43
				log.error("Error feeding mdstore: " + mdId, e);
44
				handler.failed(job, e);
45
			}
46
		});
47
	}
48

  
49
	public MDStoreFeeder getFeeder() {
50
		return feeder;
51
	}
52

  
53
	@Required
54
	public void setFeeder(final MDStoreFeeder feeder) {
55
		this.feeder = feeder;
56
	}
57

  
58
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/CreateAction.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.beans.factory.annotation.Required;
5

  
6
import eu.dnetlib.data.mdstore.MDStoreServiceException;
7
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
8
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
9
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
10
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
11
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
12

  
13
public class CreateAction extends AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> {
14

  
15
	private MDStoreProfileCreator profileCreator;
16

  
17
	@Autowired
18
	private MDStoreTransactionManager transactionManager;
19

  
20
	@Override
21
	public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws ISRegistryException {
22
		final String format = job.getParameters().get("format");
23
		final String interpretation = job.getParameters().get("interpretation");
24
		final String layout = job.getParameters().get("layout");
25

  
26
		final String mdId = profileCreator.registerProfile(format, interpretation, layout);
27

  
28
		try {
29
			transactionManager.createMDStore(mdId);
30
		} catch (MDStoreServiceException e) {
31
			throw new ISRegistryException("Error on create mdStore", e);
32
		}
33
		getDao().createMDStore(mdId, format, interpretation, layout);
34

  
35
		job.getParameters().put("id", mdId);
36

  
37
		handler.done(job);
38
	}
39

  
40
	public MDStoreProfileCreator getProfileCreator() {
41
		return profileCreator;
42
	}
43

  
44
	@Required
45
	public void setProfileCreator(final MDStoreProfileCreator profileCreator) {
46
		this.profileCreator = profileCreator;
47
	}
48

  
49
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreRetriever.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import javax.xml.ws.wsaddressing.W3CEndpointReference;
4

  
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.beans.factory.annotation.Required;
7

  
8
import com.google.common.base.Function;
9
import com.google.common.collect.Iterables;
10

  
11
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
12
import eu.dnetlib.data.mdstore.MDStoreServiceException;
13
import eu.dnetlib.data.mdstore.modular.connector.MDStore;
14
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
15
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
16
import eu.dnetlib.enabling.resultset.ResultSetFactory;
17

  
18
public class MDStoreRetriever {
19

  
20
	private MDStoreDao dao;
21

  
22
	private ResultSetFactory resultSetFactory;
23

  
24
	@Autowired
25
	private MDStoreTransactionManager transactionManager;
26

  
27
	public W3CEndpointReference deliver(final String mdId, final String from, final String until, final String recordFilter) {
28

  
29
		String currentId;
30
		try {
31
			currentId = transactionManager.readMdStore(mdId);
32
			final MDStore mdStore = dao.getMDStore(currentId);
33
			return getResultSetFactory().createResultSet(mdStore.deliver(from, until, recordFilter));
34
		} catch (MDStoreServiceException e) {
35

  
36
			return null;
37
		}
38

  
39
	}
40

  
41
	public Iterable<String> deliver(final String format, final String layout, final String interpretation) {
42
		return Iterables.concat(Iterables.transform(dao.listMDStores(format, layout, interpretation), new Function<String, Iterable<String>>() {
43

  
44
			@Override
45
			public Iterable<String> apply(final String mdId) {
46
				try {
47
					String currentId = transactionManager.readMdStore(mdId);
48
					return dao.getMDStore(currentId).iterate();
49
				} catch (MDStoreServiceException e) {
50
					return null;
51
				}
52

  
53
			}
54
		}));
55
	}
56

  
57
	public String deliverRecord(final String mdId, final String recordId) throws DocumentNotFoundException {
58
		try {
59
			String currentId = transactionManager.readMdStore(mdId);
60
			return dao.getMDStore(currentId).getRecord(recordId);
61
		} catch (MDStoreServiceException e) {
62
			return null;
63
		}
64
	}
65

  
66
	public MDStoreDao getDao() {
67
		return dao;
68
	}
69

  
70
	@Required
71
	public void setDao(final MDStoreDao dao) {
72
		this.dao = dao;
73
	}
74

  
75
	@Required
76
	public void setResultSetFactory(final ResultSetFactory resultSetFactory) {
77
		this.resultSetFactory = resultSetFactory;
78
	}
79

  
80
	public ResultSetFactory getResultSetFactory() {
81
		return resultSetFactory;
82
	}
83

  
84
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreDao.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
import java.util.List;
4

  
5
public interface MDStoreDao {
6

  
7
	MDStore getMDStore(String mdId);
8

  
9
	List<String> listMDStores();
10

  
11
	List<String> listMDStores(String format, String layout, String interpretation);
12

  
13
	void createMDStore(String mdId, String format, String interpretation, String layout);
14

  
15
	void deleteMDStore(String id);
16
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreTransactionInfo.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
import java.util.Date;
4

  
5
public class MDStoreTransactionInfo {
6

  
7
	private String id;
8
	private Boolean refresh;
9
	private Date date;
10
	private long size;
11

  
12
	/**
13
	 * @return the date
14
	 */
15
	public Date getDate() {
16
		return date;
17
	}
18

  
19
	/**
20
	 * @param date
21
	 *            the date to set
22
	 */
23
	public void setDate(final Date date) {
24
		this.date = date;
25
	}
26

  
27
	/**
28
	 * @return the id
29
	 */
30
	public String getId() {
31
		return id;
32
	}
33

  
34
	/**
35
	 * @param id
36
	 *            the id to set
37
	 */
38
	public void setId(final String id) {
39
		this.id = id;
40
	}
41

  
42
	/**
43
	 * @return the refresh
44
	 */
45
	public Boolean getRefresh() {
46
		return refresh;
47
	}
48

  
49
	/**
50
	 * @param refresh
51
	 *            the refresh to set
52
	 */
53
	public void setRefresh(final Boolean refresh) {
54
		this.refresh = refresh;
55
	}
56

  
57
	/**
58
	 * @return the size
59
	 */
60
	public long getSize() {
61
		return size;
62
	}
63

  
64
	/**
65
	 * @param size
66
	 *            the size to set
67
	 */
68
	public void setSize(final long size) {
69
		this.size = size;
70
	}
71

  
72
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreManagerInfo.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

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

  
6
public class MDStoreManagerInfo {
7

  
8
	private String mdId;
9
	private String currentId;
10
	private List<MDStoreExpiredInfo> stillUsed;
11
	private List<MDStoreTransactionInfo> transactions;
12

  
13
	public String getMdId() {
14
		return mdId;
15
	}
16

  
17
	public void setMdId(final String mdId) {
18
		this.mdId = mdId;
19
	}
20

  
21
	public String getCurrentId() {
22
		return currentId;
23
	}
24

  
25
	public void setCurrentId(final String currentId) {
26
		this.currentId = currentId;
27
	}
28

  
29
	public List<MDStoreExpiredInfo> getStillUsed() {
30
		return stillUsed;
31
	}
32

  
33
	public void setStillUsed(final List<MDStoreExpiredInfo> stillUsed) {
34
		this.stillUsed = stillUsed;
35
	}
36

  
37
	public List<MDStoreTransactionInfo> getTransactions() {
38
		return transactions;
39
	}
40

  
41
	public void setTransactions(final List<MDStoreTransactionInfo> transactions) {
42
		this.transactions = transactions;
43
	}
44

  
45
	public void addExpiredItem(final MDStoreExpiredInfo info) {
46
		if (stillUsed == null) {
47
			stillUsed = new ArrayList<MDStoreExpiredInfo>();
48
		}
49
		stillUsed.add(info);
50
	}
51

  
52
	public void addTransactionInfo(final MDStoreTransactionInfo info) {
53
		if (transactions == null) {
54
			transactions = new ArrayList<MDStoreTransactionInfo>();
55
		}
56
		transactions.add(info);
57
	}
58

  
59
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreExpiredInfo.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
import java.util.Date;
4

  
5
public class MDStoreExpiredInfo {
6

  
7
	private String id;
8
	private Date lastRead;
9

  
10
	/**
11
	 * @return the lastRead
12
	 */
13
	public Date getLastRead() {
14
		return lastRead;
15
	}
16

  
17
	/**
18
	 * @param lastRead
19
	 *            the lastRead to set
20
	 */
21
	public void setLastRead(final Date lastRead) {
22
		this.lastRead = lastRead;
23
	}
24

  
25
	/**
26
	 * @return the id
27
	 */
28
	public String getId() {
29
		return id;
30
	}
31

  
32
	/**
33
	 * @param id
34
	 *            the id to set
35
	 */
36
	public void setId(final String id) {
37
		this.id = id;
38
	}
39
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreTransactionManager.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
import eu.dnetlib.data.mdstore.MDStoreServiceException;
4

  
5
public interface MDStoreTransactionManager {
6

  
7
	/**
8
	 * Creates the md store.
9
	 * 
10
	 * @param mdId
11
	 *            the md id
12
	 * @throws MDStoreServiceException
13
	 *             the MD store service exception
14
	 */
15
	public abstract void createMDStore(String mdId) throws MDStoreServiceException;
16

  
17
	/**
18
	 * Drop md store.
19
	 * 
20
	 * @param mdId
21
	 *            the md id
22
	 * @throws MDStoreServiceException
23
	 *             the MD store service exception
24
	 */
25
	public abstract void dropMDStore(String mdId) throws MDStoreServiceException;
26

  
27
	/**
28
	 * Gets the MD store collection.
29
	 * 
30
	 * @param mdId
31
	 *            the md id
32
	 * @return the MD store collection
33
	 * @throws MDStoreServiceException
34
	 *             the MD store service exception
35
	 */
36
	public abstract String getMDStoreCollection(String mdId) throws MDStoreServiceException;
37

  
38
	/**
39
	 * Start a new transaction for writing in the mdstore this will create a temporary mdstore in which save the content. and after finished
40
	 * switch it to the existing one
41
	 * 
42
	 * @param mdId
43
	 * @param refresh
44
	 * @throws MDStoreServiceException
45
	 *             if the mdStore Id doesn't exists in the metadata
46
	 */
47
	public abstract String startTransaction(String mdId, boolean refresh) throws MDStoreServiceException;
48

  
49
	/**
50
	 * Commit the transaction
51
	 * 
52
	 * 
53
	 * @param transactionId
54
	 * @param mdId
55
	 * @return
56
	 * @throws MDStoreServiceException
57
	 */
58
	public abstract boolean commit(String transactionId, String mdId) throws MDStoreServiceException;
59

  
60
	/**
61
	 * Book a a current mdstore, so the transaction manager can't delete during a possible commit, until the resultset associate has not
62
	 * expired
63
	 * 
64
	 * @param mdStoreId
65
	 * @return
66
	 * @throws MDStoreServiceException
67
	 */
68
	public abstract String readMdStore(String mdStoreId) throws MDStoreServiceException;
69

  
70
	/**
71
	 * Return a JSON about the transaction assigned to a particular mdstore
72
	 * 
73
	 * @param mdStoreId
74
	 * @return
75
	 * @throws MDStoreServiceException
76
	 */
77
	public abstract MDStoreManagerInfo getInfoForCurrentMdStore(String mdStoreId) throws MDStoreServiceException;
78

  
79
	/**
80
	 * Manually drop an old collection assigned to a particular mdStore
81
	 * 
82
	 * @param mdId
83
	 *            : the id of the mdStore
84
	 * @param idToDrop
85
	 *            : The id of the collection to be dropped
86
	 * @return
87
	 * @throws MDStoreServiceException
88
	 */
89
	public abstract Boolean dropUsed(String mdId, String idToDrop) throws MDStoreServiceException;
90

  
91
	/**
92
	 * Manually drop an old collection assigned to a particular mdStore
93
	 * 
94
	 * @param mdId
95
	 *            : the id of the mdStore
96
	 * @param idToDrop
97
	 *            : The id of the collection to be dropped
98
	 * @return
99
	 * @throws MDStoreServiceException
100
	 */
101
	public abstract Boolean dropTransaction(String mdId, String idToDrop) throws MDStoreServiceException;
102

  
103
	/**
104
	 * Start the garbage collection of the old mdstore not used
105
	 * 
106
	 * @throws MDStoreServiceException
107
	 */
108
	public abstract void garbage() throws MDStoreServiceException;
109

  
110
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStore.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
4
import eu.dnetlib.enabling.resultset.ResultSetListener;
5

  
6
public interface MDStore {
7

  
8
	String getId();
9

  
10
	String getFormat();
11

  
12
	String getInterpretation();
13

  
14
	String getLayout();
15

  
16
	void truncate();
17

  
18
	int feed(Iterable<String> records, boolean incremental);
19

  
20
	ResultSetListener deliver(String from, String until, String recordFilter);
21

  
22
	ResultSetListener deliverIds(String from, String until, String recordFilter);
23

  
24
	Iterable<String> iterate();
25

  
26
	int getSize();
27

  
28
	void deleteRecord(String recordId);
29

  
30
	String getRecord(String recordId) throws DocumentNotFoundException;
31

  
32
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreResults.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
public class MDStoreResults {
4
	private Iterable<String> records;
5
	private int size;
6

  
7
	public MDStoreResults(Iterable<String> records, int size) {
8
		super();
9
		this.records = records;
10
		this.size = size;
11
	}
12

  
13
	public int getSize() {
14
		return size;
15
	}
16

  
17
	public void setSize(int size) {
18
		this.size = size;
19
	}
20

  
21
	public Iterable<String> getRecords() {
22
		return records;
23
	}
24

  
25
	public void setRecords(Iterable<String> records) {
26
		this.records = records;
27
	}
28
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/ModularMDStoreService.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import java.util.List;
4

  
5
import javax.xml.ws.wsaddressing.W3CEndpointReference;
6

  
7
import org.springframework.beans.factory.annotation.Required;
8

  
9
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
10
import eu.dnetlib.data.mdstore.MDStoreService;
11
import eu.dnetlib.data.mdstore.MDStoreServiceException;
12
import eu.dnetlib.enabling.resultset.IterableResultSetFactory;
13
import eu.dnetlib.enabling.tools.AbstractBaseService;
14
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
15

  
16
public class ModularMDStoreService extends AbstractBaseService implements MDStoreService {
17

  
18
	/**
19
	 * notification handler.
20
	 */
21
	private NotificationHandler notificationHandler;
22

  
23
	private MDStoreFeeder feeder;
24

  
25
	private MDStoreRetriever retriever;
26

  
27
	private IterableResultSetFactory iterableResultSetFactory;
28

  
29
	@Override
30
	public W3CEndpointReference deliverMDRecords(final String mdId, final String from, final String until, final String recordFilter)
31
			throws MDStoreServiceException {
32
		return retriever.deliver(mdId, from, until, recordFilter);
33
	}
34

  
35
	@Override
36
	public W3CEndpointReference bulkDeliverMDRecords(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
37
		return getIterableResultSetFactory().createIterableResultSet(retriever.deliver(format, layout, interpretation));
38
	}
39

  
40
	@Override
41
	public String deliverRecord(final String mdId, final String recordId) throws DocumentNotFoundException {
42
		return retriever.deliverRecord(mdId, recordId);
43
	}
44

  
45
	@Override
46
	public List<String> getListOfMDStores() throws MDStoreServiceException {
47
		return retriever.getDao().listMDStores();
48
	}
49

  
50
	@Override
51
	public List<String> listMDStores(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
52
		return retriever.getDao().listMDStores(format, layout, interpretation);
53
	}
54

  
55
	@Override
56
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
57
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
58
	}
59

  
60
	@Override
61
	public boolean storeMDRecordsFromRS(final String mdId, final String rsId, final String storingType) throws MDStoreServiceException {
62
		throw new MDStoreServiceException("not implemented, use the Blackboard asynchronous equivalent");
63
	}
64

  
65
	public NotificationHandler getNotificationHandler() {
66
		return notificationHandler;
67
	}
68

  
69
	@Required
70
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
71
		this.notificationHandler = notificationHandler;
72
	}
73

  
74
	public MDStoreFeeder getFeeder() {
75
		return feeder;
76
	}
77

  
78
	public void setFeeder(final MDStoreFeeder feeder) {
79
		this.feeder = feeder;
80
	}
81

  
82
	public MDStoreRetriever getRetriever() {
83
		return retriever;
84
	}
85

  
86
	public void setRetriever(final MDStoreRetriever retriever) {
87
		this.retriever = retriever;
88
	}
89

  
90
	public IterableResultSetFactory getIterableResultSetFactory() {
91
		return iterableResultSetFactory;
92
	}
93

  
94
	@Required
95
	public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) {
96
		this.iterableResultSetFactory = iterableResultSetFactory;
97
	}
98

  
99
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/FeedFailedCallback.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
public interface FeedFailedCallback {
4

  
5
	void call(Throwable e);
6
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/FeedDoneCallback.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
public interface FeedDoneCallback {
4

  
5
	void call(int size);
6
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5
import org.springframework.beans.factory.annotation.Required;
6

  
7
import eu.dnetlib.data.mdstore.MDStoreServiceException;
8
import eu.dnetlib.data.mdstore.modular.connector.MDStore;
9
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
10
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
11
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
12
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
13
import eu.dnetlib.enabling.tools.ServiceLocator;
14
import eu.dnetlib.miscutils.datetime.DateUtils;
15

  
16
public class MDStoreFeeder {
17

  
18
	private static final Log log = LogFactory.getLog(MDStoreFeeder.class);
19

  
20
	private MDStoreDao dao;
21

  
22
	private ResultSetClientFactory resultSetClientFactory;
23

  
24
	private ServiceLocator<ISRegistryService> registryLocator;
25

  
26
	private MDStoreTransactionManager transactionManager;
27

  
28
	private boolean syncFeed = true;
29

  
30
	public void feed(final String mdId,
31
			final String rsEpr,
32
			final String storingType,
33
			final boolean sync,
34
			final FeedDoneCallback doneCallback,
35
			final FeedFailedCallback failCallback) throws MDStoreServiceException {
36
		log.info("Start feeding mdstore " + mdId + " with epr " + rsEpr);
37

  
38
		String temporaryID = "";
39
		try {
40
			final boolean incremental = !"REFRESH".equals(storingType);
41

  
42
			temporaryID = transactionManager.startTransaction(mdId, !incremental);
43

  
44
			final MDStore mdstore = dao.getMDStore(temporaryID);
45

  
46
			final Iterable<String> records = resultSetClientFactory.getClient(rsEpr);
47

  
48
			if (!incremental) {
49
				mdstore.truncate();
50
			}
51

  
52
			final int size = mdstore.feed(records, incremental);
53

  
54
			transactionManager.commit(temporaryID, mdId);
55

  
56
			touch(mdId, size);
57

  
58
			log.info("Finished feeding mdstore " + mdId + " - new size: " + size);
59

  
60
			doneCallback.call(size);
61
		} catch (Exception e) {
62
			log.error("Error feeding mdstore: " + mdId + ", temporary id: " + temporaryID);
63
			failCallback.call(e);
64
		}
65
	}
66

  
67
	/**
68
	 * Sets the last modified date in the profile.
69
	 * 
70
	 * @param mdId
71
	 */
72
	public void touch(final String mdId, final int size) {
73
		try {
74
			final String now = DateUtils.now_ISO8601();
75

  
76
			final String mdstoreXUpdate =
77
					"for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" + "return update value $x//LAST_STORAGE_DATE with '" + now
78
							+ "'";
79

  
80
			registryLocator.getService().executeXUpdate(mdstoreXUpdate);
81

  
82
			touchSize(mdId, size);
83
		} catch (final Exception e) {
84
			throw new IllegalStateException(e);
85
		}
86
	}
87

  
88
	public void touchSize(final String mdId, final int size) {
89
		try {
90
			final String mdstoreNumberXUpdate =
91
					"for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" + "return update value $x//NUMBER_OF_RECORDS with '" + size
92
							+ "'";
93

  
94
			registryLocator.getService().executeXUpdate(mdstoreNumberXUpdate);
95
		} catch (final Exception e) {
96
			throw new IllegalStateException(e);
97
		}
98
	}
99

  
100
	public MDStoreDao getDao() {
101
		return dao;
102
	}
103

  
104
	@Required
105
	public void setDao(final MDStoreDao dao) {
106
		this.dao = dao;
107
	}
108

  
109
	public ResultSetClientFactory getResultSetClientFactory() {
110
		return resultSetClientFactory;
111
	}
112

  
113
	@Required
114
	public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) {
115
		this.resultSetClientFactory = resultSetClientFactory;
116
	}
117

  
118
	public ServiceLocator<ISRegistryService> getRegistryLocator() {
119
		return registryLocator;
120
	}
121

  
122
	@Required
123
	public void setRegistryLocator(final ServiceLocator<ISRegistryService> registryLocator) {
124
		this.registryLocator = registryLocator;
125
	}
126

  
127
	public boolean isSyncFeed() {
128
		return syncFeed;
129
	}
130

  
131
	public void setSyncFeed(final boolean syncFeed) {
132
		this.syncFeed = syncFeed;
133
	}
134

  
135
	/**
136
	 * @return the transactionManager
137
	 */
138
	public MDStoreTransactionManager getTransactionManager() {
139
		return transactionManager;
140
	}
141

  
142
	/**
143
	 * @param transactionManager
144
	 *            the transactionManager to set
145
	 */
146
	@Required
147
	public void setTransactionManager(final MDStoreTransactionManager transactionManager) {
148
		this.transactionManager = transactionManager;
149
	}
150
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/AbstractMDStoreAction.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
4

  
5
public abstract class AbstractMDStoreAction {
6
	private MDStoreDao dao;
7

  
8
	public MDStoreDao getDao() {
9
		return dao;
10
	}
11

  
12
	public void setDao(MDStoreDao dao) {
13
		this.dao = dao;
14
	}
15
	
16
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/StreamingRecordParser.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Stack;
7

  
8
import javax.xml.stream.XMLInputFactory;
9
import javax.xml.stream.XMLStreamConstants;
10
import javax.xml.stream.XMLStreamException;
11
import javax.xml.stream.XMLStreamReader;
12

  
13
/**
14
 * This method outperforms SimpleRecordParser by a vast amount, especially since we are just getting stuff in the
15
 * header.
16
 * 
17
 * @author marko
18
 * 
19
 */
20
public class StreamingRecordParser implements RecordParser {
21

  
22
	@Override
23
	public Map<String, String> parseRecord(String record) {
24

  
25
		try {
26
			XMLInputFactory factory = XMLInputFactory.newInstance();
27
			XMLStreamReader parser = factory.createXMLStreamReader(new ByteArrayInputStream(record.getBytes()));
28

  
29
			HashMap<String, String> res = new HashMap<String, String>();
30

  
31
			Stack<String> elementStack = new Stack<String>();
32
			elementStack.push("/");
33

  
34
			while (parser.hasNext()) {
35
				int event = parser.next();
36

  
37
				if (event == XMLStreamConstants.END_ELEMENT) {
38
					elementStack.pop();
39
				} else if (event == XMLStreamConstants.START_ELEMENT) {
40
					final String localName = parser.getLocalName();
41
					elementStack.push(localName);
42

  
43
					if ("objIdentifier".equals(localName)) {
44
						parser.next();
45

  
46
						res.put("id", parser.getText().trim());
47

  
48
					} else if ("identifier".equals(localName) && "efgEntity".equals(grandParent(elementStack))) {
49
						if (!res.containsKey("originalId")) {
50
							parser.next();
51
//							log.info("ZZZZZZ OK: found identifier at right depth " + elementStack);
52
							res.put("originalId", parser.getText().trim());
53
						}
54
					}
55

  
56
					else if ("identifier".equals(localName)) {
57

  
58
//						log.info("ZZZZZZ: found identifier not at right depth " + elementStack + " grand parent " + grandParent(elementStack));
59
					}
60

  
61
					if (res.containsKey("id") && res.containsKey("originalId"))
62
						return res;
63
				}
64
			}
65
			return res;
66
		} catch (XMLStreamException e) {
67
			throw new IllegalStateException(e);
68
		}
69

  
70
	}
71

  
72
	private String grandParent(Stack<String> elementStack) {
73
		if (elementStack.size() <= 3)
74
			return "";
75
		return elementStack.get(elementStack.size() - 3);
76
	}
77

  
78
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/SimpleRecordParser.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import java.io.StringReader;
4
import java.util.HashMap;
5
import java.util.Map;
6

  
7
import javax.xml.xpath.XPath;
8
import javax.xml.xpath.XPathFactory;
9

  
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.xml.sax.InputSource;
13

  
14
/**
15
 * Terrible implementation of a record parser.
16
 * 
17
 * @author marko
18
 *
19
 */
20
public class SimpleRecordParser implements RecordParser {
21
	static final Log log = LogFactory.getLog(SimpleRecordParser.class); // NOPMD by marko on 11/24/08 5:02 PM
22

  
23
	@Override
24
	public Map<String, String> parseRecord(String record) {
25
		Map<String, String> props = new HashMap<String, String>();
26

  
27
		try {
28
//			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
29
			XPath xpath = XPathFactory.newInstance().newXPath();
30

  
31
//			Document doc = builder.parse(new InputSource(new StringReader(record)));
32
			InputSource doc = new InputSource(new StringReader(record));
33
			
34
			props.put("id", xpath.evaluate("//*[local-name()='objIdentifier']", doc));
35
			props.put("originalId", xpath.evaluate("//*[local-name()='efgEntity']/*/*[local-name()='identifier']", doc));
36
			
37
//			String date = xpath.evaluate("//*[local-name()='dateOfCollection'][1]", doc);
38
//			props.put("date", new Date(date).getTime());	
39
				
40
		} catch (Exception e) {
41
			log.warn("got exception while parsing document", e);
42
			log.warn("record is:");
43
			log.warn(record);
44
			log.warn("------------");
45
		}
46
		return props;
47

  
48
	}
49

  
50
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreProfileCreator.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import javax.xml.ws.Endpoint;
4

  
5
import org.antlr.stringtemplate.StringTemplate;
6
import org.springframework.beans.factory.annotation.Required;
7

  
8
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
9
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
10
import eu.dnetlib.enabling.tools.ServiceLocator;
11
import eu.dnetlib.soap.EndpointReferenceBuilder;
12

  
13
public class MDStoreProfileCreator {
14
	/**
15
	 * registry service locator.
16
	 */
17
	private ServiceLocator<ISRegistryService> registryLocator;
18

  
19
	/**
20
	 * mdstore ds template.
21
	 */
22
	private StringTemplate mdstoreDsTemplate;
23

  
24
	/**
25
	 * service endpoint.
26
	 */
27
	private Endpoint endpoint;
28

  
29
	/**
30
	 * endpoint builder.
31
	 */
32
	private EndpointReferenceBuilder<Endpoint> eprBuilder;
33

  
34
	public String registerProfile(String format, String interpretation, String layout) throws ISRegistryException {
35
		// XXX: mini hack
36
		StringTemplate template = new StringTemplate(mdstoreDsTemplate.getTemplate());
37
		template.setAttribute("serviceUri", eprBuilder.getAddress(endpoint));
38
		template.setAttribute("format", format);
39
		template.setAttribute("interpretation", interpretation);
40
		template.setAttribute("layout", layout);
41

  
42
		return registryLocator.getService().registerProfile(template.toString());
43
	}
44

  
45
	public ServiceLocator<ISRegistryService> getRegistryLocator() {
46
		return registryLocator;
47
	}
48

  
49
	@Required
50
	public void setRegistryLocator(ServiceLocator<ISRegistryService> registryLocator) {
51
		this.registryLocator = registryLocator;
52
	}
53

  
54
	public StringTemplate getMdstoreDsTemplate() {
55
		return mdstoreDsTemplate;
56
	}
57

  
58
	@Required
59
	public void setMdstoreDsTemplate(StringTemplate mdstoreDsTemplate) {
60
		this.mdstoreDsTemplate = mdstoreDsTemplate;
61
	}
62

  
63
	public Endpoint getEndpoint() {
64
		return endpoint;
65
	}
66

  
67
	@Required
68
	public void setEndpoint(Endpoint endpoint) {
69
		this.endpoint = endpoint;
70
	}
71

  
72
	public EndpointReferenceBuilder<Endpoint> getEprBuilder() {
73
		return eprBuilder;
74
	}
75

  
76
	@Required
77
	public void setEprBuilder(EndpointReferenceBuilder<Endpoint> eprBuilder) {
78
		this.eprBuilder = eprBuilder;
79
	}
80
}
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/RecordParserFactory.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import org.springframework.beans.factory.annotation.Required;
4

  
5
import eu.dnetlib.miscutils.factory.Factory;
6

  
7
public class RecordParserFactory implements Factory<RecordParser> {
8
	
9
	private Class<? extends RecordParser> parserType;
10

  
11
	@Override
12
	public RecordParser newInstance() {
13
		try {
14
			return getParserType().newInstance();
15
		} catch (Throwable e) {
16
			throw new RuntimeException(e);
17
		} 	
18
	}
19

  
20
	@Required
21
	public void setParserType(Class<? extends RecordParser> parserType) {
22
		this.parserType = parserType;
23
	}
24

  
25
	public Class<? extends RecordParser> getParserType() {
26
		return parserType;
27
	}
28

  
29

  
30
}
0 31

  
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-3.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/BulkRecordMapperFactory.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import java.io.StringReader;
4
import java.io.StringWriter;
5
import java.util.List;
6

  
7
import javax.xml.namespace.QName;
8
import javax.xml.stream.XMLEventFactory;
9
import javax.xml.stream.XMLEventReader;
10
import javax.xml.stream.XMLEventWriter;
11
import javax.xml.stream.XMLInputFactory;
12
import javax.xml.stream.XMLOutputFactory;
13
import javax.xml.stream.XMLStreamException;
14
import javax.xml.stream.events.Namespace;
15
import javax.xml.stream.events.StartElement;
16
import javax.xml.stream.events.XMLEvent;
17

  
18
import org.apache.commons.logging.Log;
19
import org.apache.commons.logging.LogFactory;
20

  
21
import com.google.common.base.Function;
22
import com.google.common.collect.Lists;
23

  
24
import eu.dnetlib.miscutils.collections.Pair;
25
import eu.dnetlib.miscutils.factory.Factory;
26

  
27
public class BulkRecordMapperFactory implements Factory<Function<String, Pair<String, String>>> {
28
	
29
	private static final Log log = LogFactory.getLog(BulkRecordMapperFactory.class); // NOPMD by marko on 11/24/08 5:02 PM
30
	
31
	protected static final String MD_RECORD = "mdRecord";
32
	
33
	protected static final String MD_ID = "mdId";
34
	
35
	protected static final String RECORD = "record";
36

  
37
	protected ThreadLocal<XMLInputFactory> inputFactory = new ThreadLocal<XMLInputFactory>() {
38
		@Override
39
		protected XMLInputFactory initialValue() {
40
			return XMLInputFactory.newInstance();
41
		}
42
	};
43

  
44
	protected ThreadLocal<XMLOutputFactory> outputFactory = new ThreadLocal<XMLOutputFactory>() {
45
		@Override
46
		protected XMLOutputFactory initialValue() {
47
			return XMLOutputFactory.newInstance();
48
		}
49
	};
50

  
51
	protected ThreadLocal<XMLEventFactory> eventFactory = new ThreadLocal<XMLEventFactory>() {
52
		@Override
53
		protected XMLEventFactory initialValue() {
54
			return XMLEventFactory.newInstance();
55
		}
56
	};
57
	
58
	@Override
59
	public Function<String, Pair<String, String>> newInstance() {
60
		return new Function<String, Pair<String, String>>() {
61
			private String mdId = null;
62
			private String record = null;
63
			@Override
64
			public Pair<String, String> apply(String embeddedRecord) {
65
				try {
66
					final XMLEventReader parser = inputFactory.get().createXMLEventReader(new StringReader(embeddedRecord));
67

  
68
					while (parser.hasNext()) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff