From 74a62bea98248a496ae032ed694e19573cd98d0b Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 3 Sep 2018 00:50:25 +0000 Subject: Controller Blueprints Microservice Add Logger MDC using ONAP LoggerAdaptor and change swagger configuration to return the transactions information, version, etc Change-Id: Ie1dccecce0c08e7ae02c0e55c1cc5be75d5fc686 Issue-ID: CCSDK-510 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ConfigModelService.java | 107 ++++++++++++--------- .../service/rs/ConfigModelRest.java | 50 ++-------- .../service/rs/ModelTypeRest.java | 2 +- .../service/rs/ResourceDictionaryRest.java | 2 +- 4 files changed, 70 insertions(+), 91 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main') 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 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 dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - } + public ConfigModel getConfigModel(@NotNull Long id) throws BluePrintException { + ConfigModel configModel; + Optional 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 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 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 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 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 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 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 { -- cgit 1.2.3-korg