+ } catch (final ComponentException e) {
+ return Either.right(e.getResponseFormat());
+ } finally {
+ if (resultOp == null || resultOp.isRight()) {
+ janusGraphDao.rollback();
+ } else {
+ janusGraphDao.commit();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
+ }
+ }
+
+ public Either<List<ComponentInstanceAttribute>, ResponseFormat> createOrUpdateAttributeValues(final ComponentTypeEnum componentTypeEnum,
+ final String componentId,
+ final String resourceInstanceId,
+ final List<ComponentInstanceAttribute> attributes,
+ final String userId) {
+ Either<List<ComponentInstanceAttribute>, ResponseFormat> resultOp = null;
+ /*-------------------------------Validations---------------------------------*/
+ validateUserExists(userId);
+
+ if (componentTypeEnum == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertiesValues", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ return resultOp;
+ }
+ final Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade
+ .getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
+
+ if (getResourceResult.isRight()) {
+ log.debug(FAILED_TO_RETRIEVE_COMPONENT_COMPONENT_ID, componentId);
+ final ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResourceResult.right().value(), componentTypeEnum);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus, componentId));
+ }
+ final Component containerComponent = getResourceResult.left().value();
+
+ if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
+ if (Boolean.TRUE.equals(containerComponent.isArchived())) {
+ log.info(COMPONENT_ARCHIVED, componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_IS_ARCHIVED, containerComponent.getName()));
+ }
+ log.info(RESTRICTED_OPERATION_ON_SERVIVE, userId, componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ final Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent,
+ resourceInstanceId);
+ if (resourceInstanceStatus.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
+ resourceInstanceId, RESOURCE_INSTANCE, SERVICE, componentId));
+ }
+ final ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
+
+ // lock resource
+ final StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug(FAILED_TO_LOCK_SERVICE, componentId);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ }
+ final List<ComponentInstanceAttribute> updatedProperties = new ArrayList<>();
+ try {
+ for (final ComponentInstanceAttribute attribute : attributes) {
+ final ComponentInstanceAttribute componentInstanceProperty = validateAttributeExistsOnComponent(attribute, containerComponent,
+ foundResourceInstance);
+ final Either<String, ResponseFormat> updatedPropertyValue = updateAttributeObjectValue(attribute);
+ if (updatedPropertyValue.isRight()) {
+ log.error("Failed to update attribute object value of attribute: {}", attribute);
+ throw new ByResponseFormatComponentException(updatedPropertyValue.right().value());
+ }
+ updatedPropertyValue.bimap(
+ updatedValue -> {
+ componentInstanceProperty.setValue(updatedValue);
+ return updateAttributeOnContainerComponent(attribute, updatedValue,
+ containerComponent, foundResourceInstance);
+ }, Either::right);
+ updatedProperties.add(componentInstanceProperty);
+ }
+
+ final Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade
+ .updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
+ if (updateContainerRes.isRight()) {
+ final ActionStatus actionStatus = componentsUtils
+ .convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+ return resultOp;
+ }
+ resultOp = Either.left(updatedProperties);
+ return resultOp;
+
+ } catch (final ComponentException e) {
+ return Either.right(e.getResponseFormat());