Project

General

Profile

« Previous | Next » 

Revision 34223

created tag for indexing fields

View differences:

modules/cnr-modular-mdstore-service/branches/indexFields/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>4.0.4-SNAPSHOT</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-modular-mdstore-service/trunk</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>[2.2.0,3.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>[2.0.0,3.0.0)</version>
61
		</dependency>
62
		<dependency>
63
			<groupId>eu.dnetlib</groupId>
64
			<artifactId>cnr-resultset-client</artifactId>
65
			<version>[2.0.0,3.0.0)</version>
66
		</dependency>
67
	</dependencies>
68
</project>
modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreActions.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.mdstore.modular;
5

  
6
public enum MDStoreActions {
7
	CREATE,
8
	DELETE,
9
	FEED
10
}
modules/cnr-modular-mdstore-service/branches/indexFields/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
import eu.dnetlib.data.mdstore.MDStoreServiceException;
6
import eu.dnetlib.data.mdstore.modular.MDStoreDescription;
7

  
8
public interface MDStoreDao {
9

  
10
	MDStore getMDStore(String mdId) throws MDStoreServiceException;
11

  
12
	MDStore readMDStore(String mdId) throws MDStoreServiceException;
13

  
14
	MDStore startTransaction(String mdId, boolean refresh) throws MDStoreServiceException;
15

  
16
	void commit(String transactionId, String mdId) throws MDStoreServiceException;
17

  
18
	List<MDStoreDescription> listMDStores() throws MDStoreServiceException;
19

  
20
	List<String> listMDStores(String format, String layout, String interpretation) throws MDStoreServiceException;
21

  
22
	void createMDStore(String mdId, String format, String interpretation, String layout) throws MDStoreServiceException;
23

  
24
	void deleteMDStore(String id) throws MDStoreServiceException;
25

  
26
	int getCachedSize(String id) throws MDStoreServiceException;
27

  
28
	void refreshSizes() throws MDStoreServiceException;
29

  
30
	int refreshSize(String id) throws MDStoreServiceException;
31

  
32
	void startGarbage() throws MDStoreServiceException;
33

  
34
	MDStoreDBStatus getDBStatus();
35
}
modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreDBStatus.java
1
package eu.dnetlib.data.mdstore.modular.connector;
2

  
3
public class MDStoreDBStatus {
4

  
5
	private int handledDatastructures;
6
	private int usedDiskSpace;
7
	private String date;
8

  
9
	public MDStoreDBStatus() {}
10

  
11
	public MDStoreDBStatus(final int handledDatastructures, final int usedDiskSpace, final String date) {
12
		this.handledDatastructures = handledDatastructures;
13
		this.usedDiskSpace = usedDiskSpace;
14
		this.date = date;
15
	}
16

  
17
	public int getHandledDatastructures() {
18
		return handledDatastructures;
19
	}
20

  
21
	public void setHandledDatastructures(final int handledDatastructures) {
22
		this.handledDatastructures = handledDatastructures;
23
	}
24

  
25
	public int getUsedDiskSpace() {
26
		return usedDiskSpace;
27
	}
28

  
29
	public void setUsedDiskSpace(final int usedDiskSpace) {
30
		this.usedDiskSpace = usedDiskSpace;
31
	}
32

  
33
	public String getDate() {
34
		return date;
35
	}
36

  
37
	public void setDate(final String date) {
38
		this.date = date;
39
	}
40

  
41
}
modules/cnr-modular-mdstore-service/branches/indexFields/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:serviceLocator-ref="uniqueServiceLocator" 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:serviceLocator-ref="uniqueServiceLocator" 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:serviceLocator-ref="uniqueServiceLocator" />
61

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

  
65

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

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

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

  
83
	<template:instance name="serviceRegistrationManager"
84
		t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl"
85
		t:name="mdStoreServiceRegistrationManager" t:service="mdStoreService"
86
		t:endpoint="mdStoreServiceEndpoint" t:jobScheduler="jobScheduler"
87
		t:serviceRegistrator="blackboardServiceRegistrator" />
88
</beans>
modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/mdstoreds-template.xml
1
<?xml version="1.0"?>
2
<RESOURCE_PROFILE>
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="MDStoreDSResourceType" />
6
		<RESOURCE_KIND value="MDStoreDSResources" />
7
		<RESOURCE_URI value="$serviceUri$?wsdl" />
8
		<DATE_OF_CREATION value="" />
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<METADATA_FORMAT>$format$</METADATA_FORMAT>
13
			<METADATA_FORMAT_INTERPRETATION>$interpretation$
14
			</METADATA_FORMAT_INTERPRETATION>
15
			<METADATA_FORMAT_LAYOUT>$layout$</METADATA_FORMAT_LAYOUT>
16
		</CONFIGURATION>
17
		<STATUS>
18
			<PENULTIMATE_STORAGE_DATE></PENULTIMATE_STORAGE_DATE>
19
			<LAST_STORAGE_DATE></LAST_STORAGE_DATE>
20
			<NUMBER_OF_RECORDS>0</NUMBER_OF_RECORDS>
21
			<FETCHING_FREQUENCY />
22
			<STATISTICS_FIELDS />
23
		</STATUS>
24
		<SECURITY_PARAMETERS />
25
	</BODY>
26
</RESOURCE_PROFILE>
modules/cnr-modular-mdstore-service/branches/indexFields/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
	 * Verify consistency.
9
	 *
10
	 * @throws MDStoreServiceException
11
	 *             the MD store service exception
12
	 */
13
	public abstract void verifyConsistency() throws MDStoreServiceException;
14

  
15
	/**
16
	 * Creates the md store.
17
	 *
18
	 * @param mdId
19
	 *            the md id
20
	 * @throws MDStoreServiceException
21
	 *             the MD store service exception
22
	 */
23
	public abstract void createMDStore(String mdId) throws MDStoreServiceException;
24

  
25
	/**
26
	 * Drop md store.
27
	 *
28
	 * @param mdId
29
	 *            the md id
30
	 * @throws MDStoreServiceException
31
	 *             the MD store service exception
32
	 */
33
	public abstract void dropMDStore(String mdId) throws MDStoreServiceException;
34

  
35
	/**
36
	 * Gets the MD store collection.
37
	 *
38
	 * @param mdId
39
	 *            the md id
40
	 * @return the MD store collection
41
	 * @throws MDStoreServiceException
42
	 *             the MD store service exception
43
	 */
44
	public abstract String getMDStoreCollection(String mdId) throws MDStoreServiceException;
45

  
46
	/**
47
	 * Start a new transaction for writing in the mdstore this will create a temporary mdstore in which save the content. and after finished
48
	 * switch it to the existing one
49
	 *
50
	 * @param mdId
51
	 * @param refresh
52
	 * @throws MDStoreServiceException
53
	 *             if the mdStore Id doesn't exists in the metadata
54
	 */
55
	public abstract String startTransaction(String mdId, boolean refresh) throws MDStoreServiceException;
56

  
57
	/**
58
	 * Commit the transaction.
59
	 *
60
	 * @param transactionId
61
	 *            the transaction id
62
	 * @param mdstoreId
63
	 *            the mdstore id
64
	 * @param currentMDStore
65
	 *            the current md store
66
	 * @return true, if successful
67
	 * @throws MDStoreServiceException
68
	 *             the MD store service exception
69
	 */
70
	public abstract boolean commit(String transactionId, String mdstoreId, MDStore currentMDStore) throws MDStoreServiceException;
71

  
72
	/**
73
	 * Book a a current mdstore, so the transaction manager can't delete during a possible commit, until the resultset associate has not
74
	 * expired
75
	 *
76
	 * @param mdStoreId
77
	 * @return
78
	 * @throws MDStoreServiceException
79
	 */
80
	public abstract String readMdStore(String mdStoreId) throws MDStoreServiceException;
81

  
82
	/**
83
	 * Return a JSON about the transaction assigned to a particular mdstore
84
	 *
85
	 * @param mdStoreId
86
	 * @return
87
	 * @throws MDStoreServiceException
88
	 */
89
	public abstract MDStoreManagerInfo getInfoForCurrentMdStore(String mdStoreId) 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 dropUsed(String mdId, String idToDrop) throws MDStoreServiceException;
102

  
103
	/**
104
	 * Manually drop an old collection assigned to a particular mdStore
105
	 *
106
	 * @param mdId
107
	 *            : the id of the mdStore
108
	 * @param idToDrop
109
	 *            : The id of the collection to be dropped
110
	 * @return
111
	 * @throws MDStoreServiceException
112
	 */
113
	public abstract Boolean dropTransaction(String mdId, String idToDrop) throws MDStoreServiceException;
114

  
115
	/**
116
	 * Start the garbage collection of the old mdstore not used
117
	 *
118
	 * @throws MDStoreServiceException
119
	 */
120
	public abstract void garbage() throws MDStoreServiceException;
121

  
122
}
modules/cnr-modular-mdstore-service/branches/indexFields/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
	void 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/branches/indexFields/src/test/java/eu/dnetlib/enabling/tools/blackboard/BlackboardServerActionExecutorTest.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import static org.junit.Assert.assertNotNull;
4
import static org.mockito.Matchers.anyObject;
5
import static org.mockito.Matchers.eq;
6
import static org.mockito.Mockito.mock;
7
import static org.mockito.Mockito.verify;
8
import static org.mockito.Mockito.when;
9

  
10
import javax.annotation.Resource;
11

  
12
import org.junit.Before;
13
import org.junit.Test;
14
import org.junit.runner.RunWith;
15
import org.springframework.test.context.ContextConfiguration;
16
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17

  
18
import eu.dnetlib.data.mdstore.modular.MDStoreActions;
19

  
20
@RunWith(SpringJUnit4ClassRunner.class)
21
@ContextConfiguration
22
public class BlackboardServerActionExecutorTest {
23

  
24
	@Resource
25
	public transient BlackboardServerHandler blackboardHandler;
26

  
27
	@Resource
28
	public transient BlackboardServerActionExecutor<MDStoreActions> executor;
29

  
30
	@Before
31
	public void setUp() throws Exception {
32

  
33
	}
34

  
35
	@Test
36
	public void testExecutor() {
37
		assertNotNull(executor);
38

  
39
		BlackboardJob job = mock(BlackboardJob.class);
40
		when(job.getAction()).thenReturn("CREATE");
41

  
42
		executor.execute(job);
43

  
44
		verify(blackboardHandler).done(eq(job));
45
	}
46

  
47
	@Test
48
	public void testExecutorUnimplemented() {
49
		assertNotNull(executor);
50

  
51
		BlackboardJob job = mock(BlackboardJob.class);
52
		when(job.getAction()).thenReturn("DELETE");
53

  
54
		executor.execute(job);
55

  
56
		verify(blackboardHandler).failed(eq(job), (Throwable) anyObject());
57
	}
58
}
modules/cnr-modular-mdstore-service/branches/indexFields/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/branches/indexFields/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-modular-mdstore-service/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-modular-mdstore-service"}
modules/cnr-modular-mdstore-service/branches/indexFields/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/branches/indexFields/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/branches/indexFields/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/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreRetriever.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import com.google.common.base.Function;
4
import com.google.common.collect.Iterables;
5
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
6
import eu.dnetlib.data.mdstore.MDStoreServiceException;
7
import eu.dnetlib.data.mdstore.modular.connector.MDStore;
8
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
9
import eu.dnetlib.enabling.resultset.ResultSetFactory;
10
import org.springframework.beans.factory.annotation.Required;
11

  
12
import javax.xml.ws.wsaddressing.W3CEndpointReference;
13

  
14
public class MDStoreRetriever {
15

  
16
    private MDStoreDao dao;
17

  
18
    private ResultSetFactory resultSetFactory;
19

  
20
    public W3CEndpointReference deliver(final String mdId, final String from, final String until, final String recordFilter) throws MDStoreServiceException {
21
        final MDStore mdStore = dao.readMDStore(mdId);
22
        return getResultSetFactory().createResultSet(mdStore.deliver(from, until, recordFilter));
23
    }
24

  
25
    public Iterable<String> deliver(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
26
        try {
27
            return Iterables.concat(Iterables.transform(dao.listMDStores(format, layout, interpretation), new Function<String, Iterable<String>>() {
28

  
29
                @Override
30
                public Iterable<String> apply(final String mdId) {
31
                    try {
32
                        return dao.readMDStore(mdId).iterate();
33
                    } catch (MDStoreServiceException e) {
34
                        throw new RuntimeException(e);
35
                    }
36
                }
37
            }));
38
        } catch (RuntimeException e) {
39
            throw new MDStoreServiceException(e);
40
        }
41
    }
42

  
43
    public String deliverRecord(final String mdId, final String recordId) throws MDStoreServiceException, DocumentNotFoundException {
44
        return dao.getMDStore(mdId).getRecord(recordId);
45
    }
46

  
47
    public MDStoreDao getDao() {
48
        return dao;
49
    }
50

  
51
    @Required
52
    public void setDao(final MDStoreDao dao) {
53
        this.dao = dao;
54
    }
55

  
56
    @Required
57
    public void setResultSetFactory(final ResultSetFactory resultSetFactory) {
58
        this.resultSetFactory = resultSetFactory;
59
    }
60

  
61
    public ResultSetFactory getResultSetFactory() {
62
        return resultSetFactory;
63
    }
64

  
65
}
modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/AbstractMDStoreAction.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3
import java.util.concurrent.Executor;
4
import java.util.concurrent.Executors;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.antlr.stringtemplate.StringTemplate;
9
import org.apache.commons.io.IOUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.springframework.core.io.ClassPathResource;
13

  
14
import eu.dnetlib.data.mdstore.MDStoreServiceException;
15
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
16
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
17
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
18
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
19
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
20
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
21

  
22
/**
23
 * The Class AbstractMDStoreAction.
24
 */
25
public abstract class AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> {
26

  
27
	@Resource
28
	private UniqueServiceLocator serviceLocator;
29

  
30
	/** The dao. */
31
	private MDStoreDao dao;
32

  
33
	/** The executor. */
34
	private final Executor executor = Executors.newCachedThreadPool();
35

  
36
	/** Logger */
37
	private static final Log log = LogFactory.getLog(AbstractMDStoreAction.class);
38

  
39
	private static final ClassPathResource mdstoreServiceStatusTemplate = new ClassPathResource(
40
			"/eu/dnetlib/data/mdstore/modular/mdstoreServiceStatusTemplate.xml.st");
41

  
42
	/**
43
	 * Execute async.
44
	 * 
45
	 * @param handler
46
	 *            the handler
47
	 * @param job
48
	 *            the job
49
	 * @throws MDStoreServiceException
50
	 *             the MD store service exception
51
	 */
52
	protected abstract void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException;
53

  
54
	/*
55
	 * (non-Javadoc)
56
	 * 
57
	 * @see
58
	 * eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction#execute(eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler,
59
	 * eu.dnetlib.enabling.tools.blackboard.BlackboardJob)
60
	 */
61
	@Override
62
	public void execute(final BlackboardServerHandler handler, final BlackboardJob job) {
63
		executor.execute(new Runnable() {
64

  
65
			@Override
66
			public void run() {
67
				try {
68
					handler.ongoing(job);
69
					executeAsync(handler, job);
70
				} catch (MDStoreServiceException e) {
71
					handler.failed(job, e);
72
				}
73
			}
74
		});
75
	}
76

  
77
	protected void completeWithSuccess(final BlackboardServerHandler handler, final BlackboardJob job) {
78
		// Don't change this synchronization rule
79
		synchronized (this) {
80
			updateMDStoreServiceProfile(job);
81
			handler.done(job);
82
		}
83
	}
84

  
85
	protected void completeWithFail(final BlackboardServerHandler handler, final BlackboardJob job, final Throwable e) {
86
		// Don't change this synchronization rule
87
		synchronized (this) {
88
			updateMDStoreServiceProfile(job);
89
			handler.failed(job, e);
90
		}
91
	}
92

  
93
	private void updateMDStoreServiceProfile(final BlackboardJob job) {
94
		final String id = job.getServiceId();
95

  
96
		log.info("Updating mdstore service profile status, id: " + id);
97
		try {
98
			final StringTemplate st = new StringTemplate(IOUtils.toString(mdstoreServiceStatusTemplate.getInputStream()));
99
			st.setAttribute("status", dao.getDBStatus());
100
			serviceLocator.getService(ISRegistryService.class).updateProfileNode(id, "//STATUS", st.toString());
101
		} catch (Exception e) {
102
			log.error("Error upadating profile " + id, e);
103
		}
104
	}
105

  
106
	/**
107
	 * Gets the dao.
108
	 * 
109
	 * @return the dao
110
	 */
111
	public MDStoreDao getDao() {
112
		return dao;
113
	}
114

  
115
	/**
116
	 * Sets the dao.
117
	 * 
118
	 * @param dao
119
	 *            the new dao
120
	 */
121
	public void setDao(final MDStoreDao dao) {
122
		this.dao = dao;
123
	}
124

  
125
}
modules/cnr-modular-mdstore-service/branches/indexFields/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.rmi.ISRegistryService;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
10
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
11
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
12

  
13
public class DeleteAction extends AbstractMDStoreAction {
14

  
15
	private UniqueServiceLocator serviceLocator;
16

  
17
	@Autowired
18
	private MDStoreTransactionManager transactionManager;
19

  
20
	@Override
21
	public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
22
		final String currentId = job.getParameters().get("id");
23
		try {
24
			serviceLocator.getService(ISRegistryService.class).deleteProfile(currentId);
25

  
26
			transactionManager.dropMDStore(currentId);
27

  
28
			getDao().deleteMDStore(currentId);
29

  
30
			completeWithSuccess(handler, job);
31
		} catch (Exception e) {
32
			throw new MDStoreServiceException("Error deleting mdstore with id " + currentId, e);
33
		}
34
	}
35

  
36
	public UniqueServiceLocator getServiceLocator() {
37
		return serviceLocator;
38
	}
39

  
40
	@Required
41
	public void setServiceLocator(final UniqueServiceLocator serviceLocator) {
42
		this.serviceLocator = serviceLocator;
43
	}
44

  
45
}
modules/cnr-modular-mdstore-service/branches/indexFields/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.BlackboardServerHandler;
10

  
11
public class FeedAction extends AbstractMDStoreAction {
12

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

  
15
	private MDStoreFeeder feeder;
16

  
17
	@Override
18
	public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
19

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

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

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

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

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

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

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

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

  
57
}
modules/cnr-modular-mdstore-service/branches/indexFields/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.BlackboardServerHandler;
11

  
12
public class CreateAction extends AbstractMDStoreAction {
13

  
14
	private MDStoreProfileCreator profileCreator;
15

  
16
	@Autowired
17
	private MDStoreTransactionManager transactionManager;
18

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

  
25
		try {
26
			String mdId = profileCreator.registerProfile(format, interpretation, layout);
27

  
28
			transactionManager.createMDStore(mdId);
29

  
30
			getDao().createMDStore(mdId, format, interpretation, layout);
31

  
32
			job.getParameters().put("id", mdId);
33

  
34
			completeWithSuccess(handler, job);
35
		} catch (ISRegistryException e) {
36
			throw new MDStoreServiceException(e);
37
		}
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/branches/indexFields/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.locators.UniqueServiceLocator;
11
import eu.dnetlib.soap.EndpointReferenceBuilder;
12

  
13
public class MDStoreProfileCreator {
14
	/**
15
	 * service locator.
16
	 */
17
	private UniqueServiceLocator serviceLocator;
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 serviceLocator.getService(ISRegistryService.class).registerProfile(template.toString());
43
	}
44

  
45
	public StringTemplate getMdstoreDsTemplate() {
46
		return mdstoreDsTemplate;
47
	}
48

  
49
	@Required
50
	public void setMdstoreDsTemplate(StringTemplate mdstoreDsTemplate) {
51
		this.mdstoreDsTemplate = mdstoreDsTemplate;
52
	}
53

  
54
	public Endpoint getEndpoint() {
55
		return endpoint;
56
	}
57

  
58
	@Required
59
	public void setEndpoint(Endpoint endpoint) {
60
		this.endpoint = endpoint;
61
	}
62

  
63
	public EndpointReferenceBuilder<Endpoint> getEprBuilder() {
64
		return eprBuilder;
65
	}
66

  
67
	@Required
68
	public void setEprBuilder(EndpointReferenceBuilder<Endpoint> eprBuilder) {
69
		this.eprBuilder = eprBuilder;
70
	}
71

  
72
	public UniqueServiceLocator getServiceLocator() {
73
		return serviceLocator;
74
	}
75

  
76
	@Required
77
	public void setServiceLocator(UniqueServiceLocator serviceLocator) {
78
		this.serviceLocator = serviceLocator;
79
	}
80
}
modules/cnr-modular-mdstore-service/branches/indexFields/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.enabling.is.registry.rmi.ISRegistryService;
11
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
12
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
13
import eu.dnetlib.miscutils.datetime.DateUtils;
14

  
15
public class MDStoreFeeder {
16

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

  
19
	private MDStoreDao dao;
20

  
21
	private ResultSetClientFactory resultSetClientFactory;
22

  
23
	private UniqueServiceLocator serviceLocator;
24

  
25
	private boolean syncFeed = true;
26

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

  
35
		try {
36
			final boolean refresh = "REFRESH".equals(storingType);
37

  
38
			final MDStore mdstore = dao.startTransaction(mdId, refresh);
39

  
40
			final Iterable<String> records = resultSetClientFactory.getClient(rsEpr);
41

  
42
			if (refresh) {
43
				mdstore.truncate();
44
			}
45

  
46
			mdstore.feed(records, refresh);
47

  
48
			dao.commit(mdstore.getId(), mdId);
49

  
50
			int size = dao.refreshSize(mdId);
51

  
52
			touch(mdId, size);
53

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

  
56
			doneCallback.call(size);
57
		} catch (Exception e) {
58
			log.error("Error feeding mdstore: " + mdId);
59
			failCallback.call(e);
60
		}
61
	}
62

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

  
72
			final String mdstoreXUpdate =
73
					"for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" + "return update value $x//LAST_STORAGE_DATE with '" + now
74
					+ "'";
75

  
76
			serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreXUpdate);
77

  
78
			touchSize(mdId, size);
79
		} catch (final Exception e) {
80
			throw new IllegalStateException(e);
81
		}
82
	}
83

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

  
90
			serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreNumberXUpdate);
91
		} catch (final Exception e) {
92
			throw new IllegalStateException(e);
93
		}
94
	}
95

  
96
	public MDStoreDao getDao() {
97
		return dao;
98
	}
99

  
100
	@Required
101
	public void setDao(final MDStoreDao dao) {
102
		this.dao = dao;
103
	}
104

  
105
	public ResultSetClientFactory getResultSetClientFactory() {
106
		return resultSetClientFactory;
107
	}
108

  
109
	@Required
110
	public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) {
111
		this.resultSetClientFactory = resultSetClientFactory;
112
	}
113

  
114
	public boolean isSyncFeed() {
115
		return syncFeed;
116
	}
117

  
118
	public void setSyncFeed(final boolean syncFeed) {
119
		this.syncFeed = syncFeed;
120
	}
121

  
122
	public UniqueServiceLocator getServiceLocator() {
123
		return serviceLocator;
124
	}
125
	
126
	@Required
127
	public void setServiceLocator(UniqueServiceLocator serviceLocator) {
128
		this.serviceLocator = serviceLocator;
129
	}
130

  
131
}
modules/cnr-modular-mdstore-service/branches/indexFields/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 com.google.common.base.Function;
8
import com.google.common.collect.Lists;
9
import org.springframework.beans.factory.annotation.Required;
10

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

  
18
public class ModularMDStoreService extends AbstractBaseService implements MDStoreService {
19

  
20
	/**
21
	 * notification handler.
22
	 */
23
	private NotificationHandler notificationHandler;
24

  
25
	private MDStoreFeeder feeder;
26

  
27
	private MDStoreRetriever retriever;
28

  
29
	private IterableResultSetFactory iterableResultSetFactory;
30

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

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

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

  
47
	@Override
48
	public List<String> getListOfMDStores() throws MDStoreServiceException {
49
		return (Lists.transform(retriever.getDao().listMDStores(), new Function<MDStoreDescription, String>() {
50
            @Override
51
            public String apply(MDStoreDescription input) {
52
                return input.getId();
53
            }
54
        }));
55
	}
56

  
57
	@Override
58
	public List<String> listMDStores(final String format, final String layout, final String interpretation) throws MDStoreServiceException {
59
		return retriever.getDao().listMDStores(format, layout, interpretation);
60
	}
61

  
62
	@Override
63
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
64
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
65
	}
66

  
67
	@Override
68
	public boolean storeMDRecordsFromRS(final String mdId, final String rsId, final String storingType) throws MDStoreServiceException {
69
		throw new MDStoreServiceException("not implemented, use the Blackboard asynchronous equivalent");
70
	}
71

  
72
	public NotificationHandler getNotificationHandler() {
73
		return notificationHandler;
74
	}
75

  
76
	@Required
77
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
78
		this.notificationHandler = notificationHandler;
79
	}
80

  
81
	public MDStoreFeeder getFeeder() {
82
		return feeder;
83
	}
84

  
85
	public void setFeeder(final MDStoreFeeder feeder) {
86
		this.feeder = feeder;
87
	}
88

  
89
	public MDStoreRetriever getRetriever() {
90
		return retriever;
91
	}
92

  
93
	public void setRetriever(final MDStoreRetriever retriever) {
94
		this.retriever = retriever;
95
	}
96

  
97
	public IterableResultSetFactory getIterableResultSetFactory() {
98
		return iterableResultSetFactory;
99
	}
100

  
101
	@Required
102
	public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) {
103
		this.iterableResultSetFactory = iterableResultSetFactory;
104
	}
105

  
106
}
modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreDescription.java
1
package eu.dnetlib.data.mdstore.modular;
2

  
3

  
4
public class MDStoreDescription {
5

  
6
	private String id;
7

  
8
	private String format;
9

  
10
	private String layout;
11

  
12
	private String interpretation;
13

  
14
	private int size;
15

  
16
	private boolean indexed;
17

  
18
	public MDStoreDescription(final String id, final String format, final String layout, final String interpretation, final int size, final boolean indexed) {
19
		super();
20
		this.id = id;
21
		this.format = format;
22
		this.layout = layout;
23
		this.interpretation = interpretation;
24
		this.size = size;
25
		this.indexed = indexed;
26
	}
27

  
28
    public MDStoreDescription() {
29

  
30
    }
31

  
32
    public String getId() {
33
		return id;
34
	}
35

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

  
40
	public String getFormat() {
41
		return format;
42
	}
43

  
44
	public void setFormat(final String format) {
45
		this.format = format;
46
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff