1 |
42181
|
sandro.lab
|
package eu.dnetlib.oai.conf;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
import java.util.function.Function;
|
5 |
42184
|
michele.ar
|
|
6 |
42181
|
sandro.lab
|
import javax.annotation.Resource;
|
7 |
|
|
|
8 |
|
|
import org.apache.commons.lang3.StringUtils;
|
9 |
|
|
import org.apache.commons.logging.Log;
|
10 |
|
|
import org.apache.commons.logging.LogFactory;
|
11 |
|
|
import org.dom4j.DocumentException;
|
12 |
|
|
import org.springframework.beans.factory.annotation.Value;
|
13 |
|
|
import org.springframework.cache.annotation.CacheEvict;
|
14 |
|
|
import org.springframework.cache.annotation.Cacheable;
|
15 |
|
|
|
16 |
42184
|
michele.ar
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
17 |
|
|
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
|
18 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
|
19 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
20 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
21 |
|
|
import eu.dnetlib.rmi.provision.MDFInfo;
|
22 |
|
|
import eu.dnetlib.rmi.provision.OaiPublisherRuntimeException;
|
23 |
|
|
|
24 |
42181
|
sandro.lab
|
/**
|
25 |
|
|
* Helper class for common queries to the IS.
|
26 |
|
|
*
|
27 |
|
|
* @author alessia
|
28 |
|
|
*/
|
29 |
|
|
public class OAIISLookUpClient {
|
30 |
|
|
|
31 |
|
|
private static final Log log = LogFactory.getLog(OAIISLookUpClient.class); // NOPMD by marko on 11/24/08 5:02 PM
|
32 |
|
|
|
33 |
|
|
@Value("${services.oai.publisher.db.xquery}")
|
34 |
|
|
private String xpathToCurrentDB;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* lookup service.
|
38 |
|
|
*/
|
39 |
|
|
@Resource
|
40 |
|
|
private UniqueServiceLocator serviceLocator;
|
41 |
|
|
|
42 |
|
|
@Resource
|
43 |
|
|
private OAIConfigurationExistReader configuration;
|
44 |
|
|
|
45 |
|
|
public List<MDFInfo> listMetadataFormats(final boolean onlyEnabled) throws ISLookUpException, DocumentException {
|
46 |
|
|
return this.configuration.getMetadataFormatInfo(onlyEnabled);
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
@Cacheable(value = "unaryFunctions", key = "#tdsRuleId")
|
50 |
|
|
public Function<String, String> getUnaryFunctionFromTDSRule(final String tdsRuleId) {
|
51 |
|
|
log.fatal("Not using cache to get TDSRule " + tdsRuleId);
|
52 |
|
|
final String queryCodeRule = "//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='" + tdsRuleId
|
53 |
|
|
+ "']/BODY/CONFIGURATION/SCRIPT/CODE/*[local-name()='stylesheet']";
|
54 |
|
|
String xsltCode = null;
|
55 |
|
|
try {
|
56 |
|
|
xsltCode = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(queryCodeRule);
|
57 |
42184
|
michele.ar
|
} catch (final ISLookUpDocumentNotFoundException e) {
|
58 |
42181
|
sandro.lab
|
log.fatal("Unexisting TDSRule profile with identifier " + tdsRuleId);
|
59 |
|
|
throw new OaiPublisherRuntimeException(e);
|
60 |
42184
|
michele.ar
|
} catch (final ISLookUpException e) {
|
61 |
42181
|
sandro.lab
|
throw new OaiPublisherRuntimeException(e);
|
62 |
|
|
}
|
63 |
|
|
if (StringUtils.isBlank(xsltCode)) {
|
64 |
|
|
log.warn("Unexpected blank stylesheet in TDSRule profile with id: " + tdsRuleId + ". Returning identity function.");
|
65 |
|
|
return it -> it;
|
66 |
42184
|
michele.ar
|
} else {
|
67 |
|
|
return new ApplyXslt(xsltCode);
|
68 |
|
|
}
|
69 |
42181
|
sandro.lab
|
}
|
70 |
|
|
|
71 |
|
|
@Cacheable("oaiDB")
|
72 |
|
|
public String getCurrentDB() throws ISLookUpDocumentNotFoundException, ISLookUpException {
|
73 |
|
|
log.fatal("Not using cache to get the current OAI db");
|
74 |
42184
|
michele.ar
|
final String currentDBName = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(this.xpathToCurrentDB);
|
75 |
42181
|
sandro.lab
|
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 |
42184
|
michele.ar
|
return this.configuration;
|
86 |
42181
|
sandro.lab
|
}
|
87 |
|
|
|
88 |
|
|
public void setConfiguration(final OAIConfigurationExistReader configuration) {
|
89 |
|
|
this.configuration = configuration;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
}
|