aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-19 10:36:58 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-25 10:24:06 +0000
commitc9858db21d5b2e5a4f7cd2f2963fdbcb8c4e943c (patch)
treec3042ab7e1174fdd57e8a5489329cd8032e95586 /catalog-be
parentfcbf6d2541c6d033e4979784ce2373f0c5db3932 (diff)
Refactor CsarUtil::addInnerComponentsToCSAR
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I7f32d729a96f696c217631cd019105c17cb36a8c Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java56
1 files changed, 36 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 21c626bf53..65ade9539d 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
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.tosca;
import fj.F;
import fj.data.Either;
+import io.vavr.Tuple2;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -485,40 +486,55 @@ public class CsarUtils {
}
//add inner components to CSAR
- Either<ZipOutputStream, ResponseFormat> responseFormat = addInnerComponentsToCSAR(zip, innerComponentsCache);
- if (responseFormat != null) return responseFormat;
+ Either<ZipOutputStream, ResponseFormat> responseFormat = addInnerComponentsToCSAR(zip,
+ innerComponentsCache);
+ if (responseFormat != null) {
+ return responseFormat;
+ }
}
return null;
}
- private Either<ZipOutputStream, ResponseFormat> addInnerComponentsToCSAR(ZipOutputStream zip, Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache) throws IOException {
- for (Entry<String, ImmutableTriple<String, String, Component>> innerComponentTripleEntry : innerComponentsCache.entrySet()) {
-
- ImmutableTriple<String, String, Component> innerComponentTriple = innerComponentTripleEntry.getValue();
-
- Component innerComponent = innerComponentTriple.getRight();
- String icFileName = innerComponentTriple.getMiddle();
+ private Either<ZipOutputStream, ResponseFormat> addInnerComponentsToCSAR(
+ ZipOutputStream zip,
+ Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache
+ ) throws IOException {
+ for (Entry<String, ImmutableTriple<String, String, Component>> entry : innerComponentsCache.entrySet()) {
+ ImmutableTriple<String, String, Component> ict = entry.getValue();
+ Component innerComponent = ict.getRight();
+ String icFileName = ict.getMiddle();
// add component to zip
- Either<byte[], ActionStatus> entryData = getEntryData(innerComponentTriple.getLeft(), innerComponent);
- if (entryData.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
- log.debug("Failed adding to zip component {}, error {}", innerComponentTriple.getLeft(),
- entryData.right().value());
- return Either.right(responseFormat);
+ Either<Tuple2<byte[], ZipEntry>, ResponseFormat> zipEntry = toZipEntry(ict);
+ // TODO: this should not be done, we should instead compose this either further,
+ // but in order to keep this refactoring small, we'll stop here.
+ if (zipEntry.isRight()) {
+ return Either.right(zipEntry.right().value());
}
- byte[] content = entryData.left().value();
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + icFileName));
- zip.write(content);
-
+ Tuple2<byte[], ZipEntry> value = zipEntry.left().value();
+ zip.putNextEntry(value._2);
+ zip.write(value._1);
// add component interface to zip
if (!ModelConverter.isAtomicComponent(innerComponent)) {
- writeComponentInterface(innerComponent, zip, icFileName, true);
+ writeComponentInterface(innerComponent, zip, icFileName, true);
}
}
return null;
}
+ private Either<Tuple2<byte[], ZipEntry>, ResponseFormat> toZipEntry(
+ ImmutableTriple<String, String, Component> cachedEntry
+ ) {
+ String cassandraId = cachedEntry.getLeft();
+ String fileName = cachedEntry.getMiddle();
+ Component innerComponent = cachedEntry.getRight();
+ return getEntryData(cassandraId, innerComponent)
+ .right().map(status -> {
+ log.debug("Failed adding to zip component {}, error {}", cassandraId, status);
+ return componentsUtils.getResponseFormat(status);
+ }).left().map(content -> new Tuple2<>(content, new ZipEntry(DEFINITIONS_PATH + fileName)));
+ }
+
private void addSchemaFilesFromCassandra(final ZipOutputStream zip,
final byte[] schemaFileZip,
final List<String> nodesFromPackage) {