aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-01 10:23:18 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-11 08:28:35 +0000
commit5a5edfe3f6a304e3f856e618e66d71a258b2c44f (patch)
treedc38c8fd96ee0d56cb4f7fb426637aafbb18cca1 /catalog-be
parentae0f64936f9798b17b313754d643977b7567af17 (diff)
Refactor CsarUtil::writeComponentInterface
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I6a40119540c18469db44e218984b4d4b92d3f4af Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java40
1 files changed, 22 insertions, 18 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 29c0c13c8e..cba6b4f308 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
@@ -615,25 +615,29 @@ public class CsarUtils {
return cc;
}
- private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip,
- String fileName, boolean isAssociatedComponent) {
- try {
- Either<ToscaRepresentation, ToscaError> componentInterface = toscaExportUtils
- .exportComponentInterface(component, isAssociatedComponent);
- ToscaRepresentation componentInterfaceYaml = componentInterface.left().value();
- String mainYaml = componentInterfaceYaml.getMainYaml();
- String interfaceFileName = DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName);
-
- zip.putNextEntry(new ZipEntry(interfaceFileName));
- zip.write(mainYaml.getBytes());
-
- } catch (Exception e) {
- log.error("#writeComponentInterface - zip writing failed with error: ", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
+ private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(
+ Component component,
+ ZipOutputStream zip,
+ String fileName,
+ boolean isAssociatedComponent
+ ) {
+ try {
+ Either<String, ToscaError> mainYaml = toscaExportUtils
+ .exportComponentInterface(component, isAssociatedComponent)
+ .left().map(ToscaRepresentation::getMainYaml);
+
+ // TODO: This should be done outside this function to keep this testable.
+ // We can probably achieve this once the other refactorings related to SDC-2812 are merged
+ String interfaceFileName = DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName);
+ zip.putNextEntry(new ZipEntry(interfaceFileName));
+ zip.write(mainYaml.left().value().getBytes());
- return Either.left(zip);
- }
+ } catch (Exception e) {
+ log.error("#writeComponentInterface - zip writing failed with error: ", e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return Either.left(zip);
+ }
private Either<byte[], ActionStatus> getEntryData(String cassandraId, Component childComponent) {
if (cassandraId == null || cassandraId.isEmpty()) {