forked from UtrechtUniversity/yoda-ruleset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iiMetadata.r
68 lines (61 loc) · 2.38 KB
/
iiMetadata.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
# \file iiMetadata.r
# \brief This file contains rules related to metadata to a dataset.
# \author Paul Frederiks
# \author Lazlo Westerhof
# \copyright Copyright (c) 2017-2019, Utrecht University. All rights reserved.
# \license GPLv3, see LICENSE.
# \brief Remove the User AVU's from the irods AVU store.
#
# \param[in] coll Collection to scrub of user metadata
# \param[in] prefix prefix of metadata to remov
#
iiRemoveAVUs(*coll, *prefix) {
#DEBUG writeLine("serverLog", "iiRemoveAVUs: Remove all AVU's from *coll prefixed with *prefix");
msiString2KeyValPair("", *kvp);
*prefix = *prefix ++ "%";
*duplicates = list();
*prev = "";
foreach(*row in SELECT order_asc(META_COLL_ATTR_NAME), META_COLL_ATTR_VALUE WHERE COLL_NAME = *coll AND META_COLL_ATTR_NAME like *prefix) {
*attr = *row.META_COLL_ATTR_NAME;
*val = *row.META_COLL_ATTR_VALUE;
if (*attr == *prev) {
#DEBUG writeLine("serverLog", "iiRemoveAVUs: Duplicate attribute " ++ *attr);
*duplicates = cons((*attr, *val), *duplicates);
} else {
msiAddKeyVal(*kvp, *attr, *val);
#DEBUG writeLine("serverLog", "iiRemoveAVUs: Attribute=\"*attr\", Value=\"*val\" from *coll will be removed");
*prev = *attr;
}
}
msiRemoveKeyValuePairsFromObj(*kvp, *coll, "-C");
foreach(*pair in *duplicates) {
(*attr, *val) = *pair;
#DEBUG writeLine("serverLog", "iiRemoveUserAVUs: Duplicate key Attribute=\"*attr\", Value=\"*val\" from *coll will be removed");
msiString2KeyValPair("", *kvp);
msiAddKeyVal(*kvp, *attr, *val);
msiRemoveKeyValuePairsFromObj(*kvp, *coll, "-C");
}
}
# \brief Perform a vault ingest as rodsadmin.
#
iiAdminVaultIngest() {
msiExecCmd("admin-vaultingest.sh", uuClientFullName, "", "", 0, *out);
}
# \brief iiGetLatestVaultMetadataXml
#
# \param[in] vaultPackage
# \param[out] metadataXmlPath
#
iiGetLatestVaultMetadataXml(*vaultPackage, *metadataXmlPath, *metadataXmlSize) {
uuChopFileExtension(IIMETADATAXMLNAME, *baseName, *extension);
*dataNameQuery = "%*baseName[%].*extension";
*dataName = "";
*metadataXmlPath = "";
foreach (*row in SELECT DATA_NAME, DATA_SIZE WHERE COLL_NAME = *vaultPackage AND DATA_NAME like *dataNameQuery) {
if (*dataName == "" || (*dataName < *row.DATA_NAME && strlen(*dataName) <= strlen(*row.DATA_NAME))) {
*dataName = *row.DATA_NAME;
*metadataXmlPath = *vaultPackage ++ "/" ++ *dataName;
*metadataXmlSize = int(*row.DATA_SIZE);
}
}
}