--- /dev/null
+/*
+ * 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.core.data
+
+import java.util.HashMap
+
+/**
+ * ErrorCode.java Purpose: Maintain a list of HTTP status codes
+ *
+ * @author Steve Siani
+ * @version 1.0
+ */
+enum class ErrorCode (val value: Int, val httpCode: Int) {
+
+ /// TODO: Add more attribute for each needed application protocol
+ // TODO: Example: INVALID_FILE_EXTENSION(2, 415, 25)
+ GENERIC_FAILURE(1, 500) {
+ override fun message(detailMsg: String): String {
+ return "Generic failure. Details : {$detailMsg}"
+ }
+ },
+ INVALID_FILE_EXTENSION(2, 415) {
+ override fun message(detailMsg: String): String {
+ return "Unexpected file extension. Details : {$detailMsg}"
+ }
+ },
+ BLUEPRINT_PATH_MISSING(3, 503) {
+ override fun message(detailMsg: String): String {
+ return "Blueprint path missing or wrong. Details : {$detailMsg}"
+ }
+ },
+ BLUEPRINT_WRITING_FAIL(4, 503) {
+ override fun message(detailMsg: String): String {
+ return "Fail to write blueprint files. Details : {$detailMsg}"
+ }
+ },
+ IO_FILE_INTERRUPT(5, 503) {
+ override fun message(detailMsg: String): String {
+ return "IO file system interruption. Details : {$detailMsg}"
+ }
+ },
+ INVALID_REQUEST_FORMAT(6, 400) {
+ override fun message(detailMsg: String): String {
+ return "Bad request. Details : {$detailMsg}"
+ }
+ },
+ UNAUTHORIZED_REQUEST(7, 401) {
+ override fun message(detailMsg: String): String {
+ return "The request requires user authentication. Details : {$detailMsg}"
+ }
+ },
+ REQUEST_NOT_FOUND(8, 404) {
+ override fun message(detailMsg: String): String {
+ return "Request mapping doesn't exist. Details : {$detailMsg}"
+ }
+ },
+ RESOURCE_NOT_FOUND(9, 404) {
+ override fun message(detailMsg: String): String {
+ return "No response was found for this request in the server. Details : {$detailMsg}"
+ }
+ },
+ CONFLICT_ADDING_RESOURCE(10, 409) {
+ override fun message(detailMsg: String): String {
+ return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
+ }
+ };
+
+ abstract fun message(detailMsg: String): String
+
+ companion object {
+
+ private val map = HashMap<Int, ErrorCode>()
+
+ init {
+ for (errorCode in ErrorCode.values()) {
+ map[errorCode.value] = errorCode
+ }
+ }
+
+ fun valueOf(value: Int): ErrorCode? {
+ return if (map.containsKey(value)) map[value] else map[1]
+ }
+ }
+}
\ No newline at end of file
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
val definitionDir = File(definitionPath)
check(definitionDir.exists()) {
- throw BluePrintException("couldn't get definition file under path(${definitionDir.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " +
+ "path(${definitionDir.absolutePath})")
}
blueprintContext.serviceTemplate.dataTypes?.let {
Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(definitionFile.exists()) {
- throw BluePrintException("couldn't write definition file under path(${definitionFile.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write definition file under " +
+ "path(${definitionFile.absolutePath})")
}
}
Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(typeFile.exists()) {
- throw BluePrintException("couldn't write $type.json file under path(${typeFile.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write $type.json file under " +
+ "path(${typeFile.absolutePath})")
}
}
"\nTemplate-Tags: <TAGS>"
}
+
+ fun getBluePrintFile(fileName: String, targetPath: Path) : File {
+ val filePath = targetPath.resolve(fileName).toString()
+ val file = File(filePath)
+ check(file.exists()) {
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " +
+ "path(${file.absolutePath})")
+ }
+ return file
+ }
+
fun getCbaStorageDirectory(path: String): Path {
check(StringUtils.isNotBlank(path)) {
- throw BluePrintException("CBA Path is missing.")
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get " +
+ "Blueprint folder under path($path)")
}
val fileStorageLocation = Paths.get(path).toAbsolutePath().normalize()
import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelContentRepository
import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository
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.springframework.dao.DataIntegrityViolationException
import org.springframework.stereotype.Service
import java.io.File
import java.nio.file.Files
@Service
class BlueprintProcessorCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
private val bluePrintValidatorService: BluePrintValidatorService,
- private val blueprintModelContentRepository: BlueprintProcessorModelContentRepository,
private val blueprintModelRepository: BlueprintProcessorModelRepository)
: BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
// Set the Blueprint Model Content into blueprintModel
blueprintModel.blueprintModelContent = blueprintModelContent
- blueprintModelRepository.saveAndFlush(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
\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.common.ApplicationConstants;\r
import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode;\r
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService;\r
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel;\r
@Service\r
public class BlueprintModelService {\r
\r
- private static EELFLogger log = EELFManager.getInstance().getLogger(BlueprintModelService.class);\r
-\r
@Autowired\r
private BluePrintLoadConfiguration bluePrintLoadConfiguration;\r
\r
@Autowired\r
private ControllerBlueprintModelContentRepository blueprintModelContentRepository;\r
\r
- private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%d) from repo";\r
- private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%d)" +\r
- " and version(%d) from repo";\r
+ private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo";\r
+ private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" +\r
+ " and version(%s) from repo";\r
\r
/**\r
* This is a saveBlueprintModel method\r
public Mono<BlueprintModelSearch> saveBlueprintModel(FilePart filePart) throws BluePrintException {\r
try {\r
Path cbaLocation = BluePrintFileUtils.Companion\r
- .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);\r
+ .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);\r
return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> {\r
String blueprintId = bluePrintCatalogService\r
- .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false);\r
+ .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false);\r
return blueprintModelSearchRepository.findById(blueprintId).get();\r
});\r
-\r
- } catch (IOException | BluePrintException e) {\r
- return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e));\r
+ } catch (IOException e) {\r
+ throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(),\r
+ String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);\r
}\r
}\r
\r
/**\r
- * This is a publishBlueprintModel method\r
+ * This is a publishBlueprintModel method to change the status published to YES\r
*\r
* @param id id\r
* @return BlueprintModelSearch\r
* @throws BluePrintException BluePrintException\r
*/\r
public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException {\r
- // TODO Implement publish Functionality\r
- return null;\r
+ BlueprintModelSearch blueprintModelSearch;\r
+ Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository.findById(id);\r
+ if (dbBlueprintModel.isPresent()) {\r
+ blueprintModelSearch = dbBlueprintModel.get();\r
+ } else {\r
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
+ }\r
+ blueprintModelSearch.setPublished(ApplicationConstants.ACTIVE_Y);\r
+ return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch);\r
}\r
\r
/**\r
}\r
\r
/**\r
- * This is a getBlueprintModelByNameAndVersion method\r
+ * This is a getBlueprintModelSearchByNameAndVersion method\r
*\r
* @param name name\r
* @param version version\r
* @return BlueprintModelSearch\r
+ * @throws BluePrintException BluePrintException\r
*/\r
- public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)\r
- throws BluePrintException {\r
+ public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version)\r
+ throws BluePrintException {\r
BlueprintModelSearch blueprintModelSearch;\r
Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository\r
- .findByArtifactNameAndArtifactVersion(name, version);\r
+ .findByArtifactNameAndArtifactVersion(name, version);\r
if (dbBlueprintModel.isPresent()) {\r
blueprintModelSearch = dbBlueprintModel.get();\r
} else {\r
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(),\r
+ String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));\r
}\r
-\r
return blueprintModelSearch;\r
}\r
\r
/**\r
- * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource using MONO\r
+ * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version\r
*\r
+ * @param name name\r
+ * @param version version\r
* @return ResponseEntity<Resource>\r
+ * @throws BluePrintException BluePrintException\r
+ */\r
+ public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name, @NotNull String version)\r
+ throws BluePrintException {\r
+ BlueprintModel blueprintModel;\r
+ try {\r
+ blueprintModel = getBlueprintModelByNameAndVersion(name, version);\r
+ } catch (BluePrintException e) {\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
+ "downloading the CBA file: %s", e.getMessage()), e);\r
+ }\r
+ String fileName = blueprintModel.getId() + ".zip";\r
+ byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
+ return prepareResourceEntity(fileName, file);\r
+ }\r
+\r
+ /**\r
+ * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource\r
+ *\r
+ * @return ResponseEntity<Resource>\r
+ * @throws BluePrintException BluePrintException\r
*/\r
public ResponseEntity<Resource> downloadBlueprintModelFile(@NotNull String id) throws BluePrintException {\r
BlueprintModel blueprintModel;\r
try {\r
blueprintModel = getBlueprintModel(id);\r
} catch (BluePrintException e) {\r
- throw new BluePrintException("Error uploading the CBA file in channel.", e);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
+ "downloading the CBA file: %s", e.getMessage()), e);\r
}\r
String fileName = blueprintModel.getId() + ".zip";\r
byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
+ return prepareResourceEntity(fileName, file);\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param (fileName, file)\r
+ * @return ResponseEntity<Resource>\r
+ */\r
+ private ResponseEntity<Resource> prepareResourceEntity(String fileName, byte[] file) {\r
return ResponseEntity.ok()\r
- .contentType(MediaType.parseMediaType("text/plain"))\r
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")\r
- .body(new ByteArrayResource(file));\r
+ .contentType(MediaType.parseMediaType("text/plain"))\r
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")\r
+ .body(new ByteArrayResource(file));\r
}\r
\r
/**\r
if (dbBlueprintModel.isPresent()) {\r
blueprintModel = dbBlueprintModel.get();\r
} else {\r
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));\r
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
}\r
+ return blueprintModel;\r
+ }\r
\r
+ /**\r
+ * This is a getBlueprintModelByNameAndVersion method\r
+ *\r
+ * @param name name\r
+ * @param version version\r
+ * @return BlueprintModel\r
+ * @throws BluePrintException BluePrintException\r
+ */\r
+ private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)\r
+ throws BluePrintException {\r
+ BlueprintModel blueprintModel;\r
+ Optional<BlueprintModel> dbBlueprintModel = blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version);\r
+ if (dbBlueprintModel.isPresent()) {\r
+ blueprintModel = dbBlueprintModel.get();\r
+ } else {\r
+ String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
+ }\r
return blueprintModel;\r
}\r
\r
if (dbBlueprintModel.isPresent()) {\r
blueprintModelSearch = dbBlueprintModel.get();\r
} else {\r
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));\r
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
}\r
\r
return blueprintModelSearch;\r
blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get());\r
blueprintModelRepository.delete(dbBlueprintModel.get());\r
} else {\r
- throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id));\r
+ String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id);\r
+ throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
}\r
}\r
\r
/**\r
* This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database\r
*\r
- * @return List<BlueprintModelSearch> list with the controller blueprint archives\r
+ * @return List<BlueprintModelSearch> list of the controller blueprint archives\r
*/\r
public List<BlueprintModelSearch> getAllBlueprintModel() {\r
return blueprintModelSearchRepository.findAll();\r
}\r
-\r
}\r
import com.fasterxml.jackson.annotation.JsonFormat;\r
import com.fasterxml.jackson.annotation.JsonInclude;\r
import com.fasterxml.jackson.annotation.JsonInclude.Include;\r
+import com.fasterxml.jackson.annotation.JsonTypeInfo;\r
+import com.fasterxml.jackson.annotation.JsonTypeName;\r
\r
import java.io.Serializable;\r
import java.util.Date;\r
\r
@JsonInclude(Include.NON_NULL)\r
+@JsonTypeName("errorMessage")\r
+@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)\r
public class ErrorMessage implements Serializable {\r
private String message;\r
private Integer code;\r
\r
@EntityListeners({AuditingEntityListener.class})\r
@Entity\r
-@Table(name = "CONFIG_MODEL")\r
+@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"}))\r
@Proxy(lazy=false)\r
public class BlueprintModel implements Serializable {\r
private static final long serialVersionUID = 1L;\r
package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
\r
import com.fasterxml.jackson.annotation.JsonFormat;\r
+import com.fasterxml.jackson.annotation.JsonTypeInfo;\r
+import com.fasterxml.jackson.annotation.JsonTypeName;\r
import org.springframework.data.annotation.LastModifiedDate;\r
\r
import javax.persistence.*;\r
\r
@Entity\r
@Table(name = "CONFIG_MODEL")\r
+@JsonTypeName("blueprintModel")\r
+@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)\r
public class BlueprintModelSearch implements Serializable {\r
private static final long serialVersionUID = 1L;\r
\r
\r
@PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\r
public @ResponseBody\r
- Mono<BlueprintModelSearch> saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{\r
+ Mono<BlueprintModelSearch> saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{\r
return blueprintModelService.saveBlueprintModel(file);\r
}\r
\r
@DeleteMapping(path = "/{id}")\r
- public void deleteBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {\r
+ public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException {\r
this.blueprintModelService.deleteBlueprintModel(id);\r
}\r
\r
@GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
public @ResponseBody\r
- BlueprintModelSearch getBluePrintByNameAndVersion(@PathVariable(value = "name") String name,\r
- @PathVariable(value = "version") String version) throws BluePrintException {\r
- return this.blueprintModelService.getBlueprintModelByNameAndVersion(name, version);\r
+ BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name,\r
+ @PathVariable(value = "version") String version) throws BluePrintException {\r
+ return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version);\r
+ }\r
+\r
+ @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
+ public @ResponseBody\r
+ ResponseEntity<Resource> downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name,\r
+ @PathVariable(value = "version") String version) throws BluePrintException {\r
+ return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version);\r
}\r
\r
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
public @ResponseBody\r
- BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException {\r
+ BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {\r
return this.blueprintModelService.getBlueprintModelSearch(id);\r
}\r
\r
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)\r
public @ResponseBody\r
- List<BlueprintModelSearch> getAllCBA() {\r
+ List<BlueprintModelSearch> getAllBlueprintModel() {\r
return this.blueprintModelService.getAllBlueprintModel();\r
}\r
\r
return this.blueprintModelService.downloadBlueprintModelFile(id);\r
}\r
\r
- @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
+ @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
public @ResponseBody\r
BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {\r
return this.blueprintModelService.publishBlueprintModel(id);\r
--- /dev/null
+/*
+ * 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
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
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.BluePrintException
+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.springframework.dao.DataIntegrityViolationException
import org.springframework.stereotype.Service
import java.io.File
import java.nio.file.Files
@Service
class ControllerBlueprintCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
private val bluePrintValidatorService: BluePrintValidatorService,
- private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository,
private val blueprintModelRepository: ControllerBlueprintModelRepository)
: BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
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
// Set the Blueprint Model Content into blueprintModel
blueprintModel.blueprintModelContent = blueprintModelContent
- blueprintModelRepository.saveAndFlush(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
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
// 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