From b65c8eeb334a2c579a2dc0241f480d81e9309f9c Mon Sep 17 00:00:00 2001 From: priyanshu Date: Wed, 5 Sep 2018 18:05:36 +0530 Subject: Interface operation support for service - BE 1. Interface operation support for service 2. Refactored common code of operationspa 3. ONAP Bug fixes VF operations Change-Id: If1c4fd5f17626dbe568ee66ad997eb8ffb772e29 Issue-ID: SDC-1739 Signed-off-by: priyanshu --- .../sdc/be/components/impl/BaseBusinessLogic.java | 11 + .../impl/InterfaceOperationBusinessLogic.java | 74 +++---- .../validation/InterfaceOperationValidation.java | 85 ++++--- .../datamodel/utils/InterfaceUIDataConverter.java | 3 +- .../datamodel/utils/UiComponentDataConverter.java | 10 + .../sdc/be/servlets/InterfaceOperationServlet.java | 245 +++++++++++++++++++++ .../ResourceInterfaceOperationServlet.java | 243 -------------------- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 3 +- .../tosca/utils/InterfacesOperationsToscaUtil.java | 52 ++--- .../main/resources/config/error-configuration.yaml | 60 +++-- 10 files changed, 404 insertions(+), 382 deletions(-) create mode 100644 catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java delete mode 100644 catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index e7ae0612f4..fee386ab29 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -40,6 +40,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations; +import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; @@ -122,6 +123,12 @@ public abstract class BaseBusinessLogic { @Autowired protected ApplicationDataTypeCache dataTypeCache; + @Autowired + protected InterfaceOperation interfaceOperation; + + @Autowired + protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + @javax.annotation.Resource private UserValidations userValidations; @@ -156,6 +163,10 @@ public abstract class BaseBusinessLogic { this.propertyOperation = propertyOperation; } + public void setInterfaceOperation(InterfaceOperation interfaceOperation) { + this.interfaceOperation = interfaceOperation; + } + User validateUserNotEmpty(User user, String ecompErrorContext) { return userValidations.validateUserNotEmpty(user, ecompErrorContext); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 2f4519beb9..792e23af3b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -18,7 +18,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; -import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -28,9 +28,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; @@ -55,13 +53,6 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @Autowired private InterfaceOperationValidation interfaceOperationValidation; - @Autowired - private InterfaceOperation interfaceOperation; - - public void setInterfaceOperation(InterfaceOperation interfaceOperation) { - this.interfaceOperation = interfaceOperation; - } - public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) { this.interfaceOperationValidation = interfaceOperationValidation; } @@ -74,18 +65,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true); - Either lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, DELETE_INTERFACE_OPERATION); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either lockResult = lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -112,7 +98,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -126,18 +112,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true); - Either lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, GET_INTERFACE_OPERATION); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either lockResult = lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -158,13 +139,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } } - public Either getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) { + private Either getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) { if (interfaceDef != null){ return Either.left(interfaceDef); } else { @@ -195,26 +176,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId(), errorContext, true); - - InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs()); Either interfaceOperationValidationResponseEither = interfaceOperationValidation - .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate); + .validateInterfaceOperations(Collections.singletonList(operation), storedComponent, isUpdate); if(interfaceOperationValidationResponseEither.isRight()) { return Either.right(interfaceOperationValidationResponseEither.right().value()); } - Either lockResult = null; - if (lock) { - lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, errorContext); - if (lockResult.isRight()) { - LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); - titanDao.rollback(); - return Either.right(lockResult.right().value()); - } + Either lockResult = lockComponentResult(lock, storedComponent, errorContext); + if (lockResult.isRight()) { + return Either.right(lockResult.right().value()); } try { - Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName()); Either getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (getInterfaceEither.isRight()) { return Either.right(getInterfaceEither.right().value()); @@ -250,7 +224,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } finally { - if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { + if (lockResult.isLeft() && lockResult.left().value()) { graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue())); } } @@ -287,4 +261,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { operation.setUniqueId(UUID.randomUUID().toString()); operation.setImplementation(artifactDefinition); } + + private Either lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action){ + if (lock) { + Either lockResult = lockComponent(component.getUniqueId(), component, action); + if (lockResult.isRight()) { + LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(), lockResult.right().value().getFormattedMessage()); + titanDao.rollback(); + return Either.right(lockResult.right().value()); + } + } + return Either.left(true); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index affafaed12..8c90501140 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -17,29 +17,33 @@ package org.openecomp.sdc.be.components.validation; import fj.data.Either; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.elasticsearch.common.Strings; import org.openecomp.sdc.be.components.impl.ResponseFormatManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + @Component("interfaceOperationValidation") public class InterfaceOperationValidation { @@ -77,6 +81,13 @@ public class InterfaceOperationValidation { return Either.right(descriptionResponseEither.right().value()); } + Either inputPropertyExistInComponent = validateInputPropertyExistInComponent(interfaceOperation, + component.getInputs(), responseFormatManager); + if(inputPropertyExistInComponent.isRight()) { + return Either.right(inputPropertyExistInComponent.right().value()); + + } + Either inputParametersResponse = validateInputParameters(interfaceOperation, responseFormatManager); if(inputParametersResponse.isRight()) { @@ -109,14 +120,14 @@ public class InterfaceOperationValidation { } Either operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation, - component, isUpdate, responseFormatManager ); + component, isUpdate ); if(operationTypeUniqueResponse.isRight()) { return Either.right(operationTypeUniqueResponse.right().value()); } if (!operationTypeUniqueResponse.left().value()) { LOGGER.error("Interface Operation type {} already in use ", interfaceOperation.getName()); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName()); + .INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName()); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -128,7 +139,7 @@ public class InterfaceOperationValidation { LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain" + "Special character, space, numbers and should not be greater than 200 characters", operationType); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_INVALID, operationType); + .INTERFACE_OPERATION_NAME_INVALID, operationType); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -139,7 +150,7 @@ public class InterfaceOperationValidation { if (StringUtils.isEmpty(operationType)) { LOGGER.error("Interface Operation type is mandatory"); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_TYPE_MANDATORY); + .INTERFACE_OPERATION_NAME_MANDATORY); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -150,7 +161,7 @@ public class InterfaceOperationValidation { if (!Strings.isNullOrEmpty(description) && description.length() > DESCRIPTION_MAX_LENGTH) { LOGGER.error("Interface Operation description {} is invalid, maximum 200 characters allowed", description); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH); + .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, description); return Either.right(errorResponse); } return Either.left(Boolean.TRUE); @@ -163,14 +174,12 @@ public class InterfaceOperationValidation { private Either validateOperationTypeUnique( Operation interfaceOperation, org.openecomp.sdc.be.model.Component component, - boolean isUpdate, - ResponseFormatManager responseFormatManager) { + boolean isUpdate) { boolean isOperationTypeUnique = false; - Map interfaceDefinitionMap = ((Resource)component).getInterfaces(); + Map interfaceDefinitionMap = component.getInterfaces(); if(interfaceDefinitionMap.isEmpty()){ - isOperationTypeUnique = true; - return Either.left(isOperationTypeUnique); + return Either.left(true); } Collection allOperations = interfaceDefinitionMap.values().stream() @@ -178,8 +187,7 @@ public class InterfaceOperationValidation { .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream) .collect(Collectors.toList()); if(CollectionUtils.isEmpty(allOperations)){ - isOperationTypeUnique = true; - return Either.left(isOperationTypeUnique); + return Either.left(true); } Map operationTypes = new HashMap<>(); @@ -236,8 +244,6 @@ public class InterfaceOperationValidation { } return Either.left(Boolean.TRUE); } - - private Either> isInputParametersUnique(Operation operationDataDefinition) { Set inputParamNamesSet = new HashSet<>(); Set duplicateParamNamesToReturn = new HashSet<>(); @@ -277,17 +283,32 @@ public class InterfaceOperationValidation { .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); } - private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map operationTypes) { - boolean isOperationTypeUnique = false; - Optional id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName())) - .map(Map.Entry::getKey).findAny(); - if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){ - isOperationTypeUnique = true; + private Either validateInputPropertyExistInComponent(Operation operation, + List inputs, + ResponseFormatManager responseFormatManager) { + ListDataDefinition inputDefinitionListDataDefinition = operation.getInputs(); + if (inputDefinitionListDataDefinition == null) { + return Either.left(Boolean.TRUE); + } + List inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition(); + + for(OperationInputDefinition inputDefinition : inputListToscaDataDefinition ) { + if(!validateInputExistsInComponent(inputDefinition, inputs)) { + String missingPropertyName = inputDefinition.getInputId().contains(".") ? inputDefinition.getInputId().substring(inputDefinition.getInputId().indexOf(".") + 1) : inputDefinition.getInputId(); + LOGGER.error("Interface operation input property {} not found in component input properties", missingPropertyName); + ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, missingPropertyName); + return Either.right(inputResponse); + } } - return isOperationTypeUnique; + return Either.left(Boolean.TRUE); + } + + private boolean validateInputExistsInComponent(OperationInputDefinition input, + List inputs) { + return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())); } - protected ResponseFormatManager getResponseFormatManager() { + private ResponseFormatManager getResponseFormatManager() { return ResponseFormatManager.getInstance(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java index f0cdf3ec70..bdbf20a2b7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java @@ -40,7 +40,7 @@ public class InterfaceUIDataConverter { .map(interfaceOperationParamDataDefinition -> new OperationInputDefinition( interfaceOperationParamDataDefinition.getName(), interfaceOperationParamDataDefinition.getProperty(), - interfaceOperationParamDataDefinition.getMandatory(), + interfaceOperationParamDataDefinition.getMandatory() == null ? false : interfaceOperationParamDataDefinition.getMandatory(), interfaceOperationParamDataDefinition.getType() )).collect(Collectors.toList()); inputList.forEach(inputs::add); @@ -70,7 +70,6 @@ public class InterfaceUIDataConverter { } public static InterfaceOperationDataDefinition convertOperationDataToInterfaceData(Operation operationData){ - ListDataDefinition inputs = operationData.getInputs(); List inputParamList = inputs.getListToscaDataDefinition().stream() .map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(), diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java index a3731dd9b9..899a7b1cb8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java @@ -339,6 +339,9 @@ public class UiComponentDataConverter { UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition()); dataTransfer.setMetadata(metadata); break; + case INTERFACES: + setInterfaces(service, dataTransfer); + break; default: setUiTranferDataByFieldName(dataTransfer, service, fieldName); } @@ -362,6 +365,13 @@ public class UiComponentDataConverter { } } + private void setInterfaces(Service service, UiServiceDataTransfer dataTransfer) { + if (service.getInterfaces() == null) { + dataTransfer.setInterfaces(new HashMap<>()); + } else { + dataTransfer.setInterfaces(service.getInterfaces()); + } + } public static UiComponentMetadata convertToUiComponentMetadata(Component component) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java new file mode 100644 index 0000000000..815f9763f9 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java @@ -0,0 +1,245 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.be.servlets; + +import com.jcabi.aspects.Loggable; +import fj.data.Either; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import java.util.Optional; +import java.util.UUID; +import javax.inject.Singleton; +import javax.servlet.ServletContext; +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 javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; +import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datamodel.utils.InterfaceUIDataConverter; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.exception.ResponseFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Loggable(prepend = true, value = Loggable.DEBUG, trim = false) +@Path("/v1/catalog/{componentType}/{componentId}/interfaceOperations") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Api(value = "Interface Operation", description = "Interface Operation Servlet") +@Singleton +public class InterfaceOperationServlet extends AbstractValidationsServlet { + + private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/") + @ApiOperation(value = "Create Interface Operation", httpMethod = "POST", notes = "Create Interface Operation", response = InterfaceOperationDataDefinition.class) + @ApiResponses(value = {@ApiResponse(code = 201, message = "Create Interface Operation"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content"), + @ApiResponse(code = 409, message = "Interface Operation already exist")}) + public Response createInterfaceOperation( + @ApiParam(value = "Interface Operation to create", required = true) String data, + @ApiParam(value = "Component type") @PathParam("componentType") String componentType, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + return createOrUpdate(data, componentType ,componentId, request, userId, false); + } + + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/") + @ApiOperation(value = "Update Interface Operation", httpMethod = "PUT", notes = "Update Interface Operation", response = InterfaceOperationDataDefinition.class) + @ApiResponses(value = {@ApiResponse(code = 201, message = "Update Interface Operation"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content")}) + public Response updateInterfaceOperation( + @ApiParam(value = "Interface Operation to update", required = true) String data, + @ApiParam(value = "Component type") @PathParam("componentType") String componentType, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + return createOrUpdate(data, componentType,componentId, request, userId, true); + } + + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/{interfaceOperationId}") + @ApiOperation(value = "Delete Interface Operation", httpMethod = "DELETE", notes = "Delete Interface Operation", response = InterfaceOperationDataDefinition.class) + @ApiResponses(value = {@ApiResponse(code = 201, message = "Delete Interface Operation"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content")}) + public Response deleteInterfaceOperation( + @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + return delete(interfaceOperationId, componentId, request, userId); + } + + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/{interfaceOperationId}") + @ApiOperation(value = "Get Interface Operation", httpMethod = "GET", notes = "GET Interface Operation", response = InterfaceOperationDataDefinition.class) + @ApiResponses(value = {@ApiResponse(code = 201, message = "Get Interface Operation"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content")}) + public Response getInterfaceOperation( + @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, + @ApiParam(value = "Component Id") @PathParam("componentId") String componentId, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + + return get(interfaceOperationId, componentId, request, userId); + } + + private Response get (String interfaceOperationId, String componentId, HttpServletRequest request, String userId){ + ServletContext context = request.getSession().getServletContext(); + String url = request.getMethod() + " " + request.getRequestURI(); + + User modifier = new User(); + modifier.setUserId(userId); + log.debug("Start get request of {} with modifier id {}", url, userId); + + try { + String componentIdLower = componentId.toLowerCase(); + InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); + + Either actionResponse = businessLogic.getInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true); + if (actionResponse.isRight()) { + log.error("failed to get interface operation"); + return buildErrorResponse(actionResponse.right().value()); + } + + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); + Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); + } + catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations"); + log.error("get component interface operations failed with exception", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + + private Response delete (String interfaceOperationId, String componentId, HttpServletRequest + request, String userId){ + + ServletContext context = request.getSession().getServletContext(); + String url = request.getMethod() + " " + request.getRequestURI(); + + User modifier = new User(); + modifier.setUserId(userId); + log.debug("Start delete request of {} with modifier id {}", url, userId); + + try { + String componentIdLower = componentId.toLowerCase(); + InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); + + Either actionResponse = businessLogic.deleteInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true); + if (actionResponse.isRight()) { + log.error("failed to delete interface operation"); + return buildErrorResponse(actionResponse.right().value()); + } + + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); + Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); + } + catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation"); + log.error("Delete interface operation with an error", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + + private Response createOrUpdate (String data, String componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate) { + ServletContext context = request.getSession().getServletContext(); + String url = request.getMethod() + " " + request.getRequestURI(); + + User modifier = new User(); + modifier.setUserId(userId); + log.debug("Start create or update request of {} with modifier id {}", url, userId); + + try { + String componentIdLower = componentId.toLowerCase(); + InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); + + Operation operation = getMappedOperationData(data, isUpdate, modifier, ComponentTypeEnum.findByParamName(componentType)); + Either actionResponse ; + if (isUpdate) { + actionResponse = businessLogic.updateInterfaceOperation(componentIdLower, operation, modifier, true); + } else { + actionResponse = businessLogic.createInterfaceOperation(componentIdLower, operation, modifier, true); + } + + if (actionResponse.isRight()) { + log.error("failed to update or create interface operation"); + return buildErrorResponse(actionResponse.right().value()); + } + + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); + Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); + } + catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update"); + log.error("create or update interface Operation with an error", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + + private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user, ComponentTypeEnum componentTypeEnum){ + Either uiComponentEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum); + Optional opDef = uiComponentEither.left().value().getInterfaceOperations().values().stream().findFirst(); + InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition(); + if(opDef.isPresent()) { + interfaceOperationDataDefinition = opDef.get(); + if(!isUpdate) + interfaceOperationDataDefinition.setUniqueId(UUID.randomUUID().toString()); + } + return InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperationDataDefinition); + } + +} + diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java deleted file mode 100644 index 3e43dd7a91..0000000000 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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.openecomp.sdc.be.servlets; - -import com.jcabi.aspects.Loggable; -import fj.data.Either; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import java.util.Optional; -import java.util.UUID; -import javax.inject.Singleton; -import javax.servlet.ServletContext; -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 javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; -import org.openecomp.sdc.be.config.BeEcompErrorManager; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.datamodel.utils.InterfaceUIDataConverter; -import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; -import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer; -import org.openecomp.sdc.common.api.Constants; -import org.openecomp.sdc.exception.ResponseFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Loggable(prepend = true, value = Loggable.DEBUG, trim = false) -@Path("/v1/catalog/resources/{resourceId}/interfaceOperations") -@Consumes(MediaType.APPLICATION_JSON) -@Produces(MediaType.APPLICATION_JSON) -@Api(value = "Interface Operation", description = "Interface Operation Servlet") -@Singleton -public class ResourceInterfaceOperationServlet extends AbstractValidationsServlet { - - private static final Logger log = LoggerFactory.getLogger(ResourceInterfaceOperationServlet.class); - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/") - @ApiOperation(value = "Create Interface Operation", httpMethod = "POST", notes = "Create Interface Operation", response = InterfaceOperationDataDefinition.class) - @ApiResponses(value = {@ApiResponse(code = 201, message = "Create Interface Operation"), - @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 400, message = "Invalid content / Missing content"), - @ApiResponse(code = 409, message = "Interface Operation already exist")}) - public Response createInterfaceOperation( - @ApiParam(value = "Interface Operation to create", required = true) String data, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, - @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return createOrUpdate(data, resourceId, request, userId, false); - } - - @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/") - @ApiOperation(value = "Update Interface Operation", httpMethod = "PUT", notes = "Update Interface Operation", response = InterfaceOperationDataDefinition.class) - @ApiResponses(value = {@ApiResponse(code = 201, message = "Update Interface Operation"), - @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 400, message = "Invalid content / Missing content")}) - public Response updateInterfaceOperation( - @ApiParam(value = "Interface Operation to update", required = true) String data, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, - @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return createOrUpdate(data, resourceId, request, userId, true); - } - - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/{interfaceOperationId}") - @ApiOperation(value = "Delete Interface Operation", httpMethod = "DELETE", notes = "Delete Interface Operation", response = InterfaceOperationDataDefinition.class) - @ApiResponses(value = {@ApiResponse(code = 201, message = "Delete Interface Operation"), - @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 400, message = "Invalid content / Missing content")}) - public Response deleteInterfaceOperation( - @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, - @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - return delete(interfaceOperationId, resourceId, request, userId); - } - - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/{interfaceOperationId}") - @ApiOperation(value = "Get Interface Operation", httpMethod = "GET", notes = "GET Interface Operation", response = InterfaceOperationDataDefinition.class) - @ApiResponses(value = {@ApiResponse(code = 201, message = "Get Interface Operation"), - @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 400, message = "Invalid content / Missing content")}) - public Response getInterfaceOperation( - @ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId, - @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId, - @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - - return get(interfaceOperationId, resourceId, request, userId); - } - - private Response get (String interfaceOperationId, String resourceId, HttpServletRequest request, String userId){ - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); - - User modifier = new User(); - modifier.setUserId(userId); - log.debug("Start get request of {} with modifier id {}", url, userId); - - try { - String resourceIdLower = resourceId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - - Either actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); - if (actionResponse.isRight()) { - log.error("failed to get interface operation"); - return buildErrorResponse(actionResponse.right().value()); - } - - InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); - Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } - catch (Exception e) { - BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations"); - log.error("get resource interface operations failed with exception", e); - return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } - } - - private Response delete (String interfaceOperationId, String resourceId, HttpServletRequest - request, String userId){ - - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); - - User modifier = new User(); - modifier.setUserId(userId); - log.debug("Start delete request of {} with modifier id {}", url, userId); - - try { - String resourceIdLower = resourceId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - - Either actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); - if (actionResponse.isRight()) { - log.error("failed to delete interface operation"); - return buildErrorResponse(actionResponse.right().value()); - } - - InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); - Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } - catch (Exception e) { - BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation"); - log.error("Delete interface operation with an error", e); - return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } - } - - private Response createOrUpdate (String data, String resourceId, HttpServletRequest request, String userId, boolean isUpdate) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); - - User modifier = new User(); - modifier.setUserId(userId); - log.debug("Start create or update request of {} with modifier id {}", url, userId); - - try { - String resourceIdLower = resourceId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - - Operation operation = getMappedOperationData(data, isUpdate, modifier); - Either actionResponse ; - if (isUpdate) { - actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, operation, modifier, true); - } else { - actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, operation, modifier, true); - } - - if (actionResponse.isRight()) { - log.error("failed to update or create interface operation"); - return buildErrorResponse(actionResponse.right().value()); - } - - InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); - Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } - catch (Exception e) { - BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update"); - log.error("create or update interface Operation with an error", e); - return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } - } - - private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user){ - Either uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE); - Optional opDef = uiResourceEither.left().value().getInterfaceOperations().values().stream().findFirst(); - InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition(); - if(opDef.isPresent()) { - interfaceOperationDataDefinition = opDef.get(); - if(!isUpdate) - interfaceOperationDataDefinition.setUniqueId(UUID.randomUUID().toString()); - } - return InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperationDataDefinition); - } - -} - diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index e5e5f1648a..d62c2c64eb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -561,7 +561,7 @@ public class ToscaExportHandler { List inputDef = component.getInputs(); Map inputs = new HashMap<>(); - + addInterfaceDefinitionElement(component, toscaNodeType); if (inputDef != null) { inputDef.forEach(i -> { ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false); @@ -569,7 +569,6 @@ public class ToscaExportHandler { }); if (!inputs.isEmpty()) { toscaNodeType.setProperties(inputs); - addInterfaceDefinitionElement(component, toscaNodeType); } } return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index 75a65f95da..5370a7849e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -18,29 +18,25 @@ package org.openecomp.sdc.be.tosca.utils; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; + import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Product; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType; import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; -/** - * @author KATYR - * @since March 20, 2018 - */ public class InterfacesOperationsToscaUtil { @@ -50,7 +46,6 @@ public class InterfacesOperationsToscaUtil { private static final String DEFAULT = "default"; private static final String DEFAULT_HAS_UNDERSCORE = "_default"; private static final String DOT = "."; - private static final String DEFAULT_INPUT_TYPE = "string"; private static final String SELF = "SELF"; private static final String GET_PROPERTY = "get_property"; private static final String DEFAULTP = "defaultp"; @@ -65,16 +60,11 @@ public class InterfacesOperationsToscaUtil { * @return the added element */ public static Map addInterfaceTypeElement(Component component) { - Map toscaInterfaceTypes = new HashMap<>(); - if ((component instanceof Service) || (component instanceof Product)) { - return null; - } - - final Map interfaces = ((Resource) component).getInterfaces(); - if (MapUtils.isEmpty(interfaces)) { + if (component instanceof Product) { return null; } - + final Map interfaces = component.getInterfaces(); + Map toscaInterfaceTypes = new HashMap<>(); for (InterfaceDefinition interfaceDefinition : interfaces.values()) { ToscaInterfaceNodeType toscaInterfaceType = new ToscaInterfaceNodeType(); toscaInterfaceType.setDerived_from(DERIVED_FROM_STANDARD_INTERFACE); @@ -86,8 +76,6 @@ public class InterfacesOperationsToscaUtil { toscaOperations.put(operationEntry.getValue().getName(), null); //currently not initializing any of the operations' fields as it is not needed } - - toscaInterfaceType.setOperations(toscaOperations); Map interfacesAsMap = getObjectAsMap(toscaInterfaceType); Map operationsMap = (Map) interfacesAsMap.remove(OPERATIONS_KEY); @@ -95,7 +83,7 @@ public class InterfacesOperationsToscaUtil { toscaInterfaceTypes.put(interfaceDefinition.getToscaResourceName(), interfacesAsMap); } - return toscaInterfaceTypes; + return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null; } /** @@ -105,16 +93,14 @@ public class InterfacesOperationsToscaUtil { * @param nodeType to which the interfaces element will be added */ public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) { - Map toscaInterfaceDefinitions = new HashMap<>(); - - if ((component instanceof Service) || (component instanceof Product)) { + if (component instanceof Product) { return; } - - final Map interfaces = ((Resource) component).getInterfaces(); + final Map interfaces = component.getInterfaces(); if (MapUtils.isEmpty(interfaces)) { return; } + Map toscaInterfaceDefinitions = new HashMap<>(); for (InterfaceDefinition interfaceDefinition : interfaces.values()) { ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition(); final String toscaResourceName = interfaceDefinition.getToscaResourceName(); @@ -133,7 +119,7 @@ public class InterfacesOperationsToscaUtil { toscaOperation.setImplementation(operationArtifactPath); } toscaOperation.setDescription(operationEntry.getValue().getDescription()); - fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType); + fillToscaOperationInputs(operationEntry.getValue(), toscaOperation); toscaOperations.put(operationEntry.getValue().getName(), toscaOperation); } @@ -145,7 +131,9 @@ public class InterfacesOperationsToscaUtil { interfaceDefAsMap.putAll(operationsMap); toscaInterfaceDefinitions.put(getLastPartOfName(toscaResourceName), interfaceDefAsMap); } - nodeType.setInterfaces(toscaInterfaceDefinitions); + if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) { + nodeType.setInterfaces(toscaInterfaceDefinitions); + } } /*** @@ -180,8 +168,7 @@ public class InterfacesOperationsToscaUtil { } private static void fillToscaOperationInputs(OperationDataDefinition operation, - ToscaLifecycleOperationDefinition toscaOperation, - ToscaNodeType nodeType) { + ToscaLifecycleOperationDefinition toscaOperation) { if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) { toscaOperation.setInputs(null); return; @@ -192,22 +179,15 @@ public class InterfacesOperationsToscaUtil { ToscaProperty toscaInput = new ToscaProperty(); toscaInput.setDescription(input.getDescription()); String mappedPropertyName = getLastPartOfName(input.getInputId()); - toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType)); + toscaInput.setType(input.getType()); toscaInput.setDefaultp(createDefaultValue(mappedPropertyName)); + toscaInput.setRequired(input.isRequired()); toscaInputs.put(input.getName(), toscaInput); } toscaOperation.setInputs(toscaInputs); } - private static String getOperationInputType(String inputName, ToscaNodeType nodeType) { - if (nodeType.getProperties() != null - && nodeType.getProperties().containsKey(inputName)) { - return nodeType.getProperties().get(inputName).getType(); - } - return DEFAULT_INPUT_TYPE; - } - private static Map> createDefaultValue(String propertyName) { Map> getPropertyMap = new HashMap<>(); List values = new ArrayList<>(); diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml index 26fee5b28e..6156090df3 100644 --- a/catalog-be/src/main/resources/config/error-configuration.yaml +++ b/catalog-be/src/main/resources/config/error-configuration.yaml @@ -2025,50 +2025,50 @@ errors: messageId: "SVC4694" } #---------SVC4695----------------------------- -# %1 - Interface operation type - INTERFACE_OPERATION_TYPE_ALREADY_IN_USE: { +# %1 - Interface Operation Name + INTERFACE_OPERATION_NAME_ALREADY_IN_USE: { code: 400, - message: "Error: Interface Operation type %1 already in use", + message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.", messageId: "SVC4695" } #---------SVC4696----------------------------- -# %1 - workflow operation type - INTERFACE_OPERATION_TYPE_INVALID: { +# %1 - Interface Operation Name + INTERFACE_OPERATION_NAME_INVALID: { code: 400, - message: "Error: Interface Operation type %1 is Invalid, Operation type should not contain - special character, space, numbers and should not be greater than 200 characters ", + message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space, numbers and should not be greater than 200 characters.", messageId: "SVC4696" } #---------SVC4697----------------------------- - INTERFACE_OPERATION_TYPE_MANDATORY: { + INTERFACE_OPERATION_NAME_MANDATORY: { code: 404, - message: "Error: Interface Operation type is mandatory, Operation type can't be empty", + message: "Error: Interface Operation name is mandatory, Operation name can't be empty.", messageId: "SVC4697" } #---------SVC4698----------------------------- -# %1 - workflow operation description +# %1 - Interface Operation description INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: { code: 400, - message: "Error: Interface Operation description %1 is invalid, maximum 200 characters allowed", + message: "Error: Interface Operation description '%1' is invalid, maximum 200 characters allowed.", messageId: "SVC4698" } #---------SVC4699----------------------------- +# %1 - Interface Operation input parameter name INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE: { code: 400, - message: "Error: Interface Operation input parameter names %1 already in use", + message: "Error: Interface Operation input parameter name '%1' already in use, Your current changes will not be saved.", messageId: "SVC4699" } #---------SVC4700----------------------------- - INTERFACE_OPERATION_OUTPUT_NAME_INVALID: { - code: 400, - message: "Error: Interface Operation output parameters invalid, should be unique and mandatory", - messageId: "SVC4700" + INTERFACE_OPERATION_INPUT_NAME_MANDATORY: { + code: 404, + message: "Error: Interface operation input parameter name should not be empty.", + messageId: "SVC4700" } #---------SVC4701----------------------------- # %1 - resource Id INTERFACE_OPERATION_NOT_FOUND: { code: 404, - message: "Error: Interface operations not found in the resource %1", + message: "Error: Interface operation not found in the resource '%1'.", messageId: "SVC4701" } #---------SVC4702----------------------------- @@ -2127,10 +2127,24 @@ errors: message: "Error: CSAR packaging failed for %1 %2.", messageId: "SVC4706" } -#---------SVC46708----------------------------- - INTERFACE_OPERATION_INPUT_NAME_MANDATORY: { - code: 404, - message: "Error: Interface operation input parameter name should not be empty", - messageId: "SVC46707" - } +#---------SVC4704----------------------------- +# %1 - Interface Operation input property name + INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: { + code: 404, + message: "Error: Interface operation input parameter property '%1' not found in component input properties.", + messageId: "SVC4704" + } +#---------SVC4705----------------------------- +# %1 - Interface Operation output parameter name + INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: { + code: 400, + message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.", + messageId: "SVC4705" + } +#---------SVC4706----------------------------- + INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: { + code: 404, + message: "Error: Interface operation output parameter name should not be empty.", + messageId: "SVC4706" + } -- cgit 1.2.3-korg