diff options
Diffstat (limited to 'catalog-be/src/main')
2 files changed, 241 insertions, 220 deletions
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 507abb5ed6..0ffceda8e8 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 @@ -15,26 +15,7 @@ */ 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.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement; -import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue; -import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN; - import fj.data.Either; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.CollectionUtils; @@ -136,6 +117,26 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.Yaml; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; + +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.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement; +import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue; +import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN; + @Getter @Setter @org.springframework.stereotype.Component("serviceImportBusinessLogic") @@ -1042,64 +1043,64 @@ public class ServiceImportBusinessLogic { } protected Resource createResourceInstancesRelations(User user, String yamlName, Resource resource, - Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) { - log.debug("#createResourceInstancesRelations - Going to create relations "); - List<ComponentInstance> componentInstancesList = resource.getComponentInstances(); - if (((MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) && - resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances - log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", - resource.getUniqueId(), yamlName); - BeEcompErrorManager.getInstance() - .logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", - BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); - } - Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); - Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); - Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); - Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); - Map<String, Resource> originCompMap = new HashMap<>(); - List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); - - log.debug("enter ServiceImportBusinessLogic createResourceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); - Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", - "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( - DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName)); - } - Resource finalResource = resource; - uploadResInstancesMap - .values() - .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, - instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, - instArtifacts, instAttributes, originCompMap, instInputs, i)); - serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties); - serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs); - serviceImportParseLogic - .associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts); - serviceImportParseLogic.associateArtifactsToInstances(yamlName, resource, instArtifacts); - serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements); - serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes); - resource = serviceImportParseLogic.getResourceAfterCreateRelations(resource); - - serviceImportParseLogic - .addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations); - serviceImportParseLogic.associateResourceInstances(yamlName, resource, relations); - handleSubstitutionMappings(resource, uploadResInstancesMap); - log.debug("************* in create relations, getResource start"); - Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); - log.debug("************* in create relations, getResource end"); - if (eitherGetResource.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByResource( - componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource)); - } - return eitherGetResource.left().value(); + Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) { + log.debug("#createResourceInstancesRelations - Going to create relations "); + + List<ComponentInstance> componentInstancesList = resource.getComponentInstances(); + if (((MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) && + resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances + log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", resource.getUniqueId(), yamlName); + BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", BeEcompErrorManager.ErrorSeverity.ERROR); + throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); + } + Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); + Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); + Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); + Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); + Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); + Map<String, Resource> originCompMap = new HashMap<>(); + List<RequirementCapabilityRelDef> relations = new ArrayList<>(); + Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); + + log.debug("enter ServiceImportBusinessLogic createResourceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); + if(serviceBusinessLogic.dataTypeCache!=null){ + Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); + if (allDataTypes.isRight()) { + JanusGraphOperationStatus status = allDataTypes.right().value(); + BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", + "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); + throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( + DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName)); + } + Resource finalResource = resource; + uploadResInstancesMap + .values() + .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, + instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, + instArtifacts, instAttributes, originCompMap, instInputs, i)); + } + serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties); + serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs); + serviceImportParseLogic + .associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts); + serviceImportParseLogic.associateArtifactsToInstances(yamlName, resource, instArtifacts); + serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements); + serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes); + resource = serviceImportParseLogic.getResourceAfterCreateRelations(resource); + + serviceImportParseLogic + .addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations); + serviceImportParseLogic.associateResourceInstances(yamlName, resource, relations); + handleSubstitutionMappings(resource, uploadResInstancesMap); + log.debug("************* in create relations, getResource start"); + Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); + log.debug("************* in create relations, getResource end"); + if (eitherGetResource.isRight()) { + throw new ComponentException(componentsUtils.getResponseFormatByResource( + componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource)); + } + return eitherGetResource.left().value(); } protected void processProperty(Resource resource, ComponentInstance currentCompInstance, Map<String, DataTypeDefinition> allDataTypes, @@ -1446,68 +1447,72 @@ public class ServiceImportBusinessLogic { protected Service createServiceInstancesRelations(User user, String yamlName, Service service, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) { - log.debug("#createResourceInstancesRelations - Going to create relations "); - List<ComponentInstance> componentInstancesList = service.getComponentInstances(); - if (((MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)))) { // PNF can have no resource instances - log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", + + log.debug("#createResourceInstancesRelations - Going to create relations "); + List<ComponentInstance> componentInstancesList = service.getComponentInstances(); + if (((MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)))) { // PNF can have no resource instances + log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", service.getUniqueId(), yamlName); - BeEcompErrorManager.getInstance() + BeEcompErrorManager.getInstance() .logInternalDataError("createResourceInstancesRelations", "No instances found in a component or nn yaml template. ", BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); - } - Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); - Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); - Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); - Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); - Map<String, Resource> originCompMap = new HashMap<>(); - List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); - - log.debug("enter ServiceImportBusinessLogic createServiceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); - Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", - "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( - DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName)); - } - Service finalResource = service; - uploadResInstancesMap - .values() - .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, - instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, - instArtifacts, instAttributes, originCompMap, instInputs, i)); - serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties); - serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); - serviceImportParseLogic.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts); - serviceImportParseLogic.associateArtifactsToInstances(yamlName, service, instArtifacts); - serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, service, instCapabilities, instRequirements); - log.debug("enter createServiceInstancesRelations test,instRequirements:{},instCapabilities:{}", - instRequirements, instCapabilities); - serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, service, instAttributes); - ToscaElement serviceTemplate = ModelConverter.convertToToscaElement(service); - Map<String, ListCapabilityDataDefinition> capabilities = serviceTemplate.getCapabilities(); - Map<String, ListRequirementDataDefinition> requirements = serviceTemplate.getRequirements(); - - serviceImportParseLogic.associateCapabilitiesToService(yamlName, service, capabilities); - serviceImportParseLogic.associateRequirementsToService(yamlName, service, requirements); - service = getResourceAfterCreateRelations(service); - - addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations); - serviceImportParseLogic.associateResourceInstances(yamlName, service, relations); - handleSubstitutionMappings(service, uploadResInstancesMap); - log.debug("************* in create relations, getResource start"); - Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(service.getUniqueId()); - log.debug("************* in create relations, getResource end"); - if (eitherGetResource.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByComponent( - componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), service, service.getComponentType())); - } - return eitherGetResource.left().value(); + throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); + } + Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); + Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); + Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); + Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); + Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); + Map<String, Resource> originCompMap = new HashMap<>(); + List<RequirementCapabilityRelDef> relations = new ArrayList<>(); + Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); + + log.debug("enter ServiceImportBusinessLogic createServiceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); + if(serviceBusinessLogic.dataTypeCache!=null){ + Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); + if (allDataTypes.isRight()) { + JanusGraphOperationStatus status = allDataTypes.right().value(); + BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", + "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); + throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( + DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName)); + } + Service finalResource = service; + uploadResInstancesMap + .values() + .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, + instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, + instArtifacts, instAttributes, originCompMap, instInputs, i)); + + } + serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties); + serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); + serviceImportParseLogic.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts); + serviceImportParseLogic.associateArtifactsToInstances(yamlName, service, instArtifacts); + serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, service, instCapabilities, instRequirements); + log.debug("enter createServiceInstancesRelations test,instRequirements:{},instCapabilities:{}", + instRequirements, instCapabilities); + serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, service, instAttributes); + ToscaElement serviceTemplate = ModelConverter.convertToToscaElement(service); + Map<String, ListCapabilityDataDefinition> capabilities = serviceTemplate.getCapabilities(); + Map<String, ListRequirementDataDefinition> requirements = serviceTemplate.getRequirements(); + + serviceImportParseLogic.associateCapabilitiesToService(yamlName, service, capabilities); + serviceImportParseLogic.associateRequirementsToService(yamlName, service, requirements); + service = getResourceAfterCreateRelations(service); + + addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations); + serviceImportParseLogic.associateResourceInstances(yamlName, service, relations); + handleSubstitutionMappings(service, uploadResInstancesMap); + log.debug("************* in create relations, getResource start"); + Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(service.getUniqueId()); + log.debug("************* in create relations, getResource end"); + if (eitherGetResource.isRight()) { + throw new ComponentException(componentsUtils.getResponseFormatByComponent( + componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), service, service.getComponentType())); + } + return eitherGetResource.left().value(); } protected void processComponentInstance(String yamlName, Component component, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index a86d6047d4..3c53c0ca50 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -55,7 +55,6 @@ import org.openecomp.sdc.be.tosca.CsarUtils; import org.openecomp.sdc.be.utils.CommonBeUtils; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; -import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.GeneralUtility; @@ -1527,37 +1526,40 @@ public class ServiceImportParseLogic { @SuppressWarnings("unchecked") protected void setInformationalArtifactsPlaceHolder(Service service, User user) { - Map<String, ArtifactDefinition> artifactMap = service.getArtifacts(); - if (artifactMap == null) { - artifactMap = new HashMap<>(); - } - String resourceUniqueId = service.getUniqueId(); - List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration() - .getExcludeResourceCategory(); - List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration() - .getExcludeResourceType(); - Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager() - .getConfiguration().getInformationalResourceArtifacts(); - List<CategoryDefinition> categories = service.getCategories(); - boolean isCreateArtifact = true; - if (exludeResourceCategory != null) { - String category = categories.get(0).getName(); - isCreateArtifact = exludeResourceCategory.stream().noneMatch(e->e.equalsIgnoreCase(category)); - } - - if (informationalResourceArtifacts != null && isCreateArtifact) { - Set<String> keys = informationalResourceArtifacts.keySet(); - for (String informationalResourceArtifactName : keys) { - Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts - .get(informationalResourceArtifactName); - ArtifactDefinition artifactDefinition = serviceBusinessLogic.artifactsBusinessLogic.createArtifactPlaceHolderInfo( - resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user, - ArtifactGroupTypeEnum.INFORMATIONAL); - artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); + Map<String, ArtifactDefinition> artifactMap = service.getArtifacts(); + if (artifactMap == null) { + artifactMap = new HashMap<>(); } - } - service.setArtifacts(artifactMap); + String resourceUniqueId = service.getUniqueId(); + List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration() + .getExcludeResourceCategory(); + List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration() + .getExcludeResourceType(); + Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager() + .getConfiguration().getInformationalResourceArtifacts(); + List<CategoryDefinition> categories = service.getCategories(); + boolean isCreateArtifact = true; + if (exludeResourceCategory != null) { + String category = categories.get(0).getName(); + isCreateArtifact = exludeResourceCategory.stream().noneMatch(e -> e.equalsIgnoreCase(category)); + } + + if (informationalResourceArtifacts != null && isCreateArtifact) { + Set<String> keys = informationalResourceArtifacts.keySet(); + for (String informationalResourceArtifactName : keys) { + Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts + .get(informationalResourceArtifactName); + if(serviceBusinessLogic.artifactsBusinessLogic!=null){ + ArtifactDefinition artifactDefinition = serviceBusinessLogic.artifactsBusinessLogic.createArtifactPlaceHolderInfo( + resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user, + ArtifactGroupTypeEnum.INFORMATIONAL); + artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); + } + } + } + service.setArtifacts(artifactMap); + } public void rollback(boolean inTransaction, Service service, List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) { @@ -1659,21 +1661,29 @@ public class ServiceImportParseLogic { private void validateFields(Resource currentResource, Resource updateInfoResource, boolean inTransaction, boolean isNested) { - boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentResource.getVersion()); - log.debug("validate resource name before update"); - validateResourceName(currentResource, updateInfoResource, hasBeenCertified, isNested); - log.debug("validate description before update"); - serviceBusinessLogic.componentDescriptionValidator.validateAndCorrectField(null, updateInfoResource, null); - log.debug("validate icon before update"); - log.debug("validate tags before update"); - serviceBusinessLogic.componentTagsValidator.validateAndCorrectField(null, updateInfoResource, null); - log.debug("validate vendor name before update"); - log.debug("validate resource vendor model number before update"); - log.debug("validate vendor release before update"); - log.debug("validate contact info before update"); - serviceBusinessLogic.componentContactIdValidator.validateAndCorrectField(null, updateInfoResource, null); - log.debug(VALIDATE_DERIVED_BEFORE_UPDATE); - log.debug("validate category before update"); + + boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentResource.getVersion()); + log.debug("validate resource name before update"); + validateResourceName(currentResource, updateInfoResource, hasBeenCertified, isNested); + log.debug("validate description before update"); + if(serviceBusinessLogic.componentDescriptionValidator!=null){ + serviceBusinessLogic.componentDescriptionValidator.validateAndCorrectField(null, updateInfoResource, null); + } + log.debug("validate icon before update"); + log.debug("validate tags before update"); + if(serviceBusinessLogic.componentTagsValidator!=null){ + serviceBusinessLogic.componentTagsValidator.validateAndCorrectField(null, updateInfoResource, null); + } + log.debug("validate vendor name before update"); + log.debug("validate resource vendor model number before update"); + log.debug("validate vendor release before update"); + log.debug("validate contact info before update"); + if(serviceBusinessLogic.componentContactIdValidator!=null){ + serviceBusinessLogic.componentContactIdValidator.validateAndCorrectField(null, updateInfoResource, null); + } + log.debug(VALIDATE_DERIVED_BEFORE_UPDATE); + log.debug("validate category before update"); + } @@ -1720,13 +1730,16 @@ public class ServiceImportParseLogic { } protected Resource failOnChangeState(ResponseFormat response, User user, Resource oldResource, Resource newResource) { - log.info("resource {} cannot be updated. reason={}", oldResource.getUniqueId(), - response.getFormattedMessage()); - componentsUtils.auditResource(response, user, newResource, AuditingActionEnum.IMPORT_RESOURCE, - ResourceVersionInfo.newBuilder() - .state(oldResource.getLifecycleState().name()) - .version(oldResource.getVersion()) - .build()); + if(response.getRequestError() != null){ + log.info("resource {} cannot be updated. reason={}", oldResource.getUniqueId(), + response.getFormattedMessage()); + + componentsUtils.auditResource(response, user, newResource, AuditingActionEnum.IMPORT_RESOURCE, + ResourceVersionInfo.newBuilder() + .state(oldResource.getLifecycleState().name()) + .version(oldResource.getVersion()) + .build()); + } throw new ComponentException(response); } @@ -2087,40 +2100,43 @@ public class ServiceImportParseLogic { } protected void setInformationalArtifactsPlaceHolder(Resource resource, User user) { - Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts(); - if (artifactMap == null) { - artifactMap = new HashMap<>(); - } - String resourceUniqueId = resource.getUniqueId(); - List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration() - .getExcludeResourceCategory(); - List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration() - .getExcludeResourceType(); - Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager() - .getConfiguration().getInformationalResourceArtifacts(); - List<CategoryDefinition> categories = resource.getCategories(); - boolean isCreateArtifact = true; - if (exludeResourceCategory != null) { - String category = categories.get(0).getName(); - isCreateArtifact = exludeResourceCategory.stream().noneMatch(e->e.equalsIgnoreCase(category)); - } - if (isCreateArtifact && exludeResourceType != null) { - String resourceType = resource.getResourceType().name(); - isCreateArtifact = exludeResourceType.stream().noneMatch(e->e.equalsIgnoreCase(resourceType)); - } - if (informationalResourceArtifacts != null && isCreateArtifact) { - Set<String> keys = informationalResourceArtifacts.keySet(); - for (String informationalResourceArtifactName : keys) { - Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts - .get(informationalResourceArtifactName); - ArtifactDefinition artifactDefinition = serviceBusinessLogic.artifactsBusinessLogic.createArtifactPlaceHolderInfo( - resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user, - ArtifactGroupTypeEnum.INFORMATIONAL); - artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); + Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts(); + if (artifactMap == null) { + artifactMap = new HashMap<>(); } - } - resource.setArtifacts(artifactMap); + String resourceUniqueId = resource.getUniqueId(); + List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration() + .getExcludeResourceCategory(); + List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration() + .getExcludeResourceType(); + Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager() + .getConfiguration().getInformationalResourceArtifacts(); + List<CategoryDefinition> categories = resource.getCategories(); + boolean isCreateArtifact = true; + if (exludeResourceCategory != null) { + String category = categories.get(0).getName(); + isCreateArtifact = exludeResourceCategory.stream().noneMatch(e->e.equalsIgnoreCase(category)); + } + if (isCreateArtifact && exludeResourceType != null) { + String resourceType = resource.getResourceType().name(); + isCreateArtifact = exludeResourceType.stream().noneMatch(e->e.equalsIgnoreCase(resourceType)); + } + if (informationalResourceArtifacts != null && isCreateArtifact) { + Set<String> keys = informationalResourceArtifacts.keySet(); + for (String informationalResourceArtifactName : keys) { + Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts + .get(informationalResourceArtifactName); + if(serviceBusinessLogic.artifactsBusinessLogic!=null){ + ArtifactDefinition artifactDefinition = serviceBusinessLogic.artifactsBusinessLogic.createArtifactPlaceHolderInfo( + resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user, + ArtifactGroupTypeEnum.INFORMATIONAL); + artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); + } + } + } + resource.setArtifacts(artifactMap); + } public void rollback(boolean inTransaction, Resource resource, List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) { |