From a39a0026eebabe4866c81bcd12143ca40aa30e31 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Thu, 4 Aug 2022 13:26:39 +0100 Subject: get_input property value deprecated format Signed-off-by: MichaelMorris Issue-ID: SDC-4123 Change-Id: Ief79a25bbe41d67b378db6c4ad19b0d29c1830b2 --- .../be/components/impl/ComponentBusinessLogic.java | 4 ++ .../sdc/be/servlets/ComponentInstanceServlet.java | 51 +++++++++++++++++++++- .../be/servlets/ComponentInstanceServletTest.java | 7 ++- 3 files changed, 59 insertions(+), 3 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index 4372564bbd..1b28435dd8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -206,6 +206,10 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { */ public abstract Either getUiComponentDataTransferByComponentId(String componentId, List dataParamsToReturn); + + public Either getComponentMetadata(final String componentId) { + return toscaOperationFacade.getComponentMetadata(componentId); + } User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) { User validatedUser; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java index a1518c6479..a5022c0857 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java @@ -40,6 +40,7 @@ import java.io.InputStream; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -62,6 +63,8 @@ import javax.ws.rs.core.Response; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic; import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; @@ -76,9 +79,13 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.ForwardingPaths; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.enums.PropertySource; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.externalapi.servlet.representation.ReplaceVNFInfo; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; @@ -93,7 +100,9 @@ import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser; +import org.openecomp.sdc.be.resources.data.ComponentMetadataData; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; @@ -138,14 +147,16 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { private static final String SERVICES = "services"; private final GroupBusinessLogic groupBL; private final ComponentNodeFilterBusinessLogic nodeFilterBusinessLogic; + private final ComponentBusinessLogicProvider componentBusinessLogicProvider; @Inject public ComponentInstanceServlet(UserBusinessLogic userBusinessLogic, GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, ServletUtils servletUtils, - ResourceImportManager resourceImportManager, ComponentNodeFilterBusinessLogic nodeFilterBusinessLogic) { + ResourceImportManager resourceImportManager, ComponentNodeFilterBusinessLogic nodeFilterBusinessLogic, ComponentBusinessLogicProvider componentBusinessLogicProvider) { super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); this.groupBL = groupBL; this.nodeFilterBusinessLogic = nodeFilterBusinessLogic; + this.componentBusinessLogicProvider = componentBusinessLogicProvider; } @POST @@ -527,6 +538,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.STARTED, "Starting to update Resource Instance Properties for component {} ", componentId + " by " + userId); Wrapper errorWrapper = new Wrapper<>(); + ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); List propertiesToUpdate = new ArrayList<>(); if (errorWrapper.isEmpty()) { Either, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties( @@ -535,13 +547,13 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { errorWrapper.setInnerElement(propertiesToUpdateEither.right().value()); } else { propertiesToUpdate = propertiesToUpdateEither.left().value(); + handleDeprecatedComponentInstancePropertyStructure(propertiesToUpdate, componentTypeEnum); } } if (!errorWrapper.isEmpty()) { return buildErrorResponse(errorWrapper.getInnerElement()); } log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate); - ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); @@ -567,6 +579,41 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); } + private void handleDeprecatedComponentInstancePropertyStructure(final List propertiesToUpdate, + final ComponentTypeEnum componentTypeEnum) { + propertiesToUpdate.stream().forEach(property -> { + if (property.getGetInputValues() != null) { + property.getGetInputValues().stream() + .forEach(getInputValue -> property.setToscaFunction(createToscaFunction(getInputValue, componentTypeEnum))); + } + }); + } + + private ToscaGetFunctionDataDefinition createToscaFunction(final GetInputValueDataDefinition getInput, + final ComponentTypeEnum componentTypeEnum) { + final String[] inputIdSplit = getInput.getInputId().split("\\."); + + ToscaGetFunctionDataDefinition toscaFunction = new ToscaGetFunctionDataDefinition(); + toscaFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT); + toscaFunction.setPropertyUniqueId(getInput.getInputId()); + toscaFunction.setPropertySource(PropertySource.SELF); + toscaFunction.setPropertyName(inputIdSplit[1]); + toscaFunction.setSourceName(getSourceName(inputIdSplit[0], componentTypeEnum)); + toscaFunction.setSourceUniqueId(inputIdSplit[0]); + toscaFunction.setPropertyPathFromSource(Collections.singletonList(inputIdSplit[1])); + + return toscaFunction; + } + + private String getSourceName(final String componentId, final ComponentTypeEnum componentTypeEnum) { + ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum); + final Either componentEither = compBL.getComponentMetadata(componentId); + if (componentEither.isLeft()) { + return componentEither.left().value().getMetadataDataDefinition().getName(); + } + return ""; + } + @POST @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs") @Consumes(MediaType.APPLICATION_JSON) diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java index 342f9eb2ba..e77a855ef8 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java @@ -66,6 +66,7 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; +import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic; import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; @@ -130,6 +131,7 @@ class ComponentInstanceServletTest extends JerseyTest { private ResourceImportManager resourceImportManager; private ServiceBusinessLogic serviceBusinessLogic; private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic; + private ComponentBusinessLogicProvider componentBusinessLogicProvider; private ConfigurationManager configurationManager; private User user; private String inputData; @@ -201,7 +203,7 @@ class ComponentInstanceServletTest extends JerseyTest { .accept(MediaType.APPLICATION_JSON) .header("USER_ID", USER_ID) .get(Response.class); - + assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); } @@ -342,6 +344,7 @@ class ComponentInstanceServletTest extends JerseyTest { bind(resourceImportManager).to(ResourceImportManager.class); bind(serviceBusinessLogic).to(ServiceBusinessLogic.class); bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class); + bind(componentBusinessLogicProvider).to(ComponentBusinessLogicProvider.class); } }) .property("contextConfig", context); @@ -362,6 +365,7 @@ class ComponentInstanceServletTest extends JerseyTest { responseFormat = Mockito.mock(ResponseFormat.class); serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class); componentNodeFilterBusinessLogic = Mockito.mock(ComponentNodeFilterBusinessLogic.class); + componentBusinessLogicProvider = Mockito.mock(ComponentBusinessLogicProvider.class); userValidations = Mockito.mock(UserValidations.class); } @@ -482,6 +486,7 @@ class ComponentInstanceServletTest extends JerseyTest { .path(path) .request(MediaType.APPLICATION_JSON) .header("USER_ID", USER_ID).post(Entity.entity(properties, MediaType.APPLICATION_JSON)); + assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404); } -- cgit 1.2.3-korg