aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {