Skip to content

Commit

Permalink
YDA-5945: refactor update-publications.r to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
leonidastri authored Sep 5, 2024
1 parent c5a4016 commit 004ff1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
32 changes: 28 additions & 4 deletions publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import re
from datetime import datetime

import genquery
Expand Down Expand Up @@ -1314,7 +1315,7 @@ def process_republication(ctx, vault_package):
return publication_state["status"]


@rule.make(inputs=range(4), outputs=range(4, 6))
@rule.make(inputs=range(4))
def rule_update_publication(ctx, vault_package, update_datacite, update_landingpage, update_moai):
"""Rule interface for updating the publication of a vault package.
Expand All @@ -1323,10 +1324,33 @@ def rule_update_publication(ctx, vault_package, update_datacite, update_landingp
:param update_datacite: Flag that indicates updating DataCite
:param update_landingpage: Flag that indicates updating landingpage
:param update_moai: Flag that indicates updating MOAI (OAI-PMH)
:returns: "OK" if all went ok
"""
return update_publication(ctx, vault_package, update_datacite == 'Yes', update_landingpage == 'Yes', update_moai == 'Yes')
if user.user_type(ctx) != 'rodsadmin':
log.write_stdout(ctx, "User is no rodsadmin")
return

log.write_stdout(ctx, "[UPDATE PUBLICATIONS] Start for {}".format(vault_package))
collections = genquery.row_iterator(
"COLL_NAME",
"COLL_NAME like '%%/home/vault-%%' "
"AND META_COLL_ATTR_NAME = '" + constants.UUORGMETADATAPREFIX + "vault_status' "
"AND META_COLL_ATTR_VALUE = '{}'".format(str(constants.vault_package_state.PUBLISHED)),
genquery.AS_LIST,
ctx
)

packages_found = False
for collection in collections:
coll_name = collection[0]
if ((vault_package == '*' and re.match(r'/[^/]+/home/vault-.*', coll_name)) or (vault_package != '*' and re.match(r'/[^/]+/home/vault-.*', coll_name) and coll_name == vault_package)):
packages_found = True
output = update_publication(ctx, coll_name, update_datacite == 'Yes', update_landingpage == 'Yes', update_moai == 'Yes')
log.write_stdout(ctx, coll_name + ': ' + output)

if not packages_found:
log.write_stdout(ctx, "[UPDATE PUBLICATIONS] No packages found for {}".format(vault_package))
else:
log.write_stdout(ctx, "[UPDATE PUBLICATIONS] Finished for {}".format(vault_package))


def update_publication(ctx, vault_package, update_datacite=False, update_landingpage=False, update_moai=False):
Expand Down
42 changes: 1 addition & 41 deletions tools/update-publications.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,7 @@
# $ irule -r irods_rule_engine_plugin-irods_rule_language-instance -F /etc/irods/yoda-ruleset/tools/update-publications.r
#
updatePublications() {
writeLine("stdout", "[UPDATE PUBLICATIONS] Start for *package");
*packagesFound = 0;

# Scan for published vault packages.
*ContInxOld = 1;
msiAddSelectFieldToGenQuery("COLL_NAME", "", *GenQ2Inp);
msiAddConditionToGenQuery("COLL_NAME", "like", "%%/home/vault-%%", *GenQ2Inp);
msiAddConditionToGenQuery("META_COLL_ATTR_NAME", "=", UUORGMETADATAPREFIX ++ "vault_status", *GenQ2Inp);
msiAddConditionToGenQuery("META_COLL_ATTR_VALUE", "=", PUBLISHED, *GenQ2Inp);

msiExecGenQuery(*GenQ2Inp, *GenQ2Out);
msiGetContInxFromGenQueryOut(*GenQ2Out, *ContInxNew);

while(*ContInxOld > 0) {
foreach(*row in *GenQ2Out) {
*collName = *row.COLL_NAME;

# Check if this really is a vault package, or selected vault package
if ((*package == '*' && *collName like regex "/[^/]+/home/vault-.*") ||
(*package != '*' && *collName like regex "/[^/]+/home/vault-.*" && *collName == *package ) ) {
*packagesFound = 1;
*status = ''
*statusInfo = '';
rule_update_publication(*collName, *updateDatacite, *updateLandingpage, *updateMOAI, *status, *statusInfo);
writeLine("stdout", "*collName: *status *statusInfo");
}
}

*ContInxOld = *ContInxNew;
if(*ContInxOld > 0) {
msiGetMoreRows(*GenQ2Inp, *GenQ2Out, *ContInxNew);
}
}
msiCloseGenQuery(*GenQ2Inp, *GenQ2Out);

if (*packagesFound == 0) {
writeLine("stdout", "[UPDATE PUBLICATIONS] No packages found for *package")
}
else {
writeLine("stdout", "[UPDATE PUBLICATIONS] Finished for *package");
}
rule_update_publication(*package, *updateDatacite, *updateLandingpage, *updateMOAI);
}

input *updateDatacite="Yes", *updateLandingpage="Yes", *updateMOAI="Yes", *package='*'
Expand Down

0 comments on commit 004ff1f

Please sign in to comment.