forked from UtrechtUniversity/yoda-ruleset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathycDatasetLock.r
253 lines (234 loc) · 7.87 KB
/
ycDatasetLock.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# \file
# \brief lock/freeze and unlock/unfreeze datasets within a collection
# \author Ton Smeele
# \copyright Copyright (c) 2015, Utrecht university. All rights reserved
# \license GPLv3, see LICENSE
#
#test {
#*collection = "/nluu1ot/home/ton";
#*datasetId = "y";
#uuYcDatasetLock(*collection, *datasetId, *result);
#writeLine("stdout","lock result = *result");
#uuYcDatasetFreeze(*collection, *datasetId, *result);
#writeLine("stdout","freeze result = *result");
#uuYcObjectIsLocked("*collection/Newfile.txt",false, *locked, *frozen);
#writeLine("stdout","locked = *locked and frozen = *frozen");
#uuYcDatasetUnlock(*collection, *datasetId, *result);
#writeLine("stdout","unlock result = *result");
#uuYcDatasetMelt(*collection, *datasetId, *result);
#writeLine("stdout","melt result = *result");
#uuYcDatasetUnlock(*collection, *datasetId, *result);
#writeLine("stdout","unlock result = *result");
#}
uuYcDatasetLockChangeObject(*parentCollection, *objectName, *isCollection,
*lockName, *lockIt, *dateTime,*result) {
*objectType = "-d";
*path = "*parentCollection/*objectName";
if (*isCollection) {
*objectType = "-C";
*collection = *objectName;
}
if (*lockIt) {
msiString2KeyValPair("*lockName=*dateTime",*kvPair);
*result = errorcode(msiSetKeyValuePairsToObj(*kvPair, *path, *objectType));
} else { # unlock it
#
# if the lock is of type to_vault_lock this operation is
# disallowed if the object also has a to_vault_freeze lock
uuYcObjectIsLocked(*path,*isCollection,*locked,*frozen);
*allowed = (*lockName == "to_vault_freeze") || !*frozen;
if (*allowed) {
*result = 0;
# in order to remove the key we need to lookup its value(s)
if (*isCollection) {
# remove lock from collection
foreach (*row in SELECT META_COLL_ATTR_VALUE
WHERE COLL_NAME = '*path'
AND META_COLL_ATTR_NAME = '*lockName') {
msiGetValByKey(*row, "META_COLL_ATTR_VALUE", *value);
msiString2KeyValPair("*lockName=*value", *kvPair);
*result = errorcode(
msiRemoveKeyValuePairsFromObj(*kvPair, *path, "-C")
);
if (*result != 0) {
break;
}
}
} else {
# remove lock from data object
foreach (*row in SELECT META_DATA_ATTR_VALUE
WHERE DATA_NAME = '*objectName'
AND COLL_NAME = '*parentCollection'
AND META_DATA_ATTR_NAME = '*lockName'
) {
msiGetValByKey(*row,"META_DATA_ATTR_VALUE",*value);
msiString2KeyValPair("*lockName=*value",*kvPair);
*result = errorcode(
msiRemoveKeyValuePairsFromObj(
*kvPair,
"*parentCollection/*objectName",
"-d"
)
);
if (*result != 0) {
break;
}
}
} # end else remove lock from dataobject
} else { # unlock not allowed
*result = -1;
}
}
}
uuYcDatasetWalkVaultLock(*itemCollection, *itemName, *itemIsCollection, *buffer, *error) {
msiGetIcatTime(*dateTime,"unix");
uuYcDatasetLockChangeObject(*itemCollection, *itemName, *itemIsCollection,
"to_vault_lock", true, *dateTime, *error);
}
uuYcDatasetWalkVaultUnlock(*itemCollection, *itemName, *itemIsCollection, *buffer, *error) {
msiGetIcatTime(*dateTime,"unix");
uuYcDatasetLockChangeObject(*itemCollection, *itemName, *itemIsCollection,
"to_vault_lock", false, *dateTime, *error);
}
uuYcDatasetWalkFreezeLock(*itemCollection, *itemName, *itemIsCollection, *buffer, *error) {
msiGetIcatTime(*dateTime,"unix");
uuYcDatasetLockChangeObject(*itemCollection, *itemName, *itemIsCollection,
"to_vault_freeze", true, *dateTime, *error);
}
uuYcDatasetWalkFreezeUnlock(*itemCollection, *itemName, *itemIsCollection, *buffer, *error) {
msiGetIcatTime(*dateTime,"unix");
uuYcDatasetLockChangeObject(*itemCollection, *itemName, *itemIsCollection,
"to_vault_freeze", false, *dateTime, *error);
}
uuYcDatasetLockChange(*rootCollection, *datasetId, *lockName, *lockIt, *status){
*status = -1;
*lock = "Unlock";
if (*lockIt) {
*lock = "Lock";
}
*lockProcedure = "Vault";
if (*lockName == "to_vault_freeze") {
*lockProcedure = "Freeze";
}
# find the toplevel collection for this dataset
uuYcDatasetGetTopLevel(*rootCollection, *datasetId, *collection, *isCollection);
if (*collection != "") {
# we found the dataset, now change the lock on each object
if (*isCollection) {
*buffer = "dummy";
uuTreeWalk("forward", *collection, "uuYcDatasetWalk*lockProcedure*lock", *buffer, *error);
*status = *error;
# if (*error == "0") {
# *status = 0;
# }
} else {
# dataset is not a collection, let's find the objects and make the change
msiGetIcatTime(*dateTime,"unix");
*status = 0;
foreach (*row in SELECT DATA_NAME
WHERE COLL_NAME = '*collection'
AND META_DATA_ATTR_NAME = 'dataset_toplevel'
AND META_DATA_ATTR_VALUE = '*datasetId'
) {
msiGetValByKey(*row,"DATA_NAME",*dataName);
# now change it ....
uuYcDatasetLockChangeObject(
*collection,
*dataName,
false,
*lockName,
*lockIt,
*dateTime,
*error);
if (*error != 0 ) {
*status = *error;
break;
}
}
}
} else {
# result is false "dataset not found"
}
}
# \brief uuYcDatasetLock locks (all objects of) a dataset
#
# \param[in] collection collection that may have datasets
# \param[in] datasetId identifier to depict the dataset
# \param[out] status 0 upon success, otherwise nonzero
#
uuYcDatasetLock(*collection, *datasetId, *status) {
uuYcDatasetLockChange(*collection, *datasetId,"to_vault_lock", true, *status);
}
# \brief uuYcDatasetUnlock unlocks (all objects of) a dataset
#
# \param[in] collection collection that may have datasets
# \param[in] datasetId identifier to depict the dataset
# \param[out] result "true" upon success, otherwise "false"
# \param[out] status 0 upon success, otherwise nonzero
#
uuYcDatasetUnlock(*collection, *datasetId, *status) {
uuYcDatasetLockChange(*collection, *datasetId, "to_vault_lock", false, *status);
}
# \brief uuYcDatasetFreeze freeze-locks (all objects of) a dataset
#
# \param[in] collection collection that may have datasets
# \param[in] datasetId identifier to depict the dataset
# \param[out] status 0 upon success, otherwise nonzero
#
uuYcDatasetFreeze(*collection, *datasetId, *status) {
uuYcDatasetLockChange(*collection, *datasetId,"to_vault_freeze", true, *status);
}
# \brief uuYcDatasetUnfreeze undo freeze-locks (all objects of) a dataset
#
# \param[in] collection collection that may have datasets
# \param[in] datasetId identifier to depict the dataset
# \param[out] status 0 upon success, otherwise nonzero
#
uuYcDatasetMelt(*collection, *datasetId, *status) {
uuYcDatasetLockChange(*collection, *datasetId, "to_vault_freeze", false, *status);
}
# \brief uuYcObjectIsLocked query an object to see if it is locked
#
# \param[in] objectPath full path to collection of data object
# \param[in] isCollection true if path references a collection
# \param[out] locked true if the object is vault-locked
# \param[out] frozen true if the object is vault-frozen
uuYcObjectIsLocked(*objectPath, *isCollection, *locked, *frozen) {
*locked = false;
*frozen = false;
if (*isCollection) {
foreach (*row in SELECT META_COLL_ATTR_NAME
WHERE COLL_NAME = '*objectPath'
) {
msiGetValByKey(*row, "META_COLL_ATTR_NAME", *key);
if ( *key == "to_vault_lock"
|| *key == "to_vault_freeze"
) {
*locked = true;
if (*key == "to_vault_freeze") {
*frozen = true;
break;
}
}
}
} else {
uuChopPath(*objectPath, *parentCollection, *dataName);
foreach (*row in SELECT META_DATA_ATTR_NAME
WHERE COLL_NAME = '*parentCollection'
AND DATA_NAME = '*dataName'
) {
msiGetValByKey(*row, "META_DATA_ATTR_NAME", *key);
if ( *key == "to_vault_lock"
|| *key == "to_vault_freeze"
) {
*locked = true;
if (*key == "to_vault_freeze") {
*frozen = true;
break;
}
}
}
}
}
#input null
#output ruleExecOut