Fixed I/O error and removed unwanted finally clause. 70/87870/1
authorprathamesh morde <prathamesh.morde@bell.ca>
Mon, 13 May 2019 02:24:04 +0000 (22:24 -0400)
committerDan Timoney <dtimoney@att.com>
Thu, 16 May 2019 13:18:20 +0000 (13:18 +0000)
Change-Id: Id1993a4983ca103ac28655b57481bb96aa89f1f1
Issue-ID:CCSDK-1318
Signed-off-by: prathamesh morde <prathamesh.morde@bell.ca>
(cherry picked from commit a132cf34b95abf0ba2455bba28926df9b72fd4a0)

ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java
ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java

index c785053..148d0c0 100644 (file)
@@ -31,7 +31,6 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.List;
-import java.util.Optional;
 import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -138,10 +137,7 @@ public class ListenerServiceImpl implements ListenerService {
     public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) {
         List<File> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath);
         if (!zipFiles.isEmpty()) {
-            zipFiles.forEach(file -> FileUtil.deleteFile(file, cbaArchivePath.toString()));
             prepareRequestForCdsBackend(zipFiles, channel, cbaArchivePath.toString());
-        } else {
-            LOGGER.error("Could not able to read CBA archives from this location {}", cbaArchivePath);
         }
     }
 
@@ -187,7 +183,7 @@ public class ListenerServiceImpl implements ListenerService {
 
         files.forEach(zipFile -> {
             try {
-                final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile);
+                final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile, path);
 
                 // Send request to CDS Backend.
                 final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel);
@@ -209,16 +205,14 @@ public class ListenerServiceImpl implements ListenerService {
                 listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
                    SDC_LISTENER_COMPONENT);
                 LOGGER.error(errorMessage);
-            } finally {
-                FileUtil.deleteFile(zipFile, path);
             }
         });
     }
 
-    private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file) throws IOException {
+    private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file, String path) throws IOException {
         byte[] bytes = FileUtils.readFileToByteArray(file);
         FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build();
-
+        FileUtil.deleteFile(file, path);
         return BluePrintUploadInput.newBuilder()
                 .setFileChunk(fileChunk)
                 .build();
index ecb7538..aa8f8e4 100644 (file)
@@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.sdclistener.service;
 
 import static junit.framework.TestCase.assertTrue;
 import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
-import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR;
 import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
 import java.io.File;
 import java.io.IOException;
@@ -39,7 +38,6 @@ import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor;
 import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
 import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler;
 import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
-import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType;
 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
 import org.onap.sdc.impl.mock.DistributionClientResultStubImpl;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -102,8 +100,6 @@ public class ListenerServiceImplTest {
     @Test
     public void extractBluePrintFailure() {
         // Arrange
-        final String errorMessage = String
-            .format("The CBA Archive doesn't exist as per this given regex %s", CBA_ZIP_PATH);
         Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID);
         Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL);
         Mockito.doCallRealMethod().when(status)