1
|
package eu.dnetlib.data.search.utils.vocabulary;
|
2
|
|
3
|
import eu.dnetlib.domain.enabling.VocabularySearchCriteria;
|
4
|
import gr.uoa.di.driver.enabling.ISLookUp;
|
5
|
import gr.uoa.di.driver.enabling.ISLookUpException;
|
6
|
import org.apache.log4j.Logger;
|
7
|
|
8
|
import java.util.List;
|
9
|
import java.util.Locale;
|
10
|
|
11
|
public class ISVocabularyLoader extends VocabularyLoader {
|
12
|
|
13
|
private ISLookUp<eu.dnetlib.domain.enabling.Vocabulary> lookup = null;
|
14
|
|
15
|
private static Logger logger = Logger.getLogger(ISVocabularyLoader.class);
|
16
|
|
17
|
@Override
|
18
|
public eu.dnetlib.domain.enabling.Vocabulary getVocabulary(Vocabulary vocabulary, Locale locale) {
|
19
|
logger.debug("Getting vocabulary with name " + vocabulary.getName() + " and locale " + locale);
|
20
|
String localizedResourceName = ((ISVocabulary)vocabulary).getResourceName() + "_" +
|
21
|
locale.getLanguage() + "_" + locale.getCountry();
|
22
|
|
23
|
VocabularySearchCriteria criteria = new VocabularySearchCriteria();
|
24
|
criteria.setName(localizedResourceName);
|
25
|
|
26
|
List<eu.dnetlib.domain.enabling.Vocabulary> list;
|
27
|
|
28
|
|
29
|
try {
|
30
|
list = lookup.fetch(criteria);
|
31
|
|
32
|
if (list.size() > 0) {
|
33
|
return list.get(0);
|
34
|
|
35
|
} else {
|
36
|
logger.debug("The " + localizedResourceName + " does not exist in IS. Loading default vocabulary instead.");
|
37
|
criteria.setName(((ISVocabulary)vocabulary).getResourceName());
|
38
|
list = lookup.fetch(criteria);
|
39
|
|
40
|
if (list.size() > 0) {
|
41
|
return list.get(0);
|
42
|
}
|
43
|
}
|
44
|
|
45
|
} catch (ISLookUpException ise) {
|
46
|
logger.warn("Problem loading " + vocabulary.getName() + " from IS.", ise);
|
47
|
}
|
48
|
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
public ISLookUp<eu.dnetlib.domain.enabling.Vocabulary> getLookup() {
|
53
|
return lookup;
|
54
|
}
|
55
|
|
56
|
public void setLookup(ISLookUp<eu.dnetlib.domain.enabling.Vocabulary> lookup) {
|
57
|
this.lookup = lookup;
|
58
|
}
|
59
|
}
|