summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java42
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java23
2 files changed, 49 insertions, 16 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 05c1fb7ad3..3a62600433 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
@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
@@ -63,7 +64,6 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Controller;
-import org.apache.commons.lang3.StringUtils;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog/data-types")
@@ -162,10 +162,10 @@ public class DataTypeServlet extends BeGenericServlet {
String.format("Property model is not the same as the data type model. Must be '%s'", model));
}
if (StringUtils.isEmpty(dataType.getModel())) {
- dataType.setModel("SDC AID");
+ dataType.setModel(Constants.DEFAULT_MODEL_NAME);
}
final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto);
- dataTypeOperation.addPropertyToAdditionalTypeDataType(dataType, property);
+ dataTypeOperation.updatePropertyInAdditionalTypeDataType(dataType, property, true);
dataTypeBusinessLogic.updateApplicationDataTypeCache(id);
return Response.status(Status.CREATED).entity(property).build();
}
@@ -204,7 +204,7 @@ public class DataTypeServlet extends BeGenericServlet {
dataType.setModel(Constants.DEFAULT_MODEL_NAME);
}
final PropertyDefinitionDto property = dataTypeOperation.updateProperty(id, propertyDefinitionDto);
- dataTypeOperation.addPropertyToAdditionalTypeDataType(dataType, property);
+ dataTypeOperation.updatePropertyInAdditionalTypeDataType(dataType, property, true);
dataTypeBusinessLogic.updateApplicationDataTypeCache(id);
return Response.status(Status.CREATED).entity(property).build();
}
@@ -224,4 +224,38 @@ public class DataTypeServlet extends BeGenericServlet {
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
gson.toJson(dataTypeOperation.getAllDataTypeModels(dataTypeName)));
}
+
+ @DELETE
+ @Path("{dataTypeId}/{propertyId}")
+ public Response deleteProperty(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id")
+ @PathParam("dataTypeId") final String dataTypeId,
+ @Parameter(in = ParameterIn.PATH, required = true, description = "The property id to delete")
+ @PathParam("propertyId") final String propertyId) {
+ 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 (StringUtils.isEmpty(dataTypeDataDefinition.getModel())) {
+ dataTypeDataDefinition.setModel(Constants.DEFAULT_MODEL_NAME);
+ }
+ final PropertyDefinitionDto propertyDefinitionDto;
+ try {
+ propertyDefinitionDto = dataTypeOperation.deleteProperty(dataTypeDataDefinition, propertyId);
+ dataTypeOperation.updatePropertyInAdditionalTypeDataType(dataTypeDataDefinition, propertyDefinitionDto, false);
+ } catch (OperationException e) {
+ final PropertyDefinitionDto dto = new PropertyDefinitionDto();
+ dto.setName(extractNameFromPropertyId(propertyId));
+ dataTypeOperation.updatePropertyInAdditionalTypeDataType(dataTypeDataDefinition, dto, false);
+ throw e;
+ } finally {
+ dataTypeBusinessLogic.updateApplicationDataTypeCache(dataTypeId);
+ }
+ return Response.status(Status.OK).entity(propertyDefinitionDto).build();
+ }
+
+ private String extractNameFromPropertyId(final String propertyId) {
+ final String[] split = propertyId.split("\\.");
+ return split[split.length - 1];
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index 8974704199..f7ea9bb407 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -137,7 +137,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadCapabilityType(@Parameter(description = "FileInputStream") @FormDataParam("capabilityTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
ConsumerFourParam<Wrapper<Response>, String, String, Boolean> createElementsMethod = (responseWrapper, ymlPayload, model, includeToModelImport) ->
createElementsType(responseWrapper, () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload, modelName,
@@ -157,10 +157,10 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadRelationshipType(@Parameter(description = "FileInputStream") @FormDataParam("relationshipTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
- return uploadElementTypeServletLogic(
- this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName(), modelName, includeToModelDefaultImports);
+ return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName(),
+ modelName, includeToModelDefaultImports);
}
@POST
@@ -174,7 +174,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadInterfaceLifecycleType(@Parameter(description = "FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) ->
createElementsType(responseWrapper, () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, modelName,
@@ -230,7 +230,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadDataTypes(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
return uploadElementTypeServletLogic(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName,
includeToModelDefaultImports);
@@ -247,7 +247,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadDataTypesYaml(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesYaml") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
return uploadElementTypeServletLogicYaml(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName,
includeToModelDefaultImports);
@@ -263,7 +263,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "group types already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadGroupTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "FileInputStream") @FormDataParam("groupTypesZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
@@ -282,7 +282,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "policy types already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadPolicyTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
- @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "model name") @FormDataParam("model") String modelName,
@Parameter(description = "FileInputStream") @FormDataParam("policyTypesZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
@Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
@@ -331,8 +331,6 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
final Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
if (responseWrapper.isEmpty()) {
fillZipContents(yamlStringWrapper, file);
- }
- if (responseWrapper.isEmpty()) {
createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement(), modelName, includeToModelDefaultImports);
}
return responseWrapper.getInnerElement();
@@ -353,11 +351,12 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
final String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
final Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
+ final String yamlAsString = getFileAsString(file);
if (responseWrapper.isEmpty()) {
- final String yamlAsString = getFileAsString(file);
log.debug("received yaml: {}", yamlAsString);
createElementsMethod.accept(responseWrapper, yamlAsString, modelName, includeToModelDefaultImports);
}
+
return responseWrapper.getInnerElement();
} catch (final Exception e) {
log.debug(CREATE_FAILED_WITH_EXCEPTION, elementTypeName, e);