From: Francis Toth Date: Fri, 1 May 2020 17:26:03 +0000 (-0400) Subject: Refactor CsarUtils::validateNonMetaArtifact X-Git-Tag: 1.7.0~184 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=9a27b8bb9716ea3f8af5b381dc301bc6eefd9bf2;p=sdc.git Refactor CsarUtils::validateNonMetaArtifact This commit aims to refactor the CsarUtils::validateNonMetaArtifact function and make it up to standards regarding how fj.Either should be used. Signed-off-by: Francis Toth Change-Id: Icadfce7229839e53bd09926b6865f2872c39d1a5 Issue-ID: SDC-2812 --- diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index 22b655ad40..6ecb51810e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -38,6 +38,8 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -830,31 +832,31 @@ public class CsarUtils { * @param collectedWarningMessages * @return */ - public static Either validateNonMetaArtifact(String artifactPath, byte[] payloadData, Map>> collectedWarningMessages) { - Either ret; + public static Either validateNonMetaArtifact( + String artifactPath, + byte[] payloadData, + Map>> collectedWarningMessages + ) { try { String[] parsedArtifactPath = artifactPath.split(PATH_DELIMITER); - // Validate Artifact Group Type - Either eitherGroupType = detectArtifactGroupType(parsedArtifactPath[1], collectedWarningMessages); - if (eitherGroupType.isLeft()) { - final ArtifactGroupTypeEnum groupTypeEnum = eitherGroupType.left().value(); - - // Validate Artifact Type - String artifactType = parsedArtifactPath[2]; - artifactType = detectArtifactTypeVF(groupTypeEnum, artifactType, collectedWarningMessages); - - String artifactFileNameType = parsedArtifactPath[3]; - ret = Either.left(new NonMetaArtifactInfo(artifactFileNameType, artifactPath, artifactType, groupTypeEnum, payloadData, null, true)); - - } else { - ret = Either.right(eitherGroupType.right().value()); - } + String groupType = parsedArtifactPath[1]; + String receivedTypeName = parsedArtifactPath[2]; + String artifactFileNameType = parsedArtifactPath[3]; + + return detectArtifactGroupType(groupType, collectedWarningMessages) + .left().bind(artifactGroupType -> { + String artifactType = + detectArtifactTypeVF(artifactGroupType, receivedTypeName, collectedWarningMessages); + + return Either.left(new NonMetaArtifactInfo( + artifactFileNameType, artifactPath, artifactType, + artifactGroupType, payloadData, null, true + )); + }); } catch (Exception e) { log.debug("detectArtifactGroupType failed with exception", e); - ret = Either.right(false); + return Either.right(false); } - return ret; - } private static String detectArtifactTypeVFC(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName, String parentVfName, Map>> collectedWarningMessages) {