summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules
diff options
context:
space:
mode:
authorDan Timoney <dt5972@att.com>2018-09-04 15:14:31 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-04 15:14:31 +0000
commita4caff3cbcb08322c2fc2e189bfceaf1472a6f03 (patch)
treea05dd5ede4d79fbb422534bce743b4c57e017d4d /ms/controllerblueprints/modules
parent4a4a23823e3faa8872b86ae5cd3b0882b3b7899b (diff)
parent713a0958b1796d06ca19ad9be396e92999e851d6 (diff)
Merge "Controller Blueprints Microservice"
Diffstat (limited to 'ms/controllerblueprints/modules')
-rw-r--r--ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt7
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java107
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java50
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java2
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java2
5 files changed, 76 insertions, 92 deletions
diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index 2e3edb65e..4ae1f4d5d 100644
--- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -17,12 +17,17 @@
package org.onap.ccsdk.apps.controllerblueprints.core
/**
- *
+ * BluePrintConstants
*
* @author Brinda Santh
*/
object BluePrintConstants {
+ const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID"
+ const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion"
+ const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion"
+ const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"
+
const val TYPE_DEFAULT: String = "default"
const val DATA_TYPE_STRING: String = "string"
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java
index 534394a3e..a2f653c67 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java
@@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
@@ -68,6 +69,7 @@ public class ConfigModelService {
this.configModelRepository = configModelRepository;
this.configModelContentRepository = configModelContentRepository;
this.configModelCreateService = configModelCreateService;
+ log.info("Config Model Service Initiated...");
}
/**
@@ -143,8 +145,8 @@ public class ConfigModelService {
* @param version version
* @return ConfigModel
*/
- public ConfigModel getConfigModelByNameAndVersion(String name, String version) {
- ConfigModel configModel = null;
+ public ConfigModel getConfigModelByNameAndVersion(@NotNull String name, String version) throws BluePrintException {
+ ConfigModel configModel;
Optional<ConfigModel> dbConfigModel;
if (StringUtils.isNotBlank(version)) {
dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version);
@@ -153,6 +155,8 @@ public class ConfigModelService {
}
if (dbConfigModel.isPresent()) {
configModel = dbConfigModel.get();
+ } else {
+ throw new BluePrintException(String.format("failed to get config model name(%s), version(%s) from repo", name, version));
}
return configModel;
}
@@ -162,15 +166,17 @@ public class ConfigModelService {
*
* @param id id
* @return ConfigModel
+ * @throws BluePrintException BluePrintException
*/
- public ConfigModel getConfigModel(Long id) {
- ConfigModel configModel = null;
- if (id != null) {
- Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);
- if (dbConfigModel.isPresent()) {
- configModel = dbConfigModel.get();
- }
+ public ConfigModel getConfigModel(@NotNull Long id) throws BluePrintException {
+ ConfigModel configModel;
+ Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);
+ if (dbConfigModel.isPresent()) {
+ configModel = dbConfigModel.get();
+ } else {
+ throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id));
}
+
return configModel;
}
@@ -179,54 +185,56 @@ public class ConfigModelService {
*
* @param id id
* @return ConfigModel
+ * @throws BluePrintException BluePrintException
*/
- public ConfigModel getCloneConfigModel(Long id) {
+ public ConfigModel getCloneConfigModel(@NotNull Long id) throws BluePrintException {
ConfigModel configModel;
- ConfigModel cloneConfigModel = null;
- if (id != null) {
- Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);
- if (dbConfigModel.isPresent()) {
- configModel = dbConfigModel.get();
- cloneConfigModel = configModel;
- cloneConfigModel.setUpdatedBy("xxxxx@xxx.com");
- cloneConfigModel.setArtifactName("XXXX");
- cloneConfigModel.setPublished("XXXX");
- cloneConfigModel.setPublished("XXXX");
- cloneConfigModel.setUpdatedBy("XXXX");
- cloneConfigModel.setId(null);
- cloneConfigModel.setTags(null);
- cloneConfigModel.setCreatedDate(new Date());
- List<ConfigModelContent> configModelContents = cloneConfigModel.getConfigModelContents();
-
- if (CollectionUtils.isNotEmpty(configModelContents)) {
- for (ConfigModelContent configModelContent : configModelContents) {
- if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) {
- configModelContent.setId(null);
- configModelContent.setCreationDate(new Date());
-
- if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON
- .equalsIgnoreCase(configModelContent.getContentType())) {
- ServiceTemplate serviceTemplate = JacksonUtils
- .readValue(configModelContent.getContent(), ServiceTemplate.class);
- if (serviceTemplate != null && serviceTemplate.getMetadata() != null) {
- serviceTemplate.getMetadata()
- .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX");
- serviceTemplate.getMetadata()
- .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0");
- serviceTemplate.getMetadata()
- .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX");
-
- configModelContent.setContent(JacksonUtils.getJson(serviceTemplate));
- }
+ ConfigModel cloneConfigModel;
+ Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);
+ if (dbConfigModel.isPresent()) {
+ configModel = dbConfigModel.get();
+ cloneConfigModel = configModel;
+ cloneConfigModel.setUpdatedBy("xxxxx@xxx.com");
+ cloneConfigModel.setArtifactName("XXXX");
+ cloneConfigModel.setPublished("XXXX");
+ cloneConfigModel.setPublished("XXXX");
+ cloneConfigModel.setUpdatedBy("XXXX");
+ cloneConfigModel.setId(null);
+ cloneConfigModel.setTags(null);
+ cloneConfigModel.setCreatedDate(new Date());
+ List<ConfigModelContent> configModelContents = cloneConfigModel.getConfigModelContents();
+
+ if (CollectionUtils.isNotEmpty(configModelContents)) {
+ for (ConfigModelContent configModelContent : configModelContents) {
+ if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) {
+ configModelContent.setId(null);
+ configModelContent.setCreationDate(new Date());
+
+ if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON
+ .equalsIgnoreCase(configModelContent.getContentType())) {
+ ServiceTemplate serviceTemplate = JacksonUtils
+ .readValue(configModelContent.getContent(), ServiceTemplate.class);
+ if (serviceTemplate != null && serviceTemplate.getMetadata() != null) {
+ serviceTemplate.getMetadata()
+ .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX");
+ serviceTemplate.getMetadata()
+ .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0");
+ serviceTemplate.getMetadata()
+ .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX");
+
+ configModelContent.setContent(JacksonUtils.getJson(serviceTemplate));
}
}
-
}
+
}
}
+ } else {
+ throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id));
}
+
return cloneConfigModel;
}
@@ -234,14 +242,17 @@ public class ConfigModelService {
* This is a deleteConfigModel method
*
* @param id id
+ * @throws BluePrintException BluePrintException
*/
@Transactional
- public void deleteConfigModel(Long id) {
+ public void deleteConfigModel(@NotNull Long id) throws BluePrintException {
Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);
if (dbConfigModel.isPresent()) {
configModelContentRepository.deleteByConfigModel(dbConfigModel.get());
configModelRepository.delete(dbConfigModel.get());
+ } else {
+ throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id));
}
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java
index 62b683032..fc2956bea 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java
@@ -46,81 +46,49 @@ public class ConfigModelRest {
@GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException {
- try {
- return this.configModelService.getInitialConfigModel(name);
- } catch (Exception e) {
- throw new BluePrintException(2000, e.getMessage(), e);
- }
+ return this.configModelService.getInitialConfigModel(name);
}
- @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
+ @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException {
- try {
- return this.configModelService.saveConfigModel(configModel);
- } catch (Exception e) {
- throw new BluePrintException(2200, e.getMessage(), e);
- }
+ return this.configModelService.saveConfigModel(configModel);
}
@DeleteMapping(path = "/{id}")
public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
- try {
- this.configModelService.deleteConfigModel(id);
- } catch (Exception e) {
- throw new BluePrintException(2400, e.getMessage(), e);
- }
+ this.configModelService.deleteConfigModel(id);
}
@GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
- try {
- return this.configModelService.publishConfigModel(id);
- } catch (Exception e) {
- throw new BluePrintException(2500, e.getMessage(), e);
- }
+ return this.configModelService.publishConfigModel(id);
}
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
- try {
- return this.configModelService.getConfigModel(id);
- } catch (Exception e) {
- throw new BluePrintException(2001, e.getMessage(), e);
- }
+ return this.configModelService.getConfigModel(id);
}
@GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name,
@PathVariable(value = "version") String version) throws BluePrintException {
- try {
- return this.configModelService.getConfigModelByNameAndVersion(name, version);
- } catch (Exception e) {
- throw new BluePrintException(2002, e.getMessage(), e);
- }
+ return this.configModelService.getConfigModelByNameAndVersion(name, version);
}
@GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
List<ConfigModel> searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException {
- try {
- return this.configModelService.searchConfigModels(tags);
- } catch (Exception e) {
- throw new BluePrintException(2003, e.getMessage(), e);
- }
+ return this.configModelService.searchConfigModels(tags);
}
@GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
- try {
- return this.configModelService.getCloneConfigModel(id);
- } catch (Exception e) {
- throw new BluePrintException(2004, e.getMessage(), e);
- }
+ return this.configModelService.getCloneConfigModel(id);
}
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java
index 6bcbae963..082b15078 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java
@@ -70,7 +70,7 @@ public class ModelTypeRest {
}
}
- @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
+ @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException {
try {
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
index 795738cb1..a4aced60c 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
@@ -43,7 +43,7 @@ public class ResourceDictionaryRest {
this.resourceDictionaryService = dataDictionaryService;
}
- @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
+ @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary)
throws BluePrintException {