X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FComponentInstanceBusinessLogic.java;h=7cb9858484713ca38fbf4ba031bc37e67d55ee7d;hb=5d7ca5c1e86d7633a1954ae89334df18d264f82b;hp=ff98163b694a1b6ad12ad6559e63e9f9bd233510;hpb=11ffaa62b28c517e2eb3b765ab6ec54f18f1ef6a;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index ff98163b69..7cb9858484 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -1888,43 +1888,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { * @param userId * @return */ - public Either createOrUpdateAttributeValue(ComponentTypeEnum componentTypeEnum, String componentId, - String resourceInstanceId, - ComponentInstanceProperty attribute, String userId) { - Either result = null; - Wrapper errorWrapper = new Wrapper<>(); - validateUserExists(userId); - if (errorWrapper.isEmpty()) { - validateComponentTypeEnum(componentTypeEnum, "CreateOrUpdateAttributeValue", errorWrapper); - } - if (errorWrapper.isEmpty()) { - validateCanWorkOnComponent(componentId, componentTypeEnum, userId, errorWrapper); - } - if (errorWrapper.isEmpty()) { - validateComponentLock(componentId, componentTypeEnum, errorWrapper); - } - try { - if (errorWrapper.isEmpty()) { - final boolean isCreate = Objects.isNull(attribute.getValueUniqueUid()); - if (isCreate) { - result = createAttributeValue(attribute, resourceInstanceId); - } else { - result = updateAttributeValue(attribute, resourceInstanceId); - } - } else { - result = Either.right(errorWrapper.getInnerElement()); - } - return result; - } finally { - if (result == null || result.isRight()) { - janusGraphDao.rollback(); - } else { - janusGraphDao.commit(); - } - // unlock resource - graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType()); - } - } public Either, ResponseFormat> createOrUpdatePropertiesValues(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, @@ -2110,19 +2073,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } - private void setJsonObjectForSubProperty(final JSONObject jObject, final List path, String value) { - if (path.size() == 1) { - Object valueAsObject = new Yaml().loadAs(value, Object.class); - jObject.put(path.get(0), valueAsObject); - } else { - if (!jObject.has(path.get(0))) { - jObject.put(path.get(0), new JSONObject()); - } - final JSONObject jsonObject = jObject.getJSONObject(path.get(0)); - setJsonObjectForSubProperty(jsonObject, path.subList(1, path.size()), value); - } - } - public Either, ResponseFormat> createOrUpdateAttributeValues(final ComponentTypeEnum componentTypeEnum, final String componentId, final String resourceInstanceId, @@ -2248,14 +2198,35 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { private ComponentInstanceAttribute validateAttributeExistsOnComponent(final ComponentInstanceAttribute attribute, final Component containerComponent, final ComponentInstance foundResourceInstance) { - final List instanceProperties = + final List instanceAttributes = containerComponent.getComponentInstancesAttributes().get(foundResourceInstance.getUniqueId()); + final List instanceProperties = + containerComponent.getComponentInstancesProperties().get(foundResourceInstance.getUniqueId()); final Optional instanceAttribute = + instanceAttributes.stream().filter(p -> p.getName().equals(attribute.getName())).findAny(); + final Optional instanceProperty = instanceProperties.stream().filter(p -> p.getName().equals(attribute.getName())).findAny(); - if (!instanceAttribute.isPresent()) { - throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, attribute.getName()); + if (instanceAttribute.isPresent()) { + return instanceAttribute.get(); + } + if (instanceProperty.isPresent()) { + ComponentInstanceAttribute propAttribute = getComponentInstanceAttribute(instanceProperty.get()); + return propAttribute; } - return instanceAttribute.get(); + throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, attribute.getName()); + } + + private ComponentInstanceAttribute getComponentInstanceAttribute(ComponentInstanceProperty property) { + ComponentInstanceAttribute attribute = new ComponentInstanceAttribute(); + attribute.setParentUniqueId(property.getParentUniqueId()); + attribute.setName(property.getName()); + attribute.setOwnerId(property.getOwnerId()); + attribute.setType(property.getType()); + attribute.setSchema(property.getSchema()); + attribute.setUniqueId(property.getUniqueId()); + attribute.setValue(property.getValue()); + attribute.setDefaultValue(property.getDefaultValue()); + return attribute; } private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property, @@ -2498,42 +2469,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { return Either.left(newValue); } - private void validateToscaGetFunction(T property, Component parentComponent) { - final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction(); - validateGetToscaFunctionAttributes(toscaGetFunction); - validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource()); - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) { - validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel()); - return; - } - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) { - if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { - validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel()); - } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { - final ComponentInstance componentInstance = - parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) - .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); - validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel()); - } - - return; - } - if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_ATTRIBUTE) { - if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { - validateGetFunction(property, parentComponent.getAttributes(), parentComponent.getModel()); - } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { - final ComponentInstance componentInstance = - parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) - .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); - validateGetFunction(property, componentInstance.getAttributes(), parentComponent.getModel()); - } - - return; - } - - throw ToscaGetFunctionExceptionSupplier.functionNotSupported(toscaGetFunction.getFunctionType()).get(); - } - private void validateGetFunction(final T property, final List parentProperties, final String model) { @@ -3051,7 +2986,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } Component eitherOriginComponent = getInstanceOriginNode(currentResourceInstance); - DataForMergeHolder dataHolder = compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent); + DataForMergeHolder dataHolder = + compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent); ComponentInstance resResourceInfo = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);