forked from UtrechtUniversity/yoda-ruleset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathycDatasetGetToplevel.r
76 lines (71 loc) · 2.57 KB
/
ycDatasetGetToplevel.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# \file
# \brief dataset lookup function
# \author Ton Smeele
# \copyright Copyright (c) 2015, Utrecht university. All rights reserved
# \license GPLv3, see LICENSE
#
#test {
# uuYcDatasetGetTopLevel("/tsm/home/rods", "x", *collection, *isCol);
# writeLine("stdout","coll = *collection and isCol = *isCol");
#}
# \brief uuYcDatasetGetTopLevel retrieves the collection path and dataset type for a dataset
#
# \param[in] rootcollection path of a tree to search for the dataset
# \param[in] datasetid unique identifier of the dataset
# \param[out] topLevelCollection collection that has the dataset
# if dataset is not found an empty string is returned
# \param[out] topLevelIsCollection type of dataset: true = collection false = data objects
#
uuYcDatasetGetTopLevel(*rootCollection, *datasetId, *topLevelCollection, *topLevelIsCollection) {
# datasets can be
# A) one collection with a subtree
# B) one or more data objects located (possibly with other objects) in same collection
*topLevelIsCollection = false;
*topLevelCollection = "";
# try to find a collection. note we will expect 0 or 1 rows:
foreach (*row in SELECT COLL_NAME
WHERE META_COLL_ATTR_NAME = 'dataset_toplevel'
AND META_COLL_ATTR_VALUE = '*datasetId'
AND COLL_NAME LIKE '*rootCollection/%'
) {
*topLevelIsCollection = true;
msiGetValByKey(*row, "COLL_NAME", *topLevelCollection);
}
if (! *topLevelIsCollection) {
# also try the root itself
foreach (*row in SELECT COLL_NAME
WHERE META_COLL_ATTR_NAME = 'dataset_toplevel'
AND META_COLL_ATTR_VALUE = '*datasetId'
AND COLL_NAME = '*rootCollection'
) {
*topLevelIsCollection = true;
msiGetValByKey(*row, "COLL_NAME", *topLevelCollection);
}
}
if (! *topLevelIsCollection) {
# apparently not a collection, let's search for data objects instead
foreach (*row in SELECT COLL_NAME,DATA_NAME
WHERE META_DATA_ATTR_NAME = 'dataset_toplevel'
AND META_DATA_ATTR_VALUE = '*datasetId'
AND COLL_NAME LIKE '*rootCollection/%'
) {
msiGetValByKey(*row, "COLL_NAME", *topLevelCollection);
break;
}
if (*topLevelCollection == "") {
# not found yet, maybe data object(s) in the rootcollection itself?
foreach (*row in SELECT COLL_NAME,DATA_NAME
WHERE META_DATA_ATTR_NAME = 'dataset_toplevel'
AND META_DATA_ATTR_VALUE = '*datasetId'
AND COLL_NAME = '*rootCollection'
) {
msiGetValByKey(*row, "COLL_NAME", *topLevelCollection);
break;
}
} else {
# dataset not found!
}
}
}
#input null
#output ruleExecOut