Revision 45150
Added by Claudio Atzori about 7 years ago
modules/cnr-modular-mdstore-service/releases/2.0.0/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/releases/2.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/releases/2.0.0/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/releases/2.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/releases/2.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/releases/2.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.Required; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.is.registry.ISRegistryDocumentNotFoundException; |
|
6 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
7 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
8 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
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 DeleteAction extends AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> { |
|
14 |
|
|
15 |
private ServiceLocator<ISRegistryService> registryLocator; |
|
16 |
|
|
17 |
@Override |
|
18 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws ISRegistryDocumentNotFoundException, ISRegistryException { |
|
19 |
registryLocator.getService().deleteProfile(job.getParameters().get("id")); |
|
20 |
|
|
21 |
getDao().deleteMDStore(job.getParameters().get("id")); |
|
22 |
|
|
23 |
handler.done(job); |
|
24 |
} |
|
25 |
|
|
26 |
public ServiceLocator<ISRegistryService> getRegistryLocator() { |
|
27 |
return registryLocator; |
|
28 |
} |
|
29 |
|
|
30 |
@Required |
|
31 |
public void setRegistryLocator(ServiceLocator<ISRegistryService> registryLocator) { |
|
32 |
this.registryLocator = registryLocator; |
|
33 |
} |
|
34 |
|
|
35 |
} |
modules/cnr-modular-mdstore-service/releases/2.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.Required; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
6 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
7 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction; |
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
9 |
|
|
10 |
public class CreateAction extends AbstractMDStoreAction implements BlackboardServerAction<MDStoreActions> { |
|
11 |
|
|
12 |
private MDStoreProfileCreator profileCreator; |
|
13 |
|
|
14 |
@Override |
|
15 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws ISRegistryException { |
|
16 |
final String format = job.getParameters().get("format"); |
|
17 |
final String interpretation = job.getParameters().get("interpretation"); |
|
18 |
final String layout = job.getParameters().get("layout"); |
|
19 |
|
|
20 |
final String mdId = profileCreator.registerProfile(format, interpretation, layout); |
|
21 |
|
|
22 |
getDao().createMDStore(mdId, format, interpretation, layout); |
|
23 |
|
|
24 |
job.getParameters().put("id", mdId); |
|
25 |
|
|
26 |
handler.done(job); |
|
27 |
} |
|
28 |
|
|
29 |
public MDStoreProfileCreator getProfileCreator() { |
|
30 |
return profileCreator; |
|
31 |
} |
|
32 |
|
|
33 |
@Required |
|
34 |
public void setProfileCreator(final MDStoreProfileCreator profileCreator) { |
|
35 |
this.profileCreator = profileCreator; |
|
36 |
} |
|
37 |
|
|
38 |
} |
modules/cnr-modular-mdstore-service/releases/2.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/FeedAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import java.util.concurrent.Callable; |
|
4 |
|
|
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 MDStoreFeeder feeder; |
|
15 |
|
|
16 |
@Override |
|
17 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception { |
|
18 |
|
|
19 |
final String mdId = job.getParameters().get("mdId"); |
|
20 |
if (mdId == null || mdId.isEmpty()) { |
|
21 |
throw new MDStoreServiceException("Blackboard param (mdId) is empty"); |
|
22 |
} |
|
23 |
|
|
24 |
final String epr = job.getParameters().get("epr"); |
|
25 |
if (epr == null || epr.isEmpty()) { |
|
26 |
throw new MDStoreServiceException("Blackboard param (mdId) is empty"); |
|
27 |
} |
|
28 |
|
|
29 |
String storingType = job.getParameters().get("storingType"); |
|
30 |
if (storingType == null || storingType.isEmpty()) { |
|
31 |
storingType = "REFRESH"; |
|
32 |
} |
|
33 |
|
|
34 |
feeder.feed(mdId, epr, storingType, true, new Callable<Object>() { |
|
35 |
@Override |
|
36 |
public Object call() { |
|
37 |
job.getParameters().put("total", "" + getDao().getMDStore(mdId).getSize()); |
|
38 |
handler.done(job); |
|
39 |
return null; |
|
40 |
} |
|
41 |
}, new Callable<Object>() { |
|
42 |
@Override |
|
43 |
public Object call() { |
|
44 |
handler.failed(job, new Exception("Error during feeding of " + mdId)); |
|
45 |
return null; |
|
46 |
} |
|
47 |
}); |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
public MDStoreFeeder getFeeder() { |
|
52 |
return feeder; |
|
53 |
} |
|
54 |
|
|
55 |
@Required |
|
56 |
public void setFeeder(MDStoreFeeder feeder) { |
|
57 |
this.feeder = feeder; |
|
58 |
} |
|
59 |
|
|
60 |
} |
modules/cnr-modular-mdstore-service/releases/2.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) { |
|
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() { |
|
47 |
return retriever.getDao().listMDStores(); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public List<String> listMDStores(final String format, final String layout, final String interpretation) { |
|
52 |
return retriever.getDao().listMDStores(format, layout, interpretation); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public boolean storeMDRecordsFromRS(final String mdId, final String rsEpr, final String storingType) { |
|
57 |
feeder.feed(mdId, rsEpr, storingType); |
|
58 |
return true; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void notify(final String subscriptionId, final String topic, final String isId, final String message) { |
|
63 |
getNotificationHandler().notified(subscriptionId, topic, isId, message); |
|
64 |
} |
|
65 |
|
|
66 |
public NotificationHandler getNotificationHandler() { |
|
67 |
return notificationHandler; |
|
68 |
} |
|
69 |
|
|
70 |
@Required |
|
71 |
public void setNotificationHandler(final NotificationHandler notificationHandler) { |
|
72 |
this.notificationHandler = notificationHandler; |
|
73 |
} |
|
74 |
|
|
75 |
public MDStoreFeeder getFeeder() { |
|
76 |
return feeder; |
|
77 |
} |
|
78 |
|
|
79 |
public void setFeeder(final MDStoreFeeder feeder) { |
|
80 |
this.feeder = feeder; |
|
81 |
} |
|
82 |
|
|
83 |
public MDStoreRetriever getRetriever() { |
|
84 |
return retriever; |
|
85 |
} |
|
86 |
|
|
87 |
public void setRetriever(final MDStoreRetriever retriever) { |
|
88 |
this.retriever = retriever; |
|
89 |
} |
|
90 |
|
|
91 |
public IterableResultSetFactory getIterableResultSetFactory() { |
|
92 |
return iterableResultSetFactory; |
|
93 |
} |
|
94 |
|
|
95 |
@Required |
|
96 |
public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) { |
|
97 |
this.iterableResultSetFactory = iterableResultSetFactory; |
|
98 |
} |
|
99 |
|
|
100 |
} |
modules/cnr-modular-mdstore-service/releases/2.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/releases/2.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.Required; |
|
6 |
|
|
7 |
import com.google.common.base.Function; |
|
8 |
import com.google.common.collect.Iterables; |
|
9 |
|
|
10 |
import eu.dnetlib.data.mdstore.DocumentNotFoundException; |
|
11 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
12 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
13 |
import eu.dnetlib.enabling.resultset.ResultSetFactory; |
|
14 |
|
|
15 |
public class MDStoreRetriever { |
|
16 |
|
|
17 |
private MDStoreDao dao; |
|
18 |
|
|
19 |
private ResultSetFactory resultSetFactory; |
|
20 |
|
|
21 |
public W3CEndpointReference deliver(final String mdId, final String from, final String until, final String recordFilter) { |
|
22 |
|
|
23 |
final MDStore mdStore = dao.getMDStore(mdId); |
|
24 |
|
|
25 |
return getResultSetFactory().createResultSet(mdStore.deliver(from, until, recordFilter)); |
|
26 |
} |
|
27 |
|
|
28 |
public Iterable<String> deliver(final String format, final String layout, final String interpretation) { |
|
29 |
return Iterables.concat(Iterables.transform(dao.listMDStores(format, layout, interpretation), new Function<String, Iterable<String>>() { |
|
30 |
|
|
31 |
@Override |
|
32 |
public Iterable<String> apply(final String mdId) { |
|
33 |
return dao.getMDStore(mdId).iterate(); |
|
34 |
} |
|
35 |
})); |
|
36 |
} |
|
37 |
|
|
38 |
public String deliverRecord(final String mdId, final String recordId) throws DocumentNotFoundException { |
|
39 |
return dao.getMDStore(mdId).getRecord(recordId); |
|
40 |
} |
|
41 |
|
|
42 |
public MDStoreDao getDao() { |
|
43 |
return dao; |
|
44 |
} |
|
45 |
|
|
46 |
@Required |
|
47 |
public void setDao(final MDStoreDao dao) { |
|
48 |
this.dao = dao; |
|
49 |
} |
|
50 |
|
|
51 |
@Required |
|
52 |
public void setResultSetFactory(final ResultSetFactory resultSetFactory) { |
|
53 |
this.resultSetFactory = resultSetFactory; |
|
54 |
} |
|
55 |
|
|
56 |
public ResultSetFactory getResultSetFactory() { |
|
57 |
return resultSetFactory; |
|
58 |
} |
|
59 |
|
|
60 |
} |
modules/cnr-modular-mdstore-service/releases/2.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/releases/2.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/releases/2.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import java.util.concurrent.Callable; |
|
4 |
|
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
import org.springframework.beans.factory.annotation.Required; |
|
8 |
|
|
9 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
10 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
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 |
private MDStoreDao dao; |
|
18 |
|
|
19 |
private ResultSetClientFactory resultSetClientFactory; |
|
20 |
|
|
21 |
private ServiceLocator<ISRegistryService> registryLocator; |
|
22 |
|
|
23 |
private boolean syncFeed = true; |
|
24 |
|
|
25 |
static final Log log = LogFactory.getLog(MDStoreFeeder.class); |
|
26 |
|
|
27 |
public void feed(final String mdId, final String rsEpr, final String storingType) { |
|
28 |
feed(mdId, rsEpr, storingType, syncFeed, null, null); |
|
29 |
} |
|
30 |
|
|
31 |
public void feed(final String mdId, final String rsEpr, final String storingType, final boolean sync, final Callable<?> callback, final Callable<?> failCallback) { |
|
32 |
log.info("Start feeding mdstore " + mdId + " with epr " + rsEpr); |
|
33 |
|
|
34 |
final Thread feederThread = new Thread(new Runnable() { |
|
35 |
@Override |
|
36 |
public void run() { |
|
37 |
try { |
|
38 |
final MDStore mdstore = dao.getMDStore(mdId); |
|
39 |
|
|
40 |
final Iterable<String> records = resultSetClientFactory.getClient(rsEpr); |
|
41 |
|
|
42 |
final boolean incremental = !"REFRESH".equals(storingType); |
|
43 |
|
|
44 |
if (!incremental) |
|
45 |
mdstore.truncate(); |
|
46 |
|
|
47 |
final int size = mdstore.feed(records, incremental); |
|
48 |
|
|
49 |
touch(mdId, size); |
|
50 |
|
|
51 |
log.info("Stop feeding mdstore " + mdId + " - new size: " + size); |
|
52 |
|
|
53 |
if (callback != null) { |
|
54 |
try { |
|
55 |
callback.call(); |
|
56 |
} catch (Exception e) { |
|
57 |
log.error("Error executing callback", e); |
|
58 |
} |
|
59 |
} |
|
60 |
} catch (Throwable e) { |
|
61 |
log.error("Error in feeding thread", e); |
|
62 |
if (failCallback != null) { |
|
63 |
try { |
|
64 |
failCallback.call(); |
|
65 |
} catch (Exception e1) { |
|
66 |
log.error("Error executing failCallback", e); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
}); |
|
72 |
|
|
73 |
feederThread.start(); |
|
74 |
|
|
75 |
if(sync) { |
|
76 |
try { |
|
77 |
feederThread.join(); |
|
78 |
} catch (InterruptedException e) { |
|
79 |
throw new IllegalStateException(e); |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Sets the last modified date in the profile. |
|
86 |
* |
|
87 |
* @param mdId |
|
88 |
*/ |
|
89 |
public void touch(final String mdId, final int size) { |
|
90 |
try { |
|
91 |
final String now = DateUtils.now_ISO8601(); |
|
92 |
|
|
93 |
final String mdstoreXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" |
|
94 |
+ "return update value $x//LAST_STORAGE_DATE with '" + now + "'"; |
|
95 |
|
|
96 |
registryLocator.getService().executeXUpdate(mdstoreXUpdate); |
|
97 |
|
|
98 |
touchSize(mdId, size); |
|
99 |
} catch (final Exception e) { |
|
100 |
throw new IllegalStateException(e); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
public void touchSize(final String mdId, final int size) { |
|
105 |
try { |
|
106 |
final String mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" |
|
107 |
+ "return update value $x//NUMBER_OF_RECORDS with '" + size + "'"; |
|
108 |
|
|
109 |
registryLocator.getService().executeXUpdate(mdstoreNumberXUpdate); |
|
110 |
} catch (final Exception e) { |
|
111 |
throw new IllegalStateException(e); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
public MDStoreDao getDao() { |
|
116 |
return dao; |
|
117 |
} |
|
118 |
|
|
119 |
@Required |
|
120 |
public void setDao(final MDStoreDao dao) { |
|
121 |
this.dao = dao; |
|
122 |
} |
|
123 |
|
|
124 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
125 |
return resultSetClientFactory; |
|
126 |
} |
|
127 |
|
|
128 |
@Required |
|
129 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
130 |
this.resultSetClientFactory = resultSetClientFactory; |
|
131 |
} |
|
132 |
|
|
133 |
public ServiceLocator<ISRegistryService> getRegistryLocator() { |
|
134 |
return registryLocator; |
|
135 |
} |
|
136 |
|
|
137 |
@Required |
|
138 |
public void setRegistryLocator(final ServiceLocator<ISRegistryService> registryLocator) { |
|
139 |
this.registryLocator = registryLocator; |
|
140 |
} |
|
141 |
|
|
142 |
public boolean isSyncFeed() { |
|
143 |
return syncFeed; |
|
144 |
} |
|
145 |
|
|
146 |
public void setSyncFeed(boolean syncFeed) { |
|
147 |
this.syncFeed = syncFeed; |
|
148 |
} |
|
149 |
} |
modules/cnr-modular-mdstore-service/releases/2.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()) { |
|
69 |
final XMLEvent event = parser.nextEvent(); |
|
70 |
if (event != null && event.isStartElement()) { |
|
71 |
final String localName = event.asStartElement().getName().getLocalPart(); |
|
72 |
|
|
73 |
if (MD_RECORD.equals(localName)) { |
|
74 |
mdId = event.asStartElement().getAttributeByName(new QName(MD_ID)).getValue(); |
|
75 |
|
|
76 |
} else if (RECORD.equals(localName)) { |
|
77 |
record = getRecord(embeddedRecord, parser); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
} catch (final XMLStreamException e) { |
|
82 |
log.error("error parsing record: " + embeddedRecord); |
|
83 |
} |
|
84 |
return new Pair<String, String>(mdId, record); |
|
85 |
} |
|
86 |
}; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Copy the /indexRecord/result element and children, preserving namespace declarations etc. |
|
91 |
* |
|
92 |
* @param indexDocument |
|
93 |
* @param results |
|
94 |
* @param parser |
|
95 |
* @throws XMLStreamException |
|
96 |
*/ |
|
97 |
protected String getRecord(final String record, final XMLEventReader parser) throws XMLStreamException { |
|
98 |
StringWriter results = new StringWriter(); |
|
99 |
final XMLEventWriter writer = outputFactory.get().createXMLEventWriter(results); |
|
100 |
|
|
101 |
// TODO: newRecord should copy all the namespace prefixes setup in parents |
|
102 |
// fortunately the only parent of the result element is the 'indexrecord', so it should be easy to get |
|
103 |
// the namespaces declared on the root element (and fast) |
|
104 |
|
|
105 |
final List<Namespace> namespaces = Lists.newArrayList( |
|
106 |
eventFactory.get().createNamespace("dri", "http://www.driver-repository.eu/namespace/dri"), |
|
107 |
eventFactory.get().createNamespace("dr", "http://www.driver-repository.eu/namespace/dr"), |
|
108 |
eventFactory.get().createNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"), |
|
109 |
eventFactory.get().createNamespace("dc", "http://purl.org/dc/elements/1.1/")); |
|
110 |
|
|
111 |
StartElement newRecord = eventFactory.get().createStartElement("", null, RECORD, null, namespaces.iterator()); |
|
112 |
|
|
113 |
// new root record |
|
114 |
writer.add(newRecord); |
|
115 |
|
|
116 |
// copy the rest as it is |
|
117 |
while (parser.hasNext()) { |
|
118 |
final XMLEvent resultEvent = parser.nextEvent(); |
|
119 |
|
|
120 |
// TODO: replace with depth tracking instead of close tag tracking. |
|
121 |
if (resultEvent.isEndElement() && resultEvent.asEndElement().getName().getLocalPart().equals(RECORD)) { |
|
122 |
writer.add(resultEvent); |
|
123 |
break; |
|
124 |
} |
|
125 |
|
|
126 |
writer.add(resultEvent); |
|
127 |
} |
|
128 |
writer.close(); |
|
129 |
|
|
130 |
return results.toString(); |
|
131 |
} |
|
132 |
|
|
133 |
} |
modules/cnr-modular-mdstore-service/releases/2.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/releases/2.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 |
MDStore getMDStore(String mdId); |
|
7 |
|
|
8 |
List<String> listMDStores(); |
|
9 |
|
|
10 |
List<String> listMDStores(String format, String layout, String interpretation); |
|
11 |
|
|
12 |
void createMDStore(String mdId, String format, String interpretation, String layout); |
|
13 |
|
|
14 |
void deleteMDStore(String id); |
|
15 |
} |
modules/cnr-modular-mdstore-service/releases/2.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/releases/2.0.0/src/main/java/eu/dnetlib/data/mdstore/modular/RecordParser.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
/** |
|
6 |
* Parses a mdrecord and extracts the minimum information (like id, date etc) which is necessary for the mdstoring |
|
7 |
* process. |
|
8 |
* |
|
9 |
* @author marko |
|
10 |
* |
|
11 |
*/ |
|
12 |
public interface RecordParser { |
|
13 |
|
|
14 |
public Map<String, String> parseRecord(String record); |
|
15 |
|
|
16 |
} |
modules/cnr-modular-mdstore-service/releases/2.0.0/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/releases/2.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/releases/2.0.0/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.properties | ||
---|---|---|
1 |
services.mdstore.rsfactory=resultSetFactory |
|
2 |
services.mdstore.dao=mongodbMDStoreDao |
|
3 |
services.mdstore.syncFeed=true |
|
4 |
services.mdstore.recordParser=eu.dnetlib.data.mdstore.modular.StreamingRecordParser |
|
5 |
services.mdstore.rsfactory.pagesize=20 |
|
6 |
services.mdstore.discardrecords=true |
modules/cnr-modular-mdstore-service/releases/2.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 |
|
|
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/releases/2.0.0/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/releases/2.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" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
4 |
<parent> |
|
5 |
<groupId>eu.dnetlib</groupId> |
|
6 |
<artifactId>dnet-parent</artifactId> |
|
7 |
<version>1.0.0-SNAPSHOT</version> |
|
8 |
<relativePath></relativePath> |
|
9 |
</parent> |
|
10 |
<modelVersion>4.0.0</modelVersion> |
|
11 |
<groupId>eu.dnetlib</groupId> |
|
12 |
<artifactId>cnr-modular-mdstore-service</artifactId> |
|
13 |
<packaging>jar</packaging> |
|
14 |
<version>2.0.0-SNAPSHOT</version> |
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>junit</groupId> |
|
18 |
<artifactId>junit</artifactId> |
|
19 |
<version>${junit.version}</version> |
|
20 |
<scope>test</scope> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>org.springframework</groupId> |
|
24 |
<artifactId>spring-test</artifactId> |
|
25 |
<version>${spring.version}</version> |
|
26 |
<scope>test</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.mockito</groupId> |
|
30 |
<artifactId>mockito-core</artifactId> |
|
31 |
<version>1.6</version> |
|
32 |
<scope>test</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>eu.dnetlib</groupId> |
|
36 |
<artifactId>cnr-test-utils</artifactId> |
|
37 |
<version>[1.0.0-SNAPSHOT]</version> |
|
38 |
<scope>test</scope> |
|
39 |
</dependency> |
|
40 |
<dependency> |
|
41 |
<groupId>eu.dnetlib</groupId> |
|
42 |
<artifactId>cnr-rmi-api</artifactId> |
|
43 |
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> |
|
44 |
</dependency> |
|
45 |
<dependency> |
|
46 |
<groupId>eu.dnetlib</groupId> |
|
47 |
<artifactId>cnr-blackboard-common</artifactId> |
|
48 |
<version>[1.0.0-SNAPSHOT]</version> |
|
49 |
</dependency> |
|
50 |
<dependency> |
|
51 |
<groupId>eu.dnetlib</groupId> |
|
52 |
<artifactId>cnr-misc-utils</artifactId> |
|
53 |
<version>[1.0.0-SNAPSHOT]</version> |
|
54 |
</dependency> |
|
55 |
<dependency> |
|
56 |
<groupId>eu.dnetlib</groupId> |
|
57 |
<artifactId>cnr-resultset-service</artifactId> |
|
58 |
<version>[1.0.0-SNAPSHOT]</version> |
|
59 |
</dependency> |
|
60 |
<dependency> |
|
61 |
<groupId>eu.dnetlib</groupId> |
|
62 |
<artifactId>cnr-resultset-client</artifactId> |
|
63 |
<version>[1.0.0-SNAPSHOT]</version> |
|
64 |
</dependency> |
|
65 |
</dependencies> |
|
66 |
</project> |
modules/cnr-modular-mdstore-service/trunk/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/trunk/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.action.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/trunk/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.action.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/trunk/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.action.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/trunk/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; |
Also available in: Unified diff
codebase used to migrate to java8 the production system