3 |
3 |
import eu.dnetlib.domain.enabling.VocabularySearchCriteria;
|
4 |
4 |
import gr.uoa.di.driver.enabling.ISLookUp;
|
5 |
5 |
import gr.uoa.di.driver.enabling.ISLookUpException;
|
6 |
|
import gr.uoa.di.driver.enabling.resultset.ResultSet;
|
7 |
|
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory;
|
8 |
|
import gr.uoa.di.driver.xml.VocabularyXmlConverter;
|
9 |
6 |
import org.apache.log4j.Logger;
|
10 |
7 |
|
11 |
|
import javax.xml.bind.JAXBException;
|
|
8 |
import java.util.List;
|
12 |
9 |
import java.util.Locale;
|
13 |
10 |
|
14 |
11 |
public class ISVocabularyLoader extends VocabularyLoader {
|
15 |
12 |
|
16 |
|
private ResultSetFactory rsFactory = null;
|
17 |
13 |
private ISLookUp<eu.dnetlib.domain.enabling.Vocabulary> lookup = null;
|
18 |
14 |
|
19 |
15 |
private static Logger logger = Logger.getLogger(ISVocabularyLoader.class);
|
... | ... | |
27 |
23 |
VocabularySearchCriteria criteria = new VocabularySearchCriteria();
|
28 |
24 |
criteria.setName(localizedResourceName);
|
29 |
25 |
|
30 |
|
ResultSet<String> rs = null;
|
31 |
|
String xml = null;
|
|
26 |
List<eu.dnetlib.domain.enabling.Vocabulary> list;
|
32 |
27 |
|
|
28 |
|
33 |
29 |
try {
|
34 |
|
rs = rsFactory.createResultSet(lookup.search(criteria));
|
|
30 |
list = lookup.fetch(criteria);
|
35 |
31 |
|
36 |
|
if (rs.size() > 0) {
|
37 |
|
xml = rs.getElements(1, 1).get(0);
|
|
32 |
if (list.size() > 0) {
|
|
33 |
return list.get(0);
|
38 |
34 |
|
39 |
35 |
} else {
|
40 |
36 |
logger.debug("The " + localizedResourceName + " does not exist in IS. Loading default vocabulary instead.");
|
41 |
37 |
criteria.setName(((ISVocabulary)vocabulary).getResourceName());
|
42 |
|
rs = rsFactory.createResultSet(lookup.search(criteria));
|
|
38 |
list = lookup.fetch(criteria);
|
43 |
39 |
|
44 |
|
if (rs.size() > 0) {
|
45 |
|
xml = rs.getElements(1, 1).get(0);
|
|
40 |
if (list.size() > 0) {
|
|
41 |
return list.get(0);
|
46 |
42 |
}
|
47 |
43 |
}
|
48 |
44 |
|
... | ... | |
50 |
46 |
logger.warn("Problem loading " + vocabulary.getName() + " from IS.", ise);
|
51 |
47 |
}
|
52 |
48 |
|
53 |
|
if (xml != null && !xml.trim().isEmpty()) {
|
54 |
|
VocabularyXmlConverter converter = null;
|
55 |
|
try {
|
56 |
|
converter = new VocabularyXmlConverter();
|
57 |
|
rs.close();
|
58 |
|
return converter.XmlToObject(xml);
|
59 |
|
|
60 |
|
} catch (JAXBException jaxbe) {
|
61 |
|
logger.error("Unable to load vocabulary " + vocabulary.getName(), jaxbe);
|
62 |
|
}
|
63 |
|
}
|
64 |
|
|
65 |
|
//rs.close();
|
66 |
49 |
return null;
|
67 |
50 |
}
|
68 |
51 |
|
... | ... | |
73 |
56 |
public void setLookup(ISLookUp<eu.dnetlib.domain.enabling.Vocabulary> lookup) {
|
74 |
57 |
this.lookup = lookup;
|
75 |
58 |
}
|
76 |
|
|
77 |
|
public ResultSetFactory getRsFactory() {
|
78 |
|
return rsFactory;
|
79 |
|
}
|
80 |
|
|
81 |
|
public void setRsFactory(ResultSetFactory rsFactory) {
|
82 |
|
this.rsFactory = rsFactory;
|
83 |
|
}
|
84 |
59 |
}
|
moved to dnet45