Revision 48598
Added by Alessia Bardi over 7 years ago
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet45-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
<relativePath /> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<artifactId>dnet-oai-utils</artifactId> |
|
11 |
<packaging>jar</packaging> |
|
12 |
<version>4.0.1</version> |
|
13 |
<scm> |
|
14 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1</developerConnection> |
|
15 |
</scm> |
|
16 |
<dependencies> |
|
17 |
<dependency> |
|
18 |
<groupId>junit</groupId> |
|
19 |
<artifactId>junit</artifactId> |
|
20 |
<version>${junit.version}</version> |
|
21 |
<scope>test</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>cnr-misc-utils</artifactId> |
|
26 |
<version>[1.0.0,2.0.0)</version> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>com.google.guava</groupId> |
|
30 |
<artifactId>guava</artifactId> |
|
31 |
<version>${google.guava.version}</version> |
|
32 |
</dependency> |
|
33 |
<!-- Needed for locators --> |
|
34 |
<dependency> |
|
35 |
<groupId>eu.dnetlib</groupId> |
|
36 |
<artifactId>cnr-service-common</artifactId> |
|
37 |
<version>[2.1.0,3.0.0)</version> |
|
38 |
</dependency> |
|
39 |
|
|
40 |
</dependencies> |
|
41 |
</project> |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/utils/OAIParameterNames.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.utils; |
|
2 |
|
|
3 |
/** |
|
4 |
* Static class keeping track of env variable and job parameter names used by default by OAI Job nodes. |
|
5 |
* Created by alessia on 09/11/16. |
|
6 |
*/ |
|
7 |
public class OAIParameterNames { |
|
8 |
|
|
9 |
public static String OAI_COLLECTON = "oai_collection"; |
|
10 |
public static String OAI_DB = "oai_dbName"; |
|
11 |
public static String OAI_FORMAT_NAME = "oai_format"; |
|
12 |
public static String OAI_FORMAT_LAYOUT = "oai_layout"; |
|
13 |
public static String OAI_FORMAT_INTERPRETATION = "oai_interpretation"; |
|
14 |
public static String OAI_SOURCE = "oai_source"; |
|
15 |
public static String OAI_INDEXES = "oai_indexFieldNames"; |
|
16 |
public static String OAI_CONFIGURED_SETS_ONLY = "oai_configuredSetsOnly"; |
|
17 |
public static String OAI_CONFIGURATION_PROFILE = "oai_configuration"; |
|
18 |
public static String OAI_ACTION_DATE = "oai_actionDate"; |
|
19 |
/** |
|
20 |
* @Deprecated please use OAI_ACTION_DATE instead. |
|
21 |
*/ |
|
22 |
@Deprecated |
|
23 |
public static String OAI_FEED_DATE = "oai_feedDate"; |
|
24 |
public static String OAI_SKIP_DUPLICATES = "oai_skipDuplicates"; |
|
25 |
public static String OAI_DUPLICATE_XPATH = "oai_duplicateXPath"; |
|
26 |
public static String OAI_SYNC_EPR = "oai_syncEpr"; |
|
27 |
public static String OAI_ALWAYS_NEW_RECORD= "oai_alwaysNewRecord"; |
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/ISLookUpClient.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.google.common.collect.Lists; |
|
7 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherException; |
|
8 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException; |
|
9 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
10 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
11 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
12 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
13 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
14 |
import eu.dnetlib.miscutils.functional.IdentityFunction; |
|
15 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
16 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
17 |
import org.apache.commons.lang.StringUtils; |
|
18 |
import org.apache.commons.logging.Log; |
|
19 |
import org.apache.commons.logging.LogFactory; |
|
20 |
import org.dom4j.DocumentException; |
|
21 |
import org.springframework.beans.factory.annotation.Value; |
|
22 |
import org.springframework.cache.annotation.CacheEvict; |
|
23 |
import org.springframework.cache.annotation.Cacheable; |
|
24 |
|
|
25 |
/** |
|
26 |
* Helper class for common queries to the IS. |
|
27 |
* |
|
28 |
* @author alessia |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class ISLookUpClient { |
|
32 |
|
|
33 |
private static final Log log = LogFactory.getLog(ISLookUpClient.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
34 |
|
|
35 |
@Value("${services.oai.publisher.db.xquery}") |
|
36 |
private String xpathToCurrentDB; |
|
37 |
|
|
38 |
/** |
|
39 |
* lookup service. |
|
40 |
*/ |
|
41 |
@Resource |
|
42 |
private UniqueServiceLocator serviceLocator; |
|
43 |
|
|
44 |
@Resource |
|
45 |
private OAIConfigurationExistReader configuration; |
|
46 |
|
|
47 |
public List<MDFInfo> listMetadataFormats(final boolean onlyEnabled) throws ISLookUpException, DocumentException, OaiPublisherException { |
|
48 |
return Lists.newArrayList(this.configuration.getMetadataFormatInfo(onlyEnabled)); |
|
49 |
} |
|
50 |
|
|
51 |
@Cacheable(value = "unaryFunctions", key = "#tdsRuleId") |
|
52 |
public UnaryFunction<String, String> getUnaryFunctionFromTDSRule(final String tdsRuleId) { |
|
53 |
log.fatal("Not using cache to get TDSRule " + tdsRuleId); |
|
54 |
final String queryCodeRule = "//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='" + tdsRuleId |
|
55 |
+ "']/BODY/CONFIGURATION/SCRIPT/CODE/*[local-name()='stylesheet']"; |
|
56 |
String xsltCode = null; |
|
57 |
try { |
|
58 |
xsltCode = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(queryCodeRule); |
|
59 |
} catch (ISLookUpDocumentNotFoundException e) { |
|
60 |
log.fatal("Unexisting TDSRule profile with identifier " + tdsRuleId); |
|
61 |
throw new OaiPublisherRuntimeException(e); |
|
62 |
} catch (ISLookUpException e) { |
|
63 |
throw new OaiPublisherRuntimeException(e); |
|
64 |
} |
|
65 |
if (StringUtils.isBlank(xsltCode)) { |
|
66 |
log.warn("Unexpected blank stylesheet in TDSRule profile with id: " + tdsRuleId + ". Returning identity function."); |
|
67 |
return new IdentityFunction<String>(); |
|
68 |
} else return new ApplyXslt(xsltCode); |
|
69 |
} |
|
70 |
|
|
71 |
@Cacheable("oaiDB") |
|
72 |
public String getCurrentDB() throws ISLookUpDocumentNotFoundException, ISLookUpException { |
|
73 |
log.fatal("Not using cache to get the current OAI db"); |
|
74 |
String currentDBName = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xpathToCurrentDB); |
|
75 |
log.info("Current OAI DB:" + currentDBName); |
|
76 |
return currentDBName; |
|
77 |
} |
|
78 |
|
|
79 |
@CacheEvict(value = { "unaryFunctions", "oaiDB" }, allEntries = true, beforeInvocation = true) |
|
80 |
public void evictCaches() { |
|
81 |
log.info("Evicted caches oaiDB and unaryFunctions"); |
|
82 |
} |
|
83 |
|
|
84 |
public OAIConfigurationExistReader getConfiguration() { |
|
85 |
return configuration; |
|
86 |
} |
|
87 |
|
|
88 |
public void setConfiguration(final OAIConfigurationExistReader configuration) { |
|
89 |
this.configuration = configuration; |
|
90 |
} |
|
91 |
|
|
92 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/resources/eu/dnetlib/data/information/oai/publisher/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="unaryFunctions" maxElementsInMemory="5" eternal="false" |
|
32 |
timeToIdleSeconds="500" timeToLiveSeconds="500" overflowToDisk="false" /> |
|
33 |
|
|
34 |
<cache name="oaiDB" maxElementsInMemory="1" eternal="false" |
|
35 |
timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="false" /> |
|
36 |
|
|
37 |
<!-- <cache name="publisherfields" maxElementsInMemory="30" eternal="false" --> |
|
38 |
<!-- timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="false" /> --> |
|
39 |
|
|
40 |
<!-- <cache name="publisheridscheme" maxElementsInMemory="1" eternal="false" --> |
|
41 |
<!-- timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="false" /> --> |
|
42 |
|
|
43 |
<!-- <cache name="publisheridnamespace" maxElementsInMemory="1" --> |
|
44 |
<!-- eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="1800" --> |
|
45 |
<!-- overflowToDisk="false" /> --> |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
</ehcache> |
|
52 |
|
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/test/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationParserTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
import static org.junit.Assert.assertTrue; |
|
6 |
|
|
7 |
import java.io.IOException; |
|
8 |
import java.nio.charset.Charset; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
|
|
12 |
import org.apache.commons.io.IOUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.junit.Before; |
|
16 |
import org.junit.Test; |
|
17 |
import org.springframework.core.io.ClassPathResource; |
|
18 |
import org.springframework.core.io.Resource; |
|
19 |
|
|
20 |
import com.google.common.collect.ArrayListMultimap; |
|
21 |
import com.google.common.collect.Lists; |
|
22 |
import com.google.common.collect.Maps; |
|
23 |
import com.google.common.collect.Multimap; |
|
24 |
|
|
25 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
26 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
27 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
28 |
|
|
29 |
public class OAIConfigurationParserTest { |
|
30 |
|
|
31 |
private static final Log log = LogFactory.getLog(OAIConfigurationParserTest.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
32 |
|
|
33 |
/** Resource under test **/ |
|
34 |
private OAIConfigurationParser parser; |
|
35 |
/** Configuration profile to parse **/ |
|
36 |
private String configurationProfile; |
|
37 |
/** File path where to find the XML configuration profile **/ |
|
38 |
private String pathToProfile = "eu/dnetlib/data/information/oai/publisher/conf/OAIPublisherConfiguration-1.xml"; |
|
39 |
|
|
40 |
/** Expected configuration based on the profile available at the given pathToProfile. **/ |
|
41 |
private OAIConfiguration expectedConfiguration; |
|
42 |
|
|
43 |
@Before |
|
44 |
public void setUp() throws Exception { |
|
45 |
|
|
46 |
// preparing the expected configuration that we will use to perform asserts on the result of parsing |
|
47 |
expectedConfiguration = new OAIConfiguration(); |
|
48 |
Map<String, SetInfo> setsMap = Maps.newHashMap(); |
|
49 |
setsMap.put("set1", new SetInfo("set1", "set number 1", "test set", "(set =\"aSet\")", true)); |
|
50 |
expectedConfiguration.setSetsMap(setsMap); |
|
51 |
expectedConfiguration.setFieldNames(Lists.newArrayList("title", "objIdentifier", "set")); |
|
52 |
Map<String, MDFInfo> formatsMap = Maps.newHashMap(); |
|
53 |
formatsMap.put("oai_dc", new MDFInfo("oai_dc", "SCHEMA", "NAMESPACE", "oai_dc", "store", "driver", "", true)); |
|
54 |
formatsMap.put("hope", new MDFInfo("hope", "SCHEMA", "NAMESPACE", "hope", "L", "I", "country = IT", "tdsRule", true)); |
|
55 |
expectedConfiguration.setMdFormatsMap(formatsMap); |
|
56 |
expectedConfiguration.setIdNamespace("eagle"); |
|
57 |
List<PublisherField> fields = Lists.newArrayList(); |
|
58 |
String oaidcKey = "oai_dc-store-driver"; |
|
59 |
String hopeKey = "hope-L-I"; |
|
60 |
|
|
61 |
PublisherField titleField = new PublisherField(); |
|
62 |
titleField.setFieldName("title"); |
|
63 |
titleField.setRepeatable(true); |
|
64 |
Multimap<String, String> titleSources = ArrayListMultimap.create(); |
|
65 |
titleSources.put(oaidcKey, "//*[local-name() = 'title']"); |
|
66 |
titleSources.put(oaidcKey, "//*[local-name() ='alternative']"); |
|
67 |
titleSources.put(hopeKey, "//title"); |
|
68 |
titleSources.put(hopeKey, "//titleinfo"); |
|
69 |
titleField.setSources(titleSources); |
|
70 |
|
|
71 |
fields.add(titleField); |
|
72 |
|
|
73 |
PublisherField objIdField = new PublisherField(); |
|
74 |
objIdField.setFieldName("objIdentifier"); |
|
75 |
objIdField.setRepeatable(false); |
|
76 |
Multimap<String, String> objIdSources = ArrayListMultimap.create(); |
|
77 |
objIdSources.put(oaidcKey, "//*[local-name() ='objIdentifier']"); |
|
78 |
objIdField.setSources(objIdSources); |
|
79 |
|
|
80 |
fields.add(objIdField); |
|
81 |
|
|
82 |
PublisherField setField = new PublisherField(); |
|
83 |
setField.setFieldName("set"); |
|
84 |
setField.setRepeatable(true); |
|
85 |
Multimap<String, String> setSources = ArrayListMultimap.create(); |
|
86 |
setSources.put(oaidcKey, "//*[local-name() ='repositoryId']"); |
|
87 |
setField.setSources(setSources); |
|
88 |
|
|
89 |
fields.add(setField); |
|
90 |
|
|
91 |
expectedConfiguration.setFields(fields); |
|
92 |
Resource resource = new ClassPathResource(pathToProfile); |
|
93 |
// setting up the parser and the profile as a string |
|
94 |
parser = new OAIConfigurationParser(); |
|
95 |
configurationProfile = IOUtils.toString(resource.getInputStream(), Charset.forName("UTF-8")); |
|
96 |
log.info("setUp completed"); |
|
97 |
} |
|
98 |
|
|
99 |
@Test |
|
100 |
public void testSchemeIdNamespace() throws IOException { |
|
101 |
OAIConfiguration result = parser.getConfiguration(configurationProfile); |
|
102 |
System.out.println(result.getIdScheme()); |
|
103 |
System.out.println(result.getIdNamespace()); |
|
104 |
} |
|
105 |
|
|
106 |
@Test |
|
107 |
public void testGetConfiguration() throws IOException { |
|
108 |
OAIConfiguration result = parser.getConfiguration(configurationProfile); |
|
109 |
assertNotNull(result); |
|
110 |
// asserts on sets |
|
111 |
assertTrue(result.getSetsMap().containsKey("set1")); |
|
112 |
SetInfo expected = expectedConfiguration.getSetsMap().get("set1"); |
|
113 |
SetInfo parsedSet = result.getSetsMap().get("set1"); |
|
114 |
assertEquals(expected.getQuery(), parsedSet.getQuery()); |
|
115 |
assertEquals(expected.getSetDescription(), parsedSet.getSetDescription()); |
|
116 |
assertEquals(expected.getSetName(), parsedSet.getSetName()); |
|
117 |
assertEquals(expected.getSetSpec(), parsedSet.getSetSpec()); |
|
118 |
// asserts on indices |
|
119 |
assertTrue(result.getFieldNames().containsAll(expectedConfiguration.getFieldNames())); |
|
120 |
assertEquals(3, result.getFieldsFor("oai_dc", "store", "driver").size()); |
|
121 |
assertEquals(1, result.getFieldsFor("hope", "L", "I").size()); |
|
122 |
|
|
123 |
// asserts on metadata formats |
|
124 |
assertTrue(result.getMdFormatsMap().containsKey("hope")); |
|
125 |
assertTrue(result.getMdFormatsMap().containsKey("oai_dc")); |
|
126 |
MDFInfo expectedFormat = expectedConfiguration.getMdFormatsMap().get("hope"); |
|
127 |
MDFInfo parsedFormat = result.getMdFormatsMap().get("hope"); |
|
128 |
assertEquals(expectedFormat.getBaseQuery(), parsedFormat.getBaseQuery()); |
|
129 |
assertEquals(expectedFormat.getNamespace(), parsedFormat.getNamespace()); |
|
130 |
assertEquals(expectedFormat.getPrefix(), parsedFormat.getPrefix()); |
|
131 |
assertEquals(expectedFormat.getSchema(), parsedFormat.getSchema()); |
|
132 |
|
|
133 |
assertEquals(expectedFormat.getSourceFormatInterpretation(), parsedFormat.getSourceFormatInterpretation()); |
|
134 |
assertEquals(expectedFormat.getSourceFormatLayout(), parsedFormat.getSourceFormatLayout()); |
|
135 |
assertEquals(expectedFormat.getSourceFormatName(), parsedFormat.getSourceFormatName()); |
|
136 |
assertEquals(expectedFormat.getTransformationRuleID(), parsedFormat.getTransformationRuleID()); |
|
137 |
assertEquals(expectedConfiguration.getIdNamespace(), result.getIdNamespace()); |
|
138 |
assertEquals("oai", result.getIdScheme()); |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
@Test |
|
143 |
public void splitRSToken() { |
|
144 |
String token = "1434158|dli||100|5551ed26e4b0f1f9ff635bab|false|"; |
|
145 |
String[] splitted = token.split("\\|"); |
|
146 |
System.out.println(splitted.length); |
|
147 |
for (String s : splitted) { |
|
148 |
System.out.println(s); |
|
149 |
} |
|
150 |
} |
|
151 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U source:jar", |
|
2 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-oai-utils/trunk/", |
|
3 |
"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", |
|
4 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-oai-utils"} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationExistReader.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Set; |
|
6 |
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
|
|
9 |
import com.google.common.collect.ArrayListMultimap; |
|
10 |
import com.google.common.collect.Lists; |
|
11 |
import com.google.common.collect.Multimap; |
|
12 |
import com.google.common.collect.Sets; |
|
13 |
|
|
14 |
import eu.dnetlib.common.rmi.UnimplementedException; |
|
15 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException; |
|
16 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
17 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
18 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
20 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
21 |
import eu.dnetlib.enabling.tools.SplittedQueryExecutor; |
|
22 |
|
|
23 |
/** |
|
24 |
* Instances of this class read the configuration of the OAI publisher from the IS, by performing xquery on the Exist database. |
|
25 |
* |
|
26 |
* @author alessia |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class OAIConfigurationExistReader implements OAIConfigurationReader { |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private SplittedQueryExecutor queryExecutor; |
|
33 |
private String xpathToIdScheme = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']//CONFIGURATION/IDSCHEME/text()"; |
|
34 |
private String xpathToIdNamespace = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']//CONFIGURATION/IDNAMESPACE/text()"; |
|
35 |
|
|
36 |
@Override |
|
37 |
public List<SetInfo> getSets() { |
|
38 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION/OAISETS/OAISET " |
|
39 |
+ "return concat($x/spec, ':-:', $x/name, ':-:', $x//description , ':-:', $x//query, ':-:', $x/@enabled/string())"; |
|
40 |
Iterable<SetInfo> sets = this.queryExecutor.query(SetInfo.class, query, ":-:"); |
|
41 |
return Lists.newArrayList(sets); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public List<SetInfo> getSets(final boolean onlyEnabled) { |
|
46 |
if (onlyEnabled) { |
|
47 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION/OAISETS/OAISET " |
|
48 |
+ "where $x/@enabled/string() = 'true' " |
|
49 |
+ "return concat($x/spec, ':-:', $x/name, ':-:', $x//description , ':-:', $x//query, ':-:', $x/@enabled/string())"; |
|
50 |
Iterable<SetInfo> sets = this.queryExecutor.query(SetInfo.class, query, ":-:"); |
|
51 |
return Lists.newArrayList(sets); |
|
52 |
} else return this.getSets(); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public List<String> getSetSpecs() { |
|
57 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION/OAISETS/OAISET " |
|
58 |
+ "return $x/spec/string() "; |
|
59 |
List<String> names = this.queryExecutor.performQuery(query); |
|
60 |
return names; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public List<String> getSetSpecs(final boolean onlyEnabled) { |
|
65 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION/OAISETS/OAISET " |
|
66 |
+ "where $x/@enabled/string() = '" + onlyEnabled + "' " + "return $x/spec/string() "; |
|
67 |
List<String> names = this.queryExecutor.performQuery(query); |
|
68 |
return names; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public SetInfo getSetInfo(final String setSpec) { |
|
73 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION/OAISETS/OAISET " |
|
74 |
+ "where $x/spec = '" |
|
75 |
+ setSpec |
|
76 |
+ "' " |
|
77 |
+ "return concat($x/spec, ':-:', $x/name, ':-:', $x//description , ':-:', $x//query, ':-:', $x/@enabled/string())"; |
|
78 |
Iterable<SetInfo> sets = this.queryExecutor.query(SetInfo.class, query, ":-:"); |
|
79 |
if (sets.iterator().hasNext()) return sets.iterator().next(); |
|
80 |
else return null; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public List<MDFInfo> getSourceMetadataFormats() { |
|
85 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//METADATAFORMAT " |
|
86 |
+ "return concat($x//SOURCE_METADATA_FORMAT/@name/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@layout/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@interpretation/string())"; |
|
87 |
|
|
88 |
List<String> res; |
|
89 |
try { |
|
90 |
res = this.queryExecutor.getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(query); |
|
91 |
} catch (ISLookUpException e) { |
|
92 |
throw new OaiPublisherRuntimeException(e); |
|
93 |
} |
|
94 |
Set<MDFInfo> sources = Sets.newHashSet(); |
|
95 |
for (String src : res) { |
|
96 |
String[] splitted = src.split(":-:"); |
|
97 |
MDFInfo mdfInfo = new MDFInfo(); |
|
98 |
mdfInfo.setSourceFormatName(splitted[0]); |
|
99 |
mdfInfo.setSourceFormatLayout(splitted[1]); |
|
100 |
mdfInfo.setSourceFormatInterpretation(splitted[2]); |
|
101 |
sources.add(mdfInfo); |
|
102 |
} |
|
103 |
return Lists.newArrayList(sources); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public List<MDFInfo> getMetadataFormatInfo() { |
|
108 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//METADATAFORMAT " |
|
109 |
+ "return concat($x/@metadataPrefix/string(), ':-:', $x//SCHEMA , ':-:', $x//NAMESPACE, " |
|
110 |
+ "':-:', $x//SOURCE_METADATA_FORMAT/@name/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@layout/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@interpretation/string(), " |
|
111 |
+ "':-:', $x//BASE_QUERY, ':-:', $x//TRANSFORMATION_RULE, ':-:', $x/@exportable/string() )"; |
|
112 |
Iterable<MDFInfo> mdFormats = this.queryExecutor.query(MDFInfo.class, query, ":-:"); |
|
113 |
return Lists.newArrayList(mdFormats); |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public List<MDFInfo> getMetadataFormatInfo(final boolean onlyEnabled) { |
|
118 |
if (onlyEnabled) { |
|
119 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//METADATAFORMAT " |
|
120 |
+ "where $x/@exportable/string() = 'true' " |
|
121 |
+ "return concat($x/@metadataPrefix/string(), ':-:', $x//SCHEMA , ':-:', $x//NAMESPACE, " |
|
122 |
+ "':-:', $x//SOURCE_METADATA_FORMAT/@name/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@layout/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@interpretation/string(), " |
|
123 |
+ "':-:', $x//BASE_QUERY, ':-:', $x//TRANSFORMATION_RULE, ':-:', $x/@exportable/string() )"; |
|
124 |
Iterable<MDFInfo> mdFormats = this.queryExecutor.query(MDFInfo.class, query, ":-:"); |
|
125 |
return Lists.newArrayList(mdFormats); |
|
126 |
} else return getMetadataFormatInfo(); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public MDFInfo getMetadataFormatInfo(final String mdPrefix) { |
|
131 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//METADATAFORMAT " |
|
132 |
+ "where $x/@metadataPrefix/string()='" |
|
133 |
+ mdPrefix |
|
134 |
+ "' " |
|
135 |
+ "return concat($x/@metadataPrefix/string(), ':-:', $x//SCHEMA , ':-:', $x//NAMESPACE, " |
|
136 |
+ "':-:', $x//SOURCE_METADATA_FORMAT/@name/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@layout/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@interpretation/string(), " |
|
137 |
+ "':-:', $x//BASE_QUERY,':-:', $x//TRANSFORMATION_RULE, ':-:', $x/@exportable/string() )"; |
|
138 |
Iterable<MDFInfo> mdFormats = this.queryExecutor.query(MDFInfo.class, query, ":-:"); |
|
139 |
Iterator<MDFInfo> iterator = mdFormats.iterator(); |
|
140 |
if (iterator.hasNext()) return iterator.next(); |
|
141 |
else return null; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public List<PublisherField> getFields() { |
|
146 |
throw new UnimplementedException(); |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public List<PublisherField> getFields(final String format, final String interpretation, final String layout) { |
|
151 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//INDICES/INDEX " |
|
152 |
+ "return concat($x/@name, ':-:', $x/@repeatable, ':-:', string-join($x/SOURCE[@name='" |
|
153 |
+ format |
|
154 |
+ "' and @interpretation='" |
|
155 |
+ interpretation |
|
156 |
+ "' and @layout='" + layout + "']/@path, ':-:'))"; |
|
157 |
List<String> res; |
|
158 |
try { |
|
159 |
res = this.queryExecutor.getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(query); |
|
160 |
} catch (ISLookUpException e) { |
|
161 |
throw new OaiPublisherRuntimeException(e); |
|
162 |
} |
|
163 |
List<PublisherField> fields = Lists.newArrayList(); |
|
164 |
for (String index : res) { |
|
165 |
String[] splitted = index.split(":-:"); |
|
166 |
String indexName = splitted[0]; |
|
167 |
String repeatable = splitted[1]; |
|
168 |
PublisherField field = new PublisherField(); |
|
169 |
field.setFieldName(indexName); |
|
170 |
field.setRepeatable(Boolean.valueOf(repeatable)); |
|
171 |
Multimap<String, String> sources = ArrayListMultimap.create(); |
|
172 |
String mdFormat = format + "-" + layout + "-" + interpretation; |
|
173 |
for (int i = 2; i < splitted.length; i++) { |
|
174 |
sources.put(mdFormat, splitted[i]); |
|
175 |
} |
|
176 |
field.setSources(sources); |
|
177 |
fields.add(field); |
|
178 |
} |
|
179 |
return fields; |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public List<String> getFieldNames() { |
|
184 |
String query = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']//CONFIGURATION//INDICES/INDEX/@name/string()"; |
|
185 |
try { |
|
186 |
return this.queryExecutor.getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(query); |
|
187 |
} catch (ISLookUpException e) { |
|
188 |
throw new OaiPublisherRuntimeException(e); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public List<MDFInfo> getFormatsServedBy(final String sourceFormatName, final String sourceFormatLayout, final String sourceFormatInterpretation) { |
|
194 |
final String query = "for $x in collection('/db/DRIVER/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType')//CONFIGURATION//METADATAFORMAT[.//SOURCE_METADATA_FORMAT/@name = '" |
|
195 |
+ sourceFormatName |
|
196 |
+ "' and .//SOURCE_METADATA_FORMAT/@layout = '" |
|
197 |
+ sourceFormatLayout |
|
198 |
+ "' and .//SOURCE_METADATA_FORMAT/@interpretation = '" |
|
199 |
+ sourceFormatInterpretation |
|
200 |
+ "'] " |
|
201 |
+ "return concat($x/@metadataPrefix/string(), ':-:', $x//SCHEMA , ':-:', $x//NAMESPACE, " |
|
202 |
+ "':-:', $x//SOURCE_METADATA_FORMAT/@name/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@layout/string(), ':-:', $x//SOURCE_METADATA_FORMAT/@interpretation/string(), " |
|
203 |
+ "':-:', $x//BASE_QUERY, ':-:', $x//TRANSFORMATION_RULE, ':-:', $x/@exportable/string() )"; |
|
204 |
Iterable<MDFInfo> mdFormats = this.queryExecutor.query(MDFInfo.class, query, ":-:"); |
|
205 |
return Lists.newArrayList(mdFormats); |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public String getIdScheme() { |
|
210 |
try { |
|
211 |
return this.queryExecutor.getServiceLocator().getService(ISLookUpService.class).getResourceProfileByQuery(getXpathToIdScheme()); |
|
212 |
} catch (ISLookUpException e) { |
|
213 |
throw new OaiPublisherRuntimeException(e); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
@Override |
|
218 |
public String getIdNamespace() { |
|
219 |
try { |
|
220 |
return this.queryExecutor.getServiceLocator().getService(ISLookUpService.class).getResourceProfileByQuery(getXpathToIdNamespace()); |
|
221 |
} catch (ISLookUpException e) { |
|
222 |
throw new OaiPublisherRuntimeException(e); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
public SplittedQueryExecutor getQueryExecutor() { |
|
227 |
return queryExecutor; |
|
228 |
} |
|
229 |
|
|
230 |
public void setQueryExecutor(final SplittedQueryExecutor queryExecutor) { |
|
231 |
this.queryExecutor = queryExecutor; |
|
232 |
} |
|
233 |
|
|
234 |
public String getXpathToIdScheme() { |
|
235 |
return xpathToIdScheme; |
|
236 |
} |
|
237 |
|
|
238 |
public void setXpathToIdScheme(final String xpathToIdScheme) { |
|
239 |
this.xpathToIdScheme = xpathToIdScheme; |
|
240 |
} |
|
241 |
|
|
242 |
public String getXpathToIdNamespace() { |
|
243 |
return xpathToIdNamespace; |
|
244 |
} |
|
245 |
|
|
246 |
public void setXpathToIdNamespace(final String xpathToIdNamespace) { |
|
247 |
this.xpathToIdNamespace = xpathToIdNamespace; |
|
248 |
} |
|
249 |
|
|
250 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationStringReader.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
|
|
12 |
import com.google.common.base.Function; |
|
13 |
import com.google.common.base.Predicate; |
|
14 |
import com.google.common.collect.Collections2; |
|
15 |
import com.google.common.collect.Iterables; |
|
16 |
import com.google.common.collect.Lists; |
|
17 |
|
|
18 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException; |
|
19 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
20 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
21 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
22 |
|
|
23 |
/** |
|
24 |
* Instances of this class reads the OAI configuration from a string, which is the configuration profile passed in as a string. |
|
25 |
* |
|
26 |
* @author alessia |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class OAIConfigurationStringReader implements OAIConfigurationReader { |
|
30 |
|
|
31 |
private static final Log log = LogFactory.getLog(OAIConfigurationStringReader.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
32 |
|
|
33 |
private OAIConfiguration oaiConfiguration; |
|
34 |
@Resource |
|
35 |
private OAIConfigurationParser configurationParser; |
|
36 |
|
|
37 |
public OAIConfigurationStringReader() { |
|
38 |
oaiConfiguration = null; |
|
39 |
} |
|
40 |
|
|
41 |
public OAIConfigurationStringReader(final String profile) { |
|
42 |
this.readConfiguration(profile); |
|
43 |
} |
|
44 |
|
|
45 |
public void readConfiguration(final String profile) { |
|
46 |
log.debug(profile); |
|
47 |
try { |
|
48 |
oaiConfiguration = configurationParser.getConfiguration(profile); |
|
49 |
} catch (IOException e) { |
|
50 |
throw new OaiPublisherRuntimeException("Could not read OAI configuration profile", e); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
public boolean isConfigurationLoaded() { |
|
55 |
return this.oaiConfiguration != null; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public List<SetInfo> getSets() { |
|
60 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getSetsMap().values()); |
|
61 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public List<SetInfo> getSets(final boolean onlyEnabled) { |
|
66 |
if (isConfigurationLoaded()) return Lists.newArrayList(Iterables.filter(this.oaiConfiguration.getSetsMap().values(), new Predicate<SetInfo>() { |
|
67 |
|
|
68 |
/** |
|
69 |
* {@inheritDoc} |
|
70 |
* |
|
71 |
* @see com.google.common.base.Predicate#apply(java.lang.Object) |
|
72 |
*/ |
|
73 |
@Override |
|
74 |
public boolean apply(final SetInfo setInfo) { |
|
75 |
if (onlyEnabled) return setInfo.isEnabled(); |
|
76 |
else return true; |
|
77 |
} |
|
78 |
|
|
79 |
})); |
|
80 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public List<String> getSetSpecs() { |
|
85 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getSetsMap().keySet()); |
|
86 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public List<String> getSetSpecs(final boolean onlyEnabled) { |
|
91 |
if (isConfigurationLoaded()) { |
|
92 |
if (!onlyEnabled) return this.getSetSpecs(); |
|
93 |
List<SetInfo> enabled = this.getSets(true); |
|
94 |
return Lists.newArrayList(Iterables.transform(enabled, new Function<SetInfo, String>() { |
|
95 |
|
|
96 |
@Override |
|
97 |
public String apply(final SetInfo setInfo) { |
|
98 |
return setInfo.getSetSpec(); |
|
99 |
} |
|
100 |
|
|
101 |
})); |
|
102 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public List<MDFInfo> getSourceMetadataFormats() { |
|
107 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getSourcesMDF()); |
|
108 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public SetInfo getSetInfo(final String setSpec) { |
|
113 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getSetsMap().get(setSpec); |
|
114 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public List<MDFInfo> getMetadataFormatInfo() { |
|
119 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getMdFormatsMap().values()); |
|
120 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public List<MDFInfo> getMetadataFormatInfo(final boolean onlyEnabled) { |
|
125 |
if (isConfigurationLoaded()) { |
|
126 |
if (!onlyEnabled) return this.getMetadataFormatInfo(); |
|
127 |
else return Lists.newArrayList(Iterables.filter(this.oaiConfiguration.getMdFormatsMap().values(), new Predicate<MDFInfo>() { |
|
128 |
|
|
129 |
/** |
|
130 |
* {@inheritDoc} |
|
131 |
* |
|
132 |
* @see com.google.common.base.Predicate#apply(java.lang.Object) |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public boolean apply(final MDFInfo mdfInfo) { |
|
136 |
if (onlyEnabled) return mdfInfo.isEnabled(); |
|
137 |
else return true; |
|
138 |
} |
|
139 |
|
|
140 |
})); |
|
141 |
|
|
142 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public MDFInfo getMetadataFormatInfo(final String mdPrefix) { |
|
147 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getMdFormatsMap().get(mdPrefix); |
|
148 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public List<PublisherField> getFields() { |
|
153 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getFields(); |
|
154 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public List<PublisherField> getFields(final String format, final String interpretation, final String layout) { |
|
159 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getFieldsFor(format, layout, interpretation)); |
|
160 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public List<String> getFieldNames() { |
|
165 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getFieldNames(); |
|
166 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public List<MDFInfo> getFormatsServedBy(final String sourceFormatName, final String sourceFormatLayout, final String sourceFormatInterpretation) { |
|
171 |
if (isConfigurationLoaded()) { |
|
172 |
Collection<MDFInfo> unfiltered = this.oaiConfiguration.getMdFormatsMap().values(); |
|
173 |
return Lists.newArrayList(Collections2.filter(unfiltered, new Predicate<MDFInfo>() { |
|
174 |
|
|
175 |
@Override |
|
176 |
public boolean apply(final MDFInfo mdf) { |
|
177 |
return (mdf.getSourceFormatName() == sourceFormatName) && (mdf.getSourceFormatLayout() == sourceFormatLayout) |
|
178 |
&& (mdf.getSourceFormatInterpretation() == sourceFormatInterpretation); |
|
179 |
} |
|
180 |
|
|
181 |
})); |
|
182 |
|
|
183 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public String getIdScheme() { |
|
188 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getIdScheme(); |
|
189 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public String getIdNamespace() { |
|
194 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getIdNamespace(); |
|
195 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
196 |
} |
|
197 |
|
|
198 |
public OAIConfiguration getOaiConfiguration() { |
|
199 |
return oaiConfiguration; |
|
200 |
} |
|
201 |
|
|
202 |
public void setOaiConfiguration(final OAIConfiguration oaiConfiguration) { |
|
203 |
this.oaiConfiguration = oaiConfiguration; |
|
204 |
} |
|
205 |
|
|
206 |
public OAIConfigurationParser getConfigurationParser() { |
|
207 |
return configurationParser; |
|
208 |
} |
|
209 |
|
|
210 |
public void setConfigurationParser(final OAIConfigurationParser configurationParser) { |
|
211 |
this.configurationParser = configurationParser; |
|
212 |
} |
|
213 |
|
|
214 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationWriter.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
|
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
|
|
11 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
12 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
13 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
14 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
15 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
16 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
17 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
18 |
import eu.dnetlib.miscutils.functional.string.EscapeXml; |
|
19 |
|
|
20 |
public class OAIConfigurationWriter { |
|
21 |
|
|
22 |
private static final Log log = LogFactory.getLog(OAIConfigurationWriter.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
23 |
|
|
24 |
@Resource |
|
25 |
private UniqueServiceLocator serviceLocator; |
|
26 |
|
|
27 |
@Resource(name = "oaiConfigurationExistReader") |
|
28 |
private OAIConfigurationReader configuration; |
|
29 |
|
|
30 |
private boolean execute(final String xUpdate) throws ISRegistryException { |
|
31 |
log.debug("Running XUpdate:\n" + xUpdate); |
|
32 |
boolean done = this.serviceLocator.getService(ISRegistryService.class).executeXUpdate(xUpdate); |
|
33 |
if (!done) { |
|
34 |
log.fatal("Could not perform the following Xupdate:\n" + xUpdate); |
|
35 |
} |
|
36 |
return done; |
|
37 |
} |
|
38 |
|
|
39 |
public boolean updateMetadataFormat(final String mdPrefix, final MDFInfo newInfo) throws ISRegistryException { |
|
40 |
|
|
41 |
final String xUpdate = "update replace //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']" |
|
42 |
+ "//CONFIGURATION//METADATAFORMAT[./@metadataPrefix/string()='" + mdPrefix + "'] with <METADATAFORMAT exportable=\"" + newInfo.isEnabled() |
|
43 |
+ "\" metadataPrefix=\"" + newInfo.getPrefix() + "\">" + "<NAMESPACE>" + newInfo.getNamespace() + "</NAMESPACE><SCHEMA>" + newInfo.getSchema() |
|
44 |
+ "</SCHEMA><SOURCE_METADATA_FORMAT interpretation=\"" + newInfo.getSourceFormatInterpretation() + "\" layout=\"" |
|
45 |
+ newInfo.getSourceFormatLayout() + "\" name=\"" + newInfo.getSourceFormatName() + "\"/><TRANSFORMATION_RULE>" |
|
46 |
+ newInfo.getTransformationRuleID() + "</TRANSFORMATION_RULE><BASE_QUERY>" + new EscapeXml().evaluate(newInfo.getBaseQuery()) |
|
47 |
+ "</BASE_QUERY></METADATAFORMAT>"; |
|
48 |
return this.execute(xUpdate); |
|
49 |
} |
|
50 |
|
|
51 |
public boolean addMetadataFormat(final MDFInfo newInfo) throws ISRegistryException { |
|
52 |
|
|
53 |
String action = "update insert "; |
|
54 |
String newNode = "<METADATAFORMAT metadataPrefix='" + newInfo.getPrefix() + "' exportable='" + newInfo.isEnabled() + "' ><NAMESPACE>" |
|
55 |
+ newInfo.getNamespace() + "</NAMESPACE><SCHEMA>" + newInfo.getSchema() + "</SCHEMA>" + "<SOURCE_METADATA_FORMAT interpretation='" |
|
56 |
+ newInfo.getSourceFormatInterpretation() + "' layout='" + newInfo.getSourceFormatLayout() + "' name='" + newInfo.getSourceFormatName() |
|
57 |
+ "' /><TRANSFORMATION_RULE>" + newInfo.getTransformationRuleID() + "</TRANSFORMATION_RULE><BASE_QUERY>" |
|
58 |
+ new EscapeXml().evaluate(newInfo.getBaseQuery()) + "</BASE_QUERY></METADATAFORMAT>"; |
|
59 |
String targetNode = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION/METADATAFORMATS"; |
|
60 |
|
|
61 |
String xUpdate = action + newNode + " into " + targetNode; |
|
62 |
return this.execute(xUpdate); |
|
63 |
} |
|
64 |
|
|
65 |
public boolean deleteMetadataFormat(final String mdPrefix) throws ISRegistryException { |
|
66 |
String xUpdate = |
|
67 |
"update delete //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION//METADATAFORMATS/METADATAFORMAT[./@metadataPrefix/string()='" |
|
68 |
+ mdPrefix + "']"; |
|
69 |
return this.execute(xUpdate); |
|
70 |
} |
|
71 |
|
|
72 |
public boolean updateOAISet(final String setSpec, final SetInfo newInfo) throws ISRegistryException { |
|
73 |
final String xUpdate = "update replace //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']" |
|
74 |
+ "//CONFIGURATION//OAISET[spec/text()='" + setSpec + "'] with " + "<OAISET enabled=\"" + newInfo.isEnabled() + "\">" + "<spec>" |
|
75 |
+ newInfo.getSetSpec() + "</spec>" + "<name>" + newInfo.getSetName() + "</name>" + "<description>" + newInfo.getSetDescription() |
|
76 |
+ "</description>" + "<query>" + new EscapeXml().evaluate(newInfo.getQuery()) + "</query></OAISET>"; |
|
77 |
|
|
78 |
return this.execute(xUpdate); |
|
79 |
} |
|
80 |
|
|
81 |
public boolean addOAISet(final SetInfo newInfo) throws ISRegistryException { |
|
82 |
String action = "update insert "; |
|
83 |
String newNode = "<OAISET enabled=\"" + newInfo.isEnabled() + "\">" + "<spec>" + newInfo.getSetSpec() + "</spec>" + "<name>" + newInfo.getSetName() |
|
84 |
+ "</name>" + "<description>" + newInfo.getSetDescription() + "</description>" + "<query>" + new EscapeXml().evaluate(newInfo.getQuery()) |
|
85 |
+ "</query></OAISET>"; |
|
86 |
String targetNode = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION/OAISETS"; |
|
87 |
|
|
88 |
String xUpdate = action + newNode + " into " + targetNode; |
|
89 |
return this.execute(xUpdate); |
|
90 |
} |
|
91 |
|
|
92 |
public boolean deleteOAISet(final String setSpec) throws ISRegistryException { |
|
93 |
String xUpdate = |
|
94 |
"update delete //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION//OAISET[spec/text()='" |
|
95 |
+ setSpec + "']"; |
|
96 |
return this.execute(xUpdate); |
|
97 |
} |
|
98 |
|
|
99 |
public boolean updateIndices(final String format, final String layout, final String interpretation, final List<PublisherField> indexes) |
|
100 |
throws ISRegistryException { |
|
101 |
boolean dropped = this.dropIndexesFor(format, layout, interpretation); |
|
102 |
String xUpdateAction = "update insert "; |
|
103 |
String nodeTemplate = " <SOURCE name='" + format + "' layout='" + layout + "' interpretation='" + interpretation + "' "; |
|
104 |
String targetTemplate = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION/INDICES/INDEX"; |
|
105 |
if (!dropped) { return false; } |
|
106 |
for (PublisherField field : indexes) { |
|
107 |
String targetNode = targetTemplate + "[@name='" + field.getFieldName() + "']"; |
|
108 |
Collection<String> paths = field.getSources().get(format + "-" + layout + "-" + interpretation); |
|
109 |
for (String p : paths) { |
|
110 |
// insert one SOURCE node at a time, otherwise Exist complaints. |
|
111 |
String node = nodeTemplate + " path=\"" + p + "\" />"; |
|
112 |
String xUpdate = xUpdateAction + node + " into " + targetNode; |
|
113 |
boolean done = this.execute(xUpdate); |
|
114 |
if (!done) { return false; } |
|
115 |
} |
|
116 |
// finally let's update the repeatability |
|
117 |
String updateRepeatability = "update value " + targetNode + "/@repeatable with '" + field.isRepeatable() + "'"; |
|
118 |
boolean done = this.execute(updateRepeatability); |
|
119 |
if (!done) { return false; } |
|
120 |
} |
|
121 |
return true; |
|
122 |
} |
|
123 |
|
|
124 |
private boolean dropIndexesFor(final String format, final String layout, final String interpretation) throws ISRegistryException { |
|
125 |
String xUpdate = |
|
126 |
"update delete //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION//INDEX/SOURCE[./@interpretation/string()='" |
|
127 |
+ interpretation + "' and ./@name/string()='" + format + "' and ./@layout/string()='" + layout + "'] "; |
|
128 |
return this.execute(xUpdate); |
|
129 |
} |
|
130 |
|
|
131 |
public boolean addNewIndex(final String format, |
|
132 |
final String layout, |
|
133 |
final String interpretation, |
|
134 |
final String indexName, |
|
135 |
final boolean isRepeatable, |
|
136 |
final String[] paths) throws ISLookUpException, ISRegistryException { |
|
137 |
String action = "update insert "; |
|
138 |
String nodeTemplate = " <SOURCE name='" + format + "' layout='" + layout + "' interpretation='" + interpretation + "' "; |
|
139 |
String targetTemplate = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='OAIPublisherConfigurationDSResourceType']//CONFIGURATION/INDICES"; |
|
140 |
if (this.configuration.getFieldNames().contains(indexName)) { |
|
141 |
String targetNode = targetTemplate + "/INDEX[@name/string()='" + indexName + "']"; |
|
142 |
for (String p : paths) { |
|
143 |
// insert one SOURCE node at a time, otherwise Exist complaints. |
|
144 |
String node = nodeTemplate + " path=\"" + p + "\" />"; |
|
145 |
String xUpdate = action + node + " into " + targetNode; |
|
146 |
boolean done = this.execute(xUpdate); |
|
147 |
if (!done) { return false; } |
|
148 |
} |
|
149 |
} else { |
|
150 |
String targetNode = targetTemplate; |
|
151 |
String node = "<INDEX name='" + indexName + "' repeatable='" + isRepeatable + "'>"; |
|
152 |
for (String p : paths) { |
|
153 |
node += nodeTemplate + " path=\"" + p + "\" />"; |
|
154 |
} |
|
155 |
node += "</INDEX>"; |
|
156 |
String xUpdate = action + node + " into " + targetNode; |
|
157 |
boolean done = this.execute(xUpdate); |
|
158 |
if (!done) { return false; } |
|
159 |
} |
|
160 |
return true; |
|
161 |
} |
|
162 |
|
|
163 |
public OAIConfigurationReader getConfiguration() { |
|
164 |
return configuration; |
|
165 |
} |
|
166 |
|
|
167 |
public void setConfiguration(final OAIConfigurationReader configuration) { |
|
168 |
this.configuration = configuration; |
|
169 |
} |
|
170 |
|
|
171 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfiguration.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Set; |
|
7 |
|
|
8 |
import com.google.common.base.Joiner; |
|
9 |
import com.google.common.base.Predicate; |
|
10 |
import com.google.common.collect.Collections2; |
|
11 |
import com.google.common.collect.Sets; |
|
12 |
|
|
13 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
14 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
15 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
16 |
|
|
17 |
/** |
|
18 |
* An instance of this class represents an OAI Configuration profile. |
|
19 |
* |
|
20 |
* @author alessia |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class OAIConfiguration { |
|
24 |
|
|
25 |
/** |
|
26 |
* Map for OAI sets. Keys: setSpec, values: SetInfo instances. |
|
27 |
*/ |
|
28 |
private Map<String, SetInfo> setsMap; |
|
29 |
|
|
30 |
/** |
|
31 |
* Map for metadata formats. Keys: metadata prefix, values: MDFInfo instances. |
|
32 |
*/ |
|
33 |
private Map<String, MDFInfo> mdFormatsMap; |
|
34 |
|
|
35 |
private List<PublisherField> fields; |
|
36 |
|
|
37 |
private List<String> fieldNames; |
|
38 |
|
|
39 |
/** |
|
40 |
* Used to generate the OAI identifiers compliant to the protocol. See |
|
41 |
* http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. See property services.oai.publisher.id.scheme. |
|
42 |
*/ |
|
43 |
private String idScheme; |
|
44 |
/** |
|
45 |
* Used to generate the OAI identifiers compliant to the protocol. See |
|
46 |
* http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. See property services.oai.publisher.id.namespace. |
|
47 |
*/ |
|
48 |
private String idNamespace; |
|
49 |
|
|
50 |
private Set<MDFInfo> sourcesMDF = Sets.newHashSet(); |
|
51 |
|
|
52 |
public Collection<PublisherField> getFieldsFor(final String format, final String layout, final String interpretation) { |
|
53 |
final String mdRef = Joiner.on("-").join(format, layout, interpretation); |
|
54 |
return Collections2.filter(this.getFields(), new Predicate<PublisherField>() { |
|
55 |
|
|
56 |
@Override |
|
57 |
public boolean apply(final PublisherField theField) { |
|
58 |
if (theField.getSources() == null) return false; |
|
59 |
return theField.getSources().containsKey(mdRef); |
|
60 |
} |
|
61 |
|
|
62 |
}); |
|
63 |
} |
|
64 |
|
|
65 |
public Map<String, SetInfo> getSetsMap() { |
|
66 |
return setsMap; |
|
67 |
} |
|
68 |
|
|
69 |
public void setSetsMap(final Map<String, SetInfo> setsMap) { |
|
70 |
this.setsMap = setsMap; |
|
71 |
} |
|
72 |
|
|
73 |
public Map<String, MDFInfo> getMdFormatsMap() { |
|
74 |
return mdFormatsMap; |
|
75 |
} |
|
76 |
|
|
77 |
public void setMdFormatsMap(final Map<String, MDFInfo> mdFormatsMap) { |
|
78 |
this.mdFormatsMap = mdFormatsMap; |
|
79 |
} |
|
80 |
|
|
81 |
public List<PublisherField> getFields() { |
|
82 |
return fields; |
|
83 |
} |
|
84 |
|
|
85 |
public void setFields(final List<PublisherField> fields) { |
|
86 |
this.fields = fields; |
|
87 |
} |
|
88 |
|
|
89 |
public List<String> getFieldNames() { |
|
90 |
return fieldNames; |
|
91 |
} |
|
92 |
|
|
93 |
public void setFieldNames(final List<String> fieldNames) { |
|
94 |
this.fieldNames = fieldNames; |
|
95 |
} |
|
96 |
|
|
97 |
public Set<MDFInfo> getSourcesMDF() { |
|
98 |
return sourcesMDF; |
|
99 |
} |
|
100 |
|
|
101 |
public void setSourcesMDF(final Set<MDFInfo> sourcesMDF) { |
|
102 |
this.sourcesMDF = sourcesMDF; |
|
103 |
} |
|
104 |
|
|
105 |
public String getIdScheme() { |
|
106 |
return idScheme; |
|
107 |
} |
|
108 |
|
|
109 |
public void setIdScheme(final String idScheme) { |
|
110 |
this.idScheme = idScheme; |
|
111 |
} |
|
112 |
|
|
113 |
public String getIdNamespace() { |
|
114 |
return idNamespace; |
|
115 |
} |
|
116 |
|
|
117 |
public void setIdNamespace(final String idNamespace) { |
|
118 |
this.idNamespace = idNamespace; |
|
119 |
} |
|
120 |
|
|
121 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationReader.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
6 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
7 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
8 |
|
|
9 |
public interface OAIConfigurationReader { |
|
10 |
|
|
11 |
/** |
|
12 |
* Constant names of fields used by the publisher to store records in the OAIStores. If you want an index over them, you need to specify |
|
13 |
* it in the OAI Publisher Configuration profile. |
|
14 |
*/ |
|
15 |
public final static String ID_FIELD = "objIdentifier"; |
|
16 |
public final static String DATESTAMP_FIELD = "datestamp"; |
|
17 |
public final static String SET_FIELD = "set"; |
|
18 |
public final static String DELETED_FIELD = "deleted"; |
|
19 |
public final static String BODY_FIELD = "body"; |
|
20 |
public final static String UPDATED_FIELD = "updated"; |
|
21 |
public final static String LAST_COLLECTION_DATE_FIELD = "lastCollectionDate"; |
|
22 |
|
|
23 |
public List<SetInfo> getSets(); |
|
24 |
|
|
25 |
public List<SetInfo> getSets(final boolean onlyEnabled); |
|
26 |
|
|
27 |
public List<String> getSetSpecs(); |
|
28 |
|
|
29 |
public List<String> getSetSpecs(final boolean onlyEnabled); |
|
30 |
|
|
31 |
public SetInfo getSetInfo(final String setSpec); |
|
32 |
|
|
33 |
public List<MDFInfo> getMetadataFormatInfo(); |
|
34 |
|
|
35 |
public List<MDFInfo> getMetadataFormatInfo(final boolean onlyEnabled); |
|
36 |
|
|
37 |
public MDFInfo getMetadataFormatInfo(final String mdPrefix); |
|
38 |
|
|
39 |
public List<String> getFieldNames(); |
|
40 |
|
|
41 |
public List<PublisherField> getFields(); |
|
42 |
|
|
43 |
public List<PublisherField> getFields(final String format, final String interpretation, final String layout); |
|
44 |
|
|
45 |
/** |
|
46 |
* Used to generate the OAI identifiers compliant to the protocol. See |
|
47 |
* http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. |
|
48 |
*/ |
|
49 |
public String getIdScheme(); |
|
50 |
|
|
51 |
/** |
|
52 |
* Used to generate the OAI identifiers compliant to the protocol. See |
|
53 |
* http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. |
|
54 |
*/ |
|
55 |
public String getIdNamespace(); |
|
56 |
|
|
57 |
public List<MDFInfo> getSourceMetadataFormats(); |
|
58 |
|
|
59 |
public List<MDFInfo> getFormatsServedBy(String sourceFormatName, String sourceFormatLayout, String sourceFormatInterpretation); |
|
60 |
|
|
61 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/conf/OAIConfigurationParser.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.conf; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringReader; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
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 |
import javax.xml.transform.stream.StreamSource; |
|
13 |
|
|
14 |
import org.apache.commons.logging.Log; |
|
15 |
import org.apache.commons.logging.LogFactory; |
|
16 |
|
|
17 |
import com.google.common.collect.ArrayListMultimap; |
|
18 |
import com.google.common.collect.Lists; |
|
19 |
import com.google.common.collect.Maps; |
|
20 |
import com.google.common.collect.Multimap; |
|
21 |
|
|
22 |
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException; |
|
23 |
import eu.dnetlib.data.information.oai.publisher.PublisherField; |
|
24 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
25 |
import eu.dnetlib.data.information.oai.publisher.info.SetInfo; |
|
26 |
|
|
27 |
/** |
|
28 |
* Parses an XML document representing the OAI configuration profile and creates the corresponding OAIConfiguration object. |
|
29 |
* |
|
30 |
* @author alessia |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class OAIConfigurationParser { |
|
34 |
|
|
35 |
private static final Log log = LogFactory.getLog(OAIConfigurationParser.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
36 |
|
|
37 |
private final ThreadLocal<XMLInputFactory> factory = new ThreadLocal<XMLInputFactory>() { |
|
38 |
|
|
39 |
@Override |
|
40 |
protected XMLInputFactory initialValue() { |
|
41 |
return XMLInputFactory.newInstance(); |
|
42 |
} |
|
43 |
}; |
|
44 |
|
|
45 |
public OAIConfiguration getConfiguration(final String configurationProfile) throws IOException { |
|
46 |
log.debug(configurationProfile); |
|
47 |
OAIConfiguration config = new OAIConfiguration(); |
|
48 |
Map<String, SetInfo> setsMap = Maps.newHashMap(); |
|
49 |
Map<String, MDFInfo> mdFormatsMap = Maps.newHashMap(); |
|
50 |
List<String> indexNames = Lists.newArrayList(); |
|
51 |
List<PublisherField> fields = Lists.newArrayList(); |
|
52 |
try { |
|
53 |
final XMLStreamReader parser = factory.get().createXMLStreamReader(new StreamSource(new StringReader(configurationProfile))); |
|
54 |
while (parser.hasNext()) { |
|
55 |
int event = parser.next(); |
|
56 |
if (event == XMLStreamConstants.START_ELEMENT) { |
|
57 |
final String localName = parser.getLocalName(); |
|
58 |
if (localName.equals("IDSCHEME")) { |
|
59 |
config.setIdScheme(parser.getElementText()); |
|
60 |
} else if (localName.equals("IDNAMESPACE")) { |
|
61 |
config.setIdNamespace(parser.getElementText()); |
|
62 |
} else if (localName.equals("OAISET")) { |
|
63 |
boolean inSet = true; |
|
64 |
SetInfo setInfo = new SetInfo(); |
|
65 |
String enabled = parser.getAttributeValue(null, "enabled"); |
|
66 |
setInfo.setEnabled(Boolean.parseBoolean(enabled)); |
|
67 |
while (parser.hasNext() && inSet) { |
|
68 |
event = parser.next(); |
|
69 |
if (event == XMLStreamConstants.START_ELEMENT) { |
|
70 |
String setElementName = parser.getLocalName(); |
|
71 |
String setElementValue = parser.getElementText(); |
|
72 |
this.handleSetInfo(setInfo, setElementName, setElementValue); |
|
73 |
} |
|
74 |
if ((event == XMLStreamConstants.END_ELEMENT) && parser.getLocalName().equals("OAISET")) { |
|
75 |
inSet = false; |
|
76 |
setsMap.put(setInfo.getSetSpec(), setInfo); |
|
77 |
} |
|
78 |
} |
|
79 |
} else { |
|
80 |
if (localName.equals("METADATAFORMAT")) { |
|
81 |
boolean inMetadata = true; |
|
82 |
MDFInfo mdfInfo = new MDFInfo(); |
|
83 |
String exportable = parser.getAttributeValue(null, "exportable"); |
|
84 |
mdfInfo.setEnabled(Boolean.parseBoolean(exportable)); |
|
85 |
String mdPrefix = parser.getAttributeValue(null, "metadataPrefix"); |
|
86 |
mdfInfo.setPrefix(mdPrefix); |
|
87 |
while (parser.hasNext() && inMetadata) { |
|
88 |
event = parser.next(); |
|
89 |
if (event == XMLStreamConstants.START_ELEMENT) { |
|
90 |
String mdfElementName = parser.getLocalName(); |
|
91 |
if (mdfElementName.equals("SOURCE_METADATA_FORMAT")) { |
|
92 |
this.handleSourceMDF(mdfInfo, parser); |
|
93 |
config.getSourcesMDF().add(mdfInfo); |
|
94 |
} else { |
|
95 |
String mdfElementValue = parser.getElementText(); |
|
96 |
this.handleMDFInfo(mdfInfo, mdfElementName, mdfElementValue); |
|
97 |
} |
|
98 |
} |
|
99 |
if ((event == XMLStreamConstants.END_ELEMENT) && parser.getLocalName().equals("METADATAFORMAT")) { |
|
100 |
inMetadata = false; |
|
101 |
mdFormatsMap.put(mdPrefix, mdfInfo); |
|
102 |
} |
|
103 |
} |
|
104 |
} else { |
|
105 |
// INDICES |
|
106 |
if (localName.equals("INDEX")) { |
|
107 |
boolean inIndex = true; |
|
108 |
PublisherField publisherField = new PublisherField(); |
|
109 |
String indexName = parser.getAttributeValue(null, "name"); |
|
110 |
String repeatable = parser.getAttributeValue(null, "repeatable"); |
|
111 |
boolean isRepeatable = Boolean.valueOf(repeatable); |
|
112 |
indexNames.add(indexName); |
|
113 |
publisherField.setFieldName(indexName); |
|
114 |
publisherField.setRepeatable(isRepeatable); |
|
115 |
// now let's set the SOURCES |
|
116 |
Multimap<String, String> fieldSources = ArrayListMultimap.create(); |
|
117 |
while (parser.hasNext() && inIndex) { |
|
118 |
event = parser.next(); |
|
119 |
if (event == XMLStreamConstants.START_ELEMENT) { |
|
120 |
String currentElementName = parser.getLocalName(); |
|
121 |
this.handleIndex(fieldSources, indexName, parser, currentElementName); |
|
122 |
} |
|
123 |
if ((event == XMLStreamConstants.END_ELEMENT) && parser.getLocalName().equals("INDEX")) { |
|
124 |
inIndex = false; |
|
125 |
} |
|
126 |
} |
|
127 |
publisherField.setSources(fieldSources); |
|
128 |
fields.add(publisherField); |
|
129 |
|
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
config.setFields(fields); |
|
136 |
config.setFieldNames(indexNames); |
|
137 |
config.setMdFormatsMap(mdFormatsMap); |
|
138 |
config.setSetsMap(setsMap); |
|
139 |
return config; |
|
140 |
} catch (final XMLStreamException e) { |
|
141 |
throw new OaiPublisherRuntimeException(e); |
|
142 |
} |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Sets information about the indices. |
|
148 |
* |
|
149 |
* @param fieldSources |
|
150 |
* @param indexName |
|
151 |
* @param parser |
|
152 |
* @param currentLocalName |
|
153 |
*/ |
|
154 |
private void handleIndex(final Multimap<String, String> fieldSources, final String indexName, final XMLStreamReader parser, final String currentLocalName) { |
|
155 |
if (currentLocalName.equals("SOURCE")) { |
|
156 |
MDFInfo indexSource = new MDFInfo(); |
|
157 |
this.handleSourceMDF(indexSource, parser); |
|
158 |
String key = indexSource.getSourceFormatName() + "-" + indexSource.getSourceFormatLayout() + "-" + indexSource.getSourceFormatInterpretation(); |
|
159 |
fieldSources.put(key, parser.getAttributeValue(null, "path")); |
|
160 |
} else { |
|
161 |
log.warn("I do not know how to handle INDEX element with name " + currentLocalName); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Sets information about the source metadata format in the given instance of MDFInfo. |
|
167 |
* |
|
168 |
* @param mdfInfo |
|
169 |
* @param parser |
|
170 |
*/ |
|
171 |
private void handleSourceMDF(final MDFInfo mdfInfo, final XMLStreamReader parser) { |
|
172 |
String interpretation = parser.getAttributeValue(null, "interpretation"); |
|
173 |
String layout = parser.getAttributeValue(null, "layout"); |
|
174 |
String name = parser.getAttributeValue(null, "name"); |
|
175 |
mdfInfo.setSourceFormatInterpretation(interpretation); |
|
176 |
mdfInfo.setSourceFormatLayout(layout); |
|
177 |
mdfInfo.setSourceFormatName(name); |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Sets information in the MDFInfo instance based on the element name. |
|
182 |
* |
|
183 |
* @param mdfInfo |
|
184 |
* @param mdfElementName |
|
185 |
* @param mdfElementValue |
|
186 |
*/ |
|
187 |
private void handleMDFInfo(final MDFInfo mdfInfo, final String elementName, final String elementValue) { |
|
188 |
if (elementName.equals("NAMESPACE")) { |
|
189 |
mdfInfo.setNamespace(elementValue); |
|
190 |
} else { |
|
191 |
if (elementName.equals("SCHEMA")) { |
|
192 |
mdfInfo.setSchema(elementValue); |
|
193 |
} else { |
|
194 |
if (elementName.equals("TRANSFORMATION_RULE")) { |
|
195 |
mdfInfo.setTransformationRuleID(elementValue); |
|
196 |
} else { |
|
197 |
if (elementName.equals("BASE_QUERY")) { |
|
198 |
mdfInfo.setBaseQuery(elementValue); |
|
199 |
} else { |
|
200 |
log.warn("I do not know how to handle Metadata Format element with name " + elementName + " and value " + elementValue); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Sets information in the SetInfo instance based on the element name. |
|
210 |
* |
|
211 |
* @param setInfo |
|
212 |
* @param elementName |
|
213 |
* @param elementValue |
|
214 |
*/ |
|
215 |
private void handleSetInfo(final SetInfo setInfo, final String elementName, final String elementValue) { |
|
216 |
if (elementName.equals("spec")) { |
|
217 |
setInfo.setSetSpec(elementValue); |
|
218 |
} else { |
|
219 |
if (elementName.equals("name")) { |
|
220 |
setInfo.setSetName(elementValue); |
|
221 |
} else { |
|
222 |
if (elementName.equals("description")) { |
|
223 |
setInfo.setSetDescription(elementValue); |
|
224 |
} else { |
|
225 |
if (elementName.equals("query")) { |
|
226 |
setInfo.setQuery(elementValue); |
|
227 |
} else { |
|
228 |
log.warn("I do not know how to handle Set element with name " + elementName + " and value " + elementValue); |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
} |
modules/dnet-oai-utils/tags/dnet-oai-utils-4.0.1/src/main/java/eu/dnetlib/data/information/oai/publisher/info/ResumptionTokenImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.data.information.oai.publisher.info; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.apache.commons.lang.StringEscapeUtils; |
|
6 |
import org.apache.commons.lang.StringUtils; |
|
7 |
|
|
8 |
import com.google.common.collect.Lists; |
|
9 |
|
|
10 |
import eu.dnetlib.data.information.oai.publisher.BadResumptionTokenException; |
|
11 |
|
|
12 |
public class ResumptionTokenImpl implements ResumptionToken { |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-oai-utils-4.0.1