From 004ff1f35fe9e3b8e783c741a20e9e7441841f2a Mon Sep 17 00:00:00 2001 From: Leonidas Triantafyllou Date: Thu, 5 Sep 2024 16:24:37 +0200 Subject: [PATCH] YDA-5945: refactor update-publications.r to Python --- publication.py | 32 ++++++++++++++++++++++++---- tools/update-publications.r | 42 +------------------------------------ 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/publication.py b/publication.py index 31e98e3cf..47e7d3470 100644 --- a/publication.py +++ b/publication.py @@ -4,6 +4,7 @@ __copyright__ = 'Copyright (c) 2019-2024, Utrecht University' __license__ = 'GPLv3, see LICENSE' +import re from datetime import datetime import genquery @@ -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. @@ -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): diff --git a/tools/update-publications.r b/tools/update-publications.r index e4ef73069..7e7f5c1ca 100644 --- a/tools/update-publications.r +++ b/tools/update-publications.r @@ -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='*'