aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-04-24 10:29:03 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-28 09:19:04 +0000
commit33a4512b6eb6204e2209a788b06153a889629f4e (patch)
tree49e8d6a121ef5213a8419179d14570672b0a13b4 /catalog-be
parent76593bfbb1a233d76367abe903734c13b75f3a35 (diff)
Refactor CsarUtils::getEntryData
Change-Id: I1732ae05cfbe93c1bef8c249e16088a0cad34106 Issue-ID: SDC-2812 Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java38
1 files changed, 18 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 39c0a09f9c..22b655ad40 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
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.tosca;
+import fj.F;
import fj.data.Either;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -609,26 +610,23 @@ public class CsarUtils {
return Either.left(zip);
}
- private Either<byte[], ActionStatus> getEntryData(String cassandraId, Component childComponent) {
- byte[] content;
- if (cassandraId == null || cassandraId.isEmpty()) {
- Either<ToscaRepresentation, ToscaError> exportRes = toscaExportUtils.exportComponent(childComponent);
- if (exportRes.isRight()) {
- log.debug("Failed to export tosca template for child component {} error {}",
- childComponent.getUniqueId(), exportRes.right().value());
- return Either.right(componentsUtils.convertFromToscaError(exportRes.right().value()));
- }
- content = exportRes.left().value().getMainYaml().getBytes();
- } else {
- Either<byte[], ActionStatus> fromCassandra = getFromCassandra(cassandraId);
- if (fromCassandra.isRight()) {
- return Either.right(fromCassandra.right().value());
- } else {
- content = fromCassandra.left().value();
- }
- }
- return Either.left(content);
- }
+ private Either<byte[], ActionStatus> getEntryData(String cassandraId, Component childComponent) {
+ if (cassandraId == null || cassandraId.isEmpty()) {
+ return toscaExportUtils.exportComponent(childComponent)
+ .right().map(toscaErrorToActionStatus(childComponent))
+ .left().map(toscaRepresentation -> toscaRepresentation.getMainYaml().getBytes());
+ } else {
+ return getFromCassandra(cassandraId);
+ }
+ }
+
+ private F<ToscaError, ActionStatus> toscaErrorToActionStatus(Component childComponent) {
+ return toscaError -> {
+ log.debug("Failed to export tosca template for child component {} error {}",
+ childComponent.getUniqueId(), toscaError);
+ return componentsUtils.convertFromToscaError(toscaError);
+ };
+ }
private Either<byte[], ResponseFormat> getLatestSchemaFilesFromCassandra() {
Either<List<SdcSchemaFilesData>, CassandraOperationStatus> specificSchemaFiles = sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);