diff options
author | Francis Toth <francis.toth@yoppworks.com> | 2020-05-01 13:26:03 -0400 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-05-03 08:15:29 +0000 |
commit | 9a27b8bb9716ea3f8af5b381dc301bc6eefd9bf2 (patch) | |
tree | ffbe44c0d3a9af9b27debd6b422c1cb5b91689b4 /catalog-be/src/main/java | |
parent | b0982c12cc9fa0d8e642f4475ec293c7b6512c08 (diff) |
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 <francis.toth@yoppworks.com>
Change-Id: Icadfce7229839e53bd09926b6865f2872c39d1a5
Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java | 42 |
1 files changed, 22 insertions, 20 deletions
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<NonMetaArtifactInfo, Boolean> validateNonMetaArtifact(String artifactPath, byte[] payloadData, Map<String, Set<List<String>>> collectedWarningMessages) { - Either<NonMetaArtifactInfo, Boolean> ret; + public static Either<NonMetaArtifactInfo, Boolean> validateNonMetaArtifact( + String artifactPath, + byte[] payloadData, + Map<String, Set<List<String>>> collectedWarningMessages + ) { try { String[] parsedArtifactPath = artifactPath.split(PATH_DELIMITER); - // Validate Artifact Group Type - Either<ArtifactGroupTypeEnum, Boolean> 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<String, Set<List<String>>> collectedWarningMessages) { |