Applied comments from review: Change 74622 - Draft
authorSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>
Fri, 21 Dec 2018 15:31:48 +0000 (10:31 -0500)
committerSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>
Fri, 21 Dec 2018 20:43:49 +0000 (15:43 -0500)
Change-Id: I8ec37a628af98a332f568dc254e499dfdcf886ce
Issue-ID: CCSDK-418
Signed-off-by: Steve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>
18 files changed:
ms/controllerblueprints/application/opt/app/onap/config/application-dev.properties [changed mode: 0644->0755]
ms/controllerblueprints/application/opt/app/onap/config/application.properties [changed mode: 0644->0755]
ms/controllerblueprints/application/src/test/resources/application.properties [changed mode: 0644->0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java [changed mode: 0644->0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java [changed mode: 0644->0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java [new file with mode: 0755]
ms/controllerblueprints/modules/service/src/test/resources/application.properties [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 46aa2fa..46d8530
@@ -61,4 +61,7 @@ controllerblueprints.loadBluePrintPaths=./../../../components/model-catalog/blue
 controllerblueprints.loadModelType=true
 controllerblueprints.loadModeTypePaths=./../../../components/model-catalog/definition-type/starter-type
 controllerblueprints.loadResourceDictionary=true
-controllerblueprints.loadResourceDictionaryPaths=./../../../components/model-catalog/resource-dictionary/starter-dictionary
\ No newline at end of file
+controllerblueprints.loadResourceDictionaryPaths=./../../../components/model-catalog/resource-dictionary/starter-dictionary
+
+# CBA file extension
+controllerblueprints.loadCbaExtension=zip
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 2ac4ad3..d618e01
@@ -65,4 +65,7 @@ controllerblueprints.loadBluePrintPaths=model-catalog/blueprint-model/starter-bl
 controllerblueprints.loadModelType=true
 controllerblueprints.loadModeTypePaths=model-catalog/definition-type/starter-type
 controllerblueprints.loadResourceDictionary=true
-controllerblueprints.loadResourceDictionaryPaths=model-catalog/resource-dictionary/starter-dictionary
\ No newline at end of file
+controllerblueprints.loadResourceDictionaryPaths=model-catalog/resource-dictionary/starter-dictionary
+
+# CBA file extension
+controllerblueprints.loadCbaExtension=zip
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 48f70b0..9c8a96c
@@ -46,4 +46,10 @@ controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/b
 controllerblueprints.loadModelType=false\r
 controllerblueprints.loadModeTypePaths=./../../../../components/model-catalog/definition-type/starter-type\r
 controllerblueprints.loadResourceDictionary=false\r
-controllerblueprints.loadResourceDictionaryPaths=./../../../../components/model-catalog/resource-dictionary/starter-dictionary
\ No newline at end of file
+controllerblueprints.loadResourceDictionaryPaths=./../../../../components/model-catalog/resource-dictionary/starter-dictionary\r
+\r
+# CBA file extension\r
+controllerblueprints.loadCbaExtension=zip\r
+\r
+# CBA examples for tests cases\r
+controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprints
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java
new file mode 100755 (executable)
index 0000000..66ef6a9
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright © 2018 IBM Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.ccsdk.apps.controllerblueprints.service;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.CBAContentRepository;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * CBAContentService.java Purpose: Provide CBAContent Template Service processing
+ * CBAContentService
+ *
+ * @author Ruben Chang
+ * @version 1.0
+ */
+
+@Service
+public class CBAContentService {
+
+    private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class);
+
+    private CBAContentRepository cbaContentRepository;
+
+    /**
+     * Constructor of the class
+     * @param cbaContentRepository CRUD methods for entity CBAContentRepository
+     */
+    public CBAContentService(CBAContentRepository cbaContentRepository) {
+        this.cbaContentRepository = cbaContentRepository;
+        log.info("CBAContentRepository sucessfully instantiated");
+    }
+
+    /**
+     * Save the CBAContent into the CBA_CONTENT table
+     * @param cbaName The name of the file
+     * @param cbaVersion version number of the CBA archive
+     * @param cbaState int that would represent the state. Refer to the CbaStateEnum
+     * @param cbaDescription Brief description that would help to identify and recognize the CBA archive
+     * @param file the file
+     * @return CbaContent the record saved into the table CBA_CONTENT
+     */
+    public CbaContent saveCBAContent(String cbaName, String cbaVersion, int cbaState, String cbaDescription, byte[] file){
+        CbaContent cbaContent = new CbaContent();
+        cbaContent.setCbaName(cbaName);
+        cbaContent.setCbaVersion(cbaVersion);
+        cbaContent.setCbaState(cbaState);
+        cbaContent.setCbaDescription(cbaDescription);
+        cbaContent.setCbaFile(file);
+        cbaContentRepository.saveAndFlush(cbaContent);
+        return cbaContent;
+    }
+
+    /**
+     * Get the list of Controller Blueprint archives
+     * @return List<CbaContent> list with the controller blueprint archives
+     */
+    public List<CbaContent> getList(){
+        return cbaContentRepository.findAll();
+    }
+
+    /**
+     * Get a single Controller Blueprint archive by uuID
+     * @param uuID the userID controller blueprint identifier
+     * @return Optional<CbaContent>
+     */
+    public Optional<CbaContent> findByUUID(String uuID) {
+        return cbaContentRepository.findById(uuID);
+    }
+
+    /**
+     * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model
+     * @param uuid the uuid that identify the CBA
+     */
+    public void deleteCBAById(String uuid) {
+        cbaContentRepository.deleteById(uuid);
+    }
+
+}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java
new file mode 100755 (executable)
index 0000000..2011172
--- /dev/null
@@ -0,0 +1,128 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service;\r
+\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.http.codec.multipart.FilePart;\r
+import org.springframework.stereotype.Service;\r
+import org.springframework.util.FileSystemUtils;\r
+import org.springframework.util.StringUtils;\r
+import reactor.core.publisher.Mono;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+\r
+/**\r
+ * CbaFileManagementService.java Purpose: Provide Service processing CBA file management\r
+ *\r
+ * @author Steve Siani\r
+ * @version 1.0\r
+ */\r
+@Service\r
+public class CbaFileManagementService {\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(CbaFileManagementService.class);\r
+\r
+    @Value("${controllerblueprints.loadCbaExtension}")\r
+    private String cbaExtension;\r
+\r
+    private static final String CBA_FILE_NAME_PATTERN = "CBA_{0}_{1}";\r
+\r
+\r
+    /**\r
+     * cleanupSavedCBA: This method cleanup the Zip file and the unzip directory that was added.\r
+     *\r
+     * @param zipFileName zipFileName\r
+     * @param cbaFileLocation cbaFileLocation\r
+     * @return\r
+     * @throws BluePrintException BluePrintException\r
+     */\r
+    public void cleanupSavedCBA(String zipFileName, Path cbaFileLocation) throws BluePrintException {\r
+\r
+        String fileNameWithoutExtension = BluePrintFileUtils.Companion.stripFileExtension(zipFileName);\r
+\r
+        //Delete the Zip file from the repository\r
+        FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(zipFileName,cbaFileLocation));\r
+\r
+        //Delete the CBA directory from the repository\r
+        FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(fileNameWithoutExtension,cbaFileLocation));\r
+    }\r
+\r
+    /**\r
+     * This is a saveCBAFile method\r
+     * take a {@link FilePart}, transfer it to disk using a Flux of FilePart and return a {@link Mono} representing the CBA file name\r
+     *\r
+     * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save\r
+     * @return a {@link Mono} String representing the result of the operation\r
+     * @throws (BluePrintException, IOException) BluePrintException, IOException\r
+     */\r
+    public Mono<String> saveCBAFile(FilePart filePart, Path targetDirectory) throws BluePrintException, IOException {\r
+\r
+        // Normalize file name\r
+        final String fileName = StringUtils.cleanPath(filePart.filename());\r
+\r
+        // Check if the file's extension is "CBA"\r
+        if(!StringUtils.getFilenameExtension(fileName).equals(cbaExtension)) {\r
+            throw new BluePrintException("Invalid file extension required " + cbaExtension);\r
+        }\r
+\r
+        // Change file name to match a pattern\r
+        String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN);\r
+\r
+        // Copy file to the target location (Replacing existing file with the same name)\r
+        Path targetLocation = targetDirectory.resolve(changedFileName);\r
+\r
+        // if a file with the same name already exists in a repository, delete and recreate it\r
+        File file = new File(targetLocation.toString());\r
+        if (file.exists())\r
+            file.delete();\r
+        file.createNewFile();\r
+\r
+        return filePart.transferTo(file).thenReturn(changedFileName);\r
+    }\r
+\r
+    /**\r
+     * Decompress the file into the cbaFileLocation parameter\r
+     * @param zipFileName name of the zipped file\r
+     * @param cbaFileLocation path in which the zipped file will get decompressed\r
+     * @return String the path in which the file is decompressed\r
+     * @throws BluePrintException Exception in the process\r
+     */\r
+    public String decompressCBAFile(final String zipFileName, Path cbaFileLocation) throws BluePrintException {\r
+\r
+        File file = BluePrintFileUtils.Companion.getBluePrintFile(zipFileName, cbaFileLocation);\r
+        try {\r
+            Path directoryPath = Files.createDirectories(cbaFileLocation.resolve(BluePrintFileUtils.Companion.stripFileExtension(zipFileName)));\r
+            BluePrintArchiveUtils.Companion.deCompress(file, directoryPath.toString());\r
+            return directoryPath.toString();\r
+\r
+        } catch (BluePrintProcessorException | IOException ex) {\r
+            throw new BluePrintException(" Fail to decompress " + zipFileName, ex);\r
+        }\r
+\r
+    }\r
+\r
+\r
+}\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java
new file mode 100755 (executable)
index 0000000..7d616a7
--- /dev/null
@@ -0,0 +1,192 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service;\r
+\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.boot.context.event.ApplicationReadyEvent;\r
+import org.springframework.context.event.EventListener;\r
+import org.springframework.core.io.ByteArrayResource;\r
+import org.springframework.core.io.Resource;\r
+import org.springframework.http.HttpHeaders;\r
+import org.springframework.http.MediaType;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.http.codec.multipart.FilePart;\r
+import org.springframework.stereotype.Service;\r
+import reactor.core.publisher.Mono;\r
+import java.io.IOException;\r
+import java.nio.file.Path;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Optional;\r
+\r
+/**\r
+ * CbaService.java Purpose: Provide Service Template Service processing CbaService\r
+ *\r
+ * @author Steve Siani\r
+ * @version 1.0\r
+ */\r
+\r
+@Service\r
+public class CbaService {\r
+\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(CbaService.class);\r
+\r
+    @Value("${controllerblueprints.blueprintArchivePath}")\r
+    private String cbaArchivePath;\r
+    private Path cbaLocation;\r
+\r
+    @Autowired\r
+    private CbaFileManagementService cbaFileManagementService;\r
+\r
+    @Autowired\r
+    private CbaToDatabaseService cbaToDatabaseService;\r
+\r
+\r
+    /**\r
+     * This method would be used by SpringBoot to initialize the cba location\r
+     */\r
+    @EventListener(ApplicationReadyEvent.class)\r
+    private void initCbaService() {\r
+        this.cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaArchivePath);\r
+        log.info("CBA service Initiated...");\r
+    }\r
+\r
+    /**\r
+     * This is a uploadCBAFile method\r
+     * take a {@link FilePart}, transfer it to disk using WebFlux and return a {@link Mono} representing the result\r
+     *\r
+     * @param filePart - the request part containing the file to be saved\r
+     * @return a {@link Mono<  BlueprintModelResponse  >} representing the result of the operation\r
+     */\r
+    public Mono<BlueprintModelResponse> uploadCBAFile(FilePart filePart) {\r
+\r
+        try {\r
+            return this.cbaFileManagementService.saveCBAFile(filePart, cbaLocation).map(fileName -> {\r
+                ConfigModel configModel;\r
+                BlueprintModelResponse blueprintModelResponse = null;\r
+\r
+                try {\r
+                    String cbaDirectory = this.cbaFileManagementService.decompressCBAFile(fileName, cbaLocation);\r
+                    configModel = this.cbaToDatabaseService.storeBluePrints(cbaDirectory, fileName, cbaLocation.resolve(fileName));\r
+                    blueprintModelResponse = new BlueprintModelResponse(configModel.getId(), configModel.getArtifactName(), configModel.getArtifactVersion(), configModel.getArtifactDescription(), configModel.getConfigModelCBA().getCbaUUID());\r
+                } catch (BluePrintException be) {\r
+                    Mono.error(new BluePrintException("Error loading CBA in database.", be));\r
+                } finally {\r
+                    try {\r
+                        this.cbaFileManagementService.cleanupSavedCBA(fileName, cbaLocation);\r
+                    } catch (BluePrintException be) {\r
+                        Mono.error(new BluePrintException("Error while cleaning up.", be));\r
+                    }\r
+                }\r
+                return blueprintModelResponse;\r
+            });\r
+        } catch (IOException | BluePrintException e) {\r
+            return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e));\r
+        }\r
+    }\r
+\r
+    /**\r
+     * This is a deleteCba method\r
+     *\r
+     * @param id id\r
+     * @throws BluePrintException BluePrintException\r
+     */\r
+    public void deleteCBA(@NotNull Long id) throws BluePrintException {\r
+        this.cbaToDatabaseService.deleteCBA(id);\r
+    }\r
+\r
+    /**\r
+     * This is a downloadCBAFile method to find the target file to download and return a file ressource using MONO\r
+     *\r
+     * @param (id)\r
+     * @return ResponseEntity<Resource>\r
+     */\r
+    public ResponseEntity<Resource> downloadCBAFile(@NotNull String id) {\r
+        Optional<CbaContent> optionalContent = this.cbaToDatabaseService.findByUUID(id);\r
+\r
+        CbaContent cbaContent = optionalContent.get();\r
+\r
+        return ResponseEntity.ok()\r
+                .contentType(MediaType.parseMediaType("text/plain"))\r
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + cbaContent.getCbaName() + "\"")\r
+                .body(new ByteArrayResource(cbaContent.getCbaFile()));\r
+    }\r
+\r
+    /**\r
+     * This is a findCBAByID method to find a CBA By the UUID\r
+     *\r
+     * @param (id)\r
+     * @return ItemCbaResponse\r
+     */\r
+    public ItemCbaResponse findCBAByID(@NotNull String id) {\r
+        ItemCbaResponse response = new ItemCbaResponse();\r
+        Optional<CbaContent> optionalContent = this.cbaToDatabaseService.findByUUID(id);\r
+\r
+        CbaContent cbaContent = optionalContent.get();\r
+        response.setName(cbaContent.getCbaName());\r
+        response.setState(cbaContent.getCbaState());\r
+        response.setId(cbaContent.getCbaUUID());\r
+        response.setVersion(cbaContent.getCbaVersion());\r
+        response.setDescription(cbaContent.getCbaDescription());\r
+        return response;\r
+    }\r
+\r
+    /**\r
+     * This is a findAllCBA method to retrieve all the CBAs in Database\r
+     *\r
+     * @return List<ItemCbaResponse> list with the controller blueprint archives\r
+     */\r
+    public List<ItemCbaResponse> findAllCBA() {\r
+        List<ItemCbaResponse> responseList = new ArrayList<>();\r
+        List<CbaContent> cbaContents = this.cbaToDatabaseService.listCBAFiles();\r
+\r
+        for(CbaContent content: cbaContents){\r
+            ItemCbaResponse response = new ItemCbaResponse();\r
+            response.setName(content.getCbaName());\r
+            response.setState(content.getCbaState());\r
+            response.setId(content.getCbaUUID());\r
+            response.setVersion(content.getCbaVersion());\r
+            response.setDescription(content.getCbaDescription());\r
+\r
+            responseList.add(response);\r
+        }\r
+        return responseList;\r
+    }\r
+\r
+    /**\r
+     * This is a findCBAByNameAndVersion method to find a CBA by Name and version\r
+     *\r
+     * @param (name, version)\r
+     * @return\r
+     * @throws BluePrintException BluePrintException\r
+     */\r
+    public ItemCbaResponse findCBAByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException {\r
+        return null;\r
+    }\r
+}
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java
new file mode 100755 (executable)
index 0000000..3420420
--- /dev/null
@@ -0,0 +1,132 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
+\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.util.List;\r
+import java.util.Optional;\r
+\r
+/**\r
+ * This class acts as a Rest Service that would store in the Database the Blueprints.\r
+ * @author Ruben Chang\r
+ */\r
+\r
+@Service\r
+public class CbaToDatabaseService {\r
+\r
+    //Log used to trace the transactions using the EELFLogger class\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(CbaToDatabaseService.class);\r
+\r
+    @Autowired\r
+    private ConfigModelRepository configModelRepository;\r
+    @Autowired\r
+    private ConfigModelContentRepository configModelContentRepository;\r
+    @Autowired\r
+    private ConfigModelCreateService configModelCreateService; \r
+       @Autowired\r
+    private CBAContentService cbaContentService;\r
+\r
+    /**\r
+     * This method will store the blueprints into the DB on the tables CONFIG_MODEL and CONFIG_MODEL_CONTENT\r
+     * @param cbaArchiveToSave Path in which the components are stored\r
+     * @return ConfigModel The Blueprint object stored in the DB\r
+     */\r
+    public ConfigModel storeBluePrints(String cbaDirectory, String cbaFileName, Path cbaArchiveToSave) throws BluePrintException {\r
+        log.info("*************************** storeBluePrints **********************");\r
+        ConfigModel configModel = null;\r
+        CbaContent cbaContent;\r
+        String version = "1.0";//TODO Read these information from metadata\r
+        String description = "Initial description for CBA archive " + cbaFileName;//TODO\r
+\r
+        List<String> serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(cbaDirectory);\r
+        if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) {\r
+            for (String fileName : serviceTemplateDirs) {\r
+                try {\r
+                    String bluePrintPath = cbaDirectory.concat("/").concat(fileName);\r
+                    log.debug("***** Loading service template :  {}", bluePrintPath);\r
+                    configModel = ConfigModelUtils.getConfigModel(bluePrintPath);\r
+\r
+                    configModel = this.configModelCreateService.saveConfigModel(configModel);\r
+\r
+                    log.info("Loaded service template successfully: {}", fileName);\r
+                } catch (Exception e) {\r
+                    throw new BluePrintException("Load config model " + fileName + " error : "+e.getMessage());\r
+                }\r
+            }\r
+        } else {\r
+            throw new BluePrintException("Invalid structure. The unzipped file does not contains Blueprints");\r
+        }\r
+\r
+        byte[] file;\r
+        try {\r
+            file = Files.readAllBytes(cbaArchiveToSave);\r
+        } catch (IOException e) {\r
+            throw new BluePrintException("Fail to read the CBA to save in database.", e);\r
+        }\r
+\r
+        cbaContent = this.cbaContentService.saveCBAContent(cbaFileName, version, CbaStateEnum.DRAFT.getState(), description, file);\r
+        configModel.setConfigModelCBA(cbaContent);\r
+\r
+        return configModel;\r
+    }\r
+\r
+    /**\r
+     * This is a deleteConfigModel method\r
+     *\r
+     * @param id id\r
+     * @throws BluePrintException BluePrintException\r
+     */\r
+    public void deleteCBA(@NotNull Long id) throws BluePrintException {\r
+        Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);\r
+\r
+       //TODO: Delete CBA and COnfigModel\r
+\r
+    }\r
+       \r
+       /**\r
+     * Get a list of the controller blueprint archives\r
+     * @return List<CbaContent> List with the controller blueprint archives\r
+     */\r
+    public List<CbaContent> listCBAFiles() {\r
+        return this.cbaContentService.getList();\r
+    }\r
+\r
+    /**\r
+     * Find a Controller Blueprint Archive by UUID\r
+     * @param uuID the User Identifier Controller Blueprint archive\r
+     * @return Optional<CbaContent> the Controller Blueprint archive\r
+     */\r
+    public Optional<CbaContent> findByUUID(String uuID) {\r
+        return this.cbaContentService.findByUUID(uuID);\r
+    }\r
+}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index fa8e32b..f31a0ce
@@ -30,6 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository;\r
@@ -123,7 +124,7 @@ public class ConfigModelCreateService {
             String artifactName = configModel.getArtifactName();\r
             String artifactVersion = configModel.getArtifactVersion();\r
             String author = configModel.getUpdatedBy();\r
-\r
+            CbaContent configModelCBA = configModel.getConfigModelCBA();\r
 \r
             if (StringUtils.isBlank(author)) {\r
                 throw new BluePrintException("Artifact Author is missing in the Service Template");\r
@@ -181,7 +182,7 @@ public class ConfigModelCreateService {
             addConfigModelContent(dbConfigModelId, configModel);\r
 \r
             // Populate Content model types\r
-            updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author);\r
+            updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author, configModelCBA);\r
 \r
 \r
             return updateConfigModel;\r
@@ -220,7 +221,7 @@ public class ConfigModelCreateService {
     }\r
 \r
     private ConfigModel updateConfigModel(Long dbConfigModelId, String artifactName, String artifactVersion,\r
-                                          String author) throws BluePrintException {\r
+                                          String author, CbaContent configModelCBA) throws BluePrintException {\r
 \r
         ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId);\r
         // Populate tags from metadata\r
@@ -234,6 +235,7 @@ public class ConfigModelCreateService {
         dbConfigModel.setUpdatedBy(author);\r
         dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N);\r
         dbConfigModel.setTags(tags);\r
+        dbConfigModel.setConfigModelCBA(configModelCBA);\r
         configModelRepository.saveAndFlush(dbConfigModel);\r
         log.info("Config model ({}) saved successfully.", dbConfigModel.getId());\r
         return dbConfigModel;\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java
new file mode 100755 (executable)
index 0000000..14ac6af
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright © 2018 IBM Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.domain;
+
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+import org.hibernate.annotations.Proxy;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * CbaContent.java Purpose: Provide Configuration Generator for CbaContent Entity
+ *
+ * @author Ruben Chang
+ * @version 1.0
+ */
+
+@EntityListeners({AuditingEntityListener.class})
+@Entity
+@Table(name = "CBA_CONTENT")
+@Proxy(lazy=false)
+public class CbaContent implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public CbaContent() {
+        this.cbaUUID = UUID.randomUUID().toString();
+    }
+
+    @Id
+    @Column(name = "cba_uuid", nullable = false)
+    private String cbaUUID;
+
+    @Lob
+    @Column(name = "cba_file")
+    private byte[] cbaFile;
+
+    @Column(name = "cba_name")
+    private String cbaName;
+
+    @Column(name = "cba_version")
+    private String cbaVersion;
+
+    @Column(name = "cba_state")
+    private int cbaState;
+
+    @Column(name="cba_description")
+    private String cbaDescription;
+
+    @OneToMany(mappedBy = "configModelCBA", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
+    @JsonManagedReference
+    private List<ConfigModel> models = new ArrayList<>();
+
+    public String getCbaUUID() {
+        return cbaUUID;
+    }
+
+    public void setCbaUUID(String cbaUUID) {
+        this.cbaUUID = cbaUUID;
+    }
+
+    public String getCbaName() {
+        return cbaName;
+    }
+
+    public void setCbaName(String cbaName) {
+        this.cbaName = cbaName;
+    }
+
+    public String getCbaVersion() {
+        return cbaVersion;
+    }
+
+    public void setCbaVersion(String cbaVersion) {
+        this.cbaVersion = cbaVersion;
+    }
+
+    public List<ConfigModel> getModels() {
+        return models;
+    }
+
+    public void setModels(List<ConfigModel> models) { this.models = models; }
+
+    public int getCbaState() { return cbaState; }
+
+    public void setCbaState(int cbaState) { this.cbaState = cbaState; }
+
+    public String getCbaDescription() { return cbaDescription; }
+
+    public void setCbaDescription(String cbaDescription) { this.cbaDescription = cbaDescription; }
+
+    public byte[] getCbaFile() { return cbaFile; }
+
+    public void setCbaFile(byte[] cbaFile) { this.cbaFile = cbaFile; }
+
+}
old mode 100644 (file)
new mode 100755 (executable)
index 51c9a7c..dea5757
@@ -119,6 +119,10 @@ public class ConfigModel implements Serializable {
     @JsonManagedReference\r
     private List<ConfigModelContent> configModelContents = new ArrayList<>();\r
 \r
+    @ManyToOne\r
+    @JoinColumn(name = "cba_content_uuid")\r
+    private CbaContent configModelCBA;\r
+\r
     public Long getId() {\r
         return id;\r
     }\r
@@ -287,4 +291,12 @@ public class ConfigModel implements Serializable {
         this.configModelContents = configModelContents;\r
     }\r
 \r
+    public CbaContent getConfigModelCBA() {\r
+        return configModelCBA;\r
+    }\r
+    \r
+    public void setConfigModelCBA(CbaContent configModelCBA) {\r
+        this.configModelCBA = configModelCBA;\r
+    }\r
+\r
 }\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java
new file mode 100755 (executable)
index 0000000..1b67ed8
--- /dev/null
@@ -0,0 +1,78 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.model;\r
+\r
+/**\r
+ * BlueprintModelResponse.java Purpose: Model response for Upload CBA service\r
+ *\r
+ */\r
+public class BlueprintModelResponse {\r
+    private Long id;\r
+    private String name;\r
+    private String version;\r
+    private String description;\r
+    private String cbaUUID;\r
+\r
+    public BlueprintModelResponse(Long id, String name, String version, String description, String cbaUUID) {\r
+        this.id = id;\r
+        this.name = name;\r
+        this.version = version;\r
+        this.description = description;\r
+        this.cbaUUID = cbaUUID;\r
+    }\r
+\r
+    public Long getId() {\r
+        return id;\r
+    }\r
+\r
+    public void setId(Long id) {\r
+        this.id = id;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public void setName(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public String getVersion() {\r
+        return version;\r
+    }\r
+\r
+    public void setVersion(String version) {\r
+        this.version = version;\r
+    }\r
+\r
+    public String getDescription() {\r
+        return description;\r
+    }\r
+\r
+    public void setDescription(String description) {\r
+        this.description = description;\r
+    }\r
+\r
+    public String getCbaUUID() {\r
+        return cbaUUID;\r
+    }\r
+\r
+    public void setCbaUUID(String cbaUUID) {\r
+        this.cbaUUID = cbaUUID;\r
+    }\r
+}
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java
new file mode 100755 (executable)
index 0000000..0752df9
--- /dev/null
@@ -0,0 +1,58 @@
+package org.onap.ccsdk.apps.controllerblueprints.service.model;
+
+/**
+ * CLass that would represent the response for the GET methods on the CBAService class
+ */
+public class ItemCbaResponse {
+
+    private String id;
+    private String description;
+    private String name;
+    private int state;
+    private String version;
+
+    public ItemCbaResponse() {
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getState() {
+        return state;
+    }
+
+    public void setState(int state) {
+        this.state = state;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+
+}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java
new file mode 100755 (executable)
index 0000000..273a19d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2018 IBM Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.repository;
+
+import org.jetbrains.annotations.NotNull;
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * CBAContentRepository.java Purpose: Provide Configuration Generator CRUD methods for CBAContent table
+ *
+ * @author Ruben Chang
+ * @version 1.0
+ */
+@Repository
+public interface CBAContentRepository extends JpaRepository<CbaContent, String>  {
+
+    /**
+     * This is a findAll method
+     * @return List<CbaContent>
+     */
+    @Override
+    List<CbaContent> findAll();
+
+    /**
+     * Returns a CbaContent based on the cbaUUID
+     * @param cbaUUID the CbaUUID
+     * @return Optional<CbaContent>
+     */
+    @Override
+    @NotNull
+    Optional<CbaContent> findById(@NotNull String cbaUUID);
+
+    /**
+     * This is a deleteById methid
+     * @param cbaUUID the user ID for a particular CBAFile
+     */
+    @Override
+    void deleteById(@NotNull String cbaUUID);
+}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java
new file mode 100755 (executable)
index 0000000..4608b17
--- /dev/null
@@ -0,0 +1,84 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.CbaService;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.core.io.Resource;\r
+import org.springframework.http.MediaType;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.http.codec.multipart.FilePart;\r
+import org.springframework.http.codec.multipart.Part;\r
+import org.springframework.web.bind.annotation.*;\r
+import reactor.core.publisher.Flux;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * CbaRest.java Purpose: Provide a REST API to upload single and multiple CBA\r
+ *\r
+ * @author Steve Siani\r
+ * @version 1.0\r
+ */\r
+@RestController\r
+@RequestMapping(value = "/api/v1/cba")\r
+public class CbaRest {\r
+\r
+    @Autowired\r
+    private CbaService cbaService;\r
+\r
+    @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\r
+    public  Flux<BlueprintModelResponse> uploadCBA(@RequestBody Flux<Part> parts) {\r
+        return parts.filter(part -> part instanceof FilePart) // only retain file parts\r
+            .ofType(FilePart.class) // convert the flux to FilePart\r
+            .flatMap(filePart -> cbaService.uploadCBAFile(filePart)); // save each file and flatmap it to a flux of results\r
+    }\r
+\r
+    @DeleteMapping(path = "/{id}")\r
+    public void deleteCBA(@PathVariable(value = "id") Long id) throws BluePrintException {\r
+        this.cbaService.deleteCBA(id);\r
+    }\r
+\r
+    @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
+    public @ResponseBody\r
+    ItemCbaResponse getCBA(@PathVariable(value = "id") String id) {\r
+        return this.cbaService.findCBAByID(id);\r
+    }\r
+\r
+    @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)\r
+    public @ResponseBody\r
+    List<ItemCbaResponse> getAllCBA() {\r
+        return this.cbaService.findAllCBA();\r
+    }\r
+\r
+    @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
+    public @ResponseBody\r
+    ItemCbaResponse getCBAByNameAndVersion(@PathVariable(value = "name") String name,\r
+                                                          @PathVariable(value = "version") String version) throws BluePrintException {\r
+        return this.cbaService.findCBAByNameAndVersion(name, version);\r
+    }\r
+\r
+    @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
+    public @ResponseBody\r
+    ResponseEntity<Resource> downloadCBA(@PathVariable(value = "id") String id) {\r
+        return this.cbaService.downloadCBAFile(id);\r
+    }\r
+}\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java
new file mode 100755 (executable)
index 0000000..57785dd
--- /dev/null
@@ -0,0 +1,15 @@
+package org.onap.ccsdk.apps.controllerblueprints.service.utils;
+
+public enum CbaStateEnum {
+
+    DRAFT(0), VALIDATED(1), APPROVED(2);
+    int state;
+
+    CbaStateEnum(int state) {
+        this.state = state;
+    }
+
+    public int getState() {
+        return state;
+    }
+}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java
new file mode 100755 (executable)
index 0000000..d7b4aa9
--- /dev/null
@@ -0,0 +1,36 @@
+package org.onap.ccsdk.apps.controllerblueprints.service.utils;\r
+\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+import java.util.concurrent.atomic.AtomicInteger;\r
+\r
+public class CloseCondition {\r
+\r
+    AtomicInteger tasksSubmitted = new AtomicInteger(0);\r
+    AtomicInteger tasksCompleted = new AtomicInteger(0);\r
+    AtomicBoolean allTaskssubmitted = new AtomicBoolean(false);\r
+\r
+    /**\r
+     * notify all tasks have been subitted, determine of the file channel can be closed\r
+     * @return true if the asynchronous file stream can be closed\r
+     */\r
+    public boolean canCloseOnComplete() {\r
+        allTaskssubmitted.set(true);\r
+        return tasksCompleted.get() == tasksSubmitted.get();\r
+    }\r
+\r
+    /**\r
+     * notify a task has been submitted\r
+     */\r
+    public void onTaskSubmitted() {\r
+        tasksSubmitted.incrementAndGet();\r
+    }\r
+\r
+    /**\r
+     * notify a task has been completed\r
+     * @return true if the asynchronous file stream can be closed\r
+     */\r
+    public boolean onTaskCompleted() {\r
+        boolean allSubmittedClosed = tasksSubmitted.get() == tasksCompleted.incrementAndGet();\r
+        return allSubmittedClosed && allTaskssubmitted.get();\r
+    }\r
+}\r
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java
new file mode 100755 (executable)
index 0000000..e3cea38
--- /dev/null
@@ -0,0 +1,89 @@
+/*\r
+ * Copyright © 2018 IBM Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service;\r
+import org.junit.*;\r
+import org.junit.runner.RunWith;\r
+import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.boot.test.context.SpringBootTest;\r
+import org.springframework.test.context.ContextConfiguration;\r
+import org.springframework.test.context.junit4.SpringRunner;\r
+import org.springframework.util.FileSystemUtils;\r
+import java.nio.file.Path;\r
+\r
+\r
+/**\r
+ * CbaFileManagementServiceTest.java Purpose: Test the decompressing method of CbaCompressionService\r
+ *\r
+ * @author Vinal Patel\r
+ * @version 1.0\r
+ */\r
+\r
+@RunWith(SpringRunner.class)\r
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)\r
+@ContextConfiguration(classes = {TestApplication.class})\r
+public class CbaFileManagementServiceTest {\r
+\r
+    @Value("${controllerblueprints.loadBlueprintsExamplesPath}")\r
+    private String cbaPath;\r
+    private String zipfile;\r
+    private String directorypath;\r
+    private Path zipfilepath;\r
+\r
+    @Autowired\r
+    CbaFileManagementService cbaCompressionService;\r
+\r
+\r
+    /**\r
+     *\r
+     */\r
+    @Before\r
+    public void setUp() {\r
+        try {\r
+            zipfilepath = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaPath);\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+        }\r
+        zipfile = "CBA_Zip_Test.zip";\r
+        directorypath = zipfilepath.resolve(zipfile.substring(0,zipfile.lastIndexOf("."))).toAbsolutePath().toString();\r
+    }\r
+    @After\r
+    public void clenup() throws BluePrintException {\r
+\r
+        try {\r
+            //Delete the Zip file from the repository\r
+            FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(directorypath, zipfilepath));\r
+        }\r
+        catch (Exception ex){\r
+            throw new BluePrintException("Fail while cleaning up CBA saved!", ex);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @throws BluePrintException\r
+     * Test will get success if it is able to decompress CBA file and returns the folder path\r
+     */\r
+    @Test\r
+    public void testDecompressCBAFile_success() throws BluePrintException {\r
+        Assert.assertEquals(directorypath,cbaCompressionService.decompressCBAFile(zipfile,zipfilepath));\r
+    }\r
+\r
+}\r
old mode 100644 (file)
new mode 100755 (executable)
index 718616b..4e1bedf
@@ -32,4 +32,10 @@ controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/b
 controllerblueprints.loadModelType=false
 controllerblueprints.loadModeTypePaths=./../../../../components/model-catalog/definition-type/starter-type
 controllerblueprints.loadResourceDictionary=false
-controllerblueprints.loadResourceDictionaryPaths=./../../../../components/model-catalog/resource-dictionary/starter-dictionary
\ No newline at end of file
+controllerblueprints.loadResourceDictionaryPaths=./../../../../components/model-catalog/resource-dictionary/starter-dictionary
+
+# CBA file extension
+controllerblueprints.loadCbaExtension=zip
+
+# CBA examples for tests cases
+controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprints
\ No newline at end of file