1 |
34077
|
michele.ar
|
package eu.dnetlib.enabling.is;
|
2 |
|
|
|
3 |
34095
|
michele.ar
|
import java.io.StringReader;
|
4 |
34077
|
michele.ar
|
import java.util.List;
|
5 |
|
|
import java.util.UUID;
|
6 |
|
|
|
7 |
34095
|
michele.ar
|
import javax.annotation.PostConstruct;
|
8 |
34077
|
michele.ar
|
import javax.annotation.Resource;
|
9 |
|
|
|
10 |
|
|
import org.apache.commons.logging.Log;
|
11 |
|
|
import org.apache.commons.logging.LogFactory;
|
12 |
34095
|
michele.ar
|
import org.dom4j.Document;
|
13 |
|
|
import org.dom4j.Element;
|
14 |
|
|
import org.dom4j.io.SAXReader;
|
15 |
34077
|
michele.ar
|
|
16 |
|
|
import eu.dnetlib.enabling.is.dao.DnetServiceDao;
|
17 |
34139
|
michele.ar
|
import eu.dnetlib.enabling.is.jdbc.DatabaseUtils;
|
18 |
34095
|
michele.ar
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
19 |
34099
|
michele.ar
|
import eu.dnetlib.enabling.is.rmi.DnetService;
|
20 |
34077
|
michele.ar
|
import eu.dnetlib.enabling.is.rmi.InformationService;
|
21 |
|
|
import eu.dnetlib.enabling.is.rmi.InformationServiceException;
|
22 |
34095
|
michele.ar
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
23 |
34077
|
michele.ar
|
import eu.dnetlib.enabling.tools.AbstractBaseService;
|
24 |
|
|
|
25 |
|
|
public class InformationServiceImpl extends AbstractBaseService implements InformationService {
|
26 |
|
|
|
27 |
|
|
private static final Log log = LogFactory.getLog(InformationServiceImpl.class);
|
28 |
|
|
|
29 |
|
|
@Resource
|
30 |
|
|
private DnetServiceDao dnetServiceDao;
|
31 |
|
|
|
32 |
34095
|
michele.ar
|
@Resource
|
33 |
34139
|
michele.ar
|
private DatabaseUtils dbUtils;
|
34 |
|
|
|
35 |
|
|
@Resource
|
36 |
34095
|
michele.ar
|
private UniqueServiceLocator serviceLocator;
|
37 |
|
|
|
38 |
|
|
@PostConstruct
|
39 |
|
|
public void init() throws Exception {
|
40 |
34108
|
michele.ar
|
log.info("Registering services...");
|
41 |
|
|
|
42 |
34095
|
michele.ar
|
final SAXReader reader = new SAXReader();
|
43 |
|
|
|
44 |
|
|
final ISLookUpService lookup = serviceLocator.getService(ISLookUpService.class);
|
45 |
|
|
|
46 |
34108
|
michele.ar
|
final List<String> list = lookup.quickSearchProfile("for $x in collection('/db/DRIVER/ServiceResources') return $x");
|
47 |
|
|
for (String s : list) {
|
48 |
34095
|
michele.ar
|
final Document doc = reader.read(new StringReader(s));
|
49 |
|
|
final DnetService service = new DnetService();
|
50 |
34099
|
michele.ar
|
service.setName(doc.valueOf("//RESOURCE_TYPE/@value"));
|
51 |
34095
|
michele.ar
|
|
52 |
|
|
for (Object o : doc.selectNodes("//SERVICE_PROPERTIES/PROPERTY")) {
|
53 |
|
|
final Element n = (Element) o;
|
54 |
34099
|
michele.ar
|
service.getProperties().put(n.valueOf("@key"), n.valueOf("@value"));
|
55 |
34095
|
michele.ar
|
}
|
56 |
|
|
for (Object o : doc.selectNodes("//PROTOCOLS/PROTOCOL")) {
|
57 |
|
|
final Element n = (Element) o;
|
58 |
34099
|
michele.ar
|
service.getProtocols().put(n.valueOf("@name"), n.valueOf("@address"));
|
59 |
34095
|
michele.ar
|
}
|
60 |
|
|
|
61 |
|
|
registerService(service);
|
62 |
|
|
}
|
63 |
34108
|
michele.ar
|
log.info("Done, total: " + list.size());
|
64 |
34095
|
michele.ar
|
}
|
65 |
|
|
|
66 |
34077
|
michele.ar
|
@Override
|
67 |
|
|
public List<DnetService> listServices() throws InformationServiceException {
|
68 |
|
|
return dnetServiceDao.list();
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
@Override
|
72 |
|
|
public String registerService(final DnetService service) throws InformationServiceException {
|
73 |
|
|
final String id = "service:" + UUID.randomUUID();
|
74 |
|
|
service.setId(id);
|
75 |
|
|
|
76 |
|
|
dnetServiceDao.save(service);
|
77 |
|
|
|
78 |
|
|
log.info("Service " + service + " saved");
|
79 |
|
|
|
80 |
|
|
return id;
|
81 |
|
|
}
|
82 |
34139
|
michele.ar
|
|
83 |
|
|
@Override
|
84 |
|
|
public List<String> search(final String sql) throws InformationServiceException {
|
85 |
|
|
return dbUtils.search(sql);
|
86 |
|
|
}
|
87 |
34077
|
michele.ar
|
}
|