Revision 55421
Added by Alessia Bardi over 4 years ago
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-modular-mdstore-service/trunk/", "deploy_repository": "dnet45-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/dnet45-snapshots", "name": "cnr-modular-mdstore-service"} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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/tags/cnr-modular-mdstore-service-6.0.4/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/tags/cnr-modular-mdstore-service-6.0.4/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/tags/cnr-modular-mdstore-service-6.0.4/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 |
} |
|
47 |
|
|
48 |
public String getLayout() { |
|
49 |
return layout; |
|
50 |
} |
|
51 |
|
|
52 |
public void setLayout(final String layout) { |
|
53 |
this.layout = layout; |
|
54 |
} |
|
55 |
|
|
56 |
public String getInterpretation() { |
|
57 |
return interpretation; |
|
58 |
} |
|
59 |
|
|
60 |
public void setInterpretation(final String interpretation) { |
|
61 |
this.interpretation = interpretation; |
|
62 |
} |
|
63 |
|
|
64 |
public int getSize() { |
|
65 |
return size; |
|
66 |
} |
|
67 |
|
|
68 |
public void setSize(final int size) { |
|
69 |
this.size = size; |
|
70 |
} |
|
71 |
|
|
72 |
public boolean isIndexed() { |
|
73 |
return indexed; |
|
74 |
} |
|
75 |
|
|
76 |
public void setIndexed(final boolean indexed) { |
|
77 |
this.indexed = indexed; |
|
78 |
} |
|
79 |
|
|
80 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/ModularMDStoreService.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import com.google.common.base.Function; |
|
4 |
import com.google.common.collect.Lists; |
|
5 |
import eu.dnetlib.data.mdstore.DocumentNotFoundException; |
|
6 |
import eu.dnetlib.data.mdstore.MDStoreService; |
|
7 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
8 |
import eu.dnetlib.enabling.resultset.IterableResultSetFactory; |
|
9 |
import eu.dnetlib.enabling.tools.AbstractBaseService; |
|
10 |
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler; |
|
11 |
import org.springframework.beans.factory.annotation.Required; |
|
12 |
|
|
13 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
|
|
17 |
public class ModularMDStoreService extends AbstractBaseService implements MDStoreService { |
|
18 |
|
|
19 |
/** |
|
20 |
* notification handler. |
|
21 |
*/ |
|
22 |
private NotificationHandler notificationHandler; |
|
23 |
|
|
24 |
private MDStoreFeeder feeder; |
|
25 |
|
|
26 |
private MDStoreRetriever retriever; |
|
27 |
|
|
28 |
private IterableResultSetFactory iterableResultSetFactory; |
|
29 |
|
|
30 |
|
|
31 |
public List<String> getMDStoreRecords(final String mdId, final int pageSize, final int offset, final Map<String, String> queryParam) throws MDStoreServiceException { |
|
32 |
|
|
33 |
return retriever.getMDStoreRecords(mdId, pageSize, offset, queryParam); |
|
34 |
|
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public W3CEndpointReference deliverMDRecords(final String mdId, final String from, final String until, final String recordFilter) |
|
39 |
throws MDStoreServiceException { |
|
40 |
return retriever.deliver(mdId, from, until, recordFilter); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public W3CEndpointReference bulkDeliverMDRecords(final String format, final String layout, final String interpretation) throws MDStoreServiceException { |
|
45 |
return getIterableResultSetFactory().createIterableResultSet(retriever.deliver(format, layout, interpretation)); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public String deliverRecord(final String mdId, final String recordId) throws MDStoreServiceException, DocumentNotFoundException { |
|
50 |
return retriever.deliverRecord(mdId, recordId); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public List<String> getListOfMDStores() throws MDStoreServiceException { |
|
55 |
return (Lists.transform(retriever.getDao().listMDStores(), new Function<MDStoreDescription, String>() { |
|
56 |
|
|
57 |
@Override |
|
58 |
public String apply(final MDStoreDescription input) { |
|
59 |
return input.getId(); |
|
60 |
} |
|
61 |
})); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public List<String> listMDStores(final String format, final String layout, final String interpretation) throws MDStoreServiceException { |
|
66 |
return retriever.getDao().listMDStores(format, layout, interpretation); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public void notify(final String subscriptionId, final String topic, final String isId, final String message) { |
|
71 |
getNotificationHandler().notified(subscriptionId, topic, isId, message); |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public boolean storeMDRecordsFromRS(final String mdId, final String rsId, final String storingType) throws MDStoreServiceException { |
|
76 |
throw new MDStoreServiceException("not implemented, use the Blackboard asynchronous equivalent"); |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public int size(final String mdId) throws MDStoreServiceException { |
|
81 |
return this.getRetriever().getDao().getCachedSize(mdId); |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public int size(final String format, final String layout, final String interpretation) throws MDStoreServiceException { |
|
86 |
return this.getRetriever().getDao().getSumOfSizes(format, layout, interpretation); |
|
87 |
} |
|
88 |
|
|
89 |
public NotificationHandler getNotificationHandler() { |
|
90 |
return notificationHandler; |
|
91 |
} |
|
92 |
|
|
93 |
@Required |
|
94 |
public void setNotificationHandler(final NotificationHandler notificationHandler) { |
|
95 |
this.notificationHandler = notificationHandler; |
|
96 |
} |
|
97 |
|
|
98 |
public MDStoreFeeder getFeeder() { |
|
99 |
return feeder; |
|
100 |
} |
|
101 |
|
|
102 |
public void setFeeder(final MDStoreFeeder feeder) { |
|
103 |
this.feeder = feeder; |
|
104 |
} |
|
105 |
|
|
106 |
public MDStoreRetriever getRetriever() { |
|
107 |
return retriever; |
|
108 |
} |
|
109 |
|
|
110 |
public void setRetriever(final MDStoreRetriever retriever) { |
|
111 |
this.retriever = retriever; |
|
112 |
} |
|
113 |
|
|
114 |
public IterableResultSetFactory getIterableResultSetFactory() { |
|
115 |
return iterableResultSetFactory; |
|
116 |
} |
|
117 |
|
|
118 |
@Required |
|
119 |
public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) { |
|
120 |
this.iterableResultSetFactory = iterableResultSetFactory; |
|
121 |
} |
|
122 |
|
|
123 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/RecordParserFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Required; |
|
4 |
|
|
5 |
import eu.dnetlib.miscutils.factory.Factory; |
|
6 |
|
|
7 |
public class RecordParserFactory implements Factory<RecordParser> { |
|
8 |
|
|
9 |
private Class<? extends RecordParser> parserType; |
|
10 |
|
|
11 |
@Override |
|
12 |
public RecordParser newInstance() { |
|
13 |
try { |
|
14 |
return getParserType().newInstance(); |
|
15 |
} catch (Throwable e) { |
|
16 |
throw new RuntimeException(e); |
|
17 |
} |
|
18 |
} |
|
19 |
|
|
20 |
@Required |
|
21 |
public void setParserType(Class<? extends RecordParser> parserType) { |
|
22 |
this.parserType = parserType; |
|
23 |
} |
|
24 |
|
|
25 |
public Class<? extends RecordParser> getParserType() { |
|
26 |
return parserType; |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
} |
|
0 | 31 |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.springframework.beans.factory.annotation.Required; |
|
13 |
|
|
14 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
public class MDStoreRetriever { |
|
19 |
|
|
20 |
/** Logger */ |
|
21 |
private static final Log log = LogFactory.getLog(MDStoreRetriever.class); |
|
22 |
|
|
23 |
private MDStoreDao dao; |
|
24 |
|
|
25 |
private ResultSetFactory resultSetFactory; |
|
26 |
|
|
27 |
public W3CEndpointReference deliver(final String mdId, final String from, final String until, final String recordFilter) throws MDStoreServiceException { |
|
28 |
final MDStore mdStore = dao.readMDStore(mdId); |
|
29 |
return getResultSetFactory().createResultSet(mdStore.deliver(from, until, recordFilter)); |
|
30 |
} |
|
31 |
|
|
32 |
public Iterable<String> deliver(final String format, final String layout, final String interpretation) throws MDStoreServiceException { |
|
33 |
try { |
|
34 |
return Iterables.concat(Iterables.transform(dao.listMDStores(format, layout, interpretation), new Function<String, Iterable<String>>() { |
|
35 |
|
|
36 |
@Override |
|
37 |
public Iterable<String> apply(final String mdId) { |
|
38 |
log.debug("bulk deliver of mdId: " + mdId); |
|
39 |
try { |
|
40 |
return dao.readMDStore(mdId).iterate(); |
|
41 |
} catch (MDStoreServiceException e) { |
|
42 |
throw new RuntimeException(e); |
|
43 |
} |
|
44 |
} |
|
45 |
})); |
|
46 |
} catch (RuntimeException e) { |
|
47 |
throw new MDStoreServiceException(e); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public String deliverRecord(final String mdId, final String recordId) throws MDStoreServiceException, DocumentNotFoundException { |
|
52 |
return dao.getMDStore(mdId).getRecord(recordId); |
|
53 |
} |
|
54 |
|
|
55 |
public MDStoreDao getDao() { |
|
56 |
return dao; |
|
57 |
} |
|
58 |
|
|
59 |
@Required |
|
60 |
public void setDao(final MDStoreDao dao) { |
|
61 |
this.dao = dao; |
|
62 |
} |
|
63 |
|
|
64 |
public ResultSetFactory getResultSetFactory() { |
|
65 |
return resultSetFactory; |
|
66 |
} |
|
67 |
|
|
68 |
@Required |
|
69 |
public void setResultSetFactory(final ResultSetFactory resultSetFactory) { |
|
70 |
this.resultSetFactory = resultSetFactory; |
|
71 |
} |
|
72 |
|
|
73 |
public List<String> getMDStoreRecords(final String mdId, int pageSize, final int offset, final Map<String, String> queryParam) throws MDStoreServiceException { |
|
74 |
MDStore mdStore = dao.getMDStore(mdId); |
|
75 |
return mdStore.deliver(mdId, pageSize, offset, queryParam); |
|
76 |
} |
|
77 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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 |
import static eu.dnetlib.data.mdstore.modular.MDStoreConstants.*; |
|
15 |
|
|
16 |
/** |
|
17 |
* Terrible implementation of a record parser. |
|
18 |
* |
|
19 |
* @author marko |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class SimpleRecordParser implements RecordParser { |
|
23 |
static final Log log = LogFactory.getLog(SimpleRecordParser.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
24 |
|
|
25 |
private long ts; |
|
26 |
|
|
27 |
@Override |
|
28 |
public Map<String, String> parseRecord(String record) { |
|
29 |
Map<String, String> props = new HashMap<String, String>(); |
|
30 |
props.put(TIMESTAMP, String.valueOf(getTimestamp())); |
|
31 |
|
|
32 |
try { |
|
33 |
// DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
|
34 |
XPath xpath = XPathFactory.newInstance().newXPath(); |
|
35 |
|
|
36 |
// Document doc = builder.parse(new InputSource(new StringReader(record))); |
|
37 |
InputSource doc = new InputSource(new StringReader(record)); |
|
38 |
|
|
39 |
props.put(ID, xpath.evaluate("//*[local-name()='objIdentifier']", doc)); |
|
40 |
props.put("originalId", xpath.evaluate("//*[local-name()='efgEntity']/*/*[local-name()='identifier']", doc)); |
|
41 |
|
|
42 |
// String date = xpath.evaluate("//*[local-name()='dateOfCollection'][1]", doc); |
|
43 |
// props.put("date", new Date(date).getTime()); |
|
44 |
|
|
45 |
} catch (Exception e) { |
|
46 |
log.warn("got exception while parsing document", e); |
|
47 |
log.warn("record is:"); |
|
48 |
log.warn(record); |
|
49 |
log.warn("------------"); |
|
50 |
} |
|
51 |
return props; |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public void setTimestamp(final long ts) { |
|
57 |
this.ts = ts; |
|
58 |
log.debug("RecordParser date set to "+ts); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public long getTimestamp() { |
|
63 |
return ts; |
|
64 |
} |
|
65 |
|
|
66 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
|
|
16 |
import static eu.dnetlib.data.mdstore.modular.MDStoreConstants.*; |
|
17 |
|
|
18 |
/** |
|
19 |
* This method outperforms SimpleRecordParser by a vast amount, especially since we are just getting stuff in the |
|
20 |
* header. |
|
21 |
* |
|
22 |
* @author marko |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class StreamingRecordParser implements RecordParser { |
|
26 |
|
|
27 |
private static final Log log = LogFactory.getLog(StreamingRecordParser.class); |
|
28 |
private long ts; |
|
29 |
|
|
30 |
@Override |
|
31 |
public Map<String, String> parseRecord(String record) { |
|
32 |
|
|
33 |
try { |
|
34 |
XMLInputFactory factory = XMLInputFactory.newInstance(); |
|
35 |
XMLStreamReader parser = factory.createXMLStreamReader(new ByteArrayInputStream(record.getBytes())); |
|
36 |
|
|
37 |
HashMap<String, String> res = new HashMap<String, String>(); |
|
38 |
res.put(TIMESTAMP, String.valueOf(getTimestamp())); |
|
39 |
|
|
40 |
Stack<String> elementStack = new Stack<String>(); |
|
41 |
elementStack.push("/"); |
|
42 |
|
|
43 |
while (parser.hasNext()) { |
|
44 |
int event = parser.next(); |
|
45 |
|
|
46 |
if (event == XMLStreamConstants.END_ELEMENT) { |
|
47 |
elementStack.pop(); |
|
48 |
} else if (event == XMLStreamConstants.START_ELEMENT) { |
|
49 |
final String localName = parser.getLocalName(); |
|
50 |
elementStack.push(localName); |
|
51 |
|
|
52 |
if (OBJIDENTIFIER.equals(localName)) { |
|
53 |
parser.next(); |
|
54 |
|
|
55 |
res.put(ID, parser.getText().trim()); |
|
56 |
|
|
57 |
} else if ("identifier".equals(localName) && "efgEntity".equals(grandParent(elementStack))) { |
|
58 |
if (!res.containsKey("originalId")) { |
|
59 |
parser.next(); |
|
60 |
// log.info("ZZZZZZ OK: found identifier at right depth " + elementStack); |
|
61 |
res.put("originalId", parser.getText().trim()); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
else if ("identifier".equals(localName)) { |
|
66 |
|
|
67 |
// log.info("ZZZZZZ: found identifier not at right depth " + elementStack + " grand parent " + grandParent(elementStack)); |
|
68 |
} |
|
69 |
|
|
70 |
if (res.containsKey(ID) && res.containsKey("originalId")) |
|
71 |
return res; |
|
72 |
} |
|
73 |
} |
|
74 |
return res; |
|
75 |
} catch (XMLStreamException e) { |
|
76 |
throw new IllegalStateException(e); |
|
77 |
} |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
private String grandParent(Stack<String> elementStack) { |
|
82 |
if (elementStack.size() <= 3) |
|
83 |
return ""; |
|
84 |
return elementStack.get(elementStack.size() - 3); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void setTimestamp(final long ts) { |
|
89 |
this.ts = ts; |
|
90 |
log.debug("RecordParser date set to "+ts); |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public long getTimestamp() { |
|
95 |
return ts; |
|
96 |
} |
|
97 |
|
|
98 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
import com.google.common.collect.Maps; |
|
4 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
5 |
import eu.dnetlib.data.mdstore.modular.action.DoneCallback; |
|
6 |
import eu.dnetlib.data.mdstore.modular.action.FailedCallback; |
|
7 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
8 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
9 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
10 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
11 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
12 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.springframework.beans.factory.annotation.Required; |
|
16 |
|
|
17 |
import java.util.List; |
|
18 |
import java.util.Map; |
|
19 |
|
|
20 |
public class MDStoreFeeder { |
|
21 |
|
|
22 |
private static final Log log = LogFactory.getLog(MDStoreFeeder.class); |
|
23 |
|
|
24 |
private MDStoreDao dao; |
|
25 |
|
|
26 |
private ResultSetClientFactory resultSetClientFactory; |
|
27 |
|
|
28 |
private UniqueServiceLocator serviceLocator; |
|
29 |
|
|
30 |
private boolean syncFeed = true; |
|
31 |
|
|
32 |
public void feed(final String mdId, |
|
33 |
final String rsEpr, |
|
34 |
final String storingType, |
|
35 |
final boolean sync, |
|
36 |
final List<MDFormatDescription> mdformats, |
|
37 |
final DoneCallback doneCallback, |
|
38 |
final FailedCallback failCallback) throws MDStoreServiceException { |
|
39 |
log.info("Start feeding mdstore " + mdId); |
|
40 |
log.debug("Start feeding mdstore " + mdId + " with epr " + rsEpr); |
|
41 |
|
|
42 |
String transactionId = null; |
|
43 |
|
|
44 |
try { |
|
45 |
final boolean refresh = "REFRESH".equals(storingType); |
|
46 |
|
|
47 |
final MDStore mdstore = dao.startTransaction(mdId, refresh); |
|
48 |
transactionId = mdstore.getId(); |
|
49 |
|
|
50 |
final Iterable<String> records = resultSetClientFactory.getClient(rsEpr); |
|
51 |
|
|
52 |
if (refresh) { |
|
53 |
mdstore.truncate(); |
|
54 |
} |
|
55 |
int writeOps; |
|
56 |
|
|
57 |
if (mdformats == null) { |
|
58 |
writeOps = mdstore.feed(records, refresh); |
|
59 |
} else { |
|
60 |
writeOps = mdstore.feed(records, refresh, mdformats); |
|
61 |
} |
|
62 |
|
|
63 |
dao.commit(mdstore.getId(), mdId); |
|
64 |
|
|
65 |
int size = dao.refreshSize(mdId); |
|
66 |
|
|
67 |
touch(mdId, size); |
|
68 |
|
|
69 |
log.info("Finished feeding mdstore " + mdId + " - new size: " + size); |
|
70 |
|
|
71 |
doneCallback.call(buildParams(size, writeOps)); |
|
72 |
} catch (Throwable e) { |
|
73 |
if (transactionId != null) { |
|
74 |
dao.invalidTransaction(transactionId, mdId); |
|
75 |
} |
|
76 |
log.error("Error feeding mdstore: " + mdId); |
|
77 |
failCallback.call(e); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
private Map<String, String> buildParams(final int size, final int storeCount) { |
|
82 |
Map<String, String> params = Maps.newHashMap(); |
|
83 |
params.put("mdstoreSize", String.valueOf(size)); |
|
84 |
params.put("writeOps", String.valueOf(storeCount)); |
|
85 |
return params; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Sets the last modified date in the profile. |
|
90 |
* |
|
91 |
* @param mdId |
|
92 |
*/ |
|
93 |
public void touch(final String mdId, final int size) { |
|
94 |
try { |
|
95 |
final String now = DateUtils.now_ISO8601(); |
|
96 |
|
|
97 |
final String mdstoreXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" |
|
98 |
+ "return update value $x//LAST_STORAGE_DATE with '" + now + "'"; |
|
99 |
|
|
100 |
serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreXUpdate); |
|
101 |
|
|
102 |
touchSize(mdId, size); |
|
103 |
} catch (final Exception e) { |
|
104 |
throw new IllegalStateException(e); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
public void touchSize(final String mdId, final int size) { |
|
109 |
try { |
|
110 |
final String mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" |
|
111 |
+ "return update value $x//NUMBER_OF_RECORDS with '" + size + "'"; |
|
112 |
|
|
113 |
serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreNumberXUpdate); |
|
114 |
} catch (final Exception e) { |
|
115 |
throw new IllegalStateException(e); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
public MDStoreDao getDao() { |
|
120 |
return dao; |
|
121 |
} |
|
122 |
|
|
123 |
@Required |
|
124 |
public void setDao(final MDStoreDao dao) { |
|
125 |
this.dao = dao; |
|
126 |
} |
|
127 |
|
|
128 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
129 |
return resultSetClientFactory; |
|
130 |
} |
|
131 |
|
|
132 |
@Required |
|
133 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
134 |
this.resultSetClientFactory = resultSetClientFactory; |
|
135 |
} |
|
136 |
|
|
137 |
public boolean isSyncFeed() { |
|
138 |
return syncFeed; |
|
139 |
} |
|
140 |
|
|
141 |
public void setSyncFeed(final boolean syncFeed) { |
|
142 |
this.syncFeed = syncFeed; |
|
143 |
} |
|
144 |
|
|
145 |
public UniqueServiceLocator getServiceLocator() { |
|
146 |
return serviceLocator; |
|
147 |
} |
|
148 |
|
|
149 |
@Required |
|
150 |
public void setServiceLocator(final UniqueServiceLocator serviceLocator) { |
|
151 |
this.serviceLocator = serviceLocator; |
|
152 |
} |
|
153 |
|
|
154 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreConstants.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
public class MDStoreConstants { |
|
4 |
|
|
5 |
public static final String ID = "id"; |
|
6 |
public static final String OBJIDENTIFIER = "objIdentifier"; |
|
7 |
public static final String TIMESTAMP = "timestamp"; |
|
8 |
public static final String ORIGINALID = "originalId"; |
|
9 |
public static final String BODY = "body"; |
|
10 |
|
|
11 |
|
|
12 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreResults.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.connector; |
|
2 |
|
|
3 |
public class MDStoreResults { |
|
4 |
private Iterable<String> records; |
|
5 |
private int size; |
|
6 |
|
|
7 |
public MDStoreResults(Iterable<String> records, int size) { |
|
8 |
super(); |
|
9 |
this.records = records; |
|
10 |
this.size = size; |
|
11 |
} |
|
12 |
|
|
13 |
public int getSize() { |
|
14 |
return size; |
|
15 |
} |
|
16 |
|
|
17 |
public void setSize(int size) { |
|
18 |
this.size = size; |
|
19 |
} |
|
20 |
|
|
21 |
public Iterable<String> getRecords() { |
|
22 |
return records; |
|
23 |
} |
|
24 |
|
|
25 |
public void setRecords(Iterable<String> records) { |
|
26 |
this.records = records; |
|
27 |
} |
|
28 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreTransactionInfo.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.connector; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
|
|
5 |
public class MDStoreTransactionInfo { |
|
6 |
|
|
7 |
private String id; |
|
8 |
private Boolean refresh; |
|
9 |
private Date date; |
|
10 |
private long size; |
|
11 |
|
|
12 |
/** |
|
13 |
* @return the date |
|
14 |
*/ |
|
15 |
public Date getDate() { |
|
16 |
return date; |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* @param date |
|
21 |
* the date to set |
|
22 |
*/ |
|
23 |
public void setDate(final Date date) { |
|
24 |
this.date = date; |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* @return the id |
|
29 |
*/ |
|
30 |
public String getId() { |
|
31 |
return id; |
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* @param id |
|
36 |
* the id to set |
|
37 |
*/ |
|
38 |
public void setId(final String id) { |
|
39 |
this.id = id; |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* @return the refresh |
|
44 |
*/ |
|
45 |
public Boolean getRefresh() { |
|
46 |
return refresh; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @param refresh |
|
51 |
* the refresh to set |
|
52 |
*/ |
|
53 |
public void setRefresh(final Boolean refresh) { |
|
54 |
this.refresh = refresh; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* @return the size |
|
59 |
*/ |
|
60 |
public long getSize() { |
|
61 |
return size; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* @param size |
|
66 |
* the size to set |
|
67 |
*/ |
|
68 |
public void setSize(final long size) { |
|
69 |
this.size = size; |
|
70 |
} |
|
71 |
|
|
72 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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(final String mdId) throws MDStoreServiceException; |
|
11 |
|
|
12 |
MDStore readMDStore(final String mdId) throws MDStoreServiceException; |
|
13 |
|
|
14 |
MDStore startTransaction(final String mdId, final boolean refresh) throws MDStoreServiceException; |
|
15 |
|
|
16 |
void commit(final String transactionId, final String mdId) throws MDStoreServiceException; |
|
17 |
|
|
18 |
List<MDStoreDescription> listMDStores() throws MDStoreServiceException; |
|
19 |
|
|
20 |
List<String> listMDStores(final String format, final String layout, final String interpretation) throws MDStoreServiceException; |
|
21 |
|
|
22 |
void createMDStore(final String mdId, final String format, final String interpretation, final String layout) throws MDStoreServiceException; |
|
23 |
|
|
24 |
void deleteMDStore(final String id) throws MDStoreServiceException; |
|
25 |
|
|
26 |
int getCachedSize(final String id) throws MDStoreServiceException; |
|
27 |
|
|
28 |
void refreshSizes() throws MDStoreServiceException; |
|
29 |
|
|
30 |
int refreshSize(final String id) throws MDStoreServiceException; |
|
31 |
|
|
32 |
int getSumOfSizes(final String format, final String layout, final String interpretation) throws MDStoreServiceException; |
|
33 |
|
|
34 |
void startGarbage() throws MDStoreServiceException; |
|
35 |
|
|
36 |
void invalidTransaction(final String transactionId, final String mdId) throws MDStoreServiceException; |
|
37 |
|
|
38 |
MDStoreDBStatus getDBStatus(); |
|
39 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreManagerInfo.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.connector; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
public class MDStoreManagerInfo { |
|
7 |
|
|
8 |
private String mdId; |
|
9 |
private String currentId; |
|
10 |
private List<MDStoreExpiredInfo> stillUsed; |
|
11 |
private List<MDStoreTransactionInfo> transactions; |
|
12 |
|
|
13 |
public String getMdId() { |
|
14 |
return mdId; |
|
15 |
} |
|
16 |
|
|
17 |
public void setMdId(final String mdId) { |
|
18 |
this.mdId = mdId; |
|
19 |
} |
|
20 |
|
|
21 |
public String getCurrentId() { |
|
22 |
return currentId; |
|
23 |
} |
|
24 |
|
|
25 |
public void setCurrentId(final String currentId) { |
|
26 |
this.currentId = currentId; |
|
27 |
} |
|
28 |
|
|
29 |
public List<MDStoreExpiredInfo> getStillUsed() { |
|
30 |
return stillUsed; |
|
31 |
} |
|
32 |
|
|
33 |
public void setStillUsed(final List<MDStoreExpiredInfo> stillUsed) { |
|
34 |
this.stillUsed = stillUsed; |
|
35 |
} |
|
36 |
|
|
37 |
public List<MDStoreTransactionInfo> getTransactions() { |
|
38 |
return transactions; |
|
39 |
} |
|
40 |
|
|
41 |
public void setTransactions(final List<MDStoreTransactionInfo> transactions) { |
|
42 |
this.transactions = transactions; |
|
43 |
} |
|
44 |
|
|
45 |
public void addExpiredItem(final MDStoreExpiredInfo info) { |
|
46 |
if (stillUsed == null) { |
|
47 |
stillUsed = new ArrayList<MDStoreExpiredInfo>(); |
|
48 |
} |
|
49 |
stillUsed.add(info); |
|
50 |
} |
|
51 |
|
|
52 |
public void addTransactionInfo(final MDStoreTransactionInfo info) { |
|
53 |
if (transactions == null) { |
|
54 |
transactions = new ArrayList<MDStoreTransactionInfo>(); |
|
55 |
} |
|
56 |
transactions.add(info); |
|
57 |
} |
|
58 |
|
|
59 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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 |
@Override |
|
42 |
public String toString() { |
|
43 |
return "MDStoreDBStatus{" + |
|
44 |
"handledDatastructures=" + handledDatastructures + |
|
45 |
", usedDiskSpace=" + usedDiskSpace + |
|
46 |
", date='" + date + '\'' + |
|
47 |
'}'; |
|
48 |
} |
|
49 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStoreExpiredInfo.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.connector; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
|
|
5 |
public class MDStoreExpiredInfo { |
|
6 |
|
|
7 |
private String id; |
|
8 |
private Date lastRead; |
|
9 |
|
|
10 |
/** |
|
11 |
* @return the lastRead |
|
12 |
*/ |
|
13 |
public Date getLastRead() { |
|
14 |
return lastRead; |
|
15 |
} |
|
16 |
|
|
17 |
/** |
|
18 |
* @param lastRead |
|
19 |
* the lastRead to set |
|
20 |
*/ |
|
21 |
public void setLastRead(final Date lastRead) { |
|
22 |
this.lastRead = lastRead; |
|
23 |
} |
|
24 |
|
|
25 |
/** |
|
26 |
* @return the id |
|
27 |
*/ |
|
28 |
public String getId() { |
|
29 |
return id; |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* @param id |
|
34 |
* the id to set |
|
35 |
*/ |
|
36 |
public void setId(final String id) { |
|
37 |
this.id = id; |
|
38 |
} |
|
39 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStore.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.connector; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import eu.dnetlib.data.mdstore.DocumentNotFoundException; |
|
7 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
8 |
import eu.dnetlib.data.mdstore.modular.MDFormatDescription; |
|
9 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
10 |
|
|
11 |
public interface MDStore { |
|
12 |
|
|
13 |
String getId(); |
|
14 |
|
|
15 |
String getFormat(); |
|
16 |
|
|
17 |
String getInterpretation(); |
|
18 |
|
|
19 |
String getLayout(); |
|
20 |
|
|
21 |
void truncate(); |
|
22 |
|
|
23 |
int feed(Iterable<String> records, boolean incremental); |
|
24 |
|
|
25 |
int feed(Iterable<String> records, boolean incremental, List<MDFormatDescription> mdformats); |
|
26 |
|
|
27 |
ResultSetListener deliver(String from, String until, String recordFilter) throws MDStoreServiceException; |
|
28 |
|
|
29 |
ResultSetListener deliverIds(String from, String until, String recordFilter) throws MDStoreServiceException; |
|
30 |
|
|
31 |
Iterable<String> iterate(); |
|
32 |
|
|
33 |
int getSize(); |
|
34 |
|
|
35 |
void deleteRecord(String recordId); |
|
36 |
|
|
37 |
String getRecord(String recordId) throws DocumentNotFoundException; |
|
38 |
|
|
39 |
List<String> deliver(String mdId, int pageSize, int offset, Map<String, String> queryParam); |
|
40 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/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/tags/cnr-modular-mdstore-service-6.0.4/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 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
6 |
|
|
7 |
/** |
|
8 |
* Parses a mdrecord and extracts the minimum information (like id, date etc) which is necessary for the mdstoring |
|
9 |
* process. |
|
10 |
* |
|
11 |
* @author marko |
|
12 |
* |
|
13 |
*/ |
|
14 |
public interface RecordParser { |
|
15 |
|
|
16 |
Map<String, String> parseRecord(String record); |
|
17 |
|
|
18 |
void setTimestamp(long ts); |
|
19 |
|
|
20 |
default long getTimestamp() { |
|
21 |
return DateUtils.now(); |
|
22 |
} |
|
23 |
|
|
24 |
} |
modules/cnr-modular-mdstore-service/tags/cnr-modular-mdstore-service-6.0.4/src/main/java/eu/dnetlib/data/mdstore/modular/MDFormatDescription.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by sandro on 11/29/16. |
|
5 |
*/ |
|
6 |
public class MDFormatDescription { |
|
7 |
|
|
8 |
private String name; |
|
9 |
|
|
10 |
private String xpath; |
|
11 |
|
|
12 |
public MDFormatDescription() { |
|
13 |
|
|
14 |
} |
|
15 |
|
|
16 |
public MDFormatDescription(String name, String xpath) { |
|
17 |
this.name = name; |
|
18 |
this.xpath = xpath; |
|
19 |
} |
|
20 |
|
|
21 |
public String getName() { |
|
22 |
return name; |
|
23 |
} |
|
24 |
|
|
25 |
public void setName(String name) { |
|
26 |
this.name = name; |
|
27 |
} |
|
28 |
|
|
29 |
public String getXpath() { |
|
30 |
return xpath; |
|
31 |
} |
|
32 |
|
|
33 |
public void setXpath(String xpath) { |
|
34 |
this.xpath = xpath; |
|
35 |
} |
|
36 |
} |
Also available in: Unified diff
[maven-release-plugin] copy for tag cnr-modular-mdstore-service-6.0.4