From ae235a33287834a5541c4914ab7f54e821d9731d Mon Sep 17 00:00:00 2001 From: Steve Alphonse Siani Date: Fri, 28 Dec 2018 14:58:27 -0500 Subject: 1st drop integration with BluePrintCatalogService Change-Id: I0824dcaf0a36e4616c12f3ac53530e6863bee290 Issue-ID: CCSDK-418 Signed-off-by: Steve Alphonse Siani --- .../service/AutoResourceMappingService.java | 4 +- .../service/BlueprintModelService.java | 227 ++++++++++++++ .../service/CBAContentService.java | 97 ------ .../service/CbaFileManagementService.java | 128 -------- .../controllerblueprints/service/CbaService.java | 192 ------------ .../service/CbaToDatabaseService.java | 132 --------- .../service/ConfigModelCreateService.java | 330 --------------------- .../service/ConfigModelService.java | 260 ---------------- .../service/SchemaGeneratorService.java | 4 +- .../service/ServiceTemplateService.java | 131 -------- .../service/domain/BlueprintModel.java | 284 ++++++++++++++++++ .../service/domain/BlueprintModelContent.java | 170 +++++++++++ .../service/domain/BlueprintModelSearch.java | 162 ++++++++++ .../service/domain/CbaContent.java | 114 ------- .../service/domain/ConfigModel.java | 302 ------------------- .../service/domain/ConfigModelContent.java | 174 ----------- .../service/domain/ConfigModelSearch.java | 165 ----------- .../service/domain/JpaJsonNodeConverter.java | 6 +- .../service/model/BlueprintModelResponse.java | 78 ----- .../service/model/ItemCbaResponse.java | 58 ---- .../BlueprintModelContentRepository.java | 102 +++++++ .../repository/BlueprintModelRepository.java | 96 ++++++ .../repository/BlueprintModelSearchRepository.java | 69 +++++ .../service/repository/CBAContentRepository.java | 59 ---- .../repository/ConfigModelContentRepository.java | 102 ------- .../service/repository/ConfigModelRepository.java | 95 ------ .../repository/ConfigModelSearchRepository.java | 43 --- .../service/rs/BlueprintModelRest.java | 90 ++++++ .../controllerblueprints/service/rs/CbaRest.java | 84 ------ .../service/rs/ConfigModelRest.java | 95 ------ .../service/rs/ModelTypeRest.java | 73 ----- .../service/rs/ServiceTemplateRest.java | 82 ----- .../service/utils/CbaStateEnum.java | 15 - .../service/utils/CloseCondition.java | 36 --- .../service/utils/ConfigModelUtils.java | 128 -------- .../validator/ServiceTemplateValidator.java | 2 +- .../enhancer/BluePrintPolicyTypeEnhancerImpl.kt | 1 - .../service/load/BluePrintCatalogLoadService.kt | 2 +- .../service/load/BluePrintCatalogServiceImpl.kt | 103 +++++-- .../service/utils/BluePrintEnhancerUtils.kt | 43 +++ .../src/main/resources/sql/schema-local.sql | 4 +- .../service/src/main/resources/sql/schema.sql | 4 +- .../service/BlueprintModelServiceTest.java | 30 ++ .../service/CbaFileManagementServiceTest.java | 89 ------ .../service/ConfigModelServiceTest.java | 36 --- .../service/ModelTypeServiceTest.java | 4 +- .../service/common/SchemaGeneratorServiceTest.java | 4 +- .../service/rs/ConfigModelRestTest.java | 173 ----------- .../service/rs/ModelTypeRestTest.java | 4 +- .../service/rs/ResourceDictionaryRestTest.java | 105 ------- .../service/rs/ServiceTemplateRestTest.java | 156 ---------- .../service/validator/ModelTypeValidatorTest.java | 12 +- 52 files changed, 1385 insertions(+), 3574 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java mode change 100644 => 100755 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java delete mode 100755 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java (limited to 'ms/controllerblueprints/modules/service/src') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index a763d503..1965ac90 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -28,8 +30,6 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDict import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.ArrayList; 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 new file mode 100644 index 00000000..ba27742a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -0,0 +1,227 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +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; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.onap.ccsdk.apps.controllerblueprints.service.load.BluePrintLoadConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelContentRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelSearchRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +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 + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class BlueprintModelService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(BlueprintModelService.class); + + @Autowired + private BluePrintLoadConfiguration bluePrintLoadConfiguration; + + @Autowired + private BluePrintCatalogService bluePrintCatalogService; + + @Autowired + private BlueprintModelSearchRepository blueprintModelSearchRepository; + + @Autowired + private BlueprintModelRepository blueprintModelRepository; + + @Autowired + private BlueprintModelContentRepository 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"; + + /** + * This is a saveBlueprintModel method + * + * @param filePart filePart + * @return Mono + * @throws BluePrintException BluePrintException + */ + public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { + try { + Path cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); + return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { + String blueprintId = bluePrintCatalogService.uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); + return blueprintModelSearchRepository.findById(blueprintId).get(); + }); + + } catch (IOException | BluePrintException e) { + return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); + } + } + + /** + * This is a publishBlueprintModel method + * + * @param id id + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException { + // TODO Implement publish Functionality + return null; + } + + /** + * This is a searchBlueprintModels method + * + * @param tags tags + * @return List + */ + public List searchBlueprintModels(String tags) { + return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags); + } + + /** + * This is a getBlueprintModelByNameAndVersion method + * + * @param name name + * @param version version + * @return BlueprintModelSearch + */ + public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { + BlueprintModelSearch blueprintModelSearch; + Optional dbBlueprintModel = blueprintModelSearchRepository + .findByArtifactNameAndArtifactVersion(name, version); + if (dbBlueprintModel.isPresent()) { + blueprintModelSearch = dbBlueprintModel.get(); + } else { + throw new BluePrintException(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 + * + * @param (id) + * @return ResponseEntity + */ + public ResponseEntity 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); + } + String fileName = blueprintModel.getId() + ".zip"; + byte[] file = blueprintModel.getBlueprintModelContent().getContent(); + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") + .body(new ByteArrayResource(file)); + } + + /** + * This is a getBlueprintModel method + * + * @param id id + * @return BlueprintModel + * @throws BluePrintException BluePrintException + */ + private BlueprintModel getBlueprintModel(@NotNull String id) throws BluePrintException { + BlueprintModel blueprintModel; + Optional dbBlueprintModel = blueprintModelRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModel = dbBlueprintModel.get(); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + + return blueprintModel; + } + + /** + * This is a getBlueprintModelSearch method + * + * @param id id + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + public BlueprintModelSearch getBlueprintModelSearch(@NotNull String id) throws BluePrintException { + BlueprintModelSearch blueprintModelSearch; + Optional dbBlueprintModel = blueprintModelSearchRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModelSearch = dbBlueprintModel.get(); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + + return blueprintModelSearch; + } + + /** + * This is a deleteBlueprintModel method + * + * @param id id + * @throws BluePrintException BluePrintException + */ + @Transactional + public void deleteBlueprintModel(@NotNull String id) throws BluePrintException { + Optional dbBlueprintModel = blueprintModelRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()); + blueprintModelRepository.delete(dbBlueprintModel.get()); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + } + + /** + * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database + * + * @return List list with the controller blueprint archives + */ + public List getAllBlueprintModel() { + return blueprintModelSearchRepository.findAll(); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java deleted file mode 100755 index 66ef6a93..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.CBAContentRepository; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; - -/** - * CBAContentService.java Purpose: Provide CBAContent Template Service processing - * CBAContentService - * - * @author Ruben Chang - * @version 1.0 - */ - -@Service -public class CBAContentService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class); - - private CBAContentRepository cbaContentRepository; - - /** - * Constructor of the class - * @param cbaContentRepository CRUD methods for entity CBAContentRepository - */ - public CBAContentService(CBAContentRepository cbaContentRepository) { - this.cbaContentRepository = cbaContentRepository; - log.info("CBAContentRepository sucessfully instantiated"); - } - - /** - * Save the CBAContent into the CBA_CONTENT table - * @param cbaName The name of the file - * @param cbaVersion version number of the CBA archive - * @param cbaState int that would represent the state. Refer to the CbaStateEnum - * @param cbaDescription Brief description that would help to identify and recognize the CBA archive - * @param file the file - * @return CbaContent the record saved into the table CBA_CONTENT - */ - public CbaContent saveCBAContent(String cbaName, String cbaVersion, int cbaState, String cbaDescription, byte[] file){ - CbaContent cbaContent = new CbaContent(); - cbaContent.setCbaName(cbaName); - cbaContent.setCbaVersion(cbaVersion); - cbaContent.setCbaState(cbaState); - cbaContent.setCbaDescription(cbaDescription); - cbaContent.setCbaFile(file); - cbaContentRepository.saveAndFlush(cbaContent); - return cbaContent; - } - - /** - * Get the list of Controller Blueprint archives - * @return List list with the controller blueprint archives - */ - public List getList(){ - return cbaContentRepository.findAll(); - } - - /** - * Get a single Controller Blueprint archive by uuID - * @param uuID the userID controller blueprint identifier - * @return Optional - */ - public Optional findByUUID(String uuID) { - return cbaContentRepository.findById(uuID); - } - - /** - * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model - * @param uuid the uuid that identify the CBA - */ - public void deleteCBAById(String uuid) { - cbaContentRepository.deleteById(uuid); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java deleted file mode 100755 index 2011172d..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.stereotype.Service; -import org.springframework.util.FileSystemUtils; -import org.springframework.util.StringUtils; -import reactor.core.publisher.Mono; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * CbaFileManagementService.java Purpose: Provide Service processing CBA file management - * - * @author Steve Siani - * @version 1.0 - */ -@Service -public class CbaFileManagementService { - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaFileManagementService.class); - - @Value("${controllerblueprints.loadCbaExtension}") - private String cbaExtension; - - private static final String CBA_FILE_NAME_PATTERN = "CBA_{0}_{1}"; - - - /** - * cleanupSavedCBA: This method cleanup the Zip file and the unzip directory that was added. - * - * @param zipFileName zipFileName - * @param cbaFileLocation cbaFileLocation - * @return - * @throws BluePrintException BluePrintException - */ - public void cleanupSavedCBA(String zipFileName, Path cbaFileLocation) throws BluePrintException { - - String fileNameWithoutExtension = BluePrintFileUtils.Companion.stripFileExtension(zipFileName); - - //Delete the Zip file from the repository - FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(zipFileName,cbaFileLocation)); - - //Delete the CBA directory from the repository - FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(fileNameWithoutExtension,cbaFileLocation)); - } - - /** - * This is a saveCBAFile method - * take a {@link FilePart}, transfer it to disk using a Flux of FilePart and return a {@link Mono} representing the CBA file name - * - * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save - * @return a {@link Mono} String representing the result of the operation - * @throws (BluePrintException, IOException) BluePrintException, IOException - */ - public Mono saveCBAFile(FilePart filePart, Path targetDirectory) throws BluePrintException, IOException { - - // Normalize file name - final String fileName = StringUtils.cleanPath(filePart.filename()); - - // Check if the file's extension is "CBA" - if(!StringUtils.getFilenameExtension(fileName).equals(cbaExtension)) { - throw new BluePrintException("Invalid file extension required " + cbaExtension); - } - - // Change file name to match a pattern - String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); - - // Copy file to the target location (Replacing existing file with the same name) - Path targetLocation = targetDirectory.resolve(changedFileName); - - // if a file with the same name already exists in a repository, delete and recreate it - File file = new File(targetLocation.toString()); - if (file.exists()) - file.delete(); - file.createNewFile(); - - return filePart.transferTo(file).thenReturn(changedFileName); - } - - /** - * Decompress the file into the cbaFileLocation parameter - * @param zipFileName name of the zipped file - * @param cbaFileLocation path in which the zipped file will get decompressed - * @return String the path in which the file is decompressed - * @throws BluePrintException Exception in the process - */ - public String decompressCBAFile(final String zipFileName, Path cbaFileLocation) throws BluePrintException { - - File file = BluePrintFileUtils.Companion.getBluePrintFile(zipFileName, cbaFileLocation); - try { - Path directoryPath = Files.createDirectories(cbaFileLocation.resolve(BluePrintFileUtils.Companion.stripFileExtension(zipFileName))); - BluePrintArchiveUtils.Companion.deCompress(file, directoryPath.toString()); - return directoryPath.toString(); - - } catch (BluePrintProcessorException | IOException ex) { - throw new BluePrintException(" Fail to decompress " + zipFileName, ex); - } - - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java deleted file mode 100755 index 7d616a76..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * CbaService.java Purpose: Provide Service Template Service processing CbaService - * - * @author Steve Siani - * @version 1.0 - */ - -@Service -public class CbaService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaService.class); - - @Value("${controllerblueprints.blueprintArchivePath}") - private String cbaArchivePath; - private Path cbaLocation; - - @Autowired - private CbaFileManagementService cbaFileManagementService; - - @Autowired - private CbaToDatabaseService cbaToDatabaseService; - - - /** - * This method would be used by SpringBoot to initialize the cba location - */ - @EventListener(ApplicationReadyEvent.class) - private void initCbaService() { - this.cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaArchivePath); - log.info("CBA service Initiated..."); - } - - /** - * This is a uploadCBAFile method - * take a {@link FilePart}, transfer it to disk using WebFlux and return a {@link Mono} representing the result - * - * @param filePart - the request part containing the file to be saved - * @return a {@link Mono< BlueprintModelResponse >} representing the result of the operation - */ - public Mono uploadCBAFile(FilePart filePart) { - - try { - return this.cbaFileManagementService.saveCBAFile(filePart, cbaLocation).map(fileName -> { - ConfigModel configModel; - BlueprintModelResponse blueprintModelResponse = null; - - try { - String cbaDirectory = this.cbaFileManagementService.decompressCBAFile(fileName, cbaLocation); - configModel = this.cbaToDatabaseService.storeBluePrints(cbaDirectory, fileName, cbaLocation.resolve(fileName)); - blueprintModelResponse = new BlueprintModelResponse(configModel.getId(), configModel.getArtifactName(), configModel.getArtifactVersion(), configModel.getArtifactDescription(), configModel.getConfigModelCBA().getCbaUUID()); - } catch (BluePrintException be) { - Mono.error(new BluePrintException("Error loading CBA in database.", be)); - } finally { - try { - this.cbaFileManagementService.cleanupSavedCBA(fileName, cbaLocation); - } catch (BluePrintException be) { - Mono.error(new BluePrintException("Error while cleaning up.", be)); - } - } - return blueprintModelResponse; - }); - } catch (IOException | BluePrintException e) { - return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); - } - } - - /** - * This is a deleteCba method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - public void deleteCBA(@NotNull Long id) throws BluePrintException { - this.cbaToDatabaseService.deleteCBA(id); - } - - /** - * This is a downloadCBAFile method to find the target file to download and return a file ressource using MONO - * - * @param (id) - * @return ResponseEntity - */ - public ResponseEntity downloadCBAFile(@NotNull String id) { - Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); - - CbaContent cbaContent = optionalContent.get(); - - return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + cbaContent.getCbaName() + "\"") - .body(new ByteArrayResource(cbaContent.getCbaFile())); - } - - /** - * This is a findCBAByID method to find a CBA By the UUID - * - * @param (id) - * @return ItemCbaResponse - */ - public ItemCbaResponse findCBAByID(@NotNull String id) { - ItemCbaResponse response = new ItemCbaResponse(); - Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); - - CbaContent cbaContent = optionalContent.get(); - response.setName(cbaContent.getCbaName()); - response.setState(cbaContent.getCbaState()); - response.setId(cbaContent.getCbaUUID()); - response.setVersion(cbaContent.getCbaVersion()); - response.setDescription(cbaContent.getCbaDescription()); - return response; - } - - /** - * This is a findAllCBA method to retrieve all the CBAs in Database - * - * @return List list with the controller blueprint archives - */ - public List findAllCBA() { - List responseList = new ArrayList<>(); - List cbaContents = this.cbaToDatabaseService.listCBAFiles(); - - for(CbaContent content: cbaContents){ - ItemCbaResponse response = new ItemCbaResponse(); - response.setName(content.getCbaName()); - response.setState(content.getCbaState()); - response.setId(content.getCbaUUID()); - response.setVersion(content.getCbaVersion()); - response.setDescription(content.getCbaDescription()); - - responseList.add(response); - } - return responseList; - } - - /** - * This is a findCBAByNameAndVersion method to find a CBA by Name and version - * - * @param (name, version) - * @return - * @throws BluePrintException BluePrintException - */ - public ItemCbaResponse findCBAByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { - return null; - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java deleted file mode 100755 index 34204202..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.collections.CollectionUtils; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; - -/** - * This class acts as a Rest Service that would store in the Database the Blueprints. - * @author Ruben Chang - */ - -@Service -public class CbaToDatabaseService { - - //Log used to trace the transactions using the EELFLogger class - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaToDatabaseService.class); - - @Autowired - private ConfigModelRepository configModelRepository; - @Autowired - private ConfigModelContentRepository configModelContentRepository; - @Autowired - private ConfigModelCreateService configModelCreateService; - @Autowired - private CBAContentService cbaContentService; - - /** - * This method will store the blueprints into the DB on the tables CONFIG_MODEL and CONFIG_MODEL_CONTENT - * @param cbaArchiveToSave Path in which the components are stored - * @return ConfigModel The Blueprint object stored in the DB - */ - public ConfigModel storeBluePrints(String cbaDirectory, String cbaFileName, Path cbaArchiveToSave) throws BluePrintException { - log.info("*************************** storeBluePrints **********************"); - ConfigModel configModel = null; - CbaContent cbaContent; - String version = "1.0";//TODO Read these information from metadata - String description = "Initial description for CBA archive " + cbaFileName;//TODO - - List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(cbaDirectory); - if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { - for (String fileName : serviceTemplateDirs) { - try { - String bluePrintPath = cbaDirectory.concat("/").concat(fileName); - log.debug("***** Loading service template : {}", bluePrintPath); - configModel = ConfigModelUtils.getConfigModel(bluePrintPath); - - configModel = this.configModelCreateService.saveConfigModel(configModel); - - log.info("Loaded service template successfully: {}", fileName); - } catch (Exception e) { - throw new BluePrintException("Load config model " + fileName + " error : "+e.getMessage()); - } - } - } else { - throw new BluePrintException("Invalid structure. The unzipped file does not contains Blueprints"); - } - - byte[] file; - try { - file = Files.readAllBytes(cbaArchiveToSave); - } catch (IOException e) { - throw new BluePrintException("Fail to read the CBA to save in database.", e); - } - - cbaContent = this.cbaContentService.saveCBAContent(cbaFileName, version, CbaStateEnum.DRAFT.getState(), description, file); - configModel.setConfigModelCBA(cbaContent); - - return configModel; - } - - /** - * This is a deleteConfigModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - public void deleteCBA(@NotNull Long id) throws BluePrintException { - Optional dbConfigModel = configModelRepository.findById(id); - - //TODO: Delete CBA and COnfigModel - - } - - /** - * Get a list of the controller blueprint archives - * @return List List with the controller blueprint archives - */ - public List listCBAFiles() { - return this.cbaContentService.getList(); - } - - /** - * Find a Controller Blueprint Archive by UUID - * @param uuID the User Identifier Controller Blueprint archive - * @return Optional the Controller Blueprint archive - */ - public Optional findByUUID(String uuID) { - return this.cbaContentService.findByUUID(uuID); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java deleted file mode 100755 index f31a0ceb..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.IOUtils; -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; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * ServiceTemplateCreateService.java Purpose: Provide Service Template Create Service processing - * ServiceTemplateCreateService - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Service -public class ConfigModelCreateService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); - - private ConfigModelRepository configModelRepository; - - /** - * This is a ConfigModelCreateService - * - * @param configModelRepository ConfigModelRepository - */ - public ConfigModelCreateService(ConfigModelRepository configModelRepository) { - this.configModelRepository = configModelRepository; - } - - /** - * This is a createInitialServiceTemplateContent method - * - * @param templateName templateName - * @return String - * @throws BluePrintException BluePrintException - */ - public String createInitialServiceTemplateContent(String templateName) throws BluePrintException { - String serviceTemplateContent = null; - if (StringUtils.isNotBlank(templateName)) { - try { - serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() - .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); - } catch (IOException e) { - throw new BluePrintException(e.getMessage(), e); - } - - } - return serviceTemplateContent; - } - - /** - * This is a createInitialServiceTemplate method - * - * @param templateName templateName - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate createInitialServiceTemplate(String templateName) throws BluePrintException { - ServiceTemplate serviceTemplate = null; - if (StringUtils.isNotBlank(templateName)) { - try { - String serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() - .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); - if (StringUtils.isNotBlank(serviceTemplateContent)) { - serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - } - } catch (IOException e) { - throw new BluePrintException(e.getMessage(), e); - } - - } - return serviceTemplate; - } - - /** - * This is a saveConfigModel method - * - * @param configModel configModel - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - - if (configModel != null) { - String artifactName = configModel.getArtifactName(); - String artifactVersion = configModel.getArtifactVersion(); - String author = configModel.getUpdatedBy(); - CbaContent configModelCBA = configModel.getConfigModelCBA(); - - if (StringUtils.isBlank(author)) { - throw new BluePrintException("Artifact Author is missing in the Service Template"); - } - - if (StringUtils.isBlank(artifactName)) { - throw new BluePrintException("Artifact Name is missing in the Service Template"); - } - - if (StringUtils.isBlank(artifactVersion)) { - throw new BluePrintException("Artifact Version is missing in the Service Template"); - } - ConfigModel updateConfigModel; - - Optional dbConfigModelOptional = Optional.empty(); - - if (configModel.getId() != null) { - log.info("Searching for config model id : {}", configModel.getId()); - dbConfigModelOptional = configModelRepository.findById(configModel.getId()); - } - - if (!dbConfigModelOptional.isPresent()) { - log.info("Searching for config model name :" - + configModel.getArtifactName() + ", version " + configModel.getArtifactVersion()); - dbConfigModelOptional = configModelRepository.findByArtifactNameAndArtifactVersion( - configModel.getArtifactName(), configModel.getArtifactVersion()); - } - - if (dbConfigModelOptional.isPresent()) { - updateConfigModel = dbConfigModelOptional.get(); - log.info("Processing for config model id : {} with config model content count : {}" - , updateConfigModel.getId(), updateConfigModel.getConfigModelContents().size()); - } else { - ConfigModel tempConfigModel = new ConfigModel(); - tempConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - tempConfigModel.setArtifactName(artifactName); - tempConfigModel.setArtifactVersion(artifactVersion); - tempConfigModel.setUpdatedBy(author); - tempConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - tempConfigModel.setTags(artifactName); - configModelRepository.saveAndFlush(tempConfigModel); - updateConfigModel = tempConfigModel; - } - - Long dbConfigModelId = updateConfigModel.getId(); - - if (dbConfigModelId == null) { - throw new BluePrintException("failed to get the initial saved config model id."); - } - - log.info("Processing for config model id : {}", dbConfigModelId); - - deleteConfigModelContent(dbConfigModelId); - - addConfigModelContent(dbConfigModelId, configModel); - - // Populate Content model types - updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author, configModelCBA); - - - return updateConfigModel; - } else { - throw new BluePrintException("Config model information is missing"); - } - - } - - private void deleteConfigModelContent(Long dbConfigModelId) { - if (dbConfigModelId != null) { - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { - dbConfigModel.getConfigModelContents().clear(); - log.debug("Configuration Model content deleting : {}", dbConfigModel.getConfigModelContents()); - configModelRepository.saveAndFlush(dbConfigModel); - } - - } - } - - private void addConfigModelContent(Long dbConfigModelId, ConfigModel configModel) { - if (dbConfigModelId != null && configModel != null - && CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null) { - configModelContent.setId(null); - configModelContent.setConfigModel(dbConfigModel); - dbConfigModel.getConfigModelContents().add(configModelContent); - log.debug("Configuration Model content adding : {}", configModelContent); - } - } - configModelRepository.saveAndFlush(dbConfigModel); - } - } - - private ConfigModel updateConfigModel(Long dbConfigModelId, String artifactName, String artifactVersion, - String author, CbaContent configModelCBA) throws BluePrintException { - - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - // Populate tags from metadata - String tags = getConfigModelTags(dbConfigModel); - if (StringUtils.isBlank(tags)) { - throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); - } - dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - dbConfigModel.setArtifactName(artifactName); - dbConfigModel.setArtifactVersion(artifactVersion); - dbConfigModel.setUpdatedBy(author); - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - dbConfigModel.setTags(tags); - dbConfigModel.setConfigModelCBA(configModelCBA); - configModelRepository.saveAndFlush(dbConfigModel); - log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); - return dbConfigModel; - } - - private List getValidContentTypes() { - List valids = new ArrayList<>(); - valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - return valids; - - } - - private String getConfigModelTags(ConfigModel configModel) throws BluePrintException { - String tags = null; - if (CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { - - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { - - if (!getValidContentTypes().contains(configModelContent.getContentType())) { - throw new BluePrintException(configModelContent.getContentType() - + " is not a valid content type, It should be any one of this " - + getValidContentTypes()); - } - - if (configModelContent.getContentType().equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = - JacksonUtils.readValue(configModelContent.getContent(), ServiceTemplate.class); - Preconditions.checkNotNull(serviceTemplate, "failed to transform service template content"); - if (serviceTemplate.getMetadata() != null) { - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, - configModel.getUpdatedBy()); - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_VERSION, - configModel.getArtifactVersion()); - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_NAME, - configModel.getArtifactName()); - } - tags = String.valueOf(serviceTemplate.getMetadata()); - } - } - } - } - return tags; - } - - /** - * This is a publishConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException { - ConfigModel dbConfigModel = null; - Optional dbConfigModelOptional = configModelRepository.findById(id); - if (dbConfigModelOptional.isPresent()) { - dbConfigModel = dbConfigModelOptional.get(); - List configModelContents = dbConfigModel.getConfigModelContents(); - if (configModelContents != null && !configModelContents.isEmpty()) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent.getContentType() - .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null) { - validateServiceTemplate(serviceTemplate); - } - } - } - } - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); - configModelRepository.save(dbConfigModel); - log.info("Config model ({}) published successfully.", id); - } else { - throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id)); - } - return dbConfigModel; - } - - /** - * This is a validateServiceTemplate method - * - * @param serviceTemplate Service Template - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - // FIXME("Plug right Validator") - return serviceTemplate; - } -} 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 deleted file mode 100644 index b2fff26e..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; - -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; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; - -/** - * ConfigModelService.java Purpose: Provide Service Template Service processing ConfigModelService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -public class ConfigModelService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelService.class); - - private ConfigModelRepository configModelRepository; - private ConfigModelContentRepository configModelContentRepository; - private ConfigModelCreateService configModelCreateService; - private static final String CONFIG_MODEL_ID_FAILURE_MSG= "failed to get config model id(%d) from repo"; - - /** - * This is a ConfigModelService constructor. - * - * @param configModelRepository configModelRepository - * @param configModelContentRepository configModelContentRepository - * @param configModelCreateService configModelCreateService - */ - public ConfigModelService(ConfigModelRepository configModelRepository, - ConfigModelContentRepository configModelContentRepository, - ConfigModelCreateService configModelCreateService) { - this.configModelRepository = configModelRepository; - this.configModelContentRepository = configModelContentRepository; - this.configModelCreateService = configModelCreateService; - log.info("Config Model Service Initiated..."); - } - - /** - * This is a getInitialConfigModel method - * - * @param templateName templateName - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel getInitialConfigModel(String templateName) throws BluePrintException { - ConfigModel configModel = null; - if (StringUtils.isNotBlank(templateName)) { - configModel = new ConfigModel(); - configModel.setArtifactName(templateName); - configModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - configModel.setUpdatedBy("xxxxx@xxx.com"); - ConfigModelContent configModelContent = new ConfigModelContent(); - configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - configModelContent.setName(templateName); - String content = this.configModelCreateService.createInitialServiceTemplateContent(templateName); - configModelContent.setContent(content); - - List configModelContents = new ArrayList<>(); - configModelContents.add(configModelContent); - - configModel.setConfigModelContents(configModelContents); - } - return configModel; - } - - /** - * This is a saveConfigModel method - * - * @param configModel configModel - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - return this.configModelCreateService.saveConfigModel(configModel); - } - - /** - * This is a publishConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel publishConfigModel(Long id) throws BluePrintException { - return this.configModelCreateService.publishConfigModel(id); - } - - /** - * This is a searchConfigModels method - * - * @param tags tags - * @return ConfigModel - */ - public List searchConfigModels(String tags) { - List models = configModelRepository.findByTagsContainingIgnoreCase(tags); - if (models != null) { - for (ConfigModel configModel : models) { - configModel.setConfigModelContents(null); - } - } - return models; - } - - /** - * This is a getConfigModelByNameAndVersion method - * - * @param name name - * @param version version - * @return ConfigModel - */ - public ConfigModel getConfigModelByNameAndVersion(@NotNull String name, String version) throws BluePrintException { - ConfigModel configModel; - Optional dbConfigModel; - if (StringUtils.isNotBlank(version)) { - dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version); - } else { - dbConfigModel = configModelRepository.findTopByArtifactNameOrderByArtifactVersionDesc(name); - } - 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; - } - - /** - * This is a getConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - 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(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - - return configModel; - } - - /** - * This method returns clone of the given model id, by masking the other unrelated fields - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - - public ConfigModel getCloneConfigModel(@NotNull Long id) throws BluePrintException { - - ConfigModel configModel; - 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(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - - return cloneConfigModel; - } - - /** - * This is a deleteConfigModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - - @Transactional - 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(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index ff8b07a9..89af9e9a 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -24,8 +26,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.util.HashMap; import java.util.Map; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java deleted file mode 100644 index 60a83f9b..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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; - -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * ServiceTemplateService.java Purpose: Provide Service Template Create Service processing ServiceTemplateService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -public class ServiceTemplateService { - - private ResourceDictionaryRepository dataDictionaryRepository; - - private ConfigModelCreateService configModelCreateService; - private ResourceAssignmentValidationService resourceAssignmentValidationService; - - /** - * This is a SchemaGeneratorService constructor - * - * @param dataDictionaryRepository dataDictionaryRepository - * @param configModelCreateService configModelCreateService - * @param resourceAssignmentValidationService resourceAssignmentValidationService - */ - public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, - ConfigModelCreateService configModelCreateService, - ResourceAssignmentValidationService resourceAssignmentValidationService) { - this.dataDictionaryRepository = dataDictionaryRepository; - this.configModelCreateService = configModelCreateService; - this.resourceAssignmentValidationService = resourceAssignmentValidationService; - } - - /** - * This is a validateServiceTemplate method - * - * @param serviceTemplate serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - return this.configModelCreateService.validateServiceTemplate(serviceTemplate); - } - - /** - * This is a enrichServiceTemplate method - * - * @param serviceTemplate serviceTemplate - * @return ServiceTemplate - */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - //FIXME("Connect New Enrichment service") - return serviceTemplate; - } - - /** - * This is a autoMap method to map the template keys - * - * @param resourceAssignments resourceAssignments - * @return AutoMapResponse - * @throws BluePrintException BluePrintException - */ - public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { - AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository); - return autoMappingService.autoMap(resourceAssignments); - } - - /** - * This is a validateResourceAssignments method - * - * @param resourceAssignments resourceAssignments - * @return List - * @throws BluePrintException BluePrintException - */ - public List validateResourceAssignments(List resourceAssignments) - throws BluePrintException { - resourceAssignmentValidationService.validate(resourceAssignments); - return resourceAssignments; - } - - /** - * This is a generateResourceAssignments method - * - * @param templateContent templateContent - * @return List - */ - public List generateResourceAssignments(ConfigModelContent templateContent) { - List resourceAssignments = new ArrayList<>(); - if (templateContent != null && StringUtils.isNotBlank(templateContent.getContent())) { - Pattern p = Pattern.compile("(?<=\\$\\{)([^\\}]+)(?=\\})"); - Matcher m = p.matcher(templateContent.getContent()); - while (m.find()) { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(m.group()); - resourceAssignments.add(resourceAssignment); - } - } - return resourceAssignments; - } - -} 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 new file mode 100755 index 00000000..93954daa --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java @@ -0,0 +1,284 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.annotations.Proxy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * BlueprintModel.java Purpose: Provide Configuration Generator BlueprintModel Entity + * + * @author Brinda Santh + * @version 1.0 + */ + +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL") +@Proxy(lazy=false) +public class BlueprintModel implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "service_uuid") + private String serviceUUID; + + @Column(name = "distribution_id") + private String distributionId; + + @Column(name = "service_name") + private String serviceName; + + @Column(name = "service_description") + private String serviceDescription; + + @Column(name = "resource_uuid") + private String resourceUUID; + + @Column(name = "resource_instance_name") + private String resourceInstanceName; + + @Column(name = "resource_name") + private String resourceName; + + @Column(name = "resource_version") + private String resourceVersion; + + @Column(name = "resource_type") + private String resourceType; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + @ApiModelProperty(required=true) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + @ApiModelProperty(required=true) + private String artifactName; + + @Column(name = "published", nullable = false) + @ApiModelProperty(required=true) + private String published; + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required=true) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required=true) + private String tags; + + @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + private BlueprintModelContent blueprintModelContent; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceDescription() { + return serviceDescription; + } + + public void setServiceDescription(String serviceDescription) { + this.serviceDescription = serviceDescription; + } + + public String getResourceUUID() { + return resourceUUID; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public BlueprintModelContent getBlueprintModelContent() { + return blueprintModelContent; + } + + public void setBlueprintModelContent(BlueprintModelContent blueprintModelContent) { + this.blueprintModelContent = blueprintModelContent; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java new file mode 100644 index 00000000..0bfa0f12 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java @@ -0,0 +1,170 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL_CONTENT") +public class BlueprintModelContent implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_content_id") + private String id; + + @Column(name = "name", nullable = false) + @ApiModelProperty(required=true) + private String name; + + @Column(name = "content_type", nullable = false) + @ApiModelProperty(required=true) + private String contentType; + + @OneToOne + @JoinColumn(name = "config_model_id") + private BlueprintModel blueprintModel; + + @Lob + @Column(name = "description") + private String description; + + @Lob + @Column(name = "content", nullable = false) + @ApiModelProperty(required=true) + private byte[] content; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + private Date creationDate = new Date(); + + @Override + public String toString() { + return "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]"; + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + if (!(o instanceof BlueprintModelContent)) { + return false; + } + BlueprintModelContent blueprintModelContent = (BlueprintModelContent) o; + return Objects.equals(id, blueprintModelContent.id) && Objects.equals(name, blueprintModelContent.name) + && Objects.equals(contentType, blueprintModelContent.contentType); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, contentType); + } + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getContentType() { + return contentType; + } + + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + + public BlueprintModel getBlueprintModel() { + return blueprintModel; + } + + + public void setBlueprintModel(BlueprintModel blueprintModel) { + this.blueprintModel = blueprintModel; + } + + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public byte[] getContent() { + return content; + } + + + public void setContent(byte[] content) { + this.content = content; + } + + + public Date getCreationDate() { + return creationDate; + } + + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + +} 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 new file mode 100644 index 00000000..8b51bce3 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java @@ -0,0 +1,162 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.data.annotation.LastModifiedDate; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "CONFIG_MODEL") +public class BlueprintModelSearch implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + private String artifactName; + + @Column(name = "published", nullable = false) + private String published; + + @Column(name = "updated_by", nullable = false) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + private String tags; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java deleted file mode 100755 index 14ac6af1..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2018 IBM 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.domain; - -import com.fasterxml.jackson.annotation.JsonManagedReference; -import org.hibernate.annotations.Proxy; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * CbaContent.java Purpose: Provide Configuration Generator for CbaContent Entity - * - * @author Ruben Chang - * @version 1.0 - */ - -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CBA_CONTENT") -@Proxy(lazy=false) -public class CbaContent implements Serializable { - - private static final long serialVersionUID = 1L; - - public CbaContent() { - this.cbaUUID = UUID.randomUUID().toString(); - } - - @Id - @Column(name = "cba_uuid", nullable = false) - private String cbaUUID; - - @Lob - @Column(name = "cba_file") - private byte[] cbaFile; - - @Column(name = "cba_name") - private String cbaName; - - @Column(name = "cba_version") - private String cbaVersion; - - @Column(name = "cba_state") - private int cbaState; - - @Column(name="cba_description") - private String cbaDescription; - - @OneToMany(mappedBy = "configModelCBA", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @JsonManagedReference - private List models = new ArrayList<>(); - - public String getCbaUUID() { - return cbaUUID; - } - - public void setCbaUUID(String cbaUUID) { - this.cbaUUID = cbaUUID; - } - - public String getCbaName() { - return cbaName; - } - - public void setCbaName(String cbaName) { - this.cbaName = cbaName; - } - - public String getCbaVersion() { - return cbaVersion; - } - - public void setCbaVersion(String cbaVersion) { - this.cbaVersion = cbaVersion; - } - - public List getModels() { - return models; - } - - public void setModels(List models) { this.models = models; } - - public int getCbaState() { return cbaState; } - - public void setCbaState(int cbaState) { this.cbaState = cbaState; } - - public String getCbaDescription() { return cbaDescription; } - - public void setCbaDescription(String cbaDescription) { this.cbaDescription = cbaDescription; } - - public byte[] getCbaFile() { return cbaFile; } - - public void setCbaFile(byte[] cbaFile) { this.cbaFile = cbaFile; } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java deleted file mode 100755 index dea5757d..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonManagedReference; -import io.swagger.annotations.ApiModelProperty; -import org.hibernate.annotations.Proxy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * ConfigModel.java Purpose: Provide Configuration Generator ConfigModel Entity - * - * @author Brinda Santh - * @version 1.0 - */ - -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL") -@Proxy(lazy=false) -public class ConfigModel implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_id") - private Long id; - - @Column(name = "service_uuid") - private String serviceUUID; - - @Column(name = "distribution_id") - private String distributionId; - - @Column(name = "service_name") - private String serviceName; - - @Column(name = "service_description") - private String serviceDescription; - - @Column(name = "resource_uuid") - private String resourceUUID; - - @Column(name = "resource_instance_name") - private String resourceInstanceName; - - @Column(name = "resource_name") - private String resourceName; - - @Column(name = "resource_version") - private String resourceVersion; - - @Column(name = "resource_type") - private String resourceType; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - @ApiModelProperty(required=true) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - @ApiModelProperty(required=true) - private String artifactName; - - @Column(name = "published", nullable = false) - @ApiModelProperty(required=true) - private String published; - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required=true) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required=true) - private String tags; - - - @OneToMany(mappedBy = "configModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @JsonManagedReference - private List configModelContents = new ArrayList<>(); - - @ManyToOne - @JoinColumn(name = "cba_content_uuid") - private CbaContent configModelCBA; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getServiceUUID() { - return serviceUUID; - } - - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getDistributionId() { - return distributionId; - } - - public void setDistributionId(String distributionId) { - this.distributionId = distributionId; - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getServiceDescription() { - return serviceDescription; - } - - public void setServiceDescription(String serviceDescription) { - this.serviceDescription = serviceDescription; - } - - public String getResourceUUID() { - return resourceUUID; - } - - public void setResourceUUID(String resourceUUID) { - this.resourceUUID = resourceUUID; - } - - public String getResourceInstanceName() { - return resourceInstanceName; - } - - public void setResourceInstanceName(String resourceInstanceName) { - this.resourceInstanceName = resourceInstanceName; - } - - public String getResourceName() { - return resourceName; - } - - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - public String getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(String resourceVersion) { - this.resourceVersion = resourceVersion; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public List getConfigModelContents() { - return configModelContents; - } - - public void setConfigModelContents(List configModelContents) { - this.configModelContents = configModelContents; - } - - public CbaContent getConfigModelCBA() { - return configModelCBA; - } - - public void setConfigModelCBA(CbaContent configModelCBA) { - this.configModelCBA = configModelCBA; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java deleted file mode 100644 index 56135471..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.domain; - -import com.fasterxml.jackson.annotation.JsonBackReference; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.util.Date; -import java.util.Objects; - -/** - * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity - * - * @author Brinda Santh - * @version 1.0 - */ -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL_CONTENT") -public class ConfigModelContent { - - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_content_id") - private Long id; - - @Column(name = "name", nullable = false) - @ApiModelProperty(required=true) - private String name; - - @Column(name = "content_type", nullable = false) - @ApiModelProperty(required=true) - private String contentType; - - - @ManyToOne - @JoinColumn(name = "config_model_id") - @JsonBackReference - private ConfigModel configModel; - - @Lob - @Column(name = "description") - private String description; - - @Deprecated - @Lob - @Column(name = "content", nullable = false) - @ApiModelProperty(required=true) - private String content; - - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "updated_date") - private Date creationDate; - - @Override - public String toString() { - return "[" + "id = " + id + - ", name = " + name + - ", contentType = " + contentType + - "]"; - } - - @Override - public boolean equals(Object o) { - - if (o == this) { - return true; - } - if (!(o instanceof ConfigModelContent)) { - return false; - } - ConfigModelContent configModelContent = (ConfigModelContent) o; - return Objects.equals(id, configModelContent.id) && Objects.equals(name, configModelContent.name) - && Objects.equals(contentType, configModelContent.contentType); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, contentType); - } - - public Long getId() { - return id; - } - - - public void setId(Long id) { - this.id = id; - } - - - public String getName() { - return name; - } - - - public void setName(String name) { - this.name = name; - } - - - public String getContentType() { - return contentType; - } - - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - - public ConfigModel getConfigModel() { - return configModel; - } - - - public void setConfigModel(ConfigModel configModel) { - this.configModel = configModel; - } - - - public String getDescription() { - return description; - } - - - public void setDescription(String description) { - this.description = description; - } - - - public String getContent() { - return content; - } - - - public void setContent(String content) { - this.content = content; - } - - - public Date getCreationDate() { - return creationDate; - } - - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java deleted file mode 100644 index b6f0f001..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.data.annotation.LastModifiedDate; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -@Entity -@Table(name = "CONFIG_MODEL") -public class ConfigModelSearch implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_id") - private Long id; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - private String artifactName; - - @Column(name = "published", nullable = false) - private String published; - - @Column(name = "updated_by", nullable = false) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - private String tags; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public static long getSerialversionuid() { - return serialVersionUID; - } - - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java index 05f822d5..23d3a977 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -16,11 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; - import com.fasterxml.jackson.databind.JsonNode; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; /** * @author Brinda Santh */ diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java deleted file mode 100755 index 1b67ed82..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.model; - -/** - * BlueprintModelResponse.java Purpose: Model response for Upload CBA service - * - */ -public class BlueprintModelResponse { - private Long id; - private String name; - private String version; - private String description; - private String cbaUUID; - - public BlueprintModelResponse(Long id, String name, String version, String description, String cbaUUID) { - this.id = id; - this.name = name; - this.version = version; - this.description = description; - this.cbaUUID = cbaUUID; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCbaUUID() { - return cbaUUID; - } - - public void setCbaUUID(String cbaUUID) { - this.cbaUUID = cbaUUID; - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java deleted file mode 100755 index 0752df9b..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.model; - -/** - * CLass that would represent the response for the GET methods on the CBAService class - */ -public class ItemCbaResponse { - - private String id; - private String description; - private String name; - private int state; - private String version; - - public ItemCbaResponse() { - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java new file mode 100644 index 00000000..7940c944 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java @@ -0,0 +1,102 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * BlueprintModelContentRepository.java Purpose: Provide BlueprintModelContentRepository of Repository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelContentRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findTopByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional + */ + @SuppressWarnings("unused") + Optional findTopByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional + */ + @SuppressWarnings("unused") + List findByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel blueprintModel + * @return Optional + */ + @SuppressWarnings("unused") + List findByBlueprintModel(BlueprintModel blueprintModel); + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return Optional + */ + @SuppressWarnings("unused") + Optional findByBlueprintModelAndContentTypeAndName(BlueprintModel blueprintModel, + String contentType, String name); + + /** + * This is a deleteByMdeleteByBlueprintModelodelName method + * + * @param blueprintModel blueprintModel + */ + void deleteByBlueprintModel(BlueprintModel blueprintModel); + + /** + * This is a deleteById method + * + * @param id id + */ + void deleteById(@NotNull String id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java new file mode 100644 index 00000000..41316049 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java @@ -0,0 +1,96 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelRepository extends JpaRepository { + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return Optional + */ + Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return Optional + */ + @SuppressWarnings("unused") + List findTopByArtifactName(String artifactName); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + */ + @SuppressWarnings("unused") + void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a deleteById method + * + * @param id id + */ + @SuppressWarnings("unused") + void deleteById(@NotNull String id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java new file mode 100644 index 00000000..ed863563 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * BlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelSearchRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findAll method + * @return List + */ + @Override + List findAll(); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java deleted file mode 100755 index 273a19d6..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2018 IBM 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.repository; - -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * CBAContentRepository.java Purpose: Provide Configuration Generator CRUD methods for CBAContent table - * - * @author Ruben Chang - * @version 1.0 - */ -@Repository -public interface CBAContentRepository extends JpaRepository { - - /** - * This is a findAll method - * @return List - */ - @Override - List findAll(); - - /** - * Returns a CbaContent based on the cbaUUID - * @param cbaUUID the CbaUUID - * @return Optional - */ - @Override - @NotNull - Optional findById(@NotNull String cbaUUID); - - /** - * This is a deleteById methid - * @param cbaUUID the user ID for a particular CBAFile - */ - @Override - void deleteById(@NotNull String cbaUUID); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java deleted file mode 100644 index 81c26373..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * ConfigModelContentRepository.java Purpose: Provide ConfigModelContentRepository of Repository - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Repository -public interface ConfigModelContentRepository extends JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull Long id); - - /** - * This is a findTopByConfigModelAndContentType method - * - * @param configModel configModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - Optional findTopByConfigModelAndContentType(ConfigModel configModel, String contentType); - - /** - * This is a findByConfigModelAndContentType method - * - * @param configModel configModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - List findByConfigModelAndContentType(ConfigModel configModel, String contentType); - - /** - * This is a findByConfigModel method - * - * @param configModel configModel - * @return Optional - */ - @SuppressWarnings("unused") - List findByConfigModel(ConfigModel configModel); - - /** - * This is a findByConfigModelAndContentTypeAndName method - * - * @param configModel configModel - * @param contentType contentType - * @param name name - * @return Optional - */ - @SuppressWarnings("unused") - Optional findByConfigModelAndContentTypeAndName(ConfigModel configModel, - String contentType, String name); - - /** - * This is a deleteByMdeleteByConfigModelodelName method - * - * @param configModel configModel - */ - void deleteByConfigModel(ConfigModel configModel); - - /** - * This is a deleteById method - * - * @param id id - */ - void deleteById(@NotNull Long id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java deleted file mode 100644 index 0a60ab74..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ConfigModelRepository extends JpaRepository { - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull Long id); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findTopByArtifactNameOrderByArtifactIdDesc method - * - * @param artifactName artifactName - * @return Optional - */ - Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); - - /** - * This is a findTopByArtifactName method - * - * @param artifactName artifactName - * @return Optional - */ - @SuppressWarnings("unused") - List findTopByArtifactName(String artifactName); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - */ - @SuppressWarnings("unused") - void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a deleteById method - * - * @param id id - */ - @SuppressWarnings("unused") - void deleteById(@NotNull Long id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java deleted file mode 100644 index bafc3aa8..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * ConfigModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ConfigModelSearchRepository extends JpaRepository { - - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); -} 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 new file mode 100644 index 00000000..9d0b1e3e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@RestController +@RequestMapping(value = "/api/v1/blueprint-model") +public class BlueprintModelRest { + + @Autowired + private BlueprintModelService blueprintModelService; + + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public @ResponseBody + Mono saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{ + return blueprintModelService.saveBlueprintModel(file); + } + + @DeleteMapping(path = "/{id}") + 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); + } + + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.getBlueprintModelSearch(id); + } + + @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + List getAllCBA() { + return this.blueprintModelService.getAllBlueprintModel(); + } + + @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResponseEntity downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.downloadBlueprintModelFile(id); + } + + @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.publishBlueprintModel(id); + } + + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + List searchBlueprintModels(@PathVariable(value = "tags") String tags) { + return this.blueprintModelService.searchBlueprintModels(tags); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java deleted file mode 100755 index 4608b175..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.CbaService; -import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.http.codec.multipart.Part; -import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Flux; - -import java.util.List; - -/** - * CbaRest.java Purpose: Provide a REST API to upload single and multiple CBA - * - * @author Steve Siani - * @version 1.0 - */ -@RestController -@RequestMapping(value = "/api/v1/cba") -public class CbaRest { - - @Autowired - private CbaService cbaService; - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public Flux uploadCBA(@RequestBody Flux parts) { - return parts.filter(part -> part instanceof FilePart) // only retain file parts - .ofType(FilePart.class) // convert the flux to FilePart - .flatMap(filePart -> cbaService.uploadCBAFile(filePart)); // save each file and flatmap it to a flux of results - } - - @DeleteMapping(path = "/{id}") - public void deleteCBA(@PathVariable(value = "id") Long id) throws BluePrintException { - this.cbaService.deleteCBA(id); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ItemCbaResponse getCBA(@PathVariable(value = "id") String id) { - return this.cbaService.findCBAByID(id); - } - - @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List getAllCBA() { - return this.cbaService.findAllCBA(); - } - - @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ItemCbaResponse getCBAByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.cbaService.findCBAByNameAndVersion(name, version); - } - - @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResponseEntity downloadCBA(@PathVariable(value = "id") String id) { - return this.cbaService.downloadCBAFile(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 deleted file mode 100644 index b025b2ff..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/config-model") -public class ConfigModelRest { - - private ConfigModelService configModelService; - - /** - * This is a ConfigModelRest constructor. - * - * @param configModelService Config Model Service - */ - public ConfigModelRest(ConfigModelService configModelService) { - this.configModelService = configModelService; - - } - - @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { - return this.configModelService.getInitialConfigModel(name); - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { - return this.configModelService.saveConfigModel(configModel); - } - - @DeleteMapping(path = "/{id}") - public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - this.configModelService.deleteConfigModel(id); - } - - @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - return this.configModelService.publishConfigModel(id); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - 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 { - return this.configModelService.getConfigModelByNameAndVersion(name, version); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchConfigModels(@PathVariable(value = "tags") String tags) { - 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 { - 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 deleted file mode 100644 index 12ed0a57..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ModelTypeHandler; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -//@RestController -//@RequestMapping(value = "/api/v1/model-type") -public class ModelTypeRest { - - private ModelTypeHandler modelTypeService; - - /** - * This is a ModelTypeResourceImpl, used to save and get the model types stored in database - * - * @param modelTypeService Model Type Service - */ - public ModelTypeRest(ModelTypeHandler modelTypeService) { - this.modelTypeService = modelTypeService; - } - - @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public ModelType getModelTypeByName(@PathVariable(value = "name") String name) { - return modelTypeService.getModelTypeByName(name); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public List searchModelTypes(@PathVariable(value = "tags") String tags) { - return modelTypeService.searchModelTypes(tags); - } - - @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) { - return modelTypeService.getModelTypeByDefinitionType(definitionType); - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { - return modelTypeService.saveModel(modelType); - } - - @DeleteMapping(path = "/{name}") - public void deleteModelTypeByName(@PathVariable(value = "name") String name) { - modelTypeService.deleteByModelName(name); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java deleted file mode 100644 index 4c34881a..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.rs; - - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/service-template") -public class ServiceTemplateRest { - - private ServiceTemplateService serviceTemplateService; - - /** - * This is a ServiceTemplateRest constructor - * - * @param serviceTemplateService Service Template Service - */ - public ServiceTemplateRest(ServiceTemplateService serviceTemplateService) { - this.serviceTemplateService = serviceTemplateService; - } - - @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - return serviceTemplateService.enrichServiceTemplate(serviceTemplate); - } - - @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - return serviceTemplateService.validateServiceTemplate(serviceTemplate); - } - - @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { - return serviceTemplateService.autoMap(resourceAssignments); - } - - @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List validateResourceAssignments(@RequestBody List resourceAssignments) - throws BluePrintException { - return serviceTemplateService.validateResourceAssignments(resourceAssignments); - } - - @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) { - return serviceTemplateService.generateResourceAssignments(templateContent); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java deleted file mode 100755 index 57785dd8..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.utils; - -public enum CbaStateEnum { - - DRAFT(0), VALIDATED(1), APPROVED(2); - int state; - - CbaStateEnum(int state) { - this.state = state; - } - - public int getState() { - return state; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java deleted file mode 100755 index d7b4aa93..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.utils; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -public class CloseCondition { - - AtomicInteger tasksSubmitted = new AtomicInteger(0); - AtomicInteger tasksCompleted = new AtomicInteger(0); - AtomicBoolean allTaskssubmitted = new AtomicBoolean(false); - - /** - * notify all tasks have been subitted, determine of the file channel can be closed - * @return true if the asynchronous file stream can be closed - */ - public boolean canCloseOnComplete() { - allTaskssubmitted.set(true); - return tasksCompleted.get() == tasksSubmitted.get(); - } - - /** - * notify a task has been submitted - */ - public void onTaskSubmitted() { - tasksSubmitted.incrementAndGet(); - } - - /** - * notify a task has been completed - * @return true if the asynchronous file stream can be closed - */ - public boolean onTaskCompleted() { - boolean allSubmittedClosed = tasksSubmitted.get() == tasksCompleted.incrementAndGet(); - return allSubmittedClosed && allTaskssubmitted.get(); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java deleted file mode 100644 index 96931014..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.utils; - -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Deprecated -public class ConfigModelUtils { - - private ConfigModelUtils() { - - } - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelUtils.class); - - public static ConfigModel getConfigModel(String blueprintPath) throws Exception { - Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); - ToscaMetaData toscaMetaData = BluePrintMetadataUtils.Companion.toscaMetaData(blueprintPath); - - Preconditions.checkNotNull(toscaMetaData, "failed to get Blueprint Metadata information"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getEntityDefinitions()), "failed to get Blueprint Definition file"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getCreatedBy()), "failed to get Blueprint created by"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getToscaMetaFileVersion()), "failed to get Blueprint package version"); - - String bluePrintName = FilenameUtils.getBaseName(toscaMetaData.getEntityDefinitions()); - Preconditions.checkArgument(StringUtils.isNotBlank(bluePrintName), "failed to get Blueprint Definition Name"); - - // TODO - Update Rest of the Model - ConfigModel configModel = new ConfigModel(); - configModel.setUpdatedBy(toscaMetaData.getCreatedBy()); - configModel.setArtifactName(bluePrintName); - configModel.setArtifactVersion(toscaMetaData.getToscaMetaFileVersion()); - configModel.setTags(toscaMetaData.getTemplateTags()); - configModel.setArtifactType("SDNC_MODEL"); - - String blueprintContent = - getPathContent(blueprintPath + "/" + toscaMetaData.getEntityDefinitions()); - - Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "failed to get Blueprint content"); - - List configModelContents = new ArrayList<>(); - ConfigModelContent stConfigModelContent = new ConfigModelContent(); - stConfigModelContent.setName(configModel.getArtifactName()); - stConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - stConfigModelContent.setContent(blueprintContent); - configModelContents.add(stConfigModelContent); - - String velocityDir = blueprintPath + "/Templates"; - List velocityTemplateFiles = getFileOfExtension(velocityDir, new String[]{"vtl"}); - - if (CollectionUtils.isNotEmpty(velocityTemplateFiles)) { - for (File velocityTemplateFile : velocityTemplateFiles) { - if (velocityTemplateFile != null) { - String contentName = velocityTemplateFile.getName().replace(".vtl", ""); - ConfigModelContent velocityConfigModelContent = new ConfigModelContent(); - String velocityConfigContent = getPathContent(velocityTemplateFile); - velocityConfigModelContent.setName(contentName); - velocityConfigModelContent - .setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - velocityConfigModelContent.setContent(velocityConfigContent); - configModelContents.add(velocityConfigModelContent); - log.info("Loaded blueprint template successfully: {}", velocityTemplateFile.getName()); - } - } - } - configModel.setConfigModelContents(configModelContents); - - return configModel; - - } - - public static String getPathContent(String path) throws IOException { - Preconditions.checkArgument(StringUtils.isNotBlank(path), "Path is missing"); - return FileUtils.readFileToString(new File(path), Charset.defaultCharset()); - } - - public static String getPathContent(File file) throws IOException { - Preconditions.checkNotNull(file, "File is missing"); - return FileUtils.readFileToString(file, Charset.defaultCharset()); - } - - public static List getFileOfExtension(String basePath, String[] extensions) { - Preconditions.checkArgument(StringUtils.isNotBlank(basePath), "Path is missing"); - Preconditions.checkNotNull(extensions, "Extensions is missing"); - return (List) FileUtils.listFiles(new File(basePath), extensions, true); - } - - public static List getBlueprintNames(String pathName) { - File blueprintDir = new File(pathName); - Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); - String[] dirs = blueprintDir.list(DirectoryFileFilter.INSTANCE); - Preconditions.checkNotNull(dirs, "failed to find the blueprint directories" + blueprintDir.getAbsolutePath()); - return Arrays.asList(dirs); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java index c5e9e86f..6d02544e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; import java.util.HashMap; import java.util.List; diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt index 7a9fbb67..80a84fcd 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.PolicyType import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService 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 07ee0a9b..d49bcdff 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) + bluePrintCatalogService.uploadToDataBase(file.absolutePath, true) } 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/BluePrintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt old mode 100644 new mode 100755 index 8cddbb4c..761dd25a --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,39 +17,59 @@ package org.onap.ccsdk.apps.controllerblueprints.service.load +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService 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.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants +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.BlueprintModelContentRepository +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelRepository import org.springframework.stereotype.Service import java.io.File -import java.util.* +import java.nio.file.Files @Service class BluePrintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val bluePrintValidatorService: BluePrintValidatorService) : BluePrintCatalogService { + private val bluePrintValidatorService: BluePrintValidatorService, + private val blueprintModelContentRepository: BlueprintModelContentRepository, + private val blueprintModelRepository: BlueprintModelRepository) : BluePrintCatalogService { - override fun uploadToDataBase(file: String): String { - val id = UUID.randomUUID().toString() + override fun uploadToDataBase(file: String, validate: Boolean): String { + // The file name provided here is unique as we transform to UUID before storing val blueprintFile = File(file) + val fileName = blueprintFile.name + val id = BluePrintFileUtils.stripFileExtension(fileName) // If the file is directory if (blueprintFile.isDirectory) { - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintFile.absolutePath) - val valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService) - if (valid) { - val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/${id}.zip") - // zip the directory - BluePrintArchiveUtils.compress(blueprintFile, zipFile, true) - - // TODO(Upload to the Data Base) - - // After Upload to Database delete the zip file - zipFile.deleteOnExit() - } + + val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/$fileName") + // zip the directory + BluePrintArchiveUtils.compress(blueprintFile, zipFile, true) + + // Upload to the Data Base + saveToDataBase(blueprintFile, id, zipFile) + + // After Upload to Database delete the zip file + zipFile.delete() + } else { // If the file is ZIP - // TODO(Upload to the Data Base) + // unzip the CBA file to validate before store in database + val targetDir = "${bluePrintLoadConfiguration.blueprintDeployPath}/$id/" + val extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir) + + // Upload to the Data Base + saveToDataBase(extractedDirectory, id, blueprintFile) + + // After Upload to Database delete the zip file + blueprintFile.delete() + extractedDirectory.delete() } + return id } @@ -58,9 +79,57 @@ class BluePrintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePr TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } + override fun downloadFromDataBase(uuid: String, path: String): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + override fun prepareBluePrint(name: String, version: String): String { val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version" downloadFromDataBase(name, version, preparedPath) return preparedPath } + + private fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean? = false) { + // Upload to the Data Base + //val id = "save-$uuid" + 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) + } + + 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}" + + 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()) + + // Set the Blueprint Model into blueprintModelContent + blueprintModelContent.blueprintModel = blueprintModel + + // Set the Blueprint Model Content into blueprintModel + blueprintModel.blueprintModelContent = blueprintModelContent + + blueprintModelRepository.saveAndFlush(blueprintModel) + } + } } \ 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 801c22a1..2f18abfd 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 @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,13 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.StringUtils +import reactor.core.publisher.Mono +import java.io.File +import java.io.IOException +import java.nio.file.Path +import java.util.* class BluePrintEnhancerUtils { @@ -57,5 +65,40 @@ class BluePrintEnhancerUtils { bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) return artifactType } + + /** + * This is a saveCBAFile method + * take a [FilePart], transfer it to disk using a Flux of FilePart and return a [Mono] representing the CBA file name + * + * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save + * @return a [Mono] String representing the result of the operation + * @throws (BluePrintException, IOException) BluePrintException, IOException + */ + @Throws(BluePrintException::class, IOException::class) + fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Mono { + + // Normalize file name + val fileName = StringUtils.cleanPath(filePart.filename()) + + // Check if the file's extension is "CBA" + if (StringUtils.getFilenameExtension(fileName) != "zip") { + throw BluePrintException("Invalid file extension required ZIP") + } + + // Change file name to match a pattern + val changedFileName = UUID.randomUUID().toString() + ".zip" + //String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); + + // Copy file to the target location (Replacing existing file with the same name) + val targetLocation = targetDirectory.resolve(changedFileName) + + // if a file with the same name already exists in a repository, delete and recreate it + val file = File(targetLocation.toString()) + if (file.exists()) + file.delete() + file.createNewFile() + + return filePart.transferTo(file).thenReturn(changedFileName) + } } } diff --git a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql index 47e0cce7..ad5fdd05 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql +++ b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql @@ -7,7 +7,7 @@ -- table CONFIG_MODEL -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS sdnctl.CONFIG_MODEL ( - config_model_id INT(11) NOT NULL AUTO_INCREMENT, + config_model_id VARCHAR(100) NOT NULL, service_uuid VARCHAR(50) NULL DEFAULT NULL, distribution_id VARCHAR(50) NULL DEFAULT NULL, service_name VARCHAR(255) NULL DEFAULT NULL, @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS sdnctl.CONFIG_MODEL ( -- table CONFIG_MODEL_CONTENT -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS sdnctl.CONFIG_MODEL_CONTENT ( - config_model_content_id INT(11) NOT NULL AUTO_INCREMENT, + config_model_content_id VARCHAR(100) NOT NULL, config_model_id INT NOT NULL, name VARCHAR(100) NOT NULL, content_type VARCHAR(50) NOT NULL, diff --git a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql index 9c38bec0..015b03b3 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql +++ b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql @@ -2,7 +2,7 @@ -- table CONFIG_MODEL -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS configurator.CONFIG_MODEL ( - config_model_id INT(11) NOT NULL AUTO_INCREMENT, + config_model_id VARCHAR(100) NOT NULL, service_uuid VARCHAR(50) NULL DEFAULT NULL, distribution_id VARCHAR(50) NULL DEFAULT NULL, service_name VARCHAR(255) NULL DEFAULT NULL, @@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS configurator.CONFIG_MODEL ( -- table CONFIG_MODEL_CONTENT -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS configurator.CONFIG_MODEL_CONTENT ( - config_model_content_id INT(11) NOT NULL AUTO_INCREMENT, + config_model_content_id VARCHAR(100) NOT NULL, config_model_id INT NOT NULL, name VARCHAR(100) NOT NULL, content_type VARCHAR(50) NOT NULL, diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java new file mode 100644 index 00000000..0ce93b18 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelServiceTest.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2018 IBM. + * + * 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; + +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.springframework.beans.factory.annotation.Autowired; + +public class BlueprintModelServiceTest { + @Autowired + private BlueprintModelService blueprintModelService; + + @Test + public void testGetInitialConfigModel() throws BluePrintException { + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java deleted file mode 100755 index e3cea380..00000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementServiceTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright © 2018 IBM Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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; -import org.junit.*; -import org.junit.runner.RunWith; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.FileSystemUtils; -import java.nio.file.Path; - - -/** - * CbaFileManagementServiceTest.java Purpose: Test the decompressing method of CbaCompressionService - * - * @author Vinal Patel - * @version 1.0 - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class}) -public class CbaFileManagementServiceTest { - - @Value("${controllerblueprints.loadBlueprintsExamplesPath}") - private String cbaPath; - private String zipfile; - private String directorypath; - private Path zipfilepath; - - @Autowired - CbaFileManagementService cbaCompressionService; - - - /** - * - */ - @Before - public void setUp() { - try { - zipfilepath = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaPath); - } catch (Exception e) { - e.printStackTrace(); - } - zipfile = "CBA_Zip_Test.zip"; - directorypath = zipfilepath.resolve(zipfile.substring(0,zipfile.lastIndexOf("."))).toAbsolutePath().toString(); - } - @After - public void clenup() throws BluePrintException { - - try { - //Delete the Zip file from the repository - FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(directorypath, zipfilepath)); - } - catch (Exception ex){ - throw new BluePrintException("Fail while cleaning up CBA saved!", ex); - } - } - - /** - * @throws BluePrintException - * Test will get success if it is able to decompress CBA file and returns the folder path - */ - @Test - public void testDecompressCBAFile_success() throws BluePrintException { - Assert.assertEquals(directorypath,cbaCompressionService.decompressCBAFile(zipfile,zipfilepath)); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelServiceTest.java deleted file mode 100644 index d6a71e01..00000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelServiceTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * 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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.lang.System; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; - -public class ConfigModelServiceTest { - private ConfigModelService configModelService; - - @Test(expected = NullPointerException.class) - public void testGetInitialConfigModel() throws BluePrintException { - Assert.assertEquals(null, configModelService.getInitialConfigModel("")); - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java index e2bb4c5f..412e9606 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java @@ -18,7 +18,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.junit.*; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java index b70651fb..ed208db9 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java @@ -16,14 +16,14 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.service.SchemaGeneratorService; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.io.File; import java.nio.charset.Charset; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java deleted file mode 100644 index 6be86fc3..00000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T 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.rs; - -import org.junit.*; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ConfigModelRestTest { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelRestTest.class); - - @Autowired - ConfigModelRest configModelRest; - - ConfigModel configModel; - - String name = "vrr-test"; - String version = "1.0.0"; - - @Before - public void setUp() { - - } - - - @After - public void tearDown() { - } - - - @Test - public void test01getInitialConfigModel() throws Exception { - log.info("** test01getInitialConfigModel *****************"); - - String name = "default_netconf"; - ConfigModel configModel = configModelRest.getInitialConfigModel(name); - Assert.assertNotNull("Failed to get Initial Config Model , Return object is Null", configModel); - Assert.assertNotNull("Failed to get Service Template Content ", configModel.getConfigModelContents()); - } - - - @Deprecated - @Test - public void test02SaveServiceTemplate() throws Exception { - log.info("************************ test02SaveServiceTemplate ******************"); - - - configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test"); - - configModel = configModelRest.saveConfigModel(configModel); - Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); - Assert.assertNotNull("Failed to ConfigModel Id , Return ID object is Null", configModel.getId()); - Assert.assertNotNull("Failed to ConfigModel Content, Return object is Null", - configModel.getConfigModelContents()); - Assert.assertEquals("Failed in validation of ConfigModel Content count,", 3, - configModel.getConfigModelContents().size()); - - ConfigModel dbconfigModel = configModelRest.getConfigModel(configModel.getId()); - - log.info("************************ test02SaveServiceTemplate-2 ******************"); - - dbconfigModel.getConfigModelContents().remove(2); - dbconfigModel = configModelRest.saveConfigModel(dbconfigModel); - log.info("Saved Config Model " + configModel.getId()); - Assert.assertNotNull("Failed to ConfigModel, Return object is Null", dbconfigModel); - Assert.assertNotNull("Failed to ConfigModel Id ", dbconfigModel.getId()); - Assert.assertNotNull("Failed to ConfigModel Content", - dbconfigModel.getConfigModelContents()); - Assert.assertEquals("Failed to Remove the ConfigModel Content,", 2, - dbconfigModel.getConfigModelContents().size()); - - - } - - - @Test - public void test03PublishServiceTemplate() throws Exception { - log.info("** test03PublishServiceTemplate *****************"); - - ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); - log.info("Publishing Config Model " + configModel.getId()); - configModel = configModelRest.publishConfigModel(configModel.getId()); - Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); - Assert.assertNotNull("Failed to ConfigModel Id ", configModel.getId()); - Assert.assertNotNull("Failed to ConfigModel Content", configModel.getConfigModelContents()); - Assert.assertEquals("Failed to update the publish indicator", "Y", configModel.getPublished()); - } - - - @Deprecated - @Test - public void test04GetConfigModel() throws Exception { - log.info("** test04GetConfigModel *****************"); - - ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); - Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" - + configModel.getArtifactVersion() + ")", configModel); - Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); - - configModel = configModelRest.getConfigModel(configModel.getId()); - Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); - - } - - @Deprecated - @Test - public void test05GetCloneConfigModel() throws Exception { - log.info("** test05GetCloneConfigModel *****************"); - - ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); - - Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" - + configModel.getArtifactVersion() + ")", configModel); - Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); - - configModel = configModelRest.getCloneConfigModel(configModel.getId()); - Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); - } - - - @Test - public void test07SearchConfigModels() throws Exception { - log.info("** test07SearchConfigModels *****************"); - - List configModels = configModelRest.searchConfigModels("vrr-test"); - Assert.assertNotNull("Failed to search ConfigModel", configModels); - Assert.assertTrue("Failed to search ConfigModel with count", configModels.size() > 0); - // update the ServiceModelContent - } - - - @Test - public void test08DeleteConfigModels() throws Exception { - log.info("** test08DeleteConfigModels *****************"); - - ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); - configModelRest.deleteConfigModel(configModel.getId()); - - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java index d283377b..bf5db340 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java @@ -19,7 +19,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.junit.*; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java deleted file mode 100644 index 3818ae2e..00000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.rs; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.beans.factory.annotation.Autowired; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -@Deprecated -//@RunWith(SpringRunner.class) -//@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"}) -//@ContextConfiguration(classes = {TestApplication.class}) -//@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ResourceDictionaryRestTest { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryRestTest.class); - - @Autowired - protected ResourceDictionaryRest resourceDictionaryRest; - - //@Test - public void test01SaveDataDictionary() throws Exception { - String definition = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("resourcedictionary/default_definition.json"), - Charset.defaultCharset()); - - ResourceDictionary dataDictionary = new ResourceDictionary(); - dataDictionary.setName("test-name"); - dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class)); - dataDictionary.setDataType("string"); - dataDictionary.setDescription("Sample Resource Mapping"); - dataDictionary.setTags("test, ipaddress"); - dataDictionary.setUpdatedBy("xxxxxx@xxx.com"); - - dataDictionary = resourceDictionaryRest.saveResourceDictionary(dataDictionary); - - Assert.assertNotNull("Failed to get Saved Resource Dictionary", dataDictionary); - Assert.assertNotNull("Failed to get Saved Resource Dictionary, Id", dataDictionary.getName()); - - ResourceDictionary dbDataDictionary = - resourceDictionaryRest.getResourceDictionaryByName(dataDictionary.getName()); - Assert.assertNotNull("Failed to query Resource Dictionary for ID (" + dataDictionary.getName() + ")", - dbDataDictionary); - Assert.assertNotNull("Failed to query Resource Dictionary definition for ID (" + dataDictionary.getName() + ")", - dbDataDictionary.getDefinition()); - - log.trace("Saved Dictionary " + dbDataDictionary.getDefinition()); - - } - - //@Test - public void test02GetDataDictionary() throws Exception { - - ResourceDictionary dbResourceDictionary = resourceDictionaryRest.getResourceDictionaryByName("test-name"); - Assert.assertNotNull("Failed to query Resource Dictionary by Name", dbResourceDictionary); - - String tags = "ipaddress"; - - List dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByTags(tags); - Assert.assertNotNull("Failed to search ResourceDictionary by tags", dbResourceDictionaries); - Assert.assertTrue("Failed to search searchResourceDictionaryByTags by tags by count", - dbResourceDictionaries.size() > 0); - - List names = new ArrayList<>(); - names.add("test-name"); - dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByNames(names); - Assert.assertNotNull("Failed to search ResourceDictionary by Names", dbResourceDictionaries); - Assert.assertTrue("Failed to search searchResourceDictionaryByNames by tags by count", - dbResourceDictionaries.size() > 0); - - } - - //@Test - public void test03GetResourceSourceMapping() { - ResourceSourceMapping resourceSourceMapping = resourceDictionaryRest.getResourceSourceMapping(); - org.springframework.util.Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); - org.springframework.util.Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings"); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java deleted file mode 100644 index 9c02d4cf..00000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.rs; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.controller.ModelTypeController; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; - -@Deprecated -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"}) -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ServiceTemplateRestTest { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateRestTest.class); - @Autowired - ModelTypeController modelTypeRest; - - @Autowired - private ServiceTemplateRest serviceTemplateRest; - - //@Test FIXME("Enable once Complete Enhancement Service Implemented") - public void test02EnrichServiceTemplate() throws Exception { - log.info("*********** test02EnrichServiceTemplate ***********************"); - String file = "src/test/resources/enhance/enhance-template.json"; - - String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); - - ServiceTemplate serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - - serviceTemplate = serviceTemplateRest.enrichServiceTemplate(serviceTemplate); - - String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; - - FileUtils.write(new File(enhancedFile), - JacksonUtils.getJson(serviceTemplate, true), Charset.defaultCharset()); - - Assert.assertNotNull("Failed to get Enriched Blueprints, Return object is Null", serviceTemplate); - Assert.assertNotNull("Failed to get Enriched Blueprints Data Type, Return object is Null", - serviceTemplate.getDataTypes()); - Assert.assertNotNull("Failed to get Enriched Blueprints Node Type, Return object is Null", - serviceTemplate.getNodeTypes()); - log.trace("Enriched Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); - } - - //@Test FIXME("Enable once Complete Enhancement Service Implemented") - public void test03ValidateServiceTemplate() throws Exception { - log.info("*********** test03ValidateServiceTemplate *******************************************"); - String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; - String serviceTemplateContent = FileUtils.readFileToString(new File(enhancedFile), Charset.defaultCharset()); - - ServiceTemplate serviceTemplate = - JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - - serviceTemplate = serviceTemplateRest.validateServiceTemplate(serviceTemplate); - - Assert.assertNotNull("Failed to validate Service Template, Return object is Null", serviceTemplate); - Assert.assertNotNull("Failed to get Service Template Data Type, Return object is Null", - serviceTemplate.getDataTypes()); - Assert.assertNotNull("Failed to get Service Template Node Type, Return object is Null", - serviceTemplate.getNodeTypes()); - - log.trace("Validated Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); - - } - - - @Test - public void test04GenerateResourceAssignments() throws Exception { - log.info("*********** test04GenerateResourceAssignments *******************************************"); - ConfigModelContent baseConfigConfigModelContent = new ConfigModelContent(); - String baseConfigContent = FileUtils.readFileToString(new File("load/blueprints/vrr-test/Templates/base-config-template.vtl") - , Charset.defaultCharset()); - baseConfigConfigModelContent.setName("base-config-template"); - baseConfigConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - baseConfigConfigModelContent.setContent(baseConfigContent); - - List resourceAssignments = - serviceTemplateRest.generateResourceAssignments(baseConfigConfigModelContent); - - Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", resourceAssignments); - Assert.assertTrue("Failed to get ResourceAssignments count", resourceAssignments.size() > 0); - - log.trace("Validated Service Template :\n" + JacksonUtils.getJson(resourceAssignments, true)); - - - } - - //@Test - public void test05AutoMap() throws Exception { - log.info("*********** test05AutoMap *******************************************"); - - String resourceAssignmentContent = FileUtils.readFileToString( - new File("src/test/resources/resourcedictionary/automap.json"), Charset.defaultCharset()); - List batchResourceAssignment = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); - AutoMapResponse autoMapResponse = serviceTemplateRest.autoMap(batchResourceAssignment); - - Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", - autoMapResponse.getResourceAssignments()); - Assert.assertNotNull("Failed to get Data Dictionary from ResourceAssignments", - autoMapResponse.getDataDictionaries()); - Assert.assertTrue("Failed to get ResourceAssignments count", - CollectionUtils.isNotEmpty(autoMapResponse.getDataDictionaries())); - - List autoMappedResourceAssignment = autoMapResponse.getResourceAssignments(); - autoMappedResourceAssignment.forEach(resourceAssignment -> { - if ("sample-db-source".equals(resourceAssignment.getName())) { - Assert.assertEquals("Failed to assign default first source", "db", - resourceAssignment.getDictionarySource()); - } - }); - - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.java index a5eb661a..16b2bc81 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.java @@ -16,14 +16,12 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; -import static org.junit.Assert.*; - -import org.junit.*; -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ModelTypeValidator; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; - import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; public class ModelTypeValidatorTest { -- cgit 1.2.3-korg