From b734ea21ac7be393c59cf9976f0e5ddeaf27d568 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Thu, 22 Nov 2018 13:37:31 +0530 Subject: Service Workflow changes Service workflow change with few bug fixes Change-Id: Ice2376565bf46fb8d86fb6062654ec54bb2daa43 Issue-ID: SDC-1937 Signed-off-by: siddharth0905 --- .../be/components/impl/ArtifactResolverImpl.java | 16 +-- .../be/components/impl/ArtifactsBusinessLogic.java | 75 ++++++-------- .../impl/InterfaceOperationBusinessLogic.java | 11 +- .../validation/InterfaceOperationValidation.java | 31 +++--- .../servlet/ArtifactExternalServlet.java | 26 +++-- .../tosca/utils/InterfacesOperationsToscaUtil.java | 15 ++- .../sdc/be/tosca/utils/OperationArtifactUtil.java | 3 +- .../impl/InterfaceOperationBusinessLogicTest.java | 112 +++++++++++++++++++-- .../InterfaceOperationValidationTest.java | 84 ++++++++++++---- .../utils/InterfacesOperationsToscaUtilTest.java | 2 +- .../jsontitan/operations/InterfaceOperation.java | 27 +++++ .../interface-operation.page.component.ts | 8 +- .../operation-creator.component.html | 3 +- .../operation-creator.component.ts | 19 +--- .../param-row/param-row.component.html | 6 +- .../param-row/param-row.component.less | 2 +- .../param-row/param-row.component.ts | 58 +++++++++-- .../component-services/component.service.ts | 18 +--- .../src/app/ng2/services/workflow.service.ts | 23 +++-- .../TestResourceInterfaceOperation.feature | 2 +- .../TestServiceInterfaceOperation.feature | 2 +- .../operation/createOperation-with-workflow.json | 30 ++++++ .../stepDefinitions/InterfaceOperationSteps.js | 45 ++++++--- 23 files changed, 437 insertions(+), 181 deletions(-) create mode 100644 openecomp-bdd/resources/json/operation/createOperation-with-workflow.json diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java index c7f92d2184..2b23c52cd0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java @@ -54,20 +54,20 @@ public class ArtifactResolverImpl implements ArtifactsResolver { Map deploymentArtifacts = Optional.ofNullable(component.getDeploymentArtifacts()).orElse(Collections.emptyMap()); Map artifacts = Optional.ofNullable(component.getArtifacts()).orElse(Collections.emptyMap()); Map interfaceArtifacts= Collections.emptyMap(); - if (componentType == ComponentTypeEnum.RESOURCE) { - Map interfaces = ((Resource) component).getInterfaces(); - if (MapUtils.isNotEmpty(interfaces)) { - interfaceArtifacts = interfaces.values().stream() - .flatMap(inte -> inte.getOperationsMap().values().stream()) - .map(operation -> operation.getImplementationArtifact()) - .collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(), artifactDefinition -> artifactDefinition)); - } + Map interfaces = component.getInterfaces(); + if (MapUtils.isNotEmpty(interfaces)) { + interfaceArtifacts = interfaces.values().stream() + .flatMap(inte -> inte.getOperationsMap().values().stream()) + .map(operation -> operation.getImplementationArtifact()) + .collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(), + artifactDefinition -> artifactDefinition)); } Map serviceApiArtifacts = Collections.emptyMap(); if (componentType.equals(ComponentTypeEnum.SERVICE)) { serviceApiArtifacts = Optional.ofNullable(((Service) component).getServiceApiArtifacts()).orElse(Collections.emptyMap()); } + return appendAllArtifacts(deploymentArtifacts, artifacts, interfaceArtifacts, serviceApiArtifacts); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index fc4a739614..65a87d444b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -3100,24 +3100,23 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } NodeTypeEnum convertParentType = convertParentType(componentType); // fetch the resource from storage - Either resourceStorageOperationStatusEither = + Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(parentId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); + if (componentStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value(); log.debug("Failed to fetch resource information by resource id, error {}", errorStatus); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); } - Resource storedResource = resourceStorageOperationStatusEither.left().value(); + Component storedComponent = componentStorageOperationStatusEither.left().value(); String interfaceToscaName = InterfaceUtils.createInterfaceToscaResourceName( - storedResource.getName()); + storedComponent.getName()); //fetch the interface from storage - Optional interfaceDefinition = storedResource.getInterfaces().values() - .stream() - .filter(interfaceDef -> interfaceDef.getToscaResourceName() - .equals(interfaceToscaName)) - .findFirst(); + Optional interfaceDefinition = + storedComponent.getInterfaces().values().stream() + .filter(interfaceDef -> interfaceDef.getToscaResourceName() + .equals(interfaceToscaName)).findFirst(); if (!interfaceDefinition.isPresent()) { log.debug("Failed to get resource interface for resource Id {}", parentId); ResponseFormat responseFormat = componentsUtils.getResponseFormat( @@ -3154,7 +3153,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { operation.setImplementation(implementationArtifact); gotInterface.setOperationsMap(operationsMap); Either interfaceDefinitionStorageOperationStatusEither = - interfaceOperation.updateInterface(storedResource.getUniqueId(), gotInterface); + interfaceOperation.updateInterface(storedComponent.getUniqueId(), gotInterface); if (interfaceDefinitionStorageOperationStatusEither.isRight()){ StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value(); ActionStatus actionStatus = @@ -3163,16 +3162,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } String uniqueId = implementationArtifact.getUniqueId(); - Either artifactCount = artifactCassandraDao.getCountOfArtifactById(uniqueId); - if(artifactCount.isLeft()){ - CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.deleteArtifact(uniqueId); - if(cassandraOperationStatus != CassandraOperationStatus.OK){ - log.debug("Failed to persist operation {} artifact, error is {}",operation.getName(),cassandraOperationStatus); - StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus); - ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus); - return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse)); - } - } artifactData.setId(uniqueId); CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData); if(cassandraOperationStatus != CassandraOperationStatus.OK){ @@ -3647,23 +3636,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } } } - switch (component.getComponentType()) { - case RESOURCE: - Map interfaces = ((Resource) component).getInterfaces(); - if (!found && interfaces != null) { - for (Map.Entry entry : interfaces.entrySet()) { - Map operations = entry.getValue().getOperationsMap(); - for (Map.Entry entryOp : operations.entrySet()) { - if (entryOp.getValue().getImplementation() != null && entryOp.getValue() - .getImplementation() - .getUniqueId() - .equals(artifactId)) { - found = true; - break; - } - } + + Map interfaces = component.getInterfaces(); + if (!found && interfaces != null) { + for (Map.Entry entry : interfaces.entrySet()) { + Map operations = entry.getValue().getOperationsMap(); + for (Map.Entry entryOp : operations.entrySet()) { + if (entryOp.getValue().getImplementation() != null && entryOp.getValue() + .getImplementation() + .getUniqueId() + .equals(artifactId)) { + found = true; + break; } } + } + } + + switch (component.getComponentType()) { + case RESOURCE: break; case SERVICE: Map apiArtifacts = ((Service) component).getServiceApiArtifacts(); @@ -5106,18 +5097,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } private Either fetchInterfaceName(String componentId) { - Either resourceStorageOperationStatusEither = + Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); - log.debug("Failed to fetch resource information by resource id, error {}", errorStatus); + if (componentStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value(); + log.debug("Failed to fetch component information by component id, error {}", errorStatus); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); } - Resource storedResource = resourceStorageOperationStatusEither.left().value(); + Component storedComponent = componentStorageOperationStatusEither.left().value(); return Either.left(InterfaceUtils.createInterfaceToscaResourceName( - storedResource.getName())); + storedComponent.getName())); } 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 26e256fb00..fed2cac518 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 @@ -208,7 +208,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { if (getOperationEither.isRight()){ return Either.right(getOperationEither.right().value()); } - operation.setImplementation(getOperationEither.left().value().getImplementation()); + updateExistingOperation(operation, getOperationEither.left().value().getImplementation().getArtifactUUID()); result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation); } @@ -265,6 +265,15 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { operation.setImplementation(artifactDefinition); } + private void updateExistingOperation(Operation operation, String artifactUUID){ + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactUUID(artifactUUID); + artifactDefinition.setUniqueId(artifactUUID); + artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType()); + artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); + 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); 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 8c90501140..7b650e4fad 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 @@ -16,6 +16,17 @@ package org.openecomp.sdc.be.components.validation; +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; + import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -33,17 +44,6 @@ 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 { @@ -279,8 +279,8 @@ public class InterfaceOperationValidation { .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); } private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) { - return operationDataDefinition.getInputs().getListToscaDataDefinition().stream() - .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); + return operationDataDefinition.getOutputs().getListToscaDataDefinition().stream() + .anyMatch(outputParam -> outputParam.getName() == null || outputParam.getName().trim().equals(StringUtils.EMPTY)); } private Either validateInputPropertyExistInComponent(Operation operation, @@ -305,7 +305,10 @@ public class InterfaceOperationValidation { private boolean validateInputExistsInComponent(OperationInputDefinition input, List inputs) { - return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())); + return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())) + || ((input.getInputId().contains(".") + && inputs.stream().anyMatch(inp -> inp.getUniqueId().equals( + input.getInputId().substring(0, input.getInputId().lastIndexOf(".")))))) ; } private ResponseFormatManager getResponseFormatManager() { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java index c53e343512..03c5e0fbf1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java @@ -7,9 +7,9 @@ * 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. @@ -21,6 +21,14 @@ package org.openecomp.sdc.be.externalapi.servlet; import com.jcabi.aspects.Loggable; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + import fj.data.Either; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -65,11 +73,12 @@ import javax.ws.rs.core.Response; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.EnumMap; import java.util.HashMap; import java.util.Map; /** * This Servlet serves external users operations on artifacts. - * + * * @author mshitrit * */ @@ -89,7 +98,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { private static String startLog = "Start handle request of "; @POST - @Path("/resources/{uuid}/interfaces/{operationUUID}/artifacts/{artifactUUID}") + @Path("/{assetType}/{uuid}/interfaces/{operationUUID}/artifacts/{artifactUUID}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "uploads of artifact to VF operation workflow", httpMethod = "POST", notes = "uploads of artifact to VF operation workflow") @ApiResponses(value = { @@ -116,6 +125,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiParam(value = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, @ApiParam(value = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept, @ApiParam(value = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @ApiParam(value = "Asset type") @PathParam("assetType") String assetType, @ApiParam(value = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid, @ApiParam(value = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID, @ApiParam(value = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID, @@ -125,9 +135,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); - ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE; - String componentTypeValue = componentType.getValue(); - ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue); + ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(assetType); ArtifactDefinition artifactDefinition = null; if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) { @@ -144,7 +152,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { if (responseWrapper.isEmpty()) { ServletContext context = request.getSession().getServletContext(); ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, componentType, uuid, artifactUUID, operationUUID, + Either uploadArtifactEither = artifactsLogic + .updateArtifactOnInterfaceOperationByResourceUUID(data, request, ComponentTypeEnum + .findByParamName(assetType), uuid, artifactUUID, operationUUID, resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug(FAILED_TO_UPDATE_ARTIFACT); 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 c3628df17b..7afad74f64 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 @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -181,9 +182,13 @@ public class InterfacesOperationsToscaUtil { for (OperationInputDefinition input : operation.getInputs().getListToscaDataDefinition()) { ToscaProperty toscaInput = new ToscaProperty(); toscaInput.setDescription(input.getDescription()); - String mappedPropertyName = getLastPartOfName(input.getInputId()); - toscaInput.setType(input.getType()); + String mappedPropertyName = null; + if (Objects.nonNull(input.getInputId())) { + mappedPropertyName = input.getInputId().substring(input.getInputId().indexOf(DOT) + 1); + } toscaInput.setDefaultp(createDefaultValue(mappedPropertyName)); + + toscaInput.setType(input.getType()); toscaInput.setRequired(input.isRequired()); toscaInputs.put(input.getName(), toscaInput); } @@ -195,13 +200,15 @@ public class InterfacesOperationsToscaUtil { Map> getPropertyMap = new HashMap<>(); List values = new ArrayList<>(); values.add(SELF); - values.add(propertyName); + if (Objects.nonNull(propertyName) && !propertyName.isEmpty()) { + values.addAll(Arrays.asList(propertyName.split("\\."))); + } + getPropertyMap.put(GET_PROPERTY, values); return getPropertyMap; } - private static Map getObjectAsMap(Object obj) { ObjectMapper objectMapper = new ObjectMapper(); if (obj instanceof ToscaInterfaceDefinition) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java index b70ae90f7c..0d772cfcab 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java @@ -33,6 +33,7 @@ import org.openecomp.sdc.be.model.Component; 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.Service; import org.openecomp.sdc.be.tosca.CsarUtils; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; @@ -53,7 +54,7 @@ public class OperationArtifactUtil { */ static String createOperationArtifactPath(Component component, OperationDataDefinition operation, boolean isAssociatedResourceComponent) { - if (!(component instanceof Resource)) { + if (!(component instanceof Resource || component instanceof Service)) { return null; } if (isAssociatedResourceComponent) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index e8a698fec1..4227e5d5cc 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -55,6 +55,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; @@ -88,7 +89,7 @@ public class InterfaceOperationBusinessLogicTest { private final String operationId = "uniqueId1"; private Operation operation; - private static final String RESOURCE_NAME = "My-Resource_Name with space"; + private static final String RESOURCE_NAME = "Resource1"; private final ServletContext servletContext = Mockito.mock(ServletContext.class); private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class); @@ -175,13 +176,6 @@ public class InterfaceOperationBusinessLogicTest { //InterfaceOperation when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true)); - when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); - when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); - when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); - when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); - when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); // BL object @@ -211,12 +205,57 @@ public class InterfaceOperationBusinessLogicTest { validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); operation = InterfaceOperationTestUtils.createMockOperation(); + when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + Either interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); Assert.assertNotNull(interfaceOperation.left().value().getWorkflowId()); Assert.assertNotNull(interfaceOperation.left().value().getWorkflowVersionId()); } + @Test + public void createInterfaceOperationWithoutInterfaceTest() { + Resource resource = createResourceObjectCsar(true); + resource.setComponentType(ComponentTypeEnum.RESOURCE); + resource.setInterfaces(new HashMap<>()); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + operation = InterfaceOperationTestUtils.createMockOperation(); + when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.left(new InterfaceDefinition())); + + Either interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true); + Assert.assertTrue(interfaceOperation.isLeft()); + + } + + @Test + public void shouldFailCreateInterfaceOperationWhenCreateOperationFailedTest() { + Resource resource = createResourceObjectCsar(true); + resource.setInterfaces(new HashMap<>()); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + operation = InterfaceOperationTestUtils.createMockOperation(); + when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); + + Either interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true); + Assert.assertTrue(interfaceOperation.isRight()); + + } + + @Test() + public void shouldFailWhenCreateInterfaceOperationFailedTest() { + Resource resource = createResourceForInterfaceOperation(); + resource.setComponentType(ComponentTypeEnum.RESOURCE); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + operation = InterfaceOperationTestUtils.createMockOperation(); + + when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + Assert.assertTrue(bl.createInterfaceOperation(resourceId, operation, user, true).isRight()); + } + @Test public void updateInterfaceOperationTest() { validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -224,21 +263,47 @@ public class InterfaceOperationBusinessLogicTest { Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + when(interfaceOperation.updateInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + Either interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); } + @Test() + public void shouldFailWhenFailedToUpdateInterfaceOperationTest() { + validateUserRoles(Role.ADMIN, Role.DESIGNER); + operation = InterfaceOperationTestUtils.createMockOperation(); + Resource resource = createResourceForInterfaceOperation(); + resource.setComponentType(ComponentTypeEnum.RESOURCE); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); + Either interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true); + Assert.assertTrue(interfaceOperation.isRight()); + } + @Test public void deleteInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK); Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, operationId, user, true); Assert.assertTrue(deleteResourceResponseFormatEither.isLeft()); } + @Test() + public void shouldFailWhenDeleteInterfaceOperationFailedTest() { + Resource resource = createResourceForInterfaceOperation(); + resource.setComponentType(ComponentTypeEnum.RESOURCE); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); + when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK); + Assert.assertTrue(bl.deleteInterfaceOperation(resourceId, operationId, user, true).isRight()); + + } @Test public void getInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); @@ -249,6 +314,37 @@ public class InterfaceOperationBusinessLogicTest { Assert.assertTrue(getResourceResponseFormatEither.isLeft()); } + @Test + public void updateToscaResourceNameWhenComponentNameChanged() { + Component newComponent = new Resource(); + newComponent.setName("newComponent"); + Component oldComponent = createResourceForInterfaceOperation(); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(interfaceOperation.updateInterface(anyString(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); + Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isLeft()); + } + + @Test + public void shouldFailWhenComponentNameChangedButUpdateOperationFailed() { + Component newComponent = new Resource(); + newComponent.setName("newComponent"); + Component oldComponent = createResourceForInterfaceOperation(); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + + Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight()); + } + + @Test(expected = Exception.class) + public void shouldThrowExceptionWhenComponentNameChangedButUpdateOperationFailed() { + Component newComponent = new Resource(); + newComponent.setName("newComponent"); + Component oldComponent = createResourceForInterfaceOperation(); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(interfaceOperation.updateInterface(anyString(), anyObject())).thenThrow(new Exception()); + bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight(); + } + private void validateUserRoles(Role... roles) { List listOfRoles = Stream.of(roles).collect(Collectors.toList()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java index 6fe2f1308c..1a112c583b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java @@ -66,7 +66,7 @@ public class InterfaceOperationValidationTest { } @Test - public void testValidInterfaceOperation() { + public void shouldPassOperationValidationForHappyScenario() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); Collection operations = createInterfaceOperationData("op2", @@ -78,7 +78,7 @@ public class InterfaceOperationValidationTest { } @Test - public void testInterfaceOperationDescriptionLength() { + public void shouldFailWhenOperationOperationDescriptionLengthInvalid() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); Collection operations = createInterfaceOperationData("op2", @@ -94,7 +94,7 @@ public class InterfaceOperationValidationTest { @Test - public void testInterfaceOperationForEmptyType() { + public void shouldFailWhenOperationNameIsEmpty() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); Collection operations = createInterfaceOperationData("op2", @@ -106,19 +106,7 @@ public class InterfaceOperationValidationTest { } @Test - public void testInterfaceOperationForEmptyInputParam() { - operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); - operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); - Collection operations = createInterfaceOperationData("op2", - "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, - operationOutputDefinitionList,"input2"); - Either booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, component, false); - Assert.assertTrue(booleanResponseFormatEither.isRight()); - } - - @Test - public void testInterfaceOperationForNonUniqueType() { + public void shouldFailWhenOperationNamesAreNotUnique() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); Collection operations = createInterfaceOperationData("op2", @@ -130,7 +118,7 @@ public class InterfaceOperationValidationTest { } @Test - public void testInterfaceOperationTypeLength() { + public void shouldFailWhenOperationNameLengthIsInvalid() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); Collection operations = createInterfaceOperationData("op2", @@ -146,7 +134,7 @@ public class InterfaceOperationValidationTest { @Test - public void testInterfaceOperationUniqueInputParamNameInvalid() { + public void shouldFailWhenOperationInputParamNamesAreNotUnique() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2")); @@ -162,7 +150,7 @@ public class InterfaceOperationValidationTest { } @Test - public void testInterfaceOperationUniqueInputParamNameValid() { + public void shouldPassWhenOperationInputParamNamesAreUnique() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); @@ -170,14 +158,28 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update"); + Either booleanResponseFormatEither = interfaceOperationValidationUtilTest + .validateInterfaceOperations(operations, component, false); + Assert.assertTrue(booleanResponseFormatEither.isLeft()); + } + @Test + public void shouldPassWhenOperationInputParamNamesHasSubProperty() { + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); + Collection operations = createInterfaceOperationData("op2", + "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, + operationOutputDefinitionList,"update"); + operationInputDefinitionList.getListToscaDataDefinition().get(0).setInputId(operationInputDefinitionList + .getListToscaDataDefinition().get(0).getInputId().concat(".subproperty")); Either booleanResponseFormatEither = interfaceOperationValidationUtilTest .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isLeft()); } @Test - public void testInterfaceOperationInputParamNameEmpty() { + public void shouldFailWhenOperationInputParamNameEmpty() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" ")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); @@ -185,6 +187,48 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update"); + Either booleanResponseFormatEither = interfaceOperationValidationUtilTest + .validateInterfaceOperations(operations, component, false); + Assert.assertTrue(booleanResponseFormatEither.isRight()); + } + + @Test + public void shouldFailWhenOperationOutputParamNameEmpty() { + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam")); + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(" ")); + Collection operations = createInterfaceOperationData("op2", + "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, + operationOutputDefinitionList,"update"); + + Either booleanResponseFormatEither = interfaceOperationValidationUtilTest + .validateInterfaceOperations(operations, component, false); + Assert.assertTrue(booleanResponseFormatEither.isRight()); + } + + @Test + public void shouldPassWhenInterfaceOperationOutputParamNamesUnique() { + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label2")); + Collection operations = createInterfaceOperationData("op2", + "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, + operationOutputDefinitionList,"update"); + + Either booleanResponseFormatEither = interfaceOperationValidationUtilTest + .validateInterfaceOperations(operations, component, false); + Assert.assertTrue(booleanResponseFormatEither.isLeft()); + } + + @Test + public void shouldFailWhenOperationOutputParamNamesAreNotUnique() { + operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam1")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam1")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2")); + operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2")); + Collection operations = createInterfaceOperationData("op2", + "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, + operationOutputDefinitionList,"update"); Either booleanResponseFormatEither = interfaceOperationValidationUtilTest .validateInterfaceOperations(operations, component, false); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index ac53a6d930..8f34e0e29b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -146,7 +146,7 @@ public class InterfacesOperationsToscaUtilTest { component.setInterfaces(new HashMap<>()); component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); - InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, true); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); ToscaTemplate template = new ToscaTemplate("testService"); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java index 916a34c0f3..f9f2ce9b35 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import fj.data.Either; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -93,6 +94,17 @@ public class InterfaceOperation extends BaseOperation { Either getToscaElementRes; Either getToscaElementInt; + if(isUpdateAction && operation.getImplementationArtifact() != null){ + String artifactUUID = operation.getImplementationArtifact().getArtifactUUID(); + Either artifactCount = artifactCassandraDao.getCountOfArtifactById(artifactUUID); + if(artifactCount.isLeft()){ + CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); + if (cassandraStatus != CassandraOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + } + } + } + getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); if (getToscaElementRes.isRight()) { TitanOperationStatus status = getToscaElementRes.right().value(); @@ -139,6 +151,21 @@ public class InterfaceOperation extends BaseOperation { return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getInterfaceVertex.right().value())); } + if (!interfaceDef.getOperationsMap().isEmpty()) { + Either getInterfaceOpVertex = + titanDao.getChildVertex(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, + JsonParseFlagEnum.NoParse); + if (getInterfaceOpVertex.isRight()) { + List toscaDataList = new ArrayList<>(interfaceDef.getOperationsMap().values()); + StorageOperationStatus statusRes = + addToscaDataToToscaElement(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, + VertexTypeEnum.INTERFACE_OPERATION, toscaDataList, JsonPresentationFields.UNIQUE_ID); + if (!statusRes.equals(StorageOperationStatus.OK)) { + return Either.right(statusRes); + } + } + } + Optional> operationToRemove = interfaceDef.getOperationsMap().entrySet().stream() .filter(entry -> entry.getValue().getUniqueId().equals(operationToDelete)).findAny(); if (operationToRemove.isPresent()){ diff --git a/catalog-ui/src/app/ng2/pages/interface-operation/interface-operation.page.component.ts b/catalog-ui/src/app/ng2/pages/interface-operation/interface-operation.page.component.ts index da9cf5f752..e19d3457b3 100644 --- a/catalog-ui/src/app/ng2/pages/interface-operation/interface-operation.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/interface-operation/interface-operation.page.component.ts @@ -174,12 +174,11 @@ export class InterfaceOperationComponent { this.operationList.sort((a, b) => a.operationType.localeCompare(b.operationType)); if (response.workflowId && operation.workflowAssociationType === WORKFLOW_ASSOCIATION_OPTIONS.EXISTING) { - const resourceId = this.component.uuid; const operationId = response.uniqueId; const workflowId = response.workflowId; const versionId = response.workflowVersionId; const artifactId = response.artifactUUID; - this.WorkflowServiceNg2.associateWorkflowArtifact(resourceId, operationId, workflowId, versionId, artifactId).subscribe(); + this.WorkflowServiceNg2.associateWorkflowArtifact(this.component, operationId, workflowId, versionId, artifactId).subscribe(); } else if (operation.workflowAssociationType === WORKFLOW_ASSOCIATION_OPTIONS.NEW) { this.$state.go('workspace.plugins', { path: 'workflowDesigner' }); } @@ -193,13 +192,12 @@ export class InterfaceOperationComponent { this.operationList.splice(index, 1, newOperation); this.component.interfaceOperations = this.operationList; - if (newOperation.workflowId) { - const resourceId = this.component.uuid; + if (newOperation.workflowId && operation.workflowAssociationType === WORKFLOW_ASSOCIATION_OPTIONS.EXISTING) { const operationId = newOperation.uniqueId; const workflowId = newOperation.workflowId; const versionId = newOperation.workflowVersionId; const artifactId = newOperation.artifactUUID; - this.WorkflowServiceNg2.associateWorkflowArtifact(resourceId, operationId, workflowId, versionId, artifactId).subscribe(); + this.WorkflowServiceNg2.associateWorkflowArtifact(this.component, operationId, workflowId, versionId, artifactId).subscribe(); } }); } diff --git a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.html b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.html index 982cbb204c..6010bca10f 100644 --- a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.html +++ b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.html @@ -127,11 +127,10 @@ diff --git a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts index 5d3b027493..a6c1fb1c4c 100644 --- a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts +++ b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts @@ -18,7 +18,6 @@ export interface OperationCreatorInput { isService: boolean } - @Component({ selector: 'operation-creator', templateUrl: './operation-creator.component.html', @@ -33,7 +32,7 @@ export class OperationCreatorComponent { workflows: Array = []; workflowVersions: Array = []; - inputProperties: Array = []; + inputProperties: Array = []; inputPropertyTypes: { [key: string]: string }; inputParameters: Array = []; @@ -76,19 +75,10 @@ export class OperationCreatorComponent { } ngOnInit() { - this.readonly = this.input.readonly; this.isService = this.input.isService; - this.enableWorkflowAssociation = this.input.enableWorkflowAssociation && !this.isService; - - this.inputProperties = _.map(this.input.inputProperties, - (input: InputBEModel) => new DropdownValue(input.uniqueId, input.name) - ); - - this.inputPropertyTypes = {}; - _.forEach(this.input.inputProperties, (input: InputBEModel) => { - this.inputPropertyTypes[input.uniqueId] = input.type; - }); + this.enableWorkflowAssociation = this.input.enableWorkflowAssociation; + this.inputProperties = this.input.inputProperties; const inputOperation = this.input.operation; this.operation = new OperationModel(inputOperation || {}); @@ -108,13 +98,12 @@ export class OperationCreatorComponent { } else { this.reconstructOperation(); } - } reconstructOperation = () => { const inputOperation = this.input.operation; if (inputOperation) { - if (!this.enableWorkflowAssociation || !inputOperation.workflowVersionId || this.isService) { + if (!this.enableWorkflowAssociation || !inputOperation.workflowVersionId) { this.inputParameters = this.noAssignInputParameters; this.outputParameters = this.noAssignOutputParameters; this.buildParams(); diff --git a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/param-row/param-row.component.html b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/param-row/param-row.component.html index 94d2fce1ea..9a5c101e87 100644 --- a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/param-row/param-row.component.html +++ b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/param-row/param-row.component.html @@ -1,5 +1,5 @@