X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FResourceBusinessLogic.java;h=77d17ca76ae02cf7fd54ad6f330491ee11e85b8a;hb=7f07f514eacacfb54d851201c49b24acd9b5e343;hp=49cd95831c2647dc8333c4d2c5dad7726b08720a;hpb=a5e32b3d20bc078482cb08645c38ffb685c0f145;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 49cd95831c..77d17ca76a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -29,6 +29,7 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStr 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 static org.openecomp.sdc.common.api.Constants.DEFAULT_GROUP_VF_MODULE; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -46,6 +47,7 @@ import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; + import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -124,6 +126,7 @@ import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; +import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RelationshipImpl; import org.openecomp.sdc.be.model.RelationshipInfo; @@ -182,7 +185,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; + import com.google.common.annotations.VisibleForTesting; + import fj.data.Either; @org.springframework.stereotype.Component("resourceBusinessLogic") @@ -217,6 +222,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private final ModelBusinessLogic modelBusinessLogic; private IInterfaceLifecycleOperation interfaceTypeOperation; private LifecycleBusinessLogic lifecycleBusinessLogic; + private final DataTypeBusinessLogic dataTypeBusinessLogic; + private final PolicyTypeBusinessLogic policyTypeBusinessLogic; + @Autowired private ICapabilityTypeOperation capabilityTypeOperation; @Autowired @@ -247,7 +255,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator, final ComponentProjectCodeValidator componentProjectCodeValidator, final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic, - final ModelBusinessLogic modelBusinessLogic) { + final ModelBusinessLogic modelBusinessLogic, + final DataTypeBusinessLogic dataTypeBusinessLogic, final PolicyTypeBusinessLogic policyTypeBusinessLogic) { super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator); @@ -264,6 +273,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { this.propertyBusinessLogic = propertyBusinessLogic; this.policyBusinessLogic = policyBusinessLogic; this.modelBusinessLogic = modelBusinessLogic; + this.dataTypeBusinessLogic = dataTypeBusinessLogic; + this.policyTypeBusinessLogic = policyTypeBusinessLogic; } static Either rollbackWithEither(final JanusGraphDao janusGraphDao, final ActionStatus actionStatus, @@ -1031,19 +1042,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { user.getUserId()); CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID); Map nodeTypesInfo = csarInfo.extractTypesInfo(); - if (StringUtils.isNotEmpty(resource.getModel())) { - final Map dataTypesToCreate = new HashMap<>(); - for (final String dataType: csarInfo.getDataTypes().keySet()) { - final Either result = propertyOperation.getDataTypeByName(dataType, resource.getModel()); - if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) { - dataTypesToCreate.put(dataType, csarInfo.getDataTypes().get(dataType)); - } + final String model = resource.getModel(); + if (StringUtils.isNotEmpty(model)) { + final Map dataTypesToCreate = getDatatypesToCreate(model, csarInfo.getDataTypes()); + final Map policyTypesToCreate = getPolicytypesToCreate(model, csarInfo.getPolicyTypes()); + if (MapUtils.isNotEmpty(dataTypesToCreate) || MapUtils.isNotEmpty(policyTypesToCreate)) { + createModel(resource, csarInfo.getVfResourceName()); } if (MapUtils.isNotEmpty(dataTypesToCreate)) { - final String nameForGeneratedModel = resource.getModel() + "_" + csarInfo.getVfResourceName() + resource.getCsarVersion(); - final Model model = new Model(nameForGeneratedModel, resource.getModel(), ModelTypeEnum.NORMATIVE_EXTENSION); - modelBusinessLogic.createModel(model, new Yaml().dump(dataTypesToCreate)); - resource.setModel(nameForGeneratedModel); + dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), model, true); + } + if (MapUtils.isNotEmpty(policyTypesToCreate)) { + policyTypeBusinessLogic.createPolicyTypeFromYaml(new Yaml().dump(policyTypesToCreate), model, true); } } @@ -1148,6 +1158,37 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES).left().orValue(HashMap::new); } + private void createModel(final Resource resource, final String vfResourcename) { + final String nameForGeneratedModel = resource.getModel() + "_" + vfResourcename + resource.getCsarVersion(); + Model model = new Model(nameForGeneratedModel, resource.getModel(), ModelTypeEnum.NORMATIVE_EXTENSION); + modelBusinessLogic.createModel(model); + resource.setModel(nameForGeneratedModel); + } + + private Map getDatatypesToCreate(final String model, final Map dataTypes) { + final Map dataTypesToCreate = new HashMap<>(); + for (final String dataType : dataTypes.keySet()) { + final Either result = + propertyOperation.getDataTypeByName(dataType, model); + if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) { + dataTypesToCreate.put(dataType, dataTypes.get(dataType)); + } + } + return dataTypesToCreate; + } + + private Map getPolicytypesToCreate(final String model, final Map policyTypes) { + final Map policyTypesToCreate = new HashMap<>(); + for (final String policyType : policyTypes.keySet()) { + final Either result = + policyTypeOperation.getLatestPolicyTypeByType(policyType, model); + if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) { + policyTypesToCreate.put(policyType, policyTypes.get(policyType)); + } + } + return policyTypesToCreate; + } + private void createNodeTypes(String yamlName, Resource resource, boolean needLock, Map>> nodeTypesArtifactsToHandle, List nodeTypesNewCreatedArtifacts, Map nodeTypesInfo, CsarInfo csarInfo, @@ -3368,6 +3409,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ToscaArtifactDataDefinition to = new ToscaArtifactDataDefinition(); to.setFile(entry.getValue().getFile()); to.setType(entry.getValue().getType()); + if(isNotEmpty(entry.getValue().getProperties())) { + Map newPropertiesMap = new HashMap<>(); + List artifactPropsInfo = entry.getValue().getProperties(); + for(UploadPropInfo propInfo: artifactPropsInfo) { + newPropertiesMap.put(propInfo.getName(), propInfo.getValue()); + } + to.setProperties(newPropertiesMap); + } toscaArtifacts.put(entry.getKey(), to); } componentInstance.setToscaArtifacts(toscaArtifacts); @@ -3699,9 +3748,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (newResource.getResourceType().isAtomicType() && !newResource.getName().equals("Root") && newResource.getResourceType() != ResourceTypeEnum.CVFC) { ResourceTypeEnum updatedResourceType = newResource.getResourceType(); - Component derivedFromResource = getParentComponent(newResource); - if (derivedFromResource.getComponentType() == ComponentTypeEnum.RESOURCE) { - Resource parentResource = (Resource) derivedFromResource; + Optional derivedFromResourceOptional = getParentComponent(newResource); + if (derivedFromResourceOptional.isPresent() && derivedFromResourceOptional.get().getComponentType() == ComponentTypeEnum.RESOURCE) { + Resource parentResource = (Resource) derivedFromResourceOptional.get(); if (!(parentResource.isAbstract() && (ResourceTypeEnum.VFC == parentResource.getResourceType() || ResourceTypeEnum.ABSTRACT == parentResource.getResourceType())) && parentResource.getResourceType() != updatedResourceType && oldResource.getResourceType() != updatedResourceType) { @@ -3716,7 +3765,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - private Component getParentComponent(Resource newResource) { + private Optional getParentComponent(Resource newResource) { + if (newResource.getDerivedFrom() == null) { + return Optional.empty(); + } String toscaResourceNameDerivedFrom = newResource.getDerivedFrom().get(0); Either latestByToscaResourceName = toscaOperationFacade .getLatestByToscaResourceName(toscaResourceNameDerivedFrom, newResource.getModel()); @@ -3726,7 +3778,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("#mergeOldResourceMetadataWithNew - derived from resource {} not found", toscaResourceNameDerivedFrom); throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, toscaResourceNameDerivedFrom); } - return latestByToscaResourceName.left().value(); + return Optional.of(latestByToscaResourceName.left().value()); } private Resource prepareResourceForUpdate(Resource oldResource, Resource newResource, User user, boolean inTransaction, boolean needLock) { @@ -3843,7 +3895,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Resource resource, List validationObjects, AuditingActionEnum actionEnum, Either eitherResult, String type, boolean inTransaction) { - Either eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(type, inTransaction); + Either eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(UniqueIdBuilder.buildCapabilityTypeUid(resource.getModel(), type), inTransaction); if (eitherCapTypeFound.isRight()) { if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) { BeEcompErrorManager.getInstance().logBeGraphObjectMissingError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type", type); @@ -3868,7 +3920,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either eitherResult, Entry> typeEntry, boolean inTransaction) { Either eitherCapTypeFound = capabilityTypeOperation - .getCapabilityType(typeEntry.getKey(), inTransaction); + .getCapabilityType(UniqueIdBuilder.buildCapabilityTypeUid(resource.getModel(), typeEntry.getKey()), inTransaction); if (eitherCapTypeFound.isRight()) { if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) { BeEcompErrorManager.getInstance()