From: Francis Toth Date: Fri, 1 May 2020 14:23:18 +0000 (-0400) Subject: Refactor CsarUtil::writeComponentInterface X-Git-Tag: 1.7.0~139 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F106979%2F4;p=sdc.git Refactor CsarUtil::writeComponentInterface Signed-off-by: Francis Toth Change-Id: I6a40119540c18469db44e218984b4d4b92d3f4af Issue-ID: SDC-2812 --- 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 writeComponentInterface(Component component, ZipOutputStream zip, - String fileName, boolean isAssociatedComponent) { - try { - Either 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 writeComponentInterface( + Component component, + ZipOutputStream zip, + String fileName, + boolean isAssociatedComponent + ) { + try { + Either 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 getEntryData(String cassandraId, Component childComponent) { if (cassandraId == null || cassandraId.isEmpty()) {