1
|
package eu.dnetlib.functionality.modular.ui.lightui.clients;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
|
6
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
7
|
import eu.dnetlib.functionality.modular.ui.lightui.menu.LightUiMenuEntry;
|
8
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
9
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
|
14
|
public class ISLookupLightUIClient {
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(ISLookupLightUIClient.class);
|
17
|
@Autowired
|
18
|
private UniqueServiceLocator serviceLocator;
|
19
|
|
20
|
public List<LightUiMenuEntry> listMenuEntries() {
|
21
|
final String xQuery = "for $x in collection('/db/DRIVER/LightUiDSResources/LightUiDSResourceType') order by $x//UI_NAME "
|
22
|
+ "return concat ($x//UI_NAME/@id, '§§§', $x//UI_NAME, '§§§', $x//UI_DESCRIPTION)";
|
23
|
List<LightUiMenuEntry> result = new ArrayList<>();
|
24
|
try {
|
25
|
List<String> uiProfiles = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xQuery);
|
26
|
int i = 1;
|
27
|
for (String profile : uiProfiles) {
|
28
|
String[] tokens = profile.split("§§§");
|
29
|
result.add(new LightUiMenuEntry(tokens[0].trim(), tokens[1].trim(), tokens[1].trim(), tokens[2].trim(), i++));
|
30
|
}
|
31
|
return result;
|
32
|
} catch (ISLookUpException e) {
|
33
|
log.error("Error calculating lightui menu entries", e);
|
34
|
return result;
|
35
|
}
|
36
|
}
|
37
|
|
38
|
public String getLightUiProfile(final String lightuiId) throws ISLookUpException {
|
39
|
String xQuery = "for $x in collection('/db/DRIVER/LightUiDSResources/LightUiDSResourceType') where $x//UI_NAME/@id = '{id}' return $x";
|
40
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xQuery.replace("{id}", lightuiId));
|
41
|
}
|
42
|
|
43
|
}
|