Revision 49332
Added by Sandro La Bruzzo over 6 years ago
WDSUtils.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
4 | 4 |
import eu.dnetlib.miscutils.collections.Pair; |
5 |
import eu.dnetlib.rmi.enabling.ISLookUpException; |
|
5 | 6 |
import eu.dnetlib.rmi.enabling.ISLookUpService; |
6 | 7 |
import org.apache.commons.lang3.StringEscapeUtils; |
7 | 8 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
17 | 18 |
|
18 | 19 |
|
19 | 20 |
public final static Map<String, Pair<String, String>> hostedByMap = new HashMap<>(); |
21 |
public final static Map<String, Pair<String, String>> collectedFromMap = new HashMap<>(); |
|
20 | 22 |
public static String HOSTED_BY_MAP_QUERY = "for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') " + |
21 | 23 |
"where $x//FIELD/key/text()= 'archive_center' return " + |
22 | 24 |
"concat($x//DATASOURCE_ORIGINAL_ID, '<-->', $x//FIELD[./key/text()= 'archive_center' ]/value/string(), '<-->', $x//OFFICIAL_NAME)"; |
25 |
|
|
26 |
|
|
27 |
public static String COLLECTEDFROM_DATASOURCE_MAP_QUERY = "for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') " + |
|
28 |
"where $x//FIELD/key/text()!= 'archive_center' return concat($x//DATASOURCE_ORIGINAL_ID, '<-->', " + |
|
29 |
"$x//FIELD[./key/text()= 'NamespacePrefix' ]/value/string(), '<-->', $x//OFFICIAL_NAME)"; |
|
30 |
|
|
23 | 31 |
private static WDSUtils instance; |
24 | 32 |
@Autowired |
25 | 33 |
private UniqueServiceLocator serviceLocator; |
26 | 34 |
|
27 |
public static void generateHostedByMap() throws Exception { |
|
35 |
|
|
36 |
public static void generateDSMapFromQuery(final Map<String, Pair<String, String>> aMap, final String aQUERY) throws Exception { |
|
28 | 37 |
final ISLookUpService lookUpService = instance.getServiceLocator().getService(ISLookUpService.class); |
29 |
final List<String> hostedByList = lookUpService.quickSearchProfile(HOSTED_BY_MAP_QUERY);
|
|
30 |
hostedByMap.clear();
|
|
31 |
hostedByMap.putAll(
|
|
38 |
final List<String> hostedByList = lookUpService.quickSearchProfile(aQUERY);
|
|
39 |
aMap.clear();
|
|
40 |
aMap.putAll(
|
|
32 | 41 |
hostedByList.stream() |
33 | 42 |
.map(s -> s.split("<-->")) |
34 | 43 |
.map(s -> new Pair<>(StringEscapeUtils.escapeXml11(s[1]), new Pair<>(s[0], s[2]))) |
... | ... | |
37 | 46 |
Pair::getValue))); |
38 | 47 |
} |
39 | 48 |
|
49 |
public static String getNameFromDataSourcePrefix(final String datasourcePrefix) throws Exception { |
|
50 |
if (collectedFromMap.keySet().size() == 0) { |
|
51 |
generateDSMapFromQuery(collectedFromMap, COLLECTEDFROM_DATASOURCE_MAP_QUERY); |
|
52 |
} |
|
53 |
if (!collectedFromMap.containsKey(datasourcePrefix)) |
|
54 |
return ""; |
|
55 |
return collectedFromMap.get(datasourcePrefix).getValue(); |
|
56 |
} |
|
40 | 57 |
|
58 |
|
|
59 |
public static String getIdFromDataSourcePrefix(final String datasourcePrefix) throws Exception { |
|
60 |
if (collectedFromMap.keySet().size() == 0) { |
|
61 |
generateDSMapFromQuery(collectedFromMap, COLLECTEDFROM_DATASOURCE_MAP_QUERY); |
|
62 |
} |
|
63 |
if (!collectedFromMap.containsKey(datasourcePrefix)) |
|
64 |
return ""; |
|
65 |
return collectedFromMap.get(datasourcePrefix).getKey(); |
|
66 |
} |
|
67 |
|
|
68 |
|
|
41 | 69 |
public static String getDatasourceName(final String dataCenter) throws Exception { |
42 | 70 |
if (hostedByMap.keySet().isEmpty()) { |
43 |
generateHostedByMap();
|
|
71 |
generateDSMapFromQuery(hostedByMap, HOSTED_BY_MAP_QUERY);
|
|
44 | 72 |
} |
45 | 73 |
|
46 | 74 |
final Pair<String, String> result = hostedByMap.get(dataCenter); |
... | ... | |
50 | 78 |
|
51 | 79 |
public static String getDatasourceId(final String dataCenter) throws Exception { |
52 | 80 |
if (hostedByMap.keySet().isEmpty()) { |
53 |
generateHostedByMap();
|
|
81 |
generateDSMapFromQuery(hostedByMap, HOSTED_BY_MAP_QUERY);
|
|
54 | 82 |
} |
55 | 83 |
|
56 | 84 |
final Pair<String, String> result = hostedByMap.get(dataCenter); |
Also available in: Unified diff
minor