1
|
package eu.dnetlib.enabling.tools;
|
2
|
|
3
|
import org.dom4j.Document;
|
4
|
import org.springframework.stereotype.Component;
|
5
|
|
6
|
import eu.dnetlib.miscutils.functional.hash.Hashing;
|
7
|
|
8
|
@Component
|
9
|
public class XQueryUtils {
|
10
|
|
11
|
public String getCollectionAbsPath(final Document doc) {
|
12
|
return getRootCollection() + getCollectionPath(doc);
|
13
|
}
|
14
|
|
15
|
public String getCollectionPath(final Document doc) {
|
16
|
final StringBuilder buffer = new StringBuilder();
|
17
|
buffer.append(doc.valueOf("//RESOURCE_KIND/@value"));
|
18
|
buffer.append('/');
|
19
|
buffer.append(doc.valueOf("//RESOURCE_TYPE/@value"));
|
20
|
return buffer.toString();
|
21
|
}
|
22
|
|
23
|
public String getRootCollection() {
|
24
|
return "/db/DRIVER/";
|
25
|
}
|
26
|
|
27
|
public String getFileName(final Document doc) {
|
28
|
return doc.valueOf("//RESOURCE_IDENTIFIER/@value").split("_")[0];
|
29
|
}
|
30
|
|
31
|
public String getCollectionName(final String resId) {
|
32
|
final String[] components = resId.split("_");
|
33
|
if (components.length == 1) { return "DefaultCollection"; }
|
34
|
return Hashing.decodeBase64(components[1]);
|
35
|
}
|
36
|
|
37
|
public String getFileName(final String resId) {
|
38
|
return resId.split("_")[0];
|
39
|
}
|
40
|
|
41
|
public String createResourceId(final String fileName, final String coll) {
|
42
|
return fileName + "_" + Hashing.encodeBase64(coll);
|
43
|
}
|
44
|
|
45
|
}
|