aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules
diff options
context:
space:
mode:
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 2e3edb65..4ae1f4d5 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 534394a3..a2f653c6 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 62b68303..fc2956be 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 6bcbae96..082b1507 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 795738cb..a4aced60 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 {