X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FServiceImportBusinessLogic.java;h=ac14a3c683c969ed0293fd20a7d4f853f81ab19a;hb=216ea4998de9ae4ee603d7f8f5f6725b218ca710;hp=3bfa76dc4936c69364f51e62f6ae12aa44f4ceab;hpb=468d0770593e167990df815e45cde717bd845d18;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 3bfa76dc49..ac14a3c683 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.openecomp.sdc.be.components.impl; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; +import static org.apache.hc.core5.http.HttpStatus.SC_BAD_REQUEST; import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement; import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement; import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue; @@ -29,7 +31,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import fj.data.Either; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.EnumMap; @@ -47,12 +53,16 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; import java.util.stream.Collectors; +import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; import org.json.simple.JSONObject; import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarBusinessLogic; @@ -61,6 +71,7 @@ import org.openecomp.sdc.be.components.csar.ServiceCsarInfo; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; @@ -148,6 +159,7 @@ import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -163,6 +175,8 @@ import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.kpi.api.ASDCKpiApi; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.ValidationUtils; +import org.openecomp.sdc.common.zip.ZipUtils; +import org.openecomp.sdc.common.zip.exception.ZipException; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.Yaml; @@ -202,16 +216,15 @@ public class ServiceImportBusinessLogic { private final IGraphLockOperation graphLockOperation; private final ToscaFunctionService toscaFunctionService; private final DataTypeBusinessLogic dataTypeBusinessLogic; - private ApplicationDataTypeCache applicationDataTypeCache; private final ArtifactTypeOperation artifactTypeOperation; - private final GroupTypeImportManager groupTypeImportManager; private final GroupTypeOperation groupTypeOperation; - private InterfaceLifecycleOperation interfaceLifecycleTypeOperation; - private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager; - private final CapabilityTypeImportManager capabilityTypeImportManager; private final CapabilityTypeOperation capabilityTypeOperation; + private ApplicationDataTypeCache applicationDataTypeCache; + private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation; + private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager; + private final ModelOperation modelOperation; public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic, final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade, @@ -228,7 +241,8 @@ public class ServiceImportBusinessLogic { final InterfaceLifecycleOperation interfaceLifecycleTypeOperation, final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager, final CapabilityTypeImportManager capabilityTypeImportManager, - final CapabilityTypeOperation capabilityTypeOperation) { + final CapabilityTypeOperation capabilityTypeOperation, + final ModelOperation modelOperation) { this.componentsUtils = componentsUtils; this.toscaOperationFacade = toscaOperationFacade; this.serviceBusinessLogic = serviceBusinessLogic; @@ -254,6 +268,7 @@ public class ServiceImportBusinessLogic { this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager; this.capabilityTypeImportManager = capabilityTypeImportManager; this.capabilityTypeOperation = capabilityTypeOperation; + this.modelOperation = modelOperation; } @Autowired @@ -261,14 +276,64 @@ public class ServiceImportBusinessLogic { this.applicationDataTypeCache = applicationDataTypeCache; } + public Service updateServiceFromToscaTemplate(final String serviceId, final User modifier, final String data) { + final Either serviceResponseFormatEither = serviceBusinessLogic.getService(serviceId, modifier); + if (serviceResponseFormatEither.isRight()) { + throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceId); + } + final Service serviceOriginal = serviceResponseFormatEither.left().value(); + final Map metadata = (Map) new Yaml().loadAs(data, Map.class).get("metadata"); + validateServiceMetadataBeforeCreate(serviceOriginal, metadata); + + final Service newService = cloneServiceIdentifications(serviceOriginal); + final Map payload = new HashMap<>(); + payload.put("Definitions/service-" + metadata.get("name") + "-template.yml", data.getBytes()); + updateServiceMetadata(newService, metadata); + return createService(newService, AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE, modifier, payload, null); + } + + private Service cloneServiceIdentifications(final Service serviceOriginal) { + final Service newService = new Service(serviceOriginal.getComponentMetadataDefinition()); + newService.setCategories(serviceOriginal.getCategories()); + newService.setInvariantUUID(serviceOriginal.getInvariantUUID()); + newService.setUniqueId(serviceOriginal.getUniqueId()); + newService.setName(serviceOriginal.getName()); + newService.setUUID(serviceOriginal.getUUID()); + return newService; + } + + private void validateServiceMetadataBeforeCreate(final Service service, final Map metadata) { + if (MapUtils.isEmpty(metadata)) { + throw new ByActionStatusComponentException(ActionStatus.MISSING_SERVICE_METADATA); + } + final String uuid = metadata.get("UUID"); + if (!service.getUUID().equals(uuid)) { + throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "UUID"); + } + final String invariantUUID = metadata.get("invariantUUID"); + if (!service.getInvariantUUID().equals(invariantUUID)) { + throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "invariantUUID"); + } + final String name = metadata.get("name"); + if (!service.getName().equals(name)) { + throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "name"); + } + final String version = metadata.get("template_version"); + if (!service.getVersion().equals(version)) { + throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "template_version"); + } + } + public Service createService(Service service, AuditingActionEnum auditingAction, User user, Map csarUIPayload, String payloadName) { log.debug("enter createService"); - service.setCreatorUserId(user.getUserId()); - service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); - service.setVersion(INITIAL_VERSION); - service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel()); - service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED); + if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) { + service.setCreatorUserId(user.getUserId()); + service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + service.setVersion(INITIAL_VERSION); + service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel()); + service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED); + } try { final var serviceBeforeCreate = serviceBusinessLogic.validateServiceBeforeCreate(service, user, auditingAction); if (serviceBeforeCreate.isRight()) { @@ -276,10 +341,12 @@ public class ServiceImportBusinessLogic { } log.debug("enter createService,validateServiceBeforeCreate success"); String csarUUID = payloadName == null ? service.getCsarUUID() : payloadName; - log.debug("enter createService,get csarUUID:{}", csarUUID); - csarBusinessLogic.validateCsarBeforeCreate(service, csarUUID); + if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) { + log.debug("enter createService,get csarUUID:{}", csarUUID); + csarBusinessLogic.validateCsarBeforeCreate(service, csarUUID); + } log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID); - return createServiceFromCsar(service, user, csarUIPayload, csarUUID); + return createServiceFromCsar(service, user, csarUIPayload, csarUUID, auditingAction); } catch (final ComponentException e) { log.debug("Exception occurred when createService: {}", e.getMessage(), e); throw e; @@ -289,10 +356,31 @@ public class ServiceImportBusinessLogic { } } - protected Service createServiceFromCsar(Service service, User user, Map csarUIPayload, String csarUUID) { + private void updateServiceMetadata(final Service service, final Map metadata) { + metadata.entrySet().forEach(s -> { + final Optional find = + Arrays.stream(service.getClass().getMethods()).filter(method -> method.getName().equalsIgnoreCase("set" + s.getKey())).findAny(); + if (find.isPresent()) { + try { + find.get().invoke(service, s.getValue()); + } catch (final Exception e) { + log.warn("Unable to set '{}' with value '{}'", s.getKey(), s.getValue()); + } + } + }); + } + + protected Service createServiceFromCsar(Service service, User user, Map csarUIPayload, String csarUUID, + AuditingActionEnum auditingAction) { log.trace("************* created successfully from YAML, resource TOSCA "); try { - final ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID); + final ServiceCsarInfo csarInfo; + if (AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE.equals(auditingAction)) { + csarInfo = new ServiceCsarInfo(user, csarUUID, csarUIPayload, service.getName(), service.getModel(), + csarUIPayload.keySet().iterator().next(), new String(csarUIPayload.values().iterator().next()), true, modelOperation); + } else { + csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID, auditingAction); + } final String serviceModel = service.getModel(); final Map dataTypesToCreate = getDatatypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(dataTypesToCreate)) { @@ -325,7 +413,6 @@ public class ServiceImportBusinessLogic { } final Map capabilityTypesToCreate = getCapabilityTypesToCreate(serviceModel, csarInfo); - if (MapUtils.isNotEmpty(capabilityTypesToCreate)) { capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), serviceModel, true); } @@ -338,7 +425,7 @@ public class ServiceImportBusinessLogic { throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value()); } return createServiceFromYaml(service, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo, - findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId()); + findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId(), auditingAction); } catch (final ComponentException e) { log.debug("Exception occurred when createServiceFromCsar,error is:{}", e.getMessage(), e); throw e; @@ -488,6 +575,9 @@ public class ServiceImportBusinessLogic { Map combinedMappedToscaTemplate = getNewChangesToToscaTemplate(newMappedToscaTemplate, (Map) existingMappedToscaTemplate.getValue()); if (!combinedMappedToscaTemplate.equals(existingMappedToscaTemplate.getValue())) { + if (latestResource.getComponentMetadataDefinition().getMetadataDataDefinition().isNormative()) { + nodeTypeDefinition.getNodeTypeMetadata().setNormative(true); + } existingMappedToscaTemplate.setValue(combinedMappedToscaTemplate); nodeTypeDefinition.setMappedNodeType(existingMappedToscaTemplate); namesOfNodeTypesToCreate.add(nodeTypeDefinition); @@ -621,8 +711,9 @@ public class ServiceImportBusinessLogic { protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map nodeTypesInfo, CsarInfo csarInfo, - Map>> nodeTypesArtifactsToCreate, - boolean shouldLock, boolean inTransaction, String nodeName, final String userId) + Map>> nodeTypesArtifactsToCreate, + boolean shouldLock, boolean inTransaction, String nodeName, final String userId, + AuditingActionEnum auditingAction) throws BusinessLogicException { List createdArtifacts = new ArrayList<>(); Service createdService; @@ -638,7 +729,8 @@ public class ServiceImportBusinessLogic { csfyp.setNodeTypesInfo(nodeTypesInfo); csfyp.setCsarInfo(csarInfo); csfyp.setNodeName(nodeName); - createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId); + createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId, + auditingAction); log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName()); } catch (ComponentException | BusinessLogicException e) { log.debug("Create Service from yaml failed", e); @@ -651,10 +743,11 @@ public class ServiceImportBusinessLogic { } protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative, - Map>> nodeTypesArtifactsToCreate, + Map>> nodeTypesArtifactsToCreate, boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp, - final String userId) + final String userId, AuditingActionEnum auditingAction) throws BusinessLogicException { + List nodeTypesNewCreatedArtifacts = new ArrayList<>(); String yamlName = csfyp.getYamlName(); ParsedToscaYamlInfo parsedToscaYamlInfo = csfyp.getParsedToscaYamlInfo(); @@ -666,7 +759,6 @@ public class ServiceImportBusinessLogic { if (shouldLock) { Either lockResult = serviceBusinessLogic.lockComponentByName(service.getSystemName(), service, CREATE_RESOURCE); if (lockResult.isRight()) { - serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ComponentException(lockResult.right().value()); } log.debug("name is locked {} status = {}", service.getSystemName(), lockResult); @@ -684,12 +776,13 @@ public class ServiceImportBusinessLogic { service.setProperties(propertiesList); } log.trace("************* createResourceFromYaml before full create resource {}", yamlName); - service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative); + service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative, auditingAction); log.trace("************* Going to add inputs from yaml {}", yamlName); Map inputs = parsedToscaYamlInfo.getInputs(); service = serviceImportParseLogic.createInputsOnService(service, inputs); log.trace("************* Finished to add inputs from yaml {}", yamlName); - ListDataDefinition substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties(); + ListDataDefinition substitutionFilterProperties = + parsedToscaYamlInfo.getSubstitutionFilterProperties(); service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties); log.trace("************* Added Substitution filter from interface yaml {}", yamlName); Map uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances(); @@ -705,7 +798,6 @@ public class ServiceImportBusinessLogic { Either, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName()); if (validateUpdateVfGroupNamesRes.isRight()) { - serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ComponentException(validateUpdateVfGroupNamesRes.right().value()); } Map groups; @@ -717,23 +809,19 @@ public class ServiceImportBusinessLogic { } Either createGroupsOnResource = createGroupsOnResource(service, groups); if (createGroupsOnResource.isRight()) { - serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ComponentException(createGroupsOnResource.right().value()); } service = createGroupsOnResource.left().value(); Either createPoliciesOnResource = createPoliciesOnResource(service, parsedToscaYamlInfo.getPolicies()); if (createPoliciesOnResource.isRight()) { - serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ComponentException(createPoliciesOnResource.right().value()); } service = createPoliciesOnResource.left().value(); log.trace("************* Going to add artifacts from yaml {}", yamlName); - NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate); Either createArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, - createdArtifacts, yamlName, csarInfo, service, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock); + createdArtifacts, yamlName, csarInfo, service, inTransaction, shouldLock); if (createArtifactsEither.isRight()) { - serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ComponentException(createArtifactsEither.right().value()); } service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId()); @@ -765,13 +853,17 @@ public class ServiceImportBusinessLogic { final List componentInstances = component.getComponentInstances(); final String componentUniqueId = component.getUniqueId(); for (final InputDefinition input : inputs) { - if (isInputFromComponentInstanceProperty(input.getName(), componentInstances)) { + boolean isSubMapProp = false; + if (substitutionMappingProperties != null && !substitutionMappingProperties.isEmpty()) { + isSubMapProp = substitutionMappingProperties.entrySet().stream() + .anyMatch(stringEntry -> stringEntry.getValue().get(0).equals(input.getName())); + } + if (!isSubMapProp && isInputFromComponentInstanceProperty(input.getName(), componentInstances)) { associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId); } else { associateInputToServiceProperty(userId, input, component, substitutionMappingProperties); } } - Either, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId); if (either.isRight()) { throw new ComponentException(ActionStatus.GENERAL_ERROR); @@ -785,7 +877,8 @@ public class ServiceImportBusinessLogic { AtomicBoolean isInputFromCIProp = new AtomicBoolean(false); if (CollectionUtils.isNotEmpty(componentInstances)) { - outer: for (ComponentInstance instance : componentInstances) { + outer: + for (ComponentInstance instance : componentInstances) { for (PropertyDefinition instanceProperty : instance.getProperties()) { if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) { for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) { @@ -808,7 +901,8 @@ public class ServiceImportBusinessLogic { String componentInstanceId = null; ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(); - outer: for (ComponentInstance instance : componentInstances) { + outer: + for (ComponentInstance instance : componentInstances) { for (PropertyDefinition instanceProperty : instance.getProperties()) { if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) { for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) { @@ -848,8 +942,9 @@ public class ServiceImportBusinessLogic { } }); - final Optional propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get())) - .findFirst(); + final Optional propDefOptional = + properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get())) + .findFirst(); if (propDefOptional.isPresent()) { // From SELF final String componentUniqueId = component.getUniqueId(); @@ -865,6 +960,8 @@ public class ServiceImportBusinessLogic { if (either.isRight()) { throw new ComponentException(ActionStatus.GENERAL_ERROR); } + } else { + input.setMappedToComponentProperty(false); } } } @@ -894,8 +991,9 @@ public class ServiceImportBusinessLogic { boolean inTransaction, boolean shouldLock) { String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName(); Resource resource = preparedResource; - Map>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts - .getNodeTypesArtifactsToHandle(); + Map>> nodeTypesArtifactsToHandle = + nodeTypeInfoToUpdateArtifacts + .getNodeTypesArtifactsToHandle(); if (preparedResource.getResourceType() == ResourceTypeEnum.VF) { if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()) { Either, ResponseFormat> handleNodeTypeArtifactsRes = handleNodeTypeArtifacts(preparedResource, @@ -1022,7 +1120,8 @@ public class ServiceImportBusinessLogic { vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class); vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left().value()); } else { - Either>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle( + Either>, ResponseFormat> + findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle( component, artifactPathAndNameList.left().value(), csarInfo.getModifier()); if (findVfCsarArtifactsToHandleRes.isRight()) { resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value()); @@ -1181,7 +1280,6 @@ public class ServiceImportBusinessLogic { protected Either createOrUpdateArtifacts(ArtifactOperationEnum operation, List createdArtifacts, String yamlFileName, CsarInfo csarInfo, Service preparedService, - NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts, boolean inTransaction, boolean shouldLock) { Either createdCsarArtifactsEither = handleVfCsarArtifacts(preparedService, csarInfo, createdArtifacts, new ArtifactOperationInfo(false, false, operation), shouldLock, inTransaction); @@ -1313,7 +1411,8 @@ public class ServiceImportBusinessLogic { EnumMap> nodeTypeArtifactsToHandle = new EnumMap<>( ArtifactsBusinessLogic.ArtifactOperationEnum.class); Wrapper responseWrapper = new Wrapper<>(); - Either>, ResponseFormat> nodeTypeArtifactsToHandleRes = Either + Either>, ResponseFormat> + nodeTypeArtifactsToHandleRes = Either .left(nodeTypeArtifactsToHandle); try { List artifactsToUpload = new ArrayList<>(artifactPathAndNameList); @@ -1950,7 +2049,7 @@ public class ServiceImportBusinessLogic { .forEach(instanceProperty -> { toscaFunctionService.updateFunctionWithDataFromSelfComponent(instanceProperty.getToscaFunction(), updatedService, instancePropertyMap, instanceAttributeMap); - instanceProperty.setValue(instanceProperty.getToscaFunction().getValue()); + instanceProperty.setValue(StringEscapeUtils.unescapeJava(instanceProperty.getToscaFunction().getValue())); }) ); } @@ -1997,7 +2096,9 @@ public class ServiceImportBusinessLogic { instAttributes.put(resourceInstanceId, originResource.getAttributes()); addAttributeValueToResourceInstance(instAttributes, uploadComponentInstanceInfo.getAttributes()); } - if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() != null) { + if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() == null) { + instNodeFilter.put(resourceInstanceId, new UploadNodeFilterInfo()); + } else { instNodeFilter.put(resourceInstanceId, uploadComponentInstanceInfo.getUploadNodeFilterInfo()); } if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getInterfaces())) { @@ -2293,13 +2394,17 @@ public class ServiceImportBusinessLogic { //Inputs ListDataDefinition instanceInputs = instanceOperation.getInputs(); mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs); - component.getProperties() - .forEach(property -> instanceInputs.getListToscaDataDefinition().stream() - .filter(instanceInput -> instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition && - property.getName().equals(instanceInput.getToscaFunction() != null ? - ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : null)) - .forEach(oldInput -> oldInput.setType(property.getType())) - ); + if (null != instanceInputs) { + component.getProperties() + .forEach(property -> instanceInputs.getListToscaDataDefinition().stream() + .filter(instanceInput -> + instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition && + property.getName().equals(instanceInput.getToscaFunction() != null ? + ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : + null)) + .forEach(oldInput -> oldInput.setType(property.getType())) + ); + } templateOperation.setInputs(instanceInputs); //Implementation templateOperation.setImplementation(instanceOperation.getImplementation()); @@ -2714,6 +2819,9 @@ public class ServiceImportBusinessLogic { Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType()); componentInstance.setName(uploadComponentInstanceInfo.getName()); componentInstance.setIcon(origResource.getIcon()); + componentInstance.setMinOccurrences(uploadComponentInstanceInfo.getMinOccurrences()); + componentInstance.setMaxOccurrences(uploadComponentInstanceInfo.getMaxOccurrences()); + componentInstance.setInstanceCount(uploadComponentInstanceInfo.getInstanceCount()); resourcesInstancesMap.put(componentInstance, origResource); } catch (final ComponentException e) { throw e;