diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-03-02 14:42:45 +0000 |
---|---|---|
committer | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-03-10 17:32:30 +0000 |
commit | 0606cf6d6dd2cd4630f4cdd14e2e1eee626ca377 (patch) | |
tree | fbf0ee90a49cc23ac3a65d325afb15e6c2613182 /catalog-be/src/main/java | |
parent | 86c6a41b4ecf80b9edf554120ddebf572599c679 (diff) |
Support for delete of non normative interface types
Issue-ID: SDC-4423
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: Ic41a8d0e792f4f0c6effd7eb6c9bd74887a0506c
Diffstat (limited to 'catalog-be/src/main/java')
2 files changed, 114 insertions, 13 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java index b371a8c18d..49b1b741cd 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java @@ -17,8 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.openecomp.sdc.be.components.impl; +import fj.data.Either; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -30,9 +32,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.annotation.Resource; - import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -50,8 +50,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Component; -import fj.data.Either; - @Component("interfaceLifecycleTypeImportManager") public class InterfaceLifecycleTypeImportManager { @@ -67,7 +65,8 @@ public class InterfaceLifecycleTypeImportManager { public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName, final boolean includeToModelDefaultImports) { - Either<List<InterfaceDefinition>, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml, modelName); + Either<List<InterfaceDefinition>, ActionStatus> interfaces = + createInterfaceTypeFromYml(interfaceLifecycleTypesYml, modelName, !includeToModelDefaultImports); if (interfaces.isRight()) { ActionStatus status = interfaces.right().value(); ResponseFormat responseFormat = componentsUtils.getResponseFormatByGroupType(status, null); @@ -80,17 +79,28 @@ public class InterfaceLifecycleTypeImportManager { return elementTypes; } - private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName) { - final Either<List<InterfaceDefinition>, ActionStatus> interfaceTypes = commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition); - if (interfaceTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ + private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName, + final boolean normative) { + final Either<List<InterfaceDefinition>, ActionStatus> interfaceTypesEither = + commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition); + if (interfaceTypesEither.isRight()) { + return interfaceTypesEither; + } + final List<InterfaceDefinition> interfaceTypes = interfaceTypesEither.left().value(); + if (StringUtils.isNotEmpty(modelName)) { final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); if (modelOptional.isPresent()) { - interfaceTypes.left().value().forEach(interfaceType -> interfaceType.setModel(modelName)); - return interfaceTypes; + interfaceTypes.forEach(interfaceType -> { + interfaceType.setModel(modelName); + interfaceType.setUserCreated(!normative); + }); + return Either.left(interfaceTypes); } return Either.right(ActionStatus.INVALID_MODEL); + } else { + interfaceTypes.forEach(interfaceType -> interfaceType.setUserCreated(!normative)); } - return interfaceTypes; + return Either.left(interfaceTypes); } private Either<List<InterfaceDefinition>, ResponseFormat> createInterfacesByDao(List<InterfaceDefinition> interfacesToCreate) { @@ -148,8 +158,9 @@ public class InterfaceLifecycleTypeImportManager { .asList(ToscaTagNamesEnum.DERIVED_FROM.getElementName(), ToscaTagNamesEnum.DESCRIPTION.getElementName(), ToscaTagNamesEnum.VERSION.getElementName(), ToscaTagNamesEnum.METADATA.getElementName(), ToscaTagNamesEnum.INPUTS.getElementName(), ToscaTagNamesEnum.NOTIFICATIONS.getElementName()); - - Stream<Entry<String, Object>> oldFormatOperations = toscaJson.entrySet().stream().filter(interfaceEntry -> !entitySchemaEntryList.contains(interfaceEntry.getKey())); + + Stream<Entry<String, Object>> oldFormatOperations = + toscaJson.entrySet().stream().filter(interfaceEntry -> !entitySchemaEntryList.contains(interfaceEntry.getKey())); operationsMap = new HashMap<>(); oldFormatOperations.forEach(entry -> operationsMap.put(entry.getKey(), entry.getValue())); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceTypeServlet.java new file mode 100644 index 0000000000..fb46336bca --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceTypeServlet.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2023 Nordix Foundation. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.servlets; + +import com.jcabi.aspects.Loggable; +import fj.data.Either; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.tags.Tag; +import javax.ws.rs.DELETE; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; +import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException; +import org.openecomp.sdc.be.model.normatives.ElementTypeEnum; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.log.wrappers.Logger; +import org.springframework.stereotype.Controller; + +@Loggable(prepend = true, value = Loggable.DEBUG, trim = false) +@Path("/v1/catalog/interface-types") +@Tag(name = "SDCE-2 APIs") +@Server(url = "/sdc2/rest") +@Controller +public class InterfaceTypeServlet extends BeGenericServlet { + + private static final Logger log = Logger.getLogger(InterfaceTypeServlet.class); + private final InterfaceLifecycleOperation interfaceLifecycleOperation; + + public InterfaceTypeServlet(final ComponentsUtils componentsUtils, + InterfaceLifecycleOperation interfaceLifecycleOperation) { + super(componentsUtils); + this.interfaceLifecycleOperation = interfaceLifecycleOperation; + } + + @DELETE + @Path("{interfaceTypeId}") + public Response deleteInterfaceType(@Parameter(in = ParameterIn.PATH, required = true, description = "The interface type id") + @PathParam("interfaceTypeId") final String interfaceTypeId) { + final Either<InterfaceDefinition, StorageOperationStatus> interfaceTypeEither = interfaceLifecycleOperation.getInterface(interfaceTypeId); + if (interfaceTypeEither.isRight()) { + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND, + String.format("Failed to find interface type '%s'", interfaceTypeId))); + } + final InterfaceDefinition interfaceDefinition = interfaceTypeEither.left().value(); + if (!interfaceDefinition.isUserCreated()) { + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES, + ElementTypeEnum.INTERFACE_LIFECYCLE_TYPE.getToscaEntryName(), + interfaceTypeId)); + } + if (StringUtils.isEmpty(interfaceDefinition.getModel())) { + interfaceDefinition.setModel(Constants.DEFAULT_MODEL_NAME); + } + try { + interfaceLifecycleOperation.deleteInterfaceTypeById(interfaceTypeId); + interfaceLifecycleOperation.removeInterfaceTypeFromAdditionalType(interfaceDefinition); + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Type"); + log.debug("delete interface type failed with exception ", e); + throw e; + } + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); + } +} |