Revision 45144
Added by Claudio Atzori over 7 years ago
modules/dnet-oai-store-service/src/test/java/eu/dnetlib/data/oai/store/sets/MongoSetCollectionTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.sets; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
|
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
public class MongoSetCollectionTest { |
|
9 |
|
|
10 |
private MongoSetCollection mongoSetCollection; |
|
11 |
private String strangeSet = "Наукові журнали Національного Авіаційного Університету"; |
|
12 |
|
|
13 |
@Before |
|
14 |
public void setup() { |
|
15 |
this.mongoSetCollection = new MongoSetCollection(); |
|
16 |
} |
|
17 |
|
|
18 |
@Test |
|
19 |
public void test() { |
|
20 |
String normalised = this.mongoSetCollection.normalizeSetSpec(strangeSet); |
|
21 |
assertEquals(MongoSetCollection.DEFAULT_SET, normalised); |
|
22 |
} |
|
23 |
|
|
24 |
} |
modules/dnet-oai-store-service/src/test/java/eu/dnetlib/data/oai/store/mongo/MongoPublisherStoreTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.dnetlib.data.oai.store.mongo; |
|
5 |
|
|
6 |
import java.io.IOException; |
|
7 |
|
|
8 |
import org.bson.types.Binary; |
|
9 |
import org.junit.Assert; |
|
10 |
import org.junit.Test; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* @author sandro |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class MongoPublisherStoreTest { |
|
18 |
|
|
19 |
/** |
|
20 |
* Test method for {@link eu.dnetlib.data.oai.store.mongo.MongoPublisherStore#createCompressRecord(java.lang.String)}. |
|
21 |
* @throws IOException |
|
22 |
*/ |
|
23 |
@Test |
|
24 |
public void testCreateCompressRecord() throws IOException { |
|
25 |
|
|
26 |
MongoPublisherStore store = new MongoPublisherStore(); |
|
27 |
RecordInfoGenerator gen = new RecordInfoGenerator(); |
|
28 |
StringBuffer buffer = new StringBuffer(); |
|
29 |
String input =" CIAO MONDO DA SANDRO!"; |
|
30 |
|
|
31 |
for (int i=0; i< 10000; i++) { |
|
32 |
buffer.append(input); |
|
33 |
} |
|
34 |
Binary data = store.createCompressRecord(buffer.toString()); |
|
35 |
Assert.assertEquals(buffer.toString(),gen.decompressRecord(data.getData())); |
|
36 |
|
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
} |
modules/dnet-oai-store-service/src/test/java/eu/dnetlib/data/oai/store/mongo/MetadataExtractorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
|
|
5 |
import org.apache.commons.io.IOUtils; |
|
6 |
import org.dom4j.Document; |
|
7 |
import org.dom4j.io.SAXReader; |
|
8 |
import org.junit.After; |
|
9 |
import org.junit.Before; |
|
10 |
import org.junit.Test; |
|
11 |
import org.springframework.core.io.ClassPathResource; |
|
12 |
|
|
13 |
/** |
|
14 |
* MetadataExtractor Tester. |
|
15 |
* |
|
16 |
* @author alessia |
|
17 |
* @version 1.0 |
|
18 |
* @since <pre>Apr 6, 2016</pre> |
|
19 |
*/ |
|
20 |
public class MetadataExtractorTest { |
|
21 |
|
|
22 |
final MetadataExtractor extractor = new MetadataExtractor(); |
|
23 |
final SAXReader reader = new SAXReader(); |
|
24 |
private Document doc; |
|
25 |
private String filePath = "/eu/dnetlib/data/oai/store/mongo/testRecord.xml"; |
|
26 |
|
|
27 |
@Before |
|
28 |
public void before() throws Exception { |
|
29 |
String testRecord = IOUtils.toString(new ClassPathResource(filePath).getInputStream()); |
|
30 |
doc = reader.read(new StringReader(testRecord)); |
|
31 |
} |
|
32 |
|
|
33 |
@After |
|
34 |
public void after() throws Exception { |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Method: evaluate(final Document xmlDoc) |
|
39 |
*/ |
|
40 |
@Test |
|
41 |
public void testEvaluate() throws Exception { |
|
42 |
long timeStart = System.currentTimeMillis(); |
|
43 |
String metadata = extractor.evaluate(doc); |
|
44 |
long timeEnd = System.currentTimeMillis(); |
|
45 |
System.out.println("Got metadata in ms " + (timeEnd - timeStart)); |
|
46 |
System.out.println(metadata); |
|
47 |
} |
|
48 |
|
|
49 |
} |
modules/dnet-oai-store-service/src/test/java/eu/dnetlib/data/oai/store/mongo/ProvenanceExtractorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
|
|
5 |
import org.apache.commons.io.IOUtils; |
|
6 |
import org.dom4j.Document; |
|
7 |
import org.dom4j.io.SAXReader; |
|
8 |
import org.junit.After; |
|
9 |
import org.junit.Before; |
|
10 |
import org.junit.Test; |
|
11 |
import org.springframework.core.io.ClassPathResource; |
|
12 |
|
|
13 |
/** |
|
14 |
* ProvenanceExtractor Tester. |
|
15 |
* |
|
16 |
* @author <Authors name> |
|
17 |
* @version 1.0 |
|
18 |
* @since <pre>Apr 6, 2016</pre> |
|
19 |
*/ |
|
20 |
public class ProvenanceExtractorTest { |
|
21 |
|
|
22 |
final ProvenanceExtractor extractor = new ProvenanceExtractor(); |
|
23 |
final SAXReader reader = new SAXReader(); |
|
24 |
private Document doc; |
|
25 |
private String filePath = "/eu/dnetlib/data/oai/store/mongo/testRecord.xml"; |
|
26 |
|
|
27 |
@Before |
|
28 |
public void before() throws Exception { |
|
29 |
String testRecord = IOUtils.toString(new ClassPathResource(filePath).getInputStream()); |
|
30 |
doc = reader.read(new StringReader(testRecord)); |
|
31 |
} |
|
32 |
|
|
33 |
@After |
|
34 |
public void after() throws Exception { |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Method: evaluate(final Document xmlDoc) |
|
39 |
*/ |
|
40 |
@Test |
|
41 |
public void testEvaluate() throws Exception { |
|
42 |
long timeStart = System.currentTimeMillis(); |
|
43 |
String prov = extractor.evaluate(doc); |
|
44 |
long timeEnd = System.currentTimeMillis(); |
|
45 |
System.out.println("Got provenance in ms " + (timeEnd - timeStart)); |
|
46 |
System.out.println(prov); |
|
47 |
} |
|
48 |
|
|
49 |
} |
modules/dnet-oai-store-service/src/test/java/eu/dnetlib/data/oai/store/mongo/RecordInfoGeneratorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.zip.ZipEntry; |
|
5 |
import java.util.zip.ZipOutputStream; |
|
6 |
|
|
7 |
import eu.dnetlib.data.information.oai.publisher.conf.OAIConfigurationReader; |
|
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.apache.commons.io.output.ByteArrayOutputStream; |
|
10 |
import org.bson.types.Binary; |
|
11 |
import org.junit.Before; |
|
12 |
import org.junit.Test; |
|
13 |
import org.springframework.core.io.ClassPathResource; |
|
14 |
|
|
15 |
/** |
|
16 |
* RecordInfoGenerator Tester. |
|
17 |
* |
|
18 |
* @author <Authors name> |
|
19 |
* @version 1.0 |
|
20 |
* @since <pre>Apr 6, 2016</pre> |
|
21 |
*/ |
|
22 |
public class RecordInfoGeneratorTest { |
|
23 |
|
|
24 |
private RecordInfoGenerator gen = new RecordInfoGenerator(); |
|
25 |
private String filePath = "/eu/dnetlib/data/oai/store/mongo/testRecord.xml"; |
|
26 |
private Binary binaryXML; |
|
27 |
|
|
28 |
@Before |
|
29 |
public void before() throws Exception { |
|
30 |
String testRecord = IOUtils.toString(new ClassPathResource(filePath).getInputStream()); |
|
31 |
binaryXML = createCompressRecord(testRecord); |
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* Method: decompressRecord(final byte[] input) |
|
36 |
*/ |
|
37 |
@Test |
|
38 |
public void testDecompressRecord() throws Exception { |
|
39 |
long timeStart = System.currentTimeMillis(); |
|
40 |
String record = gen.decompressRecord(binaryXML.getData()); |
|
41 |
long timeEnd = System.currentTimeMillis(); |
|
42 |
System.out.println("Decompressed record in ms " + (timeEnd - timeStart)); |
|
43 |
System.out.println(record); |
|
44 |
} |
|
45 |
|
|
46 |
private Binary createCompressRecord(final String record) throws IOException { |
|
47 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
48 |
ZipOutputStream zos = new ZipOutputStream(os); |
|
49 |
ZipEntry entry = new ZipEntry(OAIConfigurationReader.BODY_FIELD); |
|
50 |
zos.putNextEntry(entry); |
|
51 |
zos.write(record.getBytes()); |
|
52 |
zos.closeEntry(); |
|
53 |
//zos.flush(); |
|
54 |
zos.close(); |
|
55 |
return new Binary(os.toByteArray()); |
|
56 |
} |
|
57 |
|
|
58 |
} |
modules/dnet-oai-store-service/src/test/resources/eu/dnetlib/test/profiles/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType/OAIPublisherConfiguration-1.xml | ||
---|---|---|
1 |
<RESOURCE_PROFILE> |
|
2 |
<HEADER> |
|
3 |
<RESOURCE_IDENTIFIER value="OAIPublisherConfiguration" /> |
|
4 |
<RESOURCE_TYPE value="OAIPublisherConfigurationDSResourceType" /> |
|
5 |
<RESOURCE_KIND value="OAIPublisherConfigurationDSResources" /> |
|
6 |
<RESOURCE_URI value="" /> |
|
7 |
<DATE_OF_CREATION value="2001-12-31T12:00:00" /> |
|
8 |
</HEADER> |
|
9 |
<BODY> |
|
10 |
<CONFIGURATION> |
|
11 |
<OAISETS> |
|
12 |
<OAISET enabled="true"> |
|
13 |
<spec>OpenAccess</spec> |
|
14 |
<name>Set of Open Access articles</name> |
|
15 |
<description>Set of records having 'OPEN' license</description> |
|
16 |
<query>(license = "OPEN")</query> |
|
17 |
</OAISET> |
|
18 |
<OAISET enabled="true"> |
|
19 |
<spec>ArticlesInNature</spec> |
|
20 |
<name>Articles published by Nature</name> |
|
21 |
<description>Set of articles published by Nature Publishing Group</description> |
|
22 |
<query>(publisher = "Nature Publishing Group")</query> |
|
23 |
</OAISET> |
|
24 |
<OAISET enabled="true"> |
|
25 |
<spec>publications</spec> |
|
26 |
<name>Publications</name> |
|
27 |
<description>Set of all Publications</description> |
|
28 |
<query>resulttypeid="publication"</query> |
|
29 |
</OAISET> |
|
30 |
</OAISETS> |
|
31 |
<METADATAFORMATS> |
|
32 |
<METADATAFORMAT exportable="true" metadataPrefix="oaf"> |
|
33 |
<NAMESPACE>http://namespace.openaire.eu/oaf</NAMESPACE> |
|
34 |
<SCHEMA>http://www.openaire.eu/schema/0.1/oaf-0.1.xsd</SCHEMA> |
|
35 |
<SOURCE_METADATA_FORMAT interpretation="openaire" layout="index" name="oaf"/> |
|
36 |
<TRANSFORMATION_RULE/> |
|
37 |
<BASE_QUERY>*</BASE_QUERY> |
|
38 |
</METADATAFORMAT> |
|
39 |
<METADATAFORMAT metadataPrefix="oai_dc" exportable="false"> |
|
40 |
<NAMESPACE>http://www.openarchives.org/OAI/2.0/oai_dc/</NAMESPACE> |
|
41 |
<SCHEMA>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</SCHEMA> |
|
42 |
<SOURCE_METADATA_FORMAT interpretation="openaire" layout="index" name="oaf"/> |
|
43 |
<TRANSFORMATION_RULE>oaf2dc_VHJhbnNmb3JtYXRpb25SdWxlRFNSZXNvdXJjZXMvVHJhbnNmb3JtYXRpb25SdWxlRFNSZXNvdXJjZVR5cGU=</TRANSFORMATION_RULE> |
|
44 |
<BASE_QUERY>oaftype="result"</BASE_QUERY> |
|
45 |
</METADATAFORMAT> |
|
46 |
</METADATAFORMATS> |
|
47 |
<INDICES> |
|
48 |
<INDEX name="objIdentifier" repeatable="false"> |
|
49 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="//*[local-name() ='objIdentifier']"/> |
|
50 |
</INDEX> |
|
51 |
<INDEX name="set" repeatable="true"> |
|
52 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="//collectedfrom/@name"/> |
|
53 |
</INDEX> |
|
54 |
<INDEX name="publisher" repeatable="true"> |
|
55 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="//publisher"/> |
|
56 |
</INDEX> |
|
57 |
<INDEX name="license" repeatable="false"> |
|
58 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="//bestlicense/@classid"/> |
|
59 |
</INDEX> |
|
60 |
<INDEX name="oaftype" repeatable="false"> |
|
61 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="local-name(//*[local-name()='entity']/*)"/> |
|
62 |
</INDEX> |
|
63 |
<INDEX name="resulttypeid" repeatable="false"> |
|
64 |
<SOURCE name="oaf" layout="index" interpretation="openaire" path="//*[local-name()='entity']/*[local-name()='result']/resulttype/@classid"/> |
|
65 |
</INDEX> |
|
66 |
</INDICES> |
|
67 |
</CONFIGURATION> |
|
68 |
<STATUS> |
|
69 |
<LAST_UPDATE value="2001-12-31T12:00:00" /> |
|
70 |
</STATUS> |
|
71 |
<SECURITY_PARAMETERS>SECURITY_PARAMETERS</SECURITY_PARAMETERS> |
|
72 |
</BODY> |
|
73 |
</RESOURCE_PROFILE> |
modules/dnet-oai-store-service/src/test/resources/eu/dnetlib/data/oai/store/mongo/testRecord.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<record xmlns:dc="http://purl.org/dc/elements/1.1/" |
|
3 |
xmlns:dr="http://www.driver-repository.eu/namespace/dr" |
|
4 |
xmlns:dri="http://www.driver-repository.eu/namespace/dri" |
|
5 |
xmlns:oaf="http://namespace.openaire.eu/oaf" |
|
6 |
xmlns:oai="http://www.openarchives.org/OAI/2.0/" |
|
7 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|
8 |
<header xmlns="http://namespace.openaire.eu/"> |
|
9 |
<dri:objIdentifier>od_______263::06235d139088d4b2ca45ace37c458a01</dri:objIdentifier> |
|
10 |
<dri:recordIdentifier>oai:DiVA.org:su-91808</dri:recordIdentifier> |
|
11 |
<dri:dateOfCollection/> |
|
12 |
<dri:mdFormat/> |
|
13 |
<dri:mdFormatInterpretation/> |
|
14 |
<dri:repositoryId>866c86e1-0e6a-4e12-b5ed-b7e0eb956381_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId> |
|
15 |
<dr:objectIdentifier/> |
|
16 |
<dr:dateOfCollection>2016-04-05T06:52:25.98Z</dr:dateOfCollection> |
|
17 |
<dr:dateOfTransformation>2016-04-05T06:53:01.394Z</dr:dateOfTransformation> |
|
18 |
<oaf:datasourceprefix>od_______263</oaf:datasourceprefix> |
|
19 |
</header> |
|
20 |
<metadata xmlns="http://namespace.openaire.eu/"> |
|
21 |
<oaf:entity> |
|
22 |
<dc:title>Evaluation and Tuning of Model Trajectoriesand Spreading Rates in the Baltic Sea Using Surface Drifter Observations</dc:title> |
|
23 |
<dc:creator>Kjellsson, Joakim</dc:creator> |
|
24 |
<dc:creator>Döös, Kristofer</dc:creator> |
|
25 |
<dc:creator>Soomere, Tarmo</dc:creator> |
|
26 |
<dc:date>2013</dc:date> |
|
27 |
<dc:description>Results from experiments with surface drifters in the Baltic Sea in 2010–2011 are presented and discussed. In a first experiment, 12 SVP-B (Surface Velocity Program, with Barometer) drifters with a drogue at 12–18 m depth were deployed in the Baltic Sea. In a second experiment, shallow drifters extending to a depth of 1.5 m were deployed in the Gulf of Finland. Results from the SVP-B drifter experiment are compared to results from a regional ocean model and a trajectory code. Differences between the observed SVP-B drifters and simulated drifters are found for absolute dispersion (i.e., squared displacement from initial position) and relative dispersion (i.e., squared distance between two initially paired drifters). The former is somewhat underestimated since the simulated currents are neither as fast nor as variable as those observed. The latter is underestimated both due to the above-mentioned reasons and due to the resolution of the ocean model. For the shallower drifters, spreading in the upper 1–2 m of the Gulf of Finland is investigated. The spreading rate is about 200 m/day for separations <0.5 km, 500 m/day for separations below 1 km and in the range of 0.5–3 km/day for separations in the range of 1–4 km. The spreading rate does not follow Richardson’s law. The initial spreading, up to a distance of about d=100–150 m, is governed by the power law d∼t 0.27 whereas for larger separations the distance increases as d∼t2.5.</dc:description> |
|
28 |
<dc:description>BalticWay</dc:description> |
|
29 |
<dc:format>application/pdf</dc:format> |
|
30 |
<dc:identifier>http://urn.kb.se/resolve?urn=urn:nbn:se:su:diva-91808</dc:identifier> |
|
31 |
<dc:language>eng</dc:language> |
|
32 |
<dc:publisher>Stockholms universitet, Meteorologiska institutionen (MISU)</dc:publisher> |
|
33 |
<dc:publisher>Stockholms universitet, Meteorologiska institutionen (MISU)</dc:publisher> |
|
34 |
<dc:publisher>Institute of Cybernetics, Tallinn University of Technology</dc:publisher> |
|
35 |
<dc:relation>Preventive Methods for Coastal Protection : Towards the Use of Ocean Dynamics for Pollution Control, p. 251-281</dc:relation> |
|
36 |
<dc:relation>info:eu-repo/grantAgreement/EC/FP7/217246</dc:relation> |
|
37 |
<dc:subject>surface drifters; rco; ocean model; trajectory;</dc:subject> |
|
38 |
<dc:type>Chapter in book</dc:type> |
|
39 |
<dc:type>info:eu-repo/semantics/bookPart</dc:type> |
|
40 |
<dc:type>text</dc:type> |
|
41 |
<dr:CobjCategory>0013</dr:CobjCategory> |
|
42 |
<dr:CobjIdentifier>urn:isbn:978-3-319-00440-2</dr:CobjIdentifier> |
|
43 |
<dr:CobjIdentifier>urn:isbn:978-3-319-00439-6</dr:CobjIdentifier> |
|
44 |
<dr:CobjIdentifier>doi:10.1007/978-3-319-00440-2_8</dr:CobjIdentifier> |
|
45 |
<oaf:dateAccepted>2013-01-01</oaf:dateAccepted> |
|
46 |
<oaf:projectid>corda_______::217246</oaf:projectid> |
|
47 |
<oaf:collectedDatasourceid>opendoar____::263</oaf:collectedDatasourceid> |
|
48 |
<oaf:accessrights>OPEN</oaf:accessrights> |
|
49 |
<oaf:hostedBy id="opendoar____::263" name="Publikationer från Stockholms universitet"/> |
|
50 |
<oaf:collectedFrom id="opendoar____::263" name="Publikationer från Stockholms universitet"/> |
|
51 |
<oaf:identifier identifierType="doi">10.1007/978-3-319-00440-2_8</oaf:identifier> |
|
52 |
</oaf:entity> |
|
53 |
</metadata> |
|
54 |
<about xmlns="http://namespace.openaire.eu/"> |
|
55 |
<provenance xmlns="http://www.openarchives.org/OAI/2.0/provenance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/provenance http://www.openarchives.org/OAI/2.0/provenance.xsd"> |
|
56 |
<originDescription altered="true" harvestDate="2016-04-05T06:52:25.98Z"> |
|
57 |
<baseURL>http://su.diva-portal.org/dice/oai</baseURL> |
|
58 |
<identifier>oai:DiVA.org:su-91808</identifier> |
|
59 |
<datestamp>2013-07-05T10:47:00Z</datestamp> |
|
60 |
<metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace> |
|
61 |
</originDescription> |
|
62 |
</provenance> |
|
63 |
<oaf:datainfo> |
|
64 |
<oaf:inferred>false</oaf:inferred> |
|
65 |
<oaf:deletedbyinference>false</oaf:deletedbyinference> |
|
66 |
<oaf:trust>0.9</oaf:trust> |
|
67 |
<oaf:inferenceprovenance/> |
|
68 |
<oaf:provenanceaction classid="sysimport:crosswalk:repository" |
|
69 |
classname="sysimport:crosswalk:repository" |
|
70 |
schemeid="dnet:provenanceActions" schemename="dnet:provenanceActions"/> |
|
71 |
</oaf:datainfo> |
|
72 |
</about> |
|
73 |
</record> |
modules/dnet-oai-store-service/src/test/resources/log4j.properties | ||
---|---|---|
1 |
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger |
|
2 |
|
|
3 |
log4j.rootLogger=WARN, CONSOLE |
|
4 |
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
|
5 |
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
|
6 |
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n |
|
7 |
|
|
8 |
log4j.logger.eu.dnetlib=INFO |
|
9 |
log4j.logger.eu.dnetlib.data=DEBUG |
modules/dnet-oai-store-service/src/main/resources/eu/dnetlib/data/oai/store/xslt/addDMFBlock.xslt | ||
---|---|---|
1 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.0"> |
|
2 |
|
|
3 |
<xsl:template match="//*[local-name()='metadata']"> |
|
4 |
<metadata> |
|
5 |
<dmf> |
|
6 |
<xsl:apply-templates/> |
|
7 |
</dmf> |
|
8 |
</metadata> |
|
9 |
</xsl:template> |
|
10 |
|
|
11 |
<xsl:template match="@*|node()"> |
|
12 |
<xsl:copy> |
|
13 |
<xsl:apply-templates select="@*|node()"/> |
|
14 |
</xsl:copy> |
|
15 |
</xsl:template> |
|
16 |
</xsl:stylesheet> |
modules/dnet-oai-store-service/src/main/resources/eu/dnetlib/data/oai/store/mongo/applicationContext-mongodb-publisher-store.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xmlns:p="http://www.springframework.org/schema/p" xmlns="http://www.springframework.org/schema/beans" |
|
4 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> |
|
5 |
|
|
6 |
<bean id="mongodbPublisherStoreDao" class="eu.dnetlib.data.oai.store.mongo.MongoPublisherStoreDAO" |
|
7 |
p:metadataCollection="metadata" /> |
|
8 |
|
|
9 |
<bean id="publisherMongoClient" class="com.mongodb.MongoClient"> |
|
10 |
<constructor-arg index="0" type="com.mongodb.ServerAddress"> |
|
11 |
<bean class="com.mongodb.ServerAddress"> |
|
12 |
<constructor-arg index="0" |
|
13 |
value="${services.publisher.oai.host}" /> |
|
14 |
<constructor-arg index="1" |
|
15 |
value="${services.publisher.oai.port}" /> |
|
16 |
</bean> |
|
17 |
</constructor-arg> |
|
18 |
</bean> |
|
19 |
|
|
20 |
<bean id="recordChangeDetector" class="eu.dnetlib.data.oai.store.DummyRecordChangeDetector" /> |
|
21 |
|
|
22 |
<bean id="metadataExtractor" class="eu.dnetlib.data.oai.store.mongo.MetadataExtractor" /> |
|
23 |
|
|
24 |
<bean id="recordInfoGenerator" class="eu.dnetlib.data.oai.store.mongo.RecordInfoGenerator" /> |
|
25 |
|
|
26 |
<bean id="mongoSetCollection" class="eu.dnetlib.data.oai.store.sets.MongoSetCollection" /> |
|
27 |
|
|
28 |
<bean id="provenanceExtractor" class="eu.dnetlib.data.oai.store.mongo.ProvenanceExtractor" /> |
|
29 |
|
|
30 |
<bean id="theOAICacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" |
|
31 |
p:cache-manager-ref="oaiStoreCacheManager" /> |
|
32 |
|
|
33 |
<bean id="oaiStoreCacheManager" |
|
34 |
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" |
|
35 |
p:cacheManagerName="oaiStoreCacheManger" |
|
36 |
p:configLocation="classpath:/eu/dnetlib/data/oai/store/mongo/cache/ehcache.xml" /> |
|
37 |
|
|
38 |
</beans> |
modules/dnet-oai-store-service/src/main/resources/eu/dnetlib/data/oai/store/mongo/cache/ehcache.xml | ||
---|---|---|
1 |
<ehcache> |
|
2 |
|
|
3 |
<!-- Sets the path to the directory where cache .data files are created. |
|
4 |
If the path is a Java System Property it is replaced by its value in the |
|
5 |
running VM. The following properties are translated: user.home - User's home |
|
6 |
directory user.dir - User's current working directory java.io.tmpdir - Default |
|
7 |
temp file path --> |
|
8 |
<!--<diskStore path="java.io.tmpdir" />--> |
|
9 |
|
|
10 |
|
|
11 |
<!--Default Cache configuration. These will applied to caches programmatically |
|
12 |
created through the CacheManager. The following attributes are required for |
|
13 |
defaultCache: maxInMemory - Sets the maximum number of objects that will |
|
14 |
be created in memory eternal - Sets whether elements are eternal. If eternal, |
|
15 |
timeouts are ignored and the element is never expired. timeToIdleSeconds |
|
16 |
- Sets the time to idle for an element before it expires. i.e. The maximum |
|
17 |
amount of time between accesses before an element expires Is only used if |
|
18 |
the element is not eternal. Optional attribute. A value of 0 means that an |
|
19 |
Element can idle for infinity timeToLiveSeconds - Sets the time to live for |
|
20 |
an element before it expires. i.e. The maximum time between creation time |
|
21 |
and when an element expires. Is only used if the element is not eternal. |
|
22 |
overflowToDisk - Sets whether elements can overflow to disk when the in-memory |
|
23 |
cache has reached the maxInMemory limit. --> |
|
24 |
|
|
25 |
<!-- <defaultCache maxElementsInMemory="1000" overflowToDisk="true" --> |
|
26 |
<!-- eternal="true" diskPersistent="false" timeToIdleSeconds="0" --> |
|
27 |
<!-- timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU" --> |
|
28 |
<!-- diskExpiryThreadIntervalSeconds="120" diskSpoolBufferSizeMB="5" /> --> |
|
29 |
|
|
30 |
|
|
31 |
<cache name="oaistores" maxElementsInMemory="100" eternal="false" |
|
32 |
timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="false" /> |
|
33 |
|
|
34 |
<cache name="oaistoresById" maxElementsInMemory="100" |
|
35 |
eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="1800" |
|
36 |
overflowToDisk="false" /> |
|
37 |
|
|
38 |
|
|
39 |
</ehcache> |
|
40 |
|
modules/dnet-oai-store-service/src/main/resources/eu/dnetlib/data/oai/store/mongo/applicationContext-mongodb-publisher-store.properties | ||
---|---|---|
1 |
services.publisher.oai.host=localhost |
|
2 |
services.publisher.oai.port=27017 |
|
3 |
#services.publisher.oai.db=oaistore |
|
4 |
|
modules/dnet-oai-store-service/src/main/resources/eu/dnetlib/applicationContext-dnet-oai-store-service.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 |
xmlns:util="http://www.springframework.org/schema/util" |
|
8 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
9 |
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd |
|
10 |
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd |
|
11 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd |
|
12 |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd |
|
13 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd |
|
14 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
|
15 |
|
|
16 |
<!-- endpoints --> |
|
17 |
<jaxws:endpoint id="oaiStoreServiceEndpoint" |
|
18 |
implementor="#oaiStoreService" implementorClass="eu.dnetlib.data.oai.store.OAIStoreService" |
|
19 |
address="/oaistore" /> |
|
20 |
|
|
21 |
<template:instance name="serviceRegistrationManager" |
|
22 |
t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl" |
|
23 |
t:name="oaiStoreServiceRegistrationManager" t:service="oaiStoreService" |
|
24 |
t:endpoint="oaiStoreServiceEndpoint" t:jobScheduler="jobScheduler" |
|
25 |
t:serviceRegistrator="blackboardServiceRegistrator" /> |
|
26 |
|
|
27 |
<bean id="oaiStoreService" class="eu.dnetlib.data.oai.store.OAIStoreServiceImpl" |
|
28 |
init-method="start" destroy-method="stop" p:notificationHandler-ref="oaiStoreNotificationHandler" /> |
|
29 |
|
|
30 |
<bean id="oaiStoreNotificationHandler" |
|
31 |
class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerExecutorNotificationHandler" |
|
32 |
p:blackboardExecutor-ref="oaiStoreBlackboardExecutor" /> |
|
33 |
|
|
34 |
<bean id="oaiStoreBlackboardExecutor" |
|
35 |
class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerActionExecutor" |
|
36 |
p:blackboardHandler-ref="blackboardHandler" |
|
37 |
p:actionType="eu.dnetlib.data.oai.store.actions.OAIStoreActions" |
|
38 |
p:incomplete="false"> |
|
39 |
<property name="actionMap"> |
|
40 |
<map> |
|
41 |
<entry key="SYNC"> |
|
42 |
<bean class="eu.dnetlib.data.oai.store.actions.SyncAction" /> |
|
43 |
</entry> |
|
44 |
<entry key="COUNT_SETS"> |
|
45 |
<bean class="eu.dnetlib.data.oai.store.actions.CountSetsAction"/> |
|
46 |
</entry> |
|
47 |
<entry key="REFRESH_CONFIG"> |
|
48 |
<bean class="eu.dnetlib.data.oai.store.actions.RefreshConfigAction" /> |
|
49 |
</entry> |
|
50 |
<entry key="ENSURE_INDEXES"> |
|
51 |
<bean class="eu.dnetlib.data.oai.store.actions.EnsureIndexesAction" /> |
|
52 |
</entry> |
|
53 |
<entry key="CREATE_STORE"> |
|
54 |
<bean class="eu.dnetlib.data.oai.store.actions.CreateStoreAction" /> |
|
55 |
</entry> |
|
56 |
<entry key="CREATE_OAI_INDEX"> |
|
57 |
<bean class="eu.dnetlib.data.oai.store.actions.CreateOAIIndexAction" /> |
|
58 |
</entry> |
|
59 |
<entry key="DROP_STORE"> |
|
60 |
<bean class="eu.dnetlib.data.oai.store.actions.DropStoreAction" /> |
|
61 |
</entry> |
|
62 |
</map> |
|
63 |
</property> |
|
64 |
</bean> |
|
65 |
|
|
66 |
<bean id="synchronizer" class="eu.dnetlib.data.oai.store.sync.OAIStoreSynchronizer" /> |
|
67 |
|
|
68 |
<bean id="oaiHelper" class="eu.dnetlib.data.oai.store.conf.OAIHelper"/> |
|
69 |
|
|
70 |
<bean id="oaiSetsCounter" class="eu.dnetlib.data.oai.store.conf.OAISetsCounter" /> |
|
71 |
|
|
72 |
<bean id="mongoCacheHelper" class="eu.dnetlib.data.oai.store.mongo.MongoPublisherCacheHelper"/> |
|
73 |
|
|
74 |
</beans> |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/Cursor.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store; |
|
2 |
|
|
3 |
import eu.dnetlib.data.information.oai.publisher.info.RecordInfo; |
|
4 |
|
|
5 |
public interface Cursor extends Iterable<RecordInfo> { |
|
6 |
|
|
7 |
int count(); |
|
8 |
|
|
9 |
boolean isBodyIncluded(); |
|
10 |
|
|
11 |
void setBodyIncluded(boolean bodyIncluded); |
|
12 |
|
|
13 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/PublisherStoreDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherException; |
|
6 |
|
|
7 |
public interface PublisherStoreDAO<X extends PublisherStore<T>, T extends Cursor> { |
|
8 |
|
|
9 |
/** |
|
10 |
* Lists all PublisherStore. |
|
11 |
* |
|
12 |
* @param dbName |
|
13 |
* name of the target database |
|
14 |
* |
|
15 |
* @return a List of PublisherStore instances. |
|
16 |
*/ |
|
17 |
List<X> listPublisherStores(final String dbName); |
|
18 |
|
|
19 |
/** |
|
20 |
* Gets the store with the given identifier. |
|
21 |
* |
|
22 |
* @param dbName |
|
23 |
* name of the target database |
|
24 |
* |
|
25 |
* @param storeId |
|
26 |
* identifier of the store to retrieve |
|
27 |
* @return a PublisherStore instance or null if there is no store with the given id. |
|
28 |
*/ |
|
29 |
X getStore(final String storeId, final String dbName); |
|
30 |
|
|
31 |
/** |
|
32 |
* Gets the store with the given properties. |
|
33 |
* |
|
34 |
* @param mdfName |
|
35 |
* name of the metadata format |
|
36 |
* @param mdfInterpretation |
|
37 |
* name of the metadata interpretation |
|
38 |
* @param mdfLayout |
|
39 |
* name of the metadata layout |
|
40 |
* @param dbName |
|
41 |
* name of the target database |
|
42 |
* @return a PublisherStore instance or null if there is no store with the given properties. |
|
43 |
*/ |
|
44 |
X getStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName); |
|
45 |
|
|
46 |
/** |
|
47 |
* Gets the store to be used as source to deliver records with the given metadata prefix. |
|
48 |
* |
|
49 |
* @param targetMetadataPrefix |
|
50 |
* prefix of the metadata format deliverable through this store |
|
51 |
* @param dbName |
|
52 |
* name of the target database |
|
53 |
* @return a PublisherStore instance or null if there is no store serving the given metadata prefix. |
|
54 |
*/ |
|
55 |
X getStoreFor(final String targetMetadataPrefix, final String dbName); |
|
56 |
|
|
57 |
/** |
|
58 |
* Create a PublisherStore with the given properties. |
|
59 |
* |
|
60 |
* @param mdfName |
|
61 |
* name of the metadata format |
|
62 |
* @param mdfInterpretation |
|
63 |
* name of the metadata interpretation |
|
64 |
* @param mdfLayout |
|
65 |
* name of the metadata layout |
|
66 |
* @param dbName |
|
67 |
* name of the target database |
|
68 |
* @return a PublisherStore instance whose identifier is automatically generated. |
|
69 |
* @throws OaiPublisherException |
|
70 |
* if there is already another PublisherStore with the given metadata format name, layout and interpretation. |
|
71 |
*/ |
|
72 |
X createStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName) throws OaiPublisherException; |
|
73 |
|
|
74 |
/** |
|
75 |
* Deletes the store with the given identifier. |
|
76 |
* |
|
77 |
* @param storeId |
|
78 |
* id of the store to delete |
|
79 |
* @param dbName |
|
80 |
* name of the target database |
|
81 |
* @return true if the store was deleted successfully, false otherwise (e.g., a store with the given id does not exist). |
|
82 |
*/ |
|
83 |
boolean deleteStore(final String storeId, final String dbName); |
|
84 |
|
|
85 |
/** |
|
86 |
* Deletes from the store with the given identifier the records belonging to the given set. |
|
87 |
* |
|
88 |
* @param storeId |
|
89 |
* id of the store to delete |
|
90 |
* @param dbName |
|
91 |
* name of the target database |
|
92 |
* @param set |
|
93 |
* name of the set |
|
94 |
* @return true if the records were deleted successfully, false otherwise (e.g., a store with the given id does not exist). |
|
95 |
*/ |
|
96 |
boolean deleteFromStore(final String storeId, final String dbName, final String set); |
|
97 |
|
|
98 |
/** |
|
99 |
* Deletes from the store with the given identifier the records belonging to the given set. |
|
100 |
* |
|
101 |
* @param mdfName |
|
102 |
* name of the metadata format |
|
103 |
* @param mdfInterpretation |
|
104 |
* name of the metadata interpretation |
|
105 |
* @param mdfLayout |
|
106 |
* name of the metadata layout |
|
107 |
* @param dbName |
|
108 |
* name of the target database |
|
109 |
* @param set |
|
110 |
* name of the set |
|
111 |
* @return true if the records were deleted successfully, false otherwise (e.g., a store with the given id does not exist). |
|
112 |
*/ |
|
113 |
boolean deleteFromStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName, final String set); |
|
114 |
|
|
115 |
/** |
|
116 |
* Deletes the store with the given properties. |
|
117 |
* |
|
118 |
* @param mdfName |
|
119 |
* name of the metadata format |
|
120 |
* @param mdfInterpretation |
|
121 |
* name of the metadata interpretation |
|
122 |
* @param mdfLayout |
|
123 |
* name of the metadata layout |
|
124 |
* @param dbName |
|
125 |
* name of the target database |
|
126 |
* @return true if the store was deleted successfully, false otherwise (e.g., a store with the given properties does not exist). |
|
127 |
*/ |
|
128 |
boolean deleteStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName); |
|
129 |
|
|
130 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/RecordChangeDetector.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store; |
|
2 |
|
|
3 |
public interface RecordChangeDetector { |
|
4 |
|
|
5 |
/** |
|
6 |
* Checks if the two records have differences based on logics that vary on the actual implementor class. |
|
7 |
* |
|
8 |
* @param record1 |
|
9 |
* first record to compare |
|
10 |
* @param record2 |
|
11 |
* second record to compare |
|
12 |
* @return true if the two records differ based on the implementor's logics |
|
13 |
*/ |
|
14 |
boolean differs(final String record1, final String record2); |
|
15 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/sets/MongoSetCollection.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.sets; |
|
2 |
|
|
3 |
import java.text.Normalizer; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.common.collect.Lists; |
|
9 |
import com.mongodb.BasicDBObject; |
|
10 |
import com.mongodb.BasicDBObjectBuilder; |
|
11 |
import com.mongodb.DBObject; |
|
12 |
import com.mongodb.MongoClient; |
|
13 |
import com.mongodb.client.FindIterable; |
|
14 |
import com.mongodb.client.MongoCollection; |
|
15 |
import com.mongodb.client.model.Filters; |
|
16 |
import com.mongodb.client.model.FindOneAndReplaceOptions; |
|
17 |
import com.mongodb.client.model.FindOneAndUpdateOptions; |
|
18 |
import com.mongodb.client.model.IndexOptions; |
|
19 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
20 |
import eu.dnetlib.data.information.oai.sets.SetCollection; |
|
21 |
import org.apache.commons.lang.StringEscapeUtils; |
|
22 |
import org.apache.commons.lang.StringUtils; |
|
23 |
import org.bson.conversions.Bson; |
|
24 |
import org.springframework.beans.factory.annotation.Autowired; |
|
25 |
|
|
26 |
public class MongoSetCollection implements SetCollection { |
|
27 |
|
|
28 |
public static String DEFAULT_SET = "OTHER"; |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private MongoClient publisherMongoClient; |
|
32 |
private String setCollection = "sets"; |
|
33 |
private String setCountCollection = "setsCount"; |
|
34 |
|
|
35 |
public void ensureIndexes(final String dbName) { |
|
36 |
this.ensureIndexesOnSets(dbName); |
|
37 |
this.ensureIndexesOnCount(dbName); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public List<SetInfo> getAllSets(final boolean enabledOnly, final String dbName) { |
|
42 |
FindIterable<DBObject> iter = null; |
|
43 |
if (!enabledOnly) { |
|
44 |
iter = this.getSetsCollection(dbName).find(); |
|
45 |
} else { |
|
46 |
Bson where = Filters.eq("enabled", true); |
|
47 |
iter = this.getSetsCollection(dbName).find(where); |
|
48 |
} |
|
49 |
return Lists.newArrayList(Iterables.transform(iter, new Function<DBObject, SetInfo>() { |
|
50 |
|
|
51 |
@Override |
|
52 |
public SetInfo apply(final DBObject dbObject) { |
|
53 |
return getSetFromDBObject(dbObject); |
|
54 |
} |
|
55 |
})); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public boolean containSet(final String set, final String dbName) { |
|
60 |
Bson query = Filters.eq("spec", set); |
|
61 |
return this.getSetsCollection(dbName).count(query) != 0; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean containEnabledSet(final String set, final String publisherDBName) { |
|
66 |
Bson query = Filters.and(Filters.eq("spec", set), Filters.eq("enabled", true)); |
|
67 |
return this.getSetsCollection(publisherDBName).count(query) != 0; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public String getSetQuery(final String set, final String dbName) { |
|
72 |
Bson query = Filters.eq("spec", set); |
|
73 |
BasicDBObject returnField = new BasicDBObject("query", 1); |
|
74 |
DBObject obj = this.getSetsCollection(dbName).find(query).projection(returnField).first(); |
|
75 |
return (String) obj.get("query"); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public int count(final String setSpec, final String mdPrefix, final String dbName) { |
|
80 |
Bson query = Filters.and(Filters.eq("spec", setSpec), Filters.eq("mdPrefix", mdPrefix)); |
|
81 |
BasicDBObject returnField = new BasicDBObject("count", 1); |
|
82 |
DBObject obj = this.getSetsCountCollection(dbName).find(query).projection(returnField).first(); |
|
83 |
if (obj == null) return 0; |
|
84 |
return (Integer) obj.get("count"); |
|
85 |
} |
|
86 |
|
|
87 |
public void updateCounts(final String setSpec, final String mdPrefix, final int count, final String dbName) { |
|
88 |
BasicDBObject countUpdate = new BasicDBObject("$set", new BasicDBObject("count", count)); |
|
89 |
Bson query = Filters.and(Filters.eq("spec", setSpec), Filters.eq("mdPrefix", mdPrefix)); |
|
90 |
this.getSetsCountCollection(dbName).findOneAndUpdate(query, countUpdate, new FindOneAndUpdateOptions().upsert(true)); |
|
91 |
} |
|
92 |
|
|
93 |
public void upsertSet(final SetInfo setInfo, final boolean fromConfiguration, final String dbName) { |
|
94 |
DBObject obj = this.getObjectFromSet(setInfo); |
|
95 |
obj.put("fromConfiguration", fromConfiguration); |
|
96 |
//this.getSetsCollection(dbName).update(new BasicDBObject("spec", setInfo.getSetSpec()), obj, true, false); |
|
97 |
this.getSetsCollection(dbName).findOneAndReplace(Filters.eq("spec", setInfo.getSetSpec()), obj, new FindOneAndReplaceOptions().upsert(true)); |
|
98 |
} |
|
99 |
|
|
100 |
public String normalizeSetSpec(final String setName) { |
|
101 |
String s = StringEscapeUtils.unescapeXml(setName); |
|
102 |
s = Normalizer.normalize(s, Normalizer.Form.NFD); |
|
103 |
// replace spaces with underscores |
|
104 |
s = s.replaceAll(" ", "_"); |
|
105 |
// remove tilde, dots... over letters |
|
106 |
s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}&&[^-_]]", ""); |
|
107 |
// change punctuation into an underscore |
|
108 |
s = s.replaceAll("[\\p{Punct}&&[^-_]]", "_"); |
|
109 |
// remove all non-word characters |
|
110 |
s = s.replaceAll("[\\W&&[^-_]]", ""); |
|
111 |
// Avoiding set '___' generated when we have "strange" set names such as those in cyrillic/ukrain |
|
112 |
// strips _ from the beginning and the end |
|
113 |
String stripped = StringUtils.strip(s, "_ "); |
|
114 |
if (StringUtils.isBlank(stripped)) { |
|
115 |
stripped = DEFAULT_SET; |
|
116 |
} |
|
117 |
return stripped; |
|
118 |
} |
|
119 |
|
|
120 |
public List<SetInfo> getConfiguredSets(final String dbName) { |
|
121 |
Bson query = Filters.eq("fromConfiguration", true); |
|
122 |
return this.findSets(query, dbName); |
|
123 |
} |
|
124 |
|
|
125 |
public List<SetInfo> getSetsFromData(final String dbName) { |
|
126 |
Bson query = Filters.eq("fromConfiguration", false); |
|
127 |
return this.findSets(query, dbName); |
|
128 |
} |
|
129 |
|
|
130 |
public void dropOAISets(final String dbName) { |
|
131 |
this.getSetsCountCollection(dbName).drop(); |
|
132 |
this.getSetsCollection(dbName).drop(); |
|
133 |
} |
|
134 |
|
|
135 |
public void dropSet(final String dbName, final String setSpec) { |
|
136 |
Bson query = Filters.eq("spec", setSpec); |
|
137 |
this.getSetsCollection(dbName).deleteMany(query); |
|
138 |
this.getSetsCountCollection(dbName).deleteMany(query); |
|
139 |
} |
|
140 |
|
|
141 |
public void dropConfigurationSets(final String dbName) { |
|
142 |
this.getSetsCollection(dbName).deleteMany(Filters.eq("fromConfiguration", true)); |
|
143 |
} |
|
144 |
|
|
145 |
protected List<SetInfo> findSets(final Bson query, final String dbName) { |
|
146 |
final FindIterable<DBObject> sets = this.getSetsCollection(dbName).find(query); |
|
147 |
List<SetInfo> res = Lists.newArrayList(); |
|
148 |
for (DBObject obj : sets) { |
|
149 |
res.add(this.getSetFromDBObject(obj)); |
|
150 |
} |
|
151 |
return res; |
|
152 |
} |
|
153 |
|
|
154 |
private SetInfo getSetFromDBObject(final DBObject obj) { |
|
155 |
SetInfo setInfo = new SetInfo(); |
|
156 |
setInfo.setEnabled((Boolean) obj.get("enabled")); |
|
157 |
setInfo.setQuery((String) obj.get("query")); |
|
158 |
setInfo.setSetDescription((String) obj.get("description")); |
|
159 |
setInfo.setSetName((String) obj.get("name")); |
|
160 |
setInfo.setSetSpec((String) obj.get("spec")); |
|
161 |
return setInfo; |
|
162 |
} |
|
163 |
|
|
164 |
private DBObject getObjectFromSet(final SetInfo s) { |
|
165 |
DBObject obj = BasicDBObjectBuilder.start("spec", s.getSetSpec()).add("name", s.getSetName()).add("description", s.getSetDescription()) |
|
166 |
.add("query", s.getQuery()).add("enabled", s.isEnabled()).get(); |
|
167 |
return obj; |
|
168 |
} |
|
169 |
|
|
170 |
private void ensureIndexesOnSets(final String dbName) { |
|
171 |
this.getSetsCollection(dbName).createIndex(new BasicDBObject("spec", 1), new IndexOptions().background(true)); |
|
172 |
this.getSetsCollection(dbName).createIndex(new BasicDBObject("fromConfiguration", 1), new IndexOptions().background(true)); |
|
173 |
} |
|
174 |
|
|
175 |
private void ensureIndexesOnCount(final String dbName) { |
|
176 |
BasicDBObject index = (BasicDBObject) BasicDBObjectBuilder.start("spec", 1).add("mdPrefix", 1).get(); |
|
177 |
this.getSetsCountCollection(dbName).createIndex(index, new IndexOptions().background(true)); |
|
178 |
} |
|
179 |
|
|
180 |
public MongoCollection<DBObject> getSetsCollection(final String dbName) { |
|
181 |
return this.getCollection(this.setCollection, dbName); |
|
182 |
} |
|
183 |
|
|
184 |
public MongoCollection<DBObject> getSetsCountCollection(final String dbName) { |
|
185 |
return this.getCollection(this.setCountCollection, dbName); |
|
186 |
} |
|
187 |
|
|
188 |
private MongoCollection<DBObject> getCollection(final String collectionName, final String dbName) { |
|
189 |
return publisherMongoClient.getDatabase(dbName).getCollection(collectionName, DBObject.class); |
|
190 |
} |
|
191 |
|
|
192 |
public String getSetCollection() { |
|
193 |
return setCollection; |
|
194 |
} |
|
195 |
|
|
196 |
public void setSetCollection(final String setCollection) { |
|
197 |
this.setCollection = setCollection; |
|
198 |
} |
|
199 |
|
|
200 |
public String getSetCountCollection() { |
|
201 |
return setCountCollection; |
|
202 |
} |
|
203 |
|
|
204 |
public void setSetCountCollection(final String setCountCollection) { |
|
205 |
this.setCountCollection = setCountCollection; |
|
206 |
} |
|
207 |
|
|
208 |
public MongoClient getPublisherMongoClient() { |
|
209 |
return publisherMongoClient; |
|
210 |
} |
|
211 |
|
|
212 |
public void setPublisherMongoClient(final MongoClient publisherMongoClient) { |
|
213 |
this.publisherMongoClient = publisherMongoClient; |
|
214 |
} |
|
215 |
|
|
216 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/mongo/MetadataExtractor.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
4 |
import org.dom4j.Document; |
|
5 |
import org.dom4j.Node; |
|
6 |
|
|
7 |
/** |
|
8 |
* Function to skip the header of the record and deliver only its metadata content as XML String. |
|
9 |
*/ |
|
10 |
public class MetadataExtractor implements UnaryFunction<String, Document> { |
|
11 |
|
|
12 |
@Override |
|
13 |
public String evaluate(final Document xmlDoc) { |
|
14 |
Node metadataNode = xmlDoc.selectSingleNode("//*[local-name() = 'metadata']/*"); |
|
15 |
//Node metadataNode = xmlDoc.selectSingleNode("/*[local-name()='record']/*[local-name() = 'metadata']/*"); |
|
16 |
return metadataNode.asXML(); |
|
17 |
} |
|
18 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/mongo/ProvenanceExtractor.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
4 |
import org.dom4j.Document; |
|
5 |
import org.dom4j.Node; |
|
6 |
|
|
7 |
/** |
|
8 |
* Function to deliver only the about/provenance content of a record as XML String. |
|
9 |
*/ |
|
10 |
public class ProvenanceExtractor implements UnaryFunction<String, Document> { |
|
11 |
|
|
12 |
@Override |
|
13 |
public String evaluate(final Document xmlDoc) { |
|
14 |
// Node provenanceNode = xmlDoc.selectSingleNode("//*[local-name() = 'about']/*[local-name() = 'provenance']"); |
|
15 |
Node provenanceNode = xmlDoc.selectSingleNode("/*[local-name()='record']/*[local-name() = 'about']/*[local-name() = 'provenance']"); |
|
16 |
if (provenanceNode != null) return provenanceNode.asXML(); |
|
17 |
else return null; |
|
18 |
} |
|
19 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/mongo/MongoPublisherStoreDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.mongodb.BasicDBObjectBuilder; |
|
7 |
import com.mongodb.DBObject; |
|
8 |
import com.mongodb.client.MongoCollection; |
|
9 |
import com.mongodb.client.MongoDatabase; |
|
10 |
import com.mongodb.client.model.Filters; |
|
11 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherException; |
|
12 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException; |
|
13 |
import eu.dnetlib.data.information.oai.publisher.conf.OAIConfigurationReader; |
|
14 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
15 |
import eu.dnetlib.data.oai.store.PublisherStoreDAO; |
|
16 |
import eu.dnetlib.data.oai.store.sets.MongoSetCollection; |
|
17 |
import org.apache.commons.logging.Log; |
|
18 |
import org.apache.commons.logging.LogFactory; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.beans.factory.annotation.Required; |
|
21 |
|
|
22 |
public class MongoPublisherStoreDAO implements PublisherStoreDAO<MongoPublisherStore, DNetOAIMongoCursor> { |
|
23 |
|
|
24 |
private static final Log log = LogFactory.getLog(MongoPublisherStoreDAO.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
25 |
|
|
26 |
@Autowired |
|
27 |
private MongoPublisherCacheHelper mongoCacheHelper; |
|
28 |
|
|
29 |
/** Name of the collection with information about the OAI stores. **/ |
|
30 |
private String metadataCollection; |
|
31 |
|
|
32 |
@Resource |
|
33 |
private MongoSetCollection mongoSetCollection; |
|
34 |
|
|
35 |
private boolean alwaysNewRecord; |
|
36 |
|
|
37 |
@Resource(name = "oaiConfigurationExistReader") |
|
38 |
private OAIConfigurationReader configuration; |
|
39 |
|
|
40 |
|
|
41 |
@Override |
|
42 |
public List<MongoPublisherStore> listPublisherStores(final String dbName) { |
|
43 |
return mongoCacheHelper.listPublisherStores(dbName, metadataCollection, alwaysNewRecord, mongoSetCollection); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public MongoPublisherStore getStore(final String storeId, final String dbName) { |
|
48 |
return mongoCacheHelper.getStoreById(storeId, dbName, metadataCollection, alwaysNewRecord, mongoSetCollection); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public MongoPublisherStore getStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName) { |
|
53 |
return this.getStore(this.generateStoreId(mdfName, mdfInterpretation, mdfLayout), dbName); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public MongoPublisherStore getStoreFor(final String targetMetadataPrefix, final String dbName) { |
|
58 |
MDFInfo info = this.configuration.getMetadataFormatInfo(targetMetadataPrefix); |
|
59 |
MongoPublisherStore store = this.getStore(info.getSourceFormatName(), info.getSourceFormatInterpretation(), info.getSourceFormatLayout(), dbName); |
|
60 |
return store; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public MongoPublisherStore createStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName) |
|
65 |
throws OaiPublisherException { |
|
66 |
log.debug("CREATING OAI STORE"); |
|
67 |
MongoDatabase db = this.mongoCacheHelper.getDB(dbName); |
|
68 |
DBObject store = createMetadataEntry(mdfName, mdfInterpretation, mdfLayout); |
|
69 |
MongoCollection<DBObject> metadata = db.getCollection(this.metadataCollection, DBObject.class); |
|
70 |
String id = (String) store.get("id"); |
|
71 |
metadata.insertOne(store); |
|
72 |
log.debug("metadata insert done for store "+id); |
|
73 |
MongoPublisherStore theStore = this.mongoCacheHelper.getStoreById(id, dbName, this.metadataCollection, this.alwaysNewRecord, this.mongoSetCollection); |
|
74 |
return theStore; |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public boolean deleteStore(final String storeId, final String dbName) { |
|
80 |
log.debug("DELETING OAI STORE "+storeId+" -- db: "+dbName); |
|
81 |
this.mongoCacheHelper.deleteFromCache(storeId, dbName); |
|
82 |
MongoDatabase db = this.mongoCacheHelper.getDB(dbName); |
|
83 |
MongoCollection<DBObject> metadata = db.getCollection(this.metadataCollection, DBObject.class); |
|
84 |
final DBObject storeDeleted = metadata.findOneAndDelete(Filters.eq("id", storeId)); |
|
85 |
if (storeDeleted == null) return false; |
|
86 |
else { |
|
87 |
db.getCollection(storeId).drop(); |
|
88 |
// TODO: should drop entries related to mdPrefix served by the store we are deleting, not all of them. |
|
89 |
this.mongoSetCollection.dropOAISets(dbName); |
|
90 |
log.debug("Deleted oaistore " + storeId + ", db: " + dbName); |
|
91 |
return true; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public boolean deleteFromStore(final String storeId, final String dbName, final String set) { |
|
97 |
String setSpec = mongoSetCollection.normalizeSetSpec(set); |
|
98 |
log.debug(String.format("DELETING OAI STORE %s BY SET %s from db %s", storeId, setSpec, dbName)); |
|
99 |
this.mongoCacheHelper.deleteFromCache(storeId, dbName); |
|
100 |
MongoDatabase db = this.mongoCacheHelper.getDB(dbName); |
|
101 |
MongoCollection<DBObject> metadata = db.getCollection(this.metadataCollection, DBObject.class); |
|
102 |
DBObject storeInfo = metadata.find(Filters.eq("id", storeId)).first(); |
|
103 |
if (storeInfo == null) return false; |
|
104 |
else { |
|
105 |
db.getCollection(storeId).deleteMany(Filters.eq(OAIConfigurationReader.SET_FIELD, setSpec)); |
|
106 |
this.mongoSetCollection.dropSet(dbName, setSpec); |
|
107 |
log.debug("Deleted set " + setSpec + " from oaistore " + storeId + ", db: " + dbName); |
|
108 |
return true; |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public boolean deleteFromStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName, final String set) { |
|
114 |
return this.deleteFromStore(this.generateStoreId(mdfName, mdfInterpretation, mdfLayout), dbName, set); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public boolean deleteStore(final String mdfName, final String mdfInterpretation, final String mdfLayout, final String dbName) { |
|
119 |
return this.deleteStore(this.generateStoreId(mdfName, mdfInterpretation, mdfLayout), dbName); |
|
120 |
} |
|
121 |
|
|
122 |
public void ensureIndex(final MongoPublisherStore store) { |
|
123 |
if (store == null) throw new OaiPublisherRuntimeException("Can't ensure index on null store"); |
|
124 |
Thread t = new Thread() { |
|
125 |
|
|
126 |
@Override |
|
127 |
public void run() { |
|
128 |
store.ensureIndices(); |
|
129 |
} |
|
130 |
}; |
|
131 |
t.start(); |
|
132 |
} |
|
133 |
|
|
134 |
public void ensureIndex(final String dbName) { |
|
135 |
List<MongoPublisherStore> stores = this.listPublisherStores(dbName); |
|
136 |
for (final MongoPublisherStore s : stores) { |
|
137 |
s.ensureIndices(); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
private DBObject createMetadataEntry(final String mdfName, final String mdfInterpretation, final String mdfLayout) { |
|
144 |
DBObject info = BasicDBObjectBuilder.start("id", generateStoreId(mdfName, mdfInterpretation, mdfLayout)).append("metadataFormat", mdfName) |
|
145 |
.append("interpretation", mdfInterpretation).append("layout", mdfLayout).get(); |
|
146 |
log.debug("Created DBObject for OAIStore metadata entry: "+info.toString()); |
|
147 |
return info; |
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
private String generateStoreId(final String mdfName, final String mdfInterpretation, final String mdfLayout) { |
|
152 |
return mdfName + "-" + mdfLayout + "-" + mdfInterpretation; |
|
153 |
} |
|
154 |
|
|
155 |
public String getMetadataCollection() { |
|
156 |
return metadataCollection; |
|
157 |
} |
|
158 |
|
|
159 |
@Required |
|
160 |
public void setMetadataCollection(final String metadataCollection) { |
|
161 |
this.metadataCollection = metadataCollection; |
|
162 |
} |
|
163 |
|
|
164 |
public OAIConfigurationReader getConfiguration() { |
|
165 |
return configuration; |
|
166 |
} |
|
167 |
|
|
168 |
public void setConfiguration(final OAIConfigurationReader configuration) { |
|
169 |
this.configuration = configuration; |
|
170 |
} |
|
171 |
|
|
172 |
public MongoSetCollection getMongoSetCollection() { |
|
173 |
return mongoSetCollection; |
|
174 |
} |
|
175 |
|
|
176 |
public void setMongoSetCollection(final MongoSetCollection mongoSetCollection) { |
|
177 |
this.mongoSetCollection = mongoSetCollection; |
|
178 |
} |
|
179 |
|
|
180 |
public boolean isAlwaysNewRecord() { |
|
181 |
return alwaysNewRecord; |
|
182 |
} |
|
183 |
|
|
184 |
public void setAlwaysNewRecord(final boolean alwaysNewRecord) { |
|
185 |
this.alwaysNewRecord = alwaysNewRecord; |
|
186 |
} |
|
187 |
|
|
188 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/mongo/DNetOAIMongoCursor.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
|
|
5 |
import com.google.common.collect.Lists; |
|
6 |
import com.mongodb.DBObject; |
|
7 |
import com.mongodb.client.MongoCursor; |
|
8 |
import eu.dnetlib.data.information.oai.publisher.info.RecordInfo; |
|
9 |
import eu.dnetlib.data.oai.store.Cursor; |
|
10 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
11 |
|
|
12 |
public class DNetOAIMongoCursor implements Cursor { |
|
13 |
|
|
14 |
/** |
|
15 |
* Underlying mongo cursor. |
|
16 |
*/ |
|
17 |
private MongoCursor<DBObject> dbCursor; |
|
18 |
private int size = 0; |
|
19 |
/** |
|
20 |
* Function to apply to records before delivering. |
|
21 |
*/ |
|
22 |
private UnaryFunction<String, String> function; |
|
23 |
|
|
24 |
/** |
|
25 |
* true if the RecordInfo returned by this Cursor must include the record body, false otherwise. |
|
26 |
*/ |
|
27 |
private boolean bodyIncluded; |
|
28 |
|
|
29 |
private RecordInfoGenerator recordInfoGenerator; |
|
30 |
private MetadataExtractor metadataExtractor; |
|
31 |
private ProvenanceExtractor provenanceExtractor; |
|
32 |
|
|
33 |
public DNetOAIMongoCursor() { |
|
34 |
super(); |
|
35 |
} |
|
36 |
|
|
37 |
public DNetOAIMongoCursor(final MongoCursor<DBObject> dbCursor, final boolean bodyIncluded, final RecordInfoGenerator recordInfoGenerator, |
|
38 |
final MetadataExtractor metadataExtractor) { |
|
39 |
this(dbCursor, null, bodyIncluded, recordInfoGenerator, metadataExtractor); |
|
40 |
} |
|
41 |
|
|
42 |
public DNetOAIMongoCursor(final MongoCursor<DBObject> dbCursor, final UnaryFunction<String, String> function, final boolean bodyIncluded, |
|
43 |
final RecordInfoGenerator recordInfoGenerator, final MetadataExtractor metadataExtractor) { |
|
44 |
super(); |
|
45 |
this.dbCursor = dbCursor; |
|
46 |
this.size = 0; |
|
47 |
this.function = function; |
|
48 |
this.bodyIncluded = bodyIncluded; |
|
49 |
this.recordInfoGenerator = recordInfoGenerator; |
|
50 |
this.metadataExtractor = metadataExtractor; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* |
|
55 |
* {@inheritDoc} |
|
56 |
*/ |
|
57 |
@Override |
|
58 |
public int count() { |
|
59 |
//I can do it because MongoCursor are always created from queries with "limit", so I do not expect the creation of the list to explode |
|
60 |
//to not exagerate, I'll get the size only if the current size is 0 |
|
61 |
if (size == 0) |
|
62 |
size = Lists.newArrayList(dbCursor).size(); |
|
63 |
return size; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* |
|
68 |
* {@inheritDoc} |
|
69 |
* |
|
70 |
* @see java.lang.Iterable#iterator() |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public Iterator<RecordInfo> iterator() { |
|
74 |
|
|
75 |
return new Iterator<RecordInfo>() { |
|
76 |
|
|
77 |
@Override |
|
78 |
public boolean hasNext() { |
|
79 |
return dbCursor.hasNext(); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public RecordInfo next() { |
|
84 |
DBObject res = dbCursor.next(); |
|
85 |
RecordInfo info = recordInfoGenerator.transformDBObject(res, bodyIncluded); |
|
86 |
if ((function != null) && bodyIncluded && (info != null)) { |
|
87 |
info.setMetadata(function.evaluate(info.getMetadata())); |
|
88 |
} |
|
89 |
return info; |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public void remove() { |
|
94 |
throw new UnsupportedOperationException(); |
|
95 |
} |
|
96 |
|
|
97 |
}; |
|
98 |
} |
|
99 |
|
|
100 |
public UnaryFunction<String, String> getFunction() { |
|
101 |
return function; |
|
102 |
} |
|
103 |
|
|
104 |
public void setFunction(final UnaryFunction<String, String> function) { |
|
105 |
this.function = function; |
|
106 |
} |
|
107 |
|
|
108 |
public MongoCursor<DBObject> getDbCursor() { |
|
109 |
return dbCursor; |
|
110 |
} |
|
111 |
|
|
112 |
public void setDbCursor(final MongoCursor<DBObject> dbCursor) { |
|
113 |
this.dbCursor = dbCursor; |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public boolean isBodyIncluded() { |
|
118 |
return this.bodyIncluded; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public void setBodyIncluded(final boolean bodyIncluded) { |
|
123 |
this.bodyIncluded = bodyIncluded; |
|
124 |
} |
|
125 |
|
|
126 |
public RecordInfoGenerator getRecordInfoGenerator() { |
|
127 |
return recordInfoGenerator; |
|
128 |
} |
|
129 |
|
|
130 |
public void setRecordInfoGenerator(final RecordInfoGenerator recordInfoGenerator) { |
|
131 |
this.recordInfoGenerator = recordInfoGenerator; |
|
132 |
} |
|
133 |
|
|
134 |
public MetadataExtractor getMetadataExtractor() { |
|
135 |
return metadataExtractor; |
|
136 |
} |
|
137 |
|
|
138 |
public void setMetadataExtractor(final MetadataExtractor metadataExtractor) { |
|
139 |
this.metadataExtractor = metadataExtractor; |
|
140 |
} |
|
141 |
|
|
142 |
public ProvenanceExtractor getProvenanceExtractor() { |
|
143 |
return provenanceExtractor; |
|
144 |
} |
|
145 |
|
|
146 |
public void setProvenanceExtractor(final ProvenanceExtractor provenanceExtractor) { |
|
147 |
this.provenanceExtractor = provenanceExtractor; |
|
148 |
} |
|
149 |
|
|
150 |
} |
modules/dnet-oai-store-service/src/main/java/eu/dnetlib/data/oai/store/mongo/MongoPublisherCacheHelper.java | ||
---|---|---|
1 |
package eu.dnetlib.data.oai.store.mongo; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.common.collect.Lists; |
|
9 |
import com.mongodb.DBObject; |
|
10 |
import com.mongodb.MongoClient; |
|
11 |
import com.mongodb.WriteConcern; |
|
12 |
import com.mongodb.client.FindIterable; |
|
13 |
import com.mongodb.client.MongoDatabase; |
|
14 |
import com.mongodb.client.model.Filters; |
|
15 |
import eu.dnetlib.data.information.oai.publisher.conf.OAIConfigurationReader; |
|
16 |
import eu.dnetlib.data.oai.store.RecordChangeDetector; |
|
17 |
import eu.dnetlib.data.oai.store.sets.MongoSetCollection; |
|
18 |
import eu.dnetlib.functionality.cql.mongo.MongoCqlTranslator; |
|
19 |
import org.apache.commons.logging.Log; |
|
20 |
import org.apache.commons.logging.LogFactory; |
|
21 |
import org.springframework.beans.factory.annotation.Autowired; |
|
22 |
import org.springframework.cache.annotation.CacheEvict; |
|
23 |
import org.springframework.cache.annotation.Cacheable; |
|
24 |
|
|
25 |
/** |
|
26 |
* Created by alessia on 19/07/16. |
|
27 |
*/ |
|
28 |
public class MongoPublisherCacheHelper { |
|
29 |
|
|
30 |
private static final Log log = LogFactory.getLog(MongoPublisherCacheHelper.class); |
|
31 |
|
|
32 |
@Autowired |
|
33 |
private MongoClient publisherMongoClient; |
|
34 |
@Resource(name = "oaiConfigurationExistReader") |
|
35 |
private OAIConfigurationReader configuration; |
|
36 |
@Resource |
|
37 |
private MetadataExtractor metadataExtractor; |
|
38 |
@Resource |
|
39 |
private RecordInfoGenerator recordInfoGenerator; |
|
40 |
@Resource |
|
41 |
private RecordChangeDetector recordChangeDetector; |
|
42 |
|
|
43 |
|
|
44 |
public MongoDatabase getDB(final String dbName) { |
|
45 |
return this.publisherMongoClient.getDatabase(dbName).withWriteConcern(WriteConcern.JOURNALED); |
|
46 |
} |
|
47 |
|
|
48 |
@Cacheable(value="oaistores", key="#dbname") |
|
49 |
public List<MongoPublisherStore> listPublisherStores(final String dbName, final String metadataCollectionName, final boolean alwaysNewRecord, final MongoSetCollection mongoSetCollection) { |
|
50 |
log.info("Not using cache for listPublisherStores on "+dbName); |
|
51 |
final MongoDatabase db = getDB(dbName); |
|
52 |
final FindIterable<DBObject> stores = db.getCollection(metadataCollectionName, DBObject.class).find(); |
|
53 |
return Lists.newArrayList( |
|
54 |
Iterables.transform(stores, new Function<DBObject, MongoPublisherStore>() { |
|
55 |
@Override |
|
56 |
public MongoPublisherStore apply(final DBObject storeInfo) { |
|
57 |
return createFromDBObject(storeInfo, db, alwaysNewRecord, mongoSetCollection); |
|
58 |
} |
|
59 |
}) |
|
60 |
); |
|
61 |
} |
|
62 |
|
|
63 |
@Cacheable(value="oaistoresById", key="#storeId + #dbName", unless="#result == null") |
|
64 |
public MongoPublisherStore getStoreById(final String storeId, final String dbName, final String metadataCollectionName, final boolean alwaysNewRecord, final MongoSetCollection mongoSetCollection) { |
|
65 |
log.info(String.format("Not using cache for getStoreById: %s", storeId)); |
|
66 |
DBObject storeInfo = getDB(dbName).getCollection(metadataCollectionName, DBObject.class).find(Filters.eq("id", storeId)).first(); |
|
67 |
log.info("Got DBObject from mongo "+dbName+"."+metadataCollectionName+", id "+storeId+" is : "+storeInfo ); |
|
68 |
return this.createFromDBObject(storeInfo, getDB(dbName), alwaysNewRecord, mongoSetCollection); |
|
69 |
} |
|
70 |
|
|
71 |
@CacheEvict(value="oaistoresById", key = "#storeId + #dbName") |
|
72 |
public void deleteFromCache(String storeId, String dbName){ |
|
73 |
log.info("Evicting "+storeId+" for db "+dbName+ " from the cache"); |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
private MongoPublisherStore createFromDBObject(final DBObject storeInfo, final MongoDatabase db, final boolean alwaysNewRecord, final MongoSetCollection mongoSetCollection) { |
|
78 |
if (storeInfo == null){ |
|
79 |
log.error("cannot create MongoPublisherStore from null DBObject"); |
|
80 |
return null; |
|
81 |
} |
|
82 |
log.debug("Creating MongoPublisherStore from DBObject "+storeInfo.toString()); |
|
83 |
String storeId = (String) storeInfo.get("id"); |
|
84 |
String mdFormat = (String) storeInfo.get("metadataFormat"); |
|
85 |
String mdInterpretation = (String) storeInfo.get("interpretation"); |
|
86 |
String mdLayout = (String) storeInfo.get("layout"); |
|
87 |
MongoPublisherStore store = new MongoPublisherStore(storeId, mdFormat, mdInterpretation, mdLayout, db.getCollection(storeId, DBObject.class), |
|
88 |
this.configuration.getFields(mdFormat, mdInterpretation, mdLayout), recordInfoGenerator, this.configuration.getIdScheme(), |
|
89 |
this.configuration.getIdNamespace(), this.metadataExtractor, this.recordChangeDetector, alwaysNewRecord, db); |
|
90 |
store.setMongoSetCollection(mongoSetCollection); |
|
91 |
return store; |
Also available in: Unified diff
codebase used to migrate to java8 the production system