aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/service')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java140
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java4
-rwxr-xr-xms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java2
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java4
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java23
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt50
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt2
-rwxr-xr-xms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt100
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt3
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java2
-rwxr-xr-xms/controllerblueprints/modules/service/src/test/resources/application.properties2
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json2
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json2
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json2
14 files changed, 245 insertions, 93 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java
index ca0e2439..3cf144f1 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java
@@ -17,11 +17,15 @@
package org.onap.ccsdk.apps.controllerblueprints.service;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode;
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel;
@@ -41,11 +45,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Mono;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Optional;
-
/**
* BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService
*
@@ -56,8 +55,6 @@ import java.util.Optional;
@Service
public class BlueprintModelService {
- private static EELFLogger log = EELFManager.getInstance().getLogger(BlueprintModelService.class);
-
@Autowired
private BluePrintLoadConfiguration bluePrintLoadConfiguration;
@@ -73,9 +70,9 @@ public class BlueprintModelService {
@Autowired
private ControllerBlueprintModelContentRepository blueprintModelContentRepository;
- private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%d) from repo";
- private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%d)" +
- " and version(%d) from repo";
+ private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo";
+ private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" +
+ " and version(%s) from repo";
/**
* This is a saveBlueprintModel method
@@ -87,28 +84,41 @@ public class BlueprintModelService {
public Mono<BlueprintModelSearch> saveBlueprintModel(FilePart filePart) throws BluePrintException {
try {
Path cbaLocation = BluePrintFileUtils.Companion
- .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);
+ .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);
return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> {
- String blueprintId = bluePrintCatalogService
- .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false);
+ String blueprintId = null;
+ try {
+ blueprintId = bluePrintCatalogService
+ .saveToDatabase(cbaLocation.toFile(), false);
+ } catch (BluePrintException e) {
+ // FIXME handle expection
+ }
return blueprintModelSearchRepository.findById(blueprintId).get();
});
-
- } catch (IOException | BluePrintException e) {
- return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e));
+ } catch (IOException e) {
+ throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(),
+ String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);
}
}
/**
- * This is a publishBlueprintModel method
+ * This is a publishBlueprintModel method to change the status published to YES
*
* @param id id
* @return BlueprintModelSearch
* @throws BluePrintException BluePrintException
*/
public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException {
- // TODO Implement publish Functionality
- return null;
+ BlueprintModelSearch blueprintModelSearch;
+ Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository.findById(id);
+ if (dbBlueprintModel.isPresent()) {
+ blueprintModelSearch = dbBlueprintModel.get();
+ } else {
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
+ }
+ blueprintModelSearch.setPublished(ApplicationConstants.ACTIVE_Y);
+ return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch);
}
/**
@@ -122,44 +132,77 @@ public class BlueprintModelService {
}
/**
- * This is a getBlueprintModelByNameAndVersion method
+ * This is a getBlueprintModelSearchByNameAndVersion method
*
* @param name name
* @param version version
* @return BlueprintModelSearch
+ * @throws BluePrintException BluePrintException
*/
- public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)
- throws BluePrintException {
+ public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version)
+ throws BluePrintException {
BlueprintModelSearch blueprintModelSearch;
Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository
- .findByArtifactNameAndArtifactVersion(name, version);
+ .findByArtifactNameAndArtifactVersion(name, version);
if (dbBlueprintModel.isPresent()) {
blueprintModelSearch = dbBlueprintModel.get();
} else {
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(),
+ String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));
}
-
return blueprintModelSearch;
}
/**
- * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource using MONO
+ * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version
*
+ * @param name name
+ * @param version version
* @return ResponseEntity<Resource>
+ * @throws BluePrintException BluePrintException
+ */
+ public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name,
+ @NotNull String version)
+ throws BluePrintException {
+ BlueprintModel blueprintModel;
+ try {
+ blueprintModel = getBlueprintModelByNameAndVersion(name, version);
+ } catch (BluePrintException e) {
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +
+ "downloading the CBA file: %s", e.getMessage()), e);
+ }
+ String fileName = blueprintModel.getId() + ".zip";
+ byte[] file = blueprintModel.getBlueprintModelContent().getContent();
+ return prepareResourceEntity(fileName, file);
+ }
+
+ /**
+ * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource
+ *
+ * @return ResponseEntity<Resource>
+ * @throws BluePrintException BluePrintException
*/
public ResponseEntity<Resource> downloadBlueprintModelFile(@NotNull String id) throws BluePrintException {
BlueprintModel blueprintModel;
try {
blueprintModel = getBlueprintModel(id);
} catch (BluePrintException e) {
- throw new BluePrintException("Error uploading the CBA file in channel.", e);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +
+ "downloading the CBA file: %s", e.getMessage()), e);
}
String fileName = blueprintModel.getId() + ".zip";
byte[] file = blueprintModel.getBlueprintModelContent().getContent();
+ return prepareResourceEntity(fileName, file);
+ }
+
+ /**
+ * @return ResponseEntity<Resource>
+ */
+ private ResponseEntity<Resource> prepareResourceEntity(String fileName, byte[] file) {
return ResponseEntity.ok()
- .contentType(MediaType.parseMediaType("text/plain"))
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
- .body(new ByteArrayResource(file));
+ .contentType(MediaType.parseMediaType("text/plain"))
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
+ .body(new ByteArrayResource(file));
}
/**
@@ -175,13 +218,33 @@ public class BlueprintModelService {
if (dbBlueprintModel.isPresent()) {
blueprintModel = dbBlueprintModel.get();
} else {
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
}
-
return blueprintModel;
}
/**
+ * This is a getBlueprintModelByNameAndVersion method
+ *
+ * @param name name
+ * @param version version
+ * @return BlueprintModel
+ * @throws BluePrintException BluePrintException
+ */
+ private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)
+ throws BluePrintException {
+ BlueprintModel blueprintModel = blueprintModelRepository
+ .findByArtifactNameAndArtifactVersion(name, version);
+ if (blueprintModel != null) {
+ return blueprintModel;
+ } else {
+ String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
+ }
+ }
+
+ /**
* This is a getBlueprintModelSearch method
*
* @param id id
@@ -194,7 +257,8 @@ public class BlueprintModelService {
if (dbBlueprintModel.isPresent()) {
blueprintModelSearch = dbBlueprintModel.get();
} else {
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
}
return blueprintModelSearch;
@@ -213,17 +277,17 @@ public class BlueprintModelService {
blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get());
blueprintModelRepository.delete(dbBlueprintModel.get());
} else {
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
}
}
/**
* This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
*
- * @return List<BlueprintModelSearch> list with the controller blueprint archives
+ * @return List<BlueprintModelSearch> list of the controller blueprint archives
*/
public List<BlueprintModelSearch> getAllBlueprintModel() {
return blueprintModelSearchRepository.findAll();
}
-
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java
index 43164126..5486262f 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java
@@ -19,11 +19,15 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeName;
import java.io.Serializable;
import java.util.Date;
@JsonInclude(Include.NON_NULL)
+@JsonTypeName("errorMessage")
+@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)
public class ErrorMessage implements Serializable {
private String message;
private Integer code;
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java
index 93954daa..245e4a80 100755
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java
@@ -36,7 +36,7 @@ import java.util.Date;
@EntityListeners({AuditingEntityListener.class})
@Entity
-@Table(name = "CONFIG_MODEL")
+@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"}))
@Proxy(lazy=false)
public class BlueprintModel implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java
index 8b51bce3..33753b2f 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java
@@ -18,6 +18,8 @@
package org.onap.ccsdk.apps.controllerblueprints.service.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeName;
import org.springframework.data.annotation.LastModifiedDate;
import javax.persistence.*;
@@ -26,6 +28,8 @@ import java.util.Date;
@Entity
@Table(name = "CONFIG_MODEL")
+@JsonTypeName("blueprintModel")
+@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)
public class BlueprintModelSearch implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java
index 9d0b1e3e..255137bf 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java
@@ -42,31 +42,38 @@ public class BlueprintModelRest {
@PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public @ResponseBody
- Mono<BlueprintModelSearch> saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{
+ Mono<BlueprintModelSearch> saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{
return blueprintModelService.saveBlueprintModel(file);
}
@DeleteMapping(path = "/{id}")
- public void deleteBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {
+ public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException {
this.blueprintModelService.deleteBlueprintModel(id);
}
@GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
- BlueprintModelSearch getBluePrintByNameAndVersion(@PathVariable(value = "name") String name,
- @PathVariable(value = "version") String version) throws BluePrintException {
- return this.blueprintModelService.getBlueprintModelByNameAndVersion(name, version);
+ BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name,
+ @PathVariable(value = "version") String version) throws BluePrintException {
+ return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version);
+ }
+
+ @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody
+ ResponseEntity<Resource> downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name,
+ @PathVariable(value = "version") String version) throws BluePrintException {
+ return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version);
}
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
- BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException {
+ BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {
return this.blueprintModelService.getBlueprintModelSearch(id);
}
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
- List<BlueprintModelSearch> getAllCBA() {
+ List<BlueprintModelSearch> getAllBlueprintModel() {
return this.blueprintModelService.getAllBlueprintModel();
}
@@ -76,7 +83,7 @@ public class BlueprintModelRest {
return this.blueprintModelService.downloadBlueprintModelFile(id);
}
- @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
+ @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {
return this.blueprintModelService.publishBlueprintModel(id);
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt
new file mode 100644
index 00000000..a0e47d72
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2018-2019 Bell Canada 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.controller
+
+import org.springframework.web.bind.annotation.RestControllerAdvice
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
+import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage
+import org.springframework.http.HttpStatus
+import org.springframework.http.ResponseEntity
+import org.springframework.web.bind.annotation.ExceptionHandler
+
+/**
+ * ControllerBlueprintExceptionHandler.java Purpose: Handle exceptions in controllerBlueprint API and provide the wright
+ * HTTP code status
+ *
+ * @author Vinal Patel
+ * @version 1.0
+ */
+@RestControllerAdvice("org.onap.ccsdk.apps.controllerblueprints")
+open class ControllerBlueprintExeptionHandler {
+
+ @ExceptionHandler
+ fun ControllerBlueprintException(e: BluePrintException): ResponseEntity<ErrorMessage> {
+ var errorCode = ErrorCode.valueOf(e.code)
+ val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
+ return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
+ }
+
+ @ExceptionHandler
+ fun ControllerBlueprintException(e: Exception): ResponseEntity<ErrorMessage> {
+ var errorCode = ErrorCode.GENERIC_FAILURE
+ val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
+ return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
index d49bcdff..4fd66ed5 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
@@ -59,7 +59,7 @@ open class BluePrintCatalogLoadService(private val bluePrintCatalogService: Blue
open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) {
try {
- bluePrintCatalogService.uploadToDataBase(file.absolutePath, true)
+ bluePrintCatalogService.saveToDatabase(file)
} catch (e: Exception) {
errorBuilder.appendln("Couldn't load DataType(${file.name}: ${e.message}")
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
index ac81f8fa..04071dd2 100755
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
@@ -18,69 +18,91 @@
package org.onap.ccsdk.apps.controllerblueprints.service.load
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent
-import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository
+import org.slf4j.LoggerFactory
+import org.springframework.dao.DataIntegrityViolationException
import org.springframework.stereotype.Service
import java.io.File
import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
/**
-Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl]
+ * Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl]
*/
@Service
-class ControllerBlueprintCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
- private val bluePrintValidatorService: BluePrintValidatorService,
- private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository,
+class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService,
+ private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
private val blueprintModelRepository: ControllerBlueprintModelRepository)
- : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
+ : BlueprintCatalogServiceImpl(bluePrintValidatorService) {
- override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) {
- var valid = false
- val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory)
- val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem
- // Validate Blueprint
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory)
- // Check Validity of blueprint
- if (checkValidity!!) {
- valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
+ private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString())
+
+ init {
+ log.info("BlueprintProcessorCatalogServiceImpl initialized")
+ }
+
+ override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version)
+
+ override fun get(name: String, version: String, extract: Boolean): Path? {
+ val path = if (extract) {
+ Paths.get("${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version")
+ } else {
+ Paths.get("${bluePrintLoadConfiguration.blueprintArchivePath}/$name/$version.zip")
}
+ blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also {
+ it.blueprintModelContent.run {
+ path.toFile().writeBytes(this!!.content!!).let {
+ return path
+ }
+ }
+ }
+ return null
+ }
- if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) {
- val metaData = bluePrintRuntimeService.bluePrintContext().metadata!!
- // FIXME("Check Duplicate for Artifact Name and Artifact Version")
- val blueprintModel = BlueprintModel()
- blueprintModel.id = id
- blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
- blueprintModel.published = ApplicationConstants.ACTIVE_N
- blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME]
- blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION]
- blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
- blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS]
- blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
+ override fun save(metadata: MutableMap<String, String>, archiveFile: File) {
- val blueprintModelContent = BlueprintModelContent()
- blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping.
- blueprintModelContent.contentType = "CBA_ZIP"
- blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
- blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content"
- blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+ val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
+ val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+
+ log.isDebugEnabled.apply {
+ blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+ log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
+ }
+ }
- // Set the Blueprint Model into blueprintModelContent
- blueprintModelContent.blueprintModel = blueprintModel
+ val blueprintModel = BlueprintModel()
+ blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+ blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
+ blueprintModel.published = ApplicationConstants.ACTIVE_N
+ blueprintModel.artifactName = artifactName
+ blueprintModel.artifactVersion = artifactVersion
+ blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
+ blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]
+ blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion"
- // Set the Blueprint Model Content into blueprintModel
- blueprintModel.blueprintModelContent = blueprintModelContent
+ val blueprintModelContent = BlueprintModelContent()
+ blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+ blueprintModelContent.contentType = "CBA_ZIP"
+ blueprintModelContent.name = "$artifactName:$artifactVersion"
+ blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content"
+ blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+ blueprintModelContent.blueprintModel = blueprintModel
+ try {
blueprintModelRepository.saveAndFlush(blueprintModel)
+ } catch (ex: DataIntegrityViolationException) {
+ throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " +
+ "is already exist in database: ${ex.message}", ex)
}
}
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
index c2d6f6aa..5e715f78 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
@@ -20,6 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.utils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType
import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
import org.onap.ccsdk.apps.controllerblueprints.core.data.RelationshipType
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
@@ -92,7 +93,7 @@ class BluePrintEnhancerUtils {
// Check if the file's extension is "CBA"
if (StringUtils.getFilenameExtension(fileName) != "zip") {
- throw BluePrintException("Invalid file extension required ZIP")
+ throw BluePrintException(ErrorCode.INVALID_FILE_EXTENSION.value, "Invalid file extension required ZIP")
}
// Change file name to match a pattern
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java
index fb11c39f..330eaa84 100644
--- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java
+++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java
@@ -55,7 +55,7 @@ public class ResourceDictionaryReactRepositoryTest {
@Test
@Commit
public void test01Save() {
- ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json", ResourceDefinition.class);
+ ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition.class);
Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition);
resourceDefinition.setName(sourceName);
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties
index 29bb2b90..24cb23a1 100755
--- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties
+++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties
@@ -20,7 +20,7 @@ logging.level.org.springframework.web=INFO
logging.level.org.hibernate.SQL=warn
logging.level.org.hibernate.type.descriptor.sql=debug
# Load Resource Source Mappings
-resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability
+resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability
# Controller Blueprints Core Configuration
controllerblueprints.blueprintDeployPath=./target/blueprints/deploy
controllerblueprints.blueprintArchivePath=./target/blueprints/archive
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json
index 3715beca..1c81b74d 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json
@@ -7,7 +7,7 @@
"required": true
},
"dictionary-name": "sample-db-source",
- "dictionary-source": "db",
+ "dictionary-source": "primary-db",
"dependencies": [
"input-source"
]
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
index b066dad6..42978f84 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
@@ -225,7 +225,7 @@
},
"input-param": false,
"dictionary-name": "sample-db-source",
- "dictionary-source": "db",
+ "dictionary-source": "primary-db",
"dependencies": [
"hostname"
],
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
index b13932b7..66f18f89 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
@@ -227,7 +227,7 @@
},
"input-param" : false,
"dictionary-name" : "sample-db-source",
- "dictionary-source" : "db",
+ "dictionary-source" : "primary-db",
"dependencies" : [ "hostname" ],
"version" : 0
}, {