summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-02-21 14:07:50 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-22 14:16:42 +0000
commit9b8d90c9cdc012ca444d35465dc2e77662e4becf (patch)
treeef9f5f6d99a5bcc5eb40d965829d9a5c0128ea76 /catalog-be/src/main/java/org
parent8aa94a97ebfff1205e85470d78202f598632dbd6 (diff)
Support delete non-normative data types
Issue-ID: SDC-4411 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I246e50d848a17178369bfb643989d5447a887017
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
index 3a62600433..404c045dec 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
@@ -59,6 +59,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
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.impl.DataTypeOperation;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
@@ -185,7 +186,8 @@ public class DataTypeServlet extends BeGenericServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response updateProperty(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id")
@PathParam("id") final String id,
- @RequestBody(description = "Property to update", required = true) final PropertyDefinitionDto propertyDefinitionDto) {
+ @RequestBody(description = "Property to update", required = true)
+ final PropertyDefinitionDto propertyDefinitionDto) {
Optional<DataTypeDataDefinition> dataTypeOptional = dataTypeOperation.getDataTypeByUid(id);
dataTypeOptional.orElseThrow(() -> {
throw new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, String.format("Failed to find data type '%s'", id));
@@ -254,6 +256,33 @@ public class DataTypeServlet extends BeGenericServlet {
return Response.status(Status.OK).entity(propertyDefinitionDto).build();
}
+ @DELETE
+ @Path("{dataTypeId}")
+ public Response deleteDatatype(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id")
+ @PathParam("dataTypeId") final String dataTypeId) {
+ final Optional<DataTypeDataDefinition> dataTypeOptional = dataTypeOperation.getDataTypeByUid(dataTypeId);
+ dataTypeOptional.orElseThrow(() -> {
+ throw new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, String.format("Failed to find data type '%s'", dataTypeId));
+ });
+ final DataTypeDataDefinition dataTypeDataDefinition = dataTypeOptional.get();
+ if (dataTypeDataDefinition.isNormative()) {
+ throw new OperationException(ActionStatus.CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES, ElementTypeEnum.DATA_TYPE.getToscaEntryName(),
+ dataTypeId);
+ }
+ if (StringUtils.isEmpty(dataTypeDataDefinition.getModel())) {
+ dataTypeDataDefinition.setModel(Constants.DEFAULT_MODEL_NAME);
+ }
+ try {
+ dataTypeOperation.deleteDataTypesByDataTypeId(dataTypeId);
+ dataTypeOperation.removeDataTypeFromAdditionalType(dataTypeDataDefinition);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Datatype");
+ log.debug("delete datatype failed with exception ", e);
+ throw e;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ }
+
private String extractNameFromPropertyId(final String propertyId) {
final String[] split = propertyId.split("\\.");
return split[split.length - 1];