From ded9f23debdb75b264c25a04667db34d0a539ad1 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Fri, 14 Jul 2023 16:24:38 +0200 Subject: [PATCH] Reorganized code --- .../gcat/persistence/ckan/CKANPackage.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 121cf0b..a2d972a 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -300,6 +300,30 @@ public class CKANPackage extends CKAN implements Moderated { } + protected ObjectNode checkAndFixAuthorAndMaintainer(ObjectNode objectNode) { + String authorName = ckanUser.getSurnameName(); + + if(authorName==null || authorName.compareTo("")==0) { + authorName = ckanUser.getName(); + } + String authorEmail = ckanUser.getEMail(); + + objectNode = checkAuthor(objectNode, authorName, authorEmail); + + if(!objectNode.has(MAINTAINER_KEY)) { + if(!objectNode.has(MAINTAINER_EMAIL_KEY)) { + objectNode.put(MAINTAINER_KEY, authorName); + objectNode.put(MAINTAINER_EMAIL_KEY, authorEmail); + }else { + // We could try to retrieve Surname and Name of the maintainer if + // he/she is present as user in the VRE or in the catalogue. + objectNode.put(MAINTAINER_KEY, objectNode.get(MAINTAINER_EMAIL_KEY).toString()); + } + } + + return objectNode; + } + /** * @param json The json to check * @param allowPartialInfo used for patch method which provide only partial information (i.e. the info to patch) @@ -374,26 +398,7 @@ public class CKANPackage extends CKAN implements Moderated { objectNode.remove(CAPACITY_KEY); } - String authorName = ckanUser.getSurnameName(); - if(authorName==null || authorName.compareTo("")==0) { - authorName = ckanUser.getName(); - } - String authorEmail = ckanUser.getEMail(); - - - objectNode = checkAuthor(objectNode, authorName, authorEmail); - - - if(!objectNode.has(MAINTAINER_KEY)) { - if(!objectNode.has(MAINTAINER_EMAIL_KEY)) { - objectNode.put(MAINTAINER_KEY, authorName); - objectNode.put(MAINTAINER_EMAIL_KEY, authorEmail); - }else { - // We could try to retrieve Surname and Name of the maintainer if - // he/she is present as user in the VRE or in the catalogue. - objectNode.put(MAINTAINER_KEY, objectNode.get(MAINTAINER_EMAIL_KEY).toString()); - } - } + objectNode = checkAndFixAuthorAndMaintainer(objectNode); getPublishingOrganization(objectNode);