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;
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")
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();
}
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();
}
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];
+ }
}