1
|
package eu.dnetlib.data.collective.transformation;
|
2
|
|
3
|
import javax.annotation.Resource;
|
4
|
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.dom4j.DocumentException;
|
8
|
|
9
|
import eu.dnetlib.data.collective.transformation.engine.functions.DateVocabulary;
|
10
|
import eu.dnetlib.data.collective.transformation.engine.functions.IVocabulary;
|
11
|
import eu.dnetlib.data.collective.transformation.engine.functions.PersonVocabulary;
|
12
|
// import eu.dnetlib.data.collective.transformation.engine.functions.PmcVocabulary;
|
13
|
import eu.dnetlib.data.collective.transformation.engine.functions.Vocabulary;
|
14
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
|
15
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
16
|
import eu.dnetlib.enabling.locators.DefaultUniqueServiceLocator;
|
17
|
|
18
|
/**
|
19
|
* @author jochen
|
20
|
*
|
21
|
*/
|
22
|
public class VocabularyRegistry {
|
23
|
|
24
|
private static final Log log = LogFactory.getLog(VocabularyRegistry.class);
|
25
|
private static final String dateVocabularyName = "DateISO8601";
|
26
|
// private static final String pmcVocabularyName = "PMC";
|
27
|
private static final String personVocabularyName = "Person";
|
28
|
|
29
|
@Resource
|
30
|
private DefaultUniqueServiceLocator uniqueServiceLocator;
|
31
|
private VocabularyMap vocabularies;
|
32
|
private boolean isInitialized = false;
|
33
|
|
34
|
public void init() {
|
35
|
String vocabularyQueryPrefix = "collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')//RESOURCE_PROFILE";
|
36
|
String targetVocabulary = "";
|
37
|
for (String key : vocabularies.getMap().keySet()) {
|
38
|
try {
|
39
|
Vocabulary v = vocabularies.getMap().get(key);
|
40
|
targetVocabulary = vocabularies.getMap().get(key).getName();
|
41
|
v.setResource(new eu.dnetlib.common.profile.Resource(uniqueServiceLocator.getIsLookupService().getResourceProfileByQuery(
|
42
|
vocabularyQueryPrefix + "[.//VOCABULARY_NAME='" + targetVocabulary + "' or .//VOCABULARY_NAME/@code='" + targetVocabulary + "'] ")));
|
43
|
} catch (ISLookUpDocumentNotFoundException e) {
|
44
|
throw new IllegalStateException("vocabulary profile not found for name or code " + targetVocabulary, e);
|
45
|
} catch (ISLookUpException e) {
|
46
|
log.fatal("ISLookupException in VocabularyRegistry, key = " + key + " : ", e);
|
47
|
throw new IllegalStateException(e);
|
48
|
} catch (DocumentException e) {
|
49
|
log.fatal("DocumentException in VocabularyRegistry, key = " + key + " : ", e);
|
50
|
throw new IllegalStateException(e);
|
51
|
}
|
52
|
}
|
53
|
vocabularies.getMap().put(dateVocabularyName, new DateVocabulary());
|
54
|
vocabularies.getMap().put(personVocabularyName, new PersonVocabulary());
|
55
|
// PmcVocabulary pmcVocab = new PmcVocabulary();
|
56
|
// pmcVocab.setMappingFile(mappingFile);
|
57
|
// vocabularies.getMap().put(pmcVocabularyName, pmcVocab);
|
58
|
isInitialized = true;
|
59
|
log.info("VocabularyRegistry is initialized.");
|
60
|
}
|
61
|
|
62
|
public IVocabulary getVocabulary(final String aVocabularyName) {
|
63
|
if (!isInitialized) {
|
64
|
init();
|
65
|
}
|
66
|
return vocabularies.getMap().get(aVocabularyName);
|
67
|
}
|
68
|
|
69
|
public VocabularyMap getVocabularies() {
|
70
|
if (!isInitialized) {
|
71
|
init();
|
72
|
}
|
73
|
return vocabularies;
|
74
|
}
|
75
|
|
76
|
public void setVocabularies(final VocabularyMap vocabularies) {
|
77
|
this.vocabularies = vocabularies;
|
78
|
}
|
79
|
|
80
|
public void addVocabulary(final String aVocabularyName, final Vocabulary aVocabulary) {
|
81
|
this.vocabularies.getMap().put(aVocabularyName, aVocabulary);
|
82
|
}
|
83
|
|
84
|
public void removeVocabulary(final String aVocabulary) {
|
85
|
this.vocabularies.getMap().remove(aVocabulary);
|
86
|
}
|
87
|
|
88
|
public DefaultUniqueServiceLocator getUniqueServiceLocator() {
|
89
|
return uniqueServiceLocator;
|
90
|
}
|
91
|
|
92
|
public void setUniqueServiceLocator(final DefaultUniqueServiceLocator uniqueServiceLocator) {
|
93
|
this.uniqueServiceLocator = uniqueServiceLocator;
|
94
|
}
|
95
|
|
96
|
}
|