Example usage for org.apache.commons.lang3.tuple ImmutablePair getRight

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair getRight

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair getRight.

Prototype

@Override
public R getRight() 

Source Link

Usage

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

private Either<List<GraphRelation>, TitanOperationStatus> associateCreatedComponentInstanceToClonedCapabilityInstances(
        String newComponentResourceId, List<ImmutablePair<CapabilityInstData, GraphEdge>> capabilityInstances) {
    TitanOperationStatus error = null;/*from  ww w.ja  v a2 s .co  m*/
    List<GraphRelation> relationsToCapabilityInstances = new ArrayList<>();
    UniqueIdData componentInstanceIdData = new UniqueIdData(NodeTypeEnum.ResourceInstance,
            newComponentResourceId);
    for (ImmutablePair<CapabilityInstData, GraphEdge> capInstPair : capabilityInstances) {
        Either<GraphRelation, TitanOperationStatus> associateComponentInstanceToCapabilityinstanceRes = titanGenericDao
                .createRelation(componentInstanceIdData, capInstPair.getLeft(), GraphEdgeLabels.CAPABILITY_INST,
                        capInstPair.getRight().getProperties());
        if (associateComponentInstanceToCapabilityinstanceRes.isRight()) {
            error = associateComponentInstanceToCapabilityinstanceRes.right().value();
            log.debug("Failed to associate capability instance {} to resource instance {}. Status is {}.",
                    capInstPair.getLeft().getUniqueId(), newComponentResourceId, error);
            break;
        } else {
            relationsToCapabilityInstances
                    .add(associateComponentInstanceToCapabilityinstanceRes.left().value());
        }
    }
    if (error == null) {
        return Either.left(relationsToCapabilityInstances);
    }
    return Either.right(error);
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

private TitanOperationStatus associateCreatedComponentInstanceToClonedCapabilityInstances(TitanVertex riVertex,
        String newComponentResourceId, List<ImmutablePair<TitanVertex, GraphEdge>> capabilityInstances) {
    TitanOperationStatus error = null;//from w  w  w  .ja  v  a  2s . co m
    for (ImmutablePair<TitanVertex, GraphEdge> capInstPair : capabilityInstances) {
        TitanOperationStatus associateComponentInstanceToCapabilityinstanceRes = titanGenericDao.createEdge(
                riVertex, capInstPair.getLeft(), GraphEdgeLabels.CAPABILITY_INST,
                capInstPair.getRight().getProperties());
        if (!associateComponentInstanceToCapabilityinstanceRes.equals(TitanOperationStatus.OK)) {
            error = associateComponentInstanceToCapabilityinstanceRes;
            log.debug("Failed to associate capability instance {} to resource instance {} status is {} .",
                    capInstPair.getLeft(), newComponentResourceId, error);
            break;
        }
    }
    if (error == null) {
        return TitanOperationStatus.OK;
    }
    return error;
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

private Either<List<GraphRelation>, TitanOperationStatus> associateComponentInstanceToCapabilityInstancesOfResourceInstance(
        ComponentInstance componentInstance) {
    TitanOperationStatus error = null;/*from w  ww .j  a  va  2s .c  o  m*/
    String resourceId = componentInstance.getComponentUid();
    String componentResourceId = componentInstance.getUniqueId();
    UniqueIdData componentInstanceIdData = new UniqueIdData(NodeTypeEnum.ResourceInstance, componentResourceId);
    List<ImmutablePair<ComponentInstanceData, GraphEdge>> resourceInstancesPair;
    List<ImmutablePair<CapabilityInstData, GraphEdge>> allCapabilityInstancesList = new ArrayList<>();
    List<GraphRelation> relationsToCapabilityInstances = new ArrayList<>();
    Either<List<ImmutablePair<ComponentInstanceData, GraphEdge>>, TitanOperationStatus> getAllResourceInstanceRes = titanGenericDao
            .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), resourceId,
                    GraphEdgeLabels.RESOURCE_INST, NodeTypeEnum.ResourceInstance, ComponentInstanceData.class);
    if (getAllResourceInstanceRes.isRight()
            && !getAllResourceInstanceRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
        error = getAllResourceInstanceRes.right().value();
        log.debug("Failed to retrieve resource instances from resource {}. Status is {}.", resourceId, error);
    }
    if (getAllResourceInstanceRes.isLeft()) {
        resourceInstancesPair = getAllResourceInstanceRes.left().value();
        ComponentInstanceData ri;
        for (ImmutablePair<ComponentInstanceData, GraphEdge> riPair : resourceInstancesPair) {
            ri = riPair.getLeft();
            Either<List<ImmutablePair<CapabilityInstData, GraphEdge>>, TitanOperationStatus> getCapabilityInstancesRes = titanGenericDao
                    .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance),
                            ri.getUniqueId(), GraphEdgeLabels.CAPABILITY_INST, NodeTypeEnum.CapabilityInst,
                            CapabilityInstData.class);
            if (getCapabilityInstancesRes.isRight()
                    && !getCapabilityInstancesRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
                error = getCapabilityInstancesRes.right().value();
                log.debug("Failed to retrieve capability instances of resource instance {}. Status is {}",
                        ri.getUniqueId(), error);
                break;
            }
            if (getCapabilityInstancesRes.isLeft()) {
                allCapabilityInstancesList.addAll(getCapabilityInstancesRes.left().value());
            }
        }
    }
    if (error == null && !allCapabilityInstancesList.isEmpty()) {
        for (ImmutablePair<CapabilityInstData, GraphEdge> capInstPair : allCapabilityInstancesList) {
            Either<GraphRelation, TitanOperationStatus> associateComponentInstanceToCapabilityinstanceRes = titanGenericDao
                    .createRelation(componentInstanceIdData, capInstPair.getLeft(),
                            GraphEdgeLabels.CAPABILITY_INST, capInstPair.getRight().getProperties());
            if (associateComponentInstanceToCapabilityinstanceRes.isRight()) {
                error = associateComponentInstanceToCapabilityinstanceRes.right().value();
                log.debug("Failed to associate capability instance {} to resource instance {}. Status is {}",
                        capInstPair.getLeft().getUniqueId(), componentResourceId, error);
                break;
            } else {
                relationsToCapabilityInstances
                        .add(associateComponentInstanceToCapabilityinstanceRes.left().value());
            }
        }
    }
    if (error == null) {
        return Either.left(relationsToCapabilityInstances);
    }
    return Either.right(error);
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

/**
 * update value of attribute on resource instance
 * /*from  www.jav a2 s.  co  m*/
 * @param resourceInstanceProerty
 * @param resourceInstanceId
 * @return
 */
public Either<PropertyValueData, TitanOperationStatus> updatePropertyOfResourceInstance(
        ComponentInstanceProperty resourceInstanceProerty, String resourceInstanceId, boolean isValidate) {

    Wrapper<TitanOperationStatus> errorWrapper = new Wrapper<>();
    UpdateDataContainer<PropertyData, PropertyValueData> updateDataContainer = new UpdateDataContainer<>(
            GraphEdgeLabels.PROPERTY_IMPL, (() -> PropertyData.class), (() -> PropertyValueData.class),
            NodeTypeEnum.Property, NodeTypeEnum.PropertyValue);

    preUpdateElementOfResourceInstanceValidations(updateDataContainer, resourceInstanceProerty,
            resourceInstanceId, errorWrapper);
    if (!errorWrapper.isEmpty()) {
        return Either.right(errorWrapper.getInnerElement());
    }

    else {
        String value = resourceInstanceProerty.getValue();
        // Specific Validation Logic
        PropertyData propertyData = updateDataContainer.getDataWrapper().getInnerElement();

        String innerType = null;

        PropertyDataDefinition propDataDef = propertyData.getPropertyDataDefinition();
        String propertyType = propDataDef.getType();
        ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
        log.debug("The type of the property {} is {}", propertyData.getUniqueId(), propertyType);

        if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
            SchemaDefinition def = propDataDef.getSchema();
            if (def == null) {
                log.debug("Schema doesn't exists for property of type {}", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            PropertyDataDefinition propDef = def.getProperty();
            if (propDef == null) {
                log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            innerType = propDef.getType();
        }
        // Specific Update Logic
        Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
        if (allDataTypes.isRight()) {
            TitanOperationStatus status = allDataTypes.right().value();
            BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                    "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
            return Either.right(status);
        }
        Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, value,
                isValidate, innerType, allDataTypes.left().value());

        String newValue = value;
        if (isValid.isRight()) {
            Boolean res = isValid.right().value();
            if (res == false) {
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
        } else {
            Object object = isValid.left().value();
            if (object != null) {
                newValue = object.toString();
            }
        }
        PropertyValueData propertyValueData = updateDataContainer.getValueDataWrapper().getInnerElement();
        log.debug("Going to update property value from {} to {}", propertyValueData.getValue(), newValue);
        propertyValueData.setValue(newValue);

        ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType,
                resourceInstanceProerty.getRules(), innerType, allDataTypes.left().value(), isValidate);
        if (pair.getRight() != null && pair.getRight() == false) {
            BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(),
                    resourceInstanceProerty.getName(), propertyType);
            return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
        }
        propertyOperation.updateRulesInPropertyValue(propertyValueData, resourceInstanceProerty,
                resourceInstanceId);

        Either<PropertyValueData, TitanOperationStatus> updateRes = titanGenericDao
                .updateNode(propertyValueData, PropertyValueData.class);
        if (updateRes.isRight()) {
            TitanOperationStatus status = updateRes.right().value();
            return Either.right(status);
        } else {
            return Either.left(updateRes.left().value());
        }
    }

}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

/**
 * add property to resource instance/*from  ww w. j ava 2s .c o  m*/
 * 
 * @param resourceInstanceProperty
 * @param resourceInstanceId
 * @param index
 * @return
 */
public Either<PropertyValueData, TitanOperationStatus> addPropertyToResourceInstance(
        ComponentInstanceProperty resourceInstanceProperty, String resourceInstanceId, boolean isValidate,
        Integer index) {

    Either<ComponentInstanceData, TitanOperationStatus> findResInstanceRes = titanGenericDao.getNode(
            UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), resourceInstanceId,
            ComponentInstanceData.class);

    if (findResInstanceRes.isRight()) {
        TitanOperationStatus status = findResInstanceRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }
        return Either.right(status);
    }

    String propertyId = resourceInstanceProperty.getUniqueId();
    Either<PropertyData, TitanOperationStatus> findPropertyDefRes = titanGenericDao
            .getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Property), propertyId, PropertyData.class);

    if (findPropertyDefRes.isRight()) {
        TitanOperationStatus status = findPropertyDefRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }
        return Either.right(status);
    }

    String valueUniqueUid = resourceInstanceProperty.getValueUniqueUid();
    if (valueUniqueUid == null) {

        PropertyData propertyData = findPropertyDefRes.left().value();
        ComponentInstanceData resourceInstanceData = findResInstanceRes.left().value();

        ImmutablePair<TitanOperationStatus, String> isPropertyValueExists = propertyOperation
                .findPropertyValue(resourceInstanceId, propertyId);
        if (isPropertyValueExists.getLeft() == TitanOperationStatus.ALREADY_EXIST) {
            log.debug("The property {} already added to the resource instance {}", propertyId,
                    resourceInstanceId);
            resourceInstanceProperty.setValueUniqueUid(isPropertyValueExists.getRight());
            Either<PropertyValueData, TitanOperationStatus> updatePropertyOfResourceInstance = updatePropertyOfResourceInstance(
                    resourceInstanceProperty, resourceInstanceId, isValidate);
            if (updatePropertyOfResourceInstance.isRight()) {
                BeEcompErrorManager.getInstance()
                        .logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                                "Failed to update property value on instance. Status is "
                                        + updatePropertyOfResourceInstance.right().value(),
                                ErrorSeverity.ERROR);
                return Either.right(updatePropertyOfResourceInstance.right().value());
            }
            return Either.left(updatePropertyOfResourceInstance.left().value());
        }

        if (isPropertyValueExists.getLeft() != TitanOperationStatus.NOT_FOUND) {
            log.debug("After finding property value of {} on component instance {}", propertyId,
                    resourceInstanceId);
            return Either.right(isPropertyValueExists.getLeft());
        }

        String innerType = null;

        PropertyDataDefinition propDataDef = propertyData.getPropertyDataDefinition();
        String propertyType = propDataDef.getType();
        String value = resourceInstanceProperty.getValue();
        ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);

        if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
            SchemaDefinition def = propDataDef.getSchema();
            if (def == null) {
                log.debug("Schema doesn't exists for property of type {}", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            PropertyDataDefinition propDef = def.getProperty();
            if (propDef == null) {
                log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            innerType = propDef.getType();
        }

        log.debug("Before validateAndUpdatePropertyValue");
        Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
        if (allDataTypes.isRight()) {
            TitanOperationStatus status = allDataTypes.right().value();
            BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                    "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
            return Either.right(status);
        }
        Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, value,
                isValidate, innerType, allDataTypes.left().value());
        log.debug("After validateAndUpdatePropertyValue. isValid = {}", isValid);

        String newValue = value;
        if (isValid.isRight()) {
            Boolean res = isValid.right().value();
            if (res == false) {
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
        } else {
            Object object = isValid.left().value();
            if (object != null) {
                newValue = object.toString();
            }
        }

        String uniqueId = UniqueIdBuilder
                .buildResourceInstancePropertyValueUid(resourceInstanceData.getUniqueId(), index);
        PropertyValueData propertyValueData = new PropertyValueData();
        propertyValueData.setUniqueId(uniqueId);
        propertyValueData.setValue(newValue);

        log.debug("Before validateAndUpdateRules");
        ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType,
                resourceInstanceProperty.getRules(), innerType, allDataTypes.left().value(), isValidate);
        log.debug("After validateAndUpdateRules. pair = {}", pair);
        if (pair.getRight() != null && pair.getRight() == false) {
            BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(),
                    resourceInstanceProperty.getName(), propertyType);
            return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
        }
        propertyOperation.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty,
                resourceInstanceId);

        log.debug("Before adding property value to graph {}", propertyValueData);
        Either<PropertyValueData, TitanOperationStatus> createNodeResult = titanGenericDao
                .createNode(propertyValueData, PropertyValueData.class);
        log.debug("After adding property value to graph {}", propertyValueData);

        if (createNodeResult.isRight()) {
            TitanOperationStatus operationStatus = createNodeResult.right().value();
            return Either.right(operationStatus);
        }
        propertyValueData = createNodeResult.left().value();

        Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao
                .createRelation(propertyValueData, propertyData, GraphEdgeLabels.PROPERTY_IMPL, null);

        if (createRelResult.isRight()) {
            TitanOperationStatus operationStatus = createRelResult.right().value();
            // TODO: change logger
            log.error("Failed to associate property value " + uniqueId + " to property " + propertyId
                    + " in graph. status is " + operationStatus);
            return Either.right(operationStatus);
        }

        createRelResult = titanGenericDao.createRelation(resourceInstanceData, propertyValueData,
                GraphEdgeLabels.PROPERTY_VALUE, null);

        if (createRelResult.isRight()) {
            TitanOperationStatus operationStatus = createRelResult.right().value();
            // TODO: change logger
            log.error("Failed to associate resource instance " + resourceInstanceId + " property value "
                    + uniqueId + " in graph. status is " + operationStatus);
            return Either.right(operationStatus);
        }

        return Either.left(propertyValueData);
    } else {
        log.error("property value already exists.");
        return Either.right(TitanOperationStatus.ALREADY_EXIST);
    }

}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

public Either<ComponentInstanceProperty, TitanOperationStatus> addPropertyToResourceInstance(
        ComponentInstanceProperty resourceInstanceProperty, TitanVertex resourceInstanceVertex,
        boolean isValidate, Integer index, String resourceInstanceId) {

    String propertyId = resourceInstanceProperty.getUniqueId();
    Either<PropertyData, TitanOperationStatus> findPropertyDefRes = titanGenericDao
            .getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Property), propertyId, PropertyData.class);

    if (findPropertyDefRes.isRight()) {
        TitanOperationStatus status = findPropertyDefRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }//www  .  j  a  va  2 s  .co  m
        return Either.right(status);
    }

    String valueUniqueUid = resourceInstanceProperty.getValueUniqueUid();
    if (valueUniqueUid == null) {

        PropertyData propertyData = findPropertyDefRes.left().value();

        ImmutablePair<TitanOperationStatus, String> isPropertyValueExists = propertyOperation
                .findPropertyValue(resourceInstanceId, propertyId);
        if (isPropertyValueExists.getLeft() == TitanOperationStatus.ALREADY_EXIST) {
            log.trace("The property {} already added to the resource instance {}", propertyId,
                    resourceInstanceId);
            resourceInstanceProperty.setValueUniqueUid(isPropertyValueExists.getRight());
            Either<PropertyValueData, TitanOperationStatus> updatePropertyOfResourceInstance = updatePropertyOfResourceInstance(
                    resourceInstanceProperty, resourceInstanceId, isValidate);
            if (updatePropertyOfResourceInstance.isRight()) {
                BeEcompErrorManager.getInstance()
                        .logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                                "Failed to update property value on instance. Status is "
                                        + updatePropertyOfResourceInstance.right().value(),
                                ErrorSeverity.ERROR);
                return Either.right(updatePropertyOfResourceInstance.right().value());
            }
            return Either.right(TitanOperationStatus.OK);
        }

        if (isPropertyValueExists.getLeft() != TitanOperationStatus.NOT_FOUND) {
            log.trace("After finding property value of {} on componenet instance {}", propertyId,
                    resourceInstanceId);
            return Either.right(isPropertyValueExists.getLeft());
        }

        String innerType = null;

        PropertyDataDefinition propDataDef = propertyData.getPropertyDataDefinition();
        String propertyType = propDataDef.getType();
        String value = resourceInstanceProperty.getValue();
        ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);

        if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
            SchemaDefinition def = propDataDef.getSchema();
            if (def == null) {
                log.debug("Schema doesn't exists for property of type {}", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            PropertyDataDefinition propDef = def.getProperty();
            if (propDef == null) {
                log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            innerType = propDef.getType();
        }

        log.trace("Before validateAndUpdatePropertyValue");
        Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
        if (allDataTypes.isRight()) {
            TitanOperationStatus status = allDataTypes.right().value();
            BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                    "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
            return Either.right(status);
        }
        Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, value,
                isValidate, innerType, allDataTypes.left().value());
        log.trace("After validateAndUpdatePropertyValue. isValid = {}", isValid);

        String newValue = value;
        if (isValid.isRight()) {
            Boolean res = isValid.right().value();
            if (res == false) {
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
        } else {
            Object object = isValid.left().value();
            if (object != null) {
                newValue = object.toString();
            }
        }

        String uniqueId = UniqueIdBuilder.buildResourceInstancePropertyValueUid(resourceInstanceId, index);
        PropertyValueData propertyValueData = new PropertyValueData();
        propertyValueData.setUniqueId(uniqueId);
        propertyValueData.setValue(newValue);

        log.trace("Before validateAndUpdateRules");
        ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType,
                resourceInstanceProperty.getRules(), innerType, allDataTypes.left().value(), isValidate);
        log.debug("After validateAndUpdateRules. pair = {}", pair);
        if (pair.getRight() != null && pair.getRight() == false) {
            BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(),
                    resourceInstanceProperty.getName(), propertyType);
            return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
        }
        propertyOperation.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty,
                resourceInstanceId);

        log.trace("Before adding property value to graph {}", propertyValueData);
        Either<PropertyValueData, TitanOperationStatus> createNodeResult = titanGenericDao
                .createNode(propertyValueData, PropertyValueData.class);
        log.trace("After adding property value to graph {}", propertyValueData);

        if (createNodeResult.isRight()) {
            TitanOperationStatus operationStatus = createNodeResult.right().value();
            return Either.right(operationStatus);
        }
        propertyValueData = createNodeResult.left().value();

        Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao
                .createRelation(propertyValueData, propertyData, GraphEdgeLabels.PROPERTY_IMPL, null);

        if (createRelResult.isRight()) {
            TitanOperationStatus operationStatus = createRelResult.right().value();
            // TODO: change logger
            log.error("Failed to associate property value " + uniqueId + " to property " + propertyId
                    + " in graph. status is " + operationStatus);
            return Either.right(operationStatus);
        }

        TitanOperationStatus edgeResult = titanGenericDao.createEdge(resourceInstanceVertex, propertyValueData,
                GraphEdgeLabels.PROPERTY_VALUE, null);

        if (!edgeResult.equals(TitanOperationStatus.OK)) {
            log.error("Failed to associate resource instance " + resourceInstanceId + " property value "
                    + uniqueId + " in graph. status is " + edgeResult);
            return Either.right(edgeResult);
        }

        ComponentInstanceProperty propertyValueResult = propertyOperation
                .buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
        log.debug("The returned ResourceInstanceProperty is {}", propertyValueResult);

        return Either.left(propertyValueResult);
    } else {
        log.debug("property value already exists.");
        return Either.right(TitanOperationStatus.ALREADY_EXIST);
    }

}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

/**
 * add property to resource instance/*www . j  ava2s .co  m*/
 * 
 * @param resourceInstanceProperty
 * @param resourceInstanceId
 * @param index
 * @return
 */
public Either<InputValueData, TitanOperationStatus> addInputToResourceInstance(
        ComponentInstanceInput resourceInstanceInput, String resourceInstanceId, Integer index) {

    Either<ComponentInstanceData, TitanOperationStatus> findResInstanceRes = titanGenericDao.getNode(
            UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), resourceInstanceId,
            ComponentInstanceData.class);

    if (findResInstanceRes.isRight()) {
        TitanOperationStatus status = findResInstanceRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }
        return Either.right(status);
    }

    String propertyId = resourceInstanceInput.getUniqueId();
    Either<InputsData, TitanOperationStatus> findPropertyDefRes = titanGenericDao
            .getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Input), propertyId, InputsData.class);

    if (findPropertyDefRes.isRight()) {
        TitanOperationStatus status = findPropertyDefRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }
        return Either.right(status);
    }

    String valueUniqueUid = resourceInstanceInput.getValueUniqueUid();
    if (valueUniqueUid == null) {

        InputsData propertyData = findPropertyDefRes.left().value();

        ComponentInstanceData resourceInstanceData = findResInstanceRes.left().value();

        ImmutablePair<TitanOperationStatus, String> isInputValueExists = inputOperation
                .findInputValue(resourceInstanceId, propertyId);
        if (isInputValueExists.getLeft() == TitanOperationStatus.ALREADY_EXIST) {
            log.debug("The property {} already added to the resource insance {}", propertyId,
                    resourceInstanceId);
            resourceInstanceInput.setValueUniqueUid(isInputValueExists.getRight());
            /*
             * Either<InputValueData, TitanOperationStatus> updatePropertyOfResourceInstance = updatePropertyOfResourceInstance(resourceInstanceInput, resourceInstanceId); if (updatePropertyOfResourceInstance.isRight()) {
             * BeEcompErrorManager.getInstance().logInternalFlowError( "UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + updatePropertyOfResourceInstance.right().value(), ErrorSeverity.ERROR);
             * return Either.right(updatePropertyOfResourceInstance.right().value() ); } return Either.left(updatePropertyOfResourceInstance.left().value());
             */
        }

        if (isInputValueExists.getLeft() != TitanOperationStatus.NOT_FOUND) {
            log.debug("After finding input value of {} on compnent instance {}", propertyId,
                    resourceInstanceId);
            return Either.right(isInputValueExists.getLeft());
        }

        String innerType = null;

        PropertyDataDefinition propDataDef = propertyData.getPropertyDataDefinition();
        String propertyType = propDataDef.getType();
        String value = resourceInstanceInput.getValue();
        ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);

        if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
            SchemaDefinition def = propDataDef.getSchema();
            if (def == null) {
                log.debug("Schema doesn't exists for property of type {}", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            PropertyDataDefinition propDef = def.getProperty();
            if (propDef == null) {
                log.debug("Property in Schema Definition inside property of type {} doesn't exists", type);
                return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
            }
            innerType = propDef.getType();
        }

        log.debug("Before validateAndUpdatePropertyValue");
        Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
        if (allDataTypes.isRight()) {
            TitanOperationStatus status = allDataTypes.right().value();
            BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
                    "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
            return Either.right(status);
        }
        //   Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, value, innerType, allDataTypes.left().value());
        //   log.debug("After validateAndUpdatePropertyValue. isValid = {}", isValid);

        /*String newValue = value;
        if (isValid.isRight()) {
           Boolean res = isValid.right().value();
           if (res == false) {
              return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
           }
        } else {
           Object object = isValid.left().value();
           if (object != null) {
              newValue = object.toString();
           }
        }*/

        String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(resourceInstanceData.getUniqueId(),
                index);
        InputValueData propertyValueData = new InputValueData();
        propertyValueData.setUniqueId(uniqueId);
        propertyValueData.setValue(value);

        log.debug("Before validateAndUpdateRules");
        ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType,
                resourceInstanceInput.getRules(), innerType, allDataTypes.left().value(), true);
        log.debug("After validateAndUpdateRules. pair = {}", pair);
        if (pair.getRight() != null && pair.getRight() == false) {
            BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(),
                    resourceInstanceInput.getName(), propertyType);
            return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
        }
        // propertyOperation.addRulesToNewPropertyValue(propertyValueData,
        // resourceInstanceInput, resourceInstanceId);

        log.debug("Before adding property value to graph {}", propertyValueData);
        Either<InputValueData, TitanOperationStatus> createNodeResult = titanGenericDao
                .createNode(propertyValueData, InputValueData.class);
        log.debug("After adding property value to graph {}", propertyValueData);

        if (createNodeResult.isRight()) {
            TitanOperationStatus operationStatus = createNodeResult.right().value();
            return Either.right(operationStatus);
        }

        Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao
                .createRelation(propertyValueData, propertyData, GraphEdgeLabels.INPUT_IMPL, null);

        if (createRelResult.isRight()) {
            TitanOperationStatus operationStatus = createRelResult.right().value();
            // TODO: change logger
            log.error("Failed to associate property value {} to property {} in graph. Status is {}", uniqueId,
                    propertyId, operationStatus);
            return Either.right(operationStatus);
        }

        Map<String, Object> properties1 = new HashMap<String, Object>();

        properties1.put(GraphEdgePropertiesDictionary.NAME.getProperty(),
                resourceInstanceData.getComponentInstDataDefinition().getName());
        properties1.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(),
                resourceInstanceData.getComponentInstDataDefinition().getUniqueId());

        createRelResult = titanGenericDao.createRelation(resourceInstanceData, propertyValueData,
                GraphEdgeLabels.INPUT_VALUE, properties1);

        if (createRelResult.isRight()) {
            TitanOperationStatus operationStatus = createNodeResult.right().value();
            // TODO: change logger
            log.error("Failed to associate resource instance {} property value {} in graph. Status is {}",
                    resourceInstanceId, uniqueId, operationStatus);
            return Either.right(operationStatus);

        }

        // inputOperation.associatePropertyToInput(resourceInstanceId,
        // resourceInstanceInput.getInputId(), propertyValueData,
        // resourceInstanceInput.getName());

        return Either.left(createNodeResult.left().value());
    } else {
        log.error("property value already exists.");
        return Either.right(TitanOperationStatus.ALREADY_EXIST);
    }

}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

public Either<Map<String, Map<String, ComponentInstanceProperty>>, TitanOperationStatus> findAllPropertyValueOnInstances(
        Map<String, ImmutablePair<ComponentInstance, Integer>> processedInstances) {

    if (processedInstances == null) {
        return Either.right(TitanOperationStatus.OK);
    }/*from   w  w  w . j  a  v a2s.co m*/

    Set<Entry<String, ImmutablePair<ComponentInstance, Integer>>> entrySet = processedInstances.entrySet();

    Map<String, Map<String, ComponentInstanceProperty>> propertyToInstanceValue = new HashMap<>();

    for (Entry<String, ImmutablePair<ComponentInstance, Integer>> entry : entrySet) {

        String compInstUniqueId = entry.getKey();

        ImmutablePair<ComponentInstance, Integer> pair = entry.getValue();

        ComponentInstance componentInstance = pair.getLeft();
        Integer level = pair.getRight();

        Either<List<ComponentInstanceProperty>, TitanOperationStatus> propeprtyValueOnCIResult = findPropertyValueOnComponentInstance(
                componentInstance);

        if (propeprtyValueOnCIResult.isRight()) {
            TitanOperationStatus status = propeprtyValueOnCIResult.right().value();
            if (status != TitanOperationStatus.OK) {
                return Either.right(status);
            }
            continue;
        }

        List<ComponentInstanceProperty> propertyValuesOnCI = propeprtyValueOnCIResult.left().value();
        if (propeprtyValueOnCIResult != null) {
            for (ComponentInstanceProperty instanceProperty : propertyValuesOnCI) {
                boolean result = addPropertyValue(compInstUniqueId, instanceProperty, propertyToInstanceValue);
                if (result == false) {
                    return Either.right(TitanOperationStatus.ALREADY_EXIST);
                }
            }
        }

    }

    return Either.left(propertyToInstanceValue);
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

/**
 * clone capability instances of resource instance
 * //from   w w  w . j a v  a  2  s. c o  m
 * @param createdComponentInstance
 * @param resourceInstance
 * @return
 */
private Either<Map<ImmutablePair<CapabilityInstData, GraphEdge>, List<PropertyValueData>>, TitanOperationStatus> cloneCapabilityInstancesOfResourceInstance(
        ComponentInstanceData createdComponentInstance, ComponentInstance resourceInstance) {
    TitanOperationStatus error = null;
    String resourceInstanceId = resourceInstance.getUniqueId();
    log.debug("Before cloning of capability instances of resource instance {}.", resourceInstanceId);

    Map<ImmutablePair<CapabilityInstData, GraphEdge>, List<PropertyValueData>> result = new HashMap<>();
    Either<ImmutablePair<CapabilityInstData, List<PropertyValueData>>, TitanOperationStatus> cloneAssociateCIWithPropertyValuesRes;
    Either<List<ImmutablePair<CapabilityInstData, GraphEdge>>, TitanOperationStatus> getAllCapabilityInstancesRes = capabilityInstanceOperation
            .getAllCapabilityInstancesOfResourceInstance(resourceInstanceId);
    if (getAllCapabilityInstancesRes.isRight()
            && !getAllCapabilityInstancesRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
        error = getAllCapabilityInstancesRes.right().value();
        log.debug("Failed to get capability instances of component instance {}. Status is {}",
                resourceInstanceId, error);
    }
    if (getAllCapabilityInstancesRes.isLeft()) {
        List<ImmutablePair<CapabilityInstData, GraphEdge>> capabilityInstances = getAllCapabilityInstancesRes
                .left().value();
        Map<String, List<CapabilityDefinition>> allCapabilitiesMap = resourceInstance.getCapabilities();
        List<CapabilityDefinition> allCapabilitiesList = new ArrayList<>();
        for (List<CapabilityDefinition> curList : allCapabilitiesMap.values()) {
            allCapabilitiesList.addAll(curList);
        }
        Map<String, CapabilityDefinition> capabilities = allCapabilitiesList.stream()
                .collect(Collectors.toMap(CapabilityDefinition::getUniqueId, Function.identity()));
        String propertyName = GraphPropertiesDictionary.CAPABILITY_ID.getProperty();
        for (ImmutablePair<CapabilityInstData, GraphEdge> capabilityInstPair : capabilityInstances) {
            String capabilityId = (String) capabilityInstPair.getRight().getProperties().get(propertyName);
            CapabilityDefinition relatedCapability = capabilities.get(capabilityId);
            cloneAssociateCIWithPropertyValuesRes = capabilityInstanceOperation
                    .cloneAssociateCapabilityInstanceWithPropertyValues(createdComponentInstance,
                            relatedCapability, capabilityInstPair);
            if (cloneAssociateCIWithPropertyValuesRes.isRight()) {
                error = cloneAssociateCIWithPropertyValuesRes.right().value();
                log.debug("Failed to clone capability instances {} of component instance {}. Status is {}",
                        capabilityInstPair.getLeft().getUniqueId(), resourceInstanceId, error);
                break;
            } else {
                result.put(
                        new ImmutablePair<CapabilityInstData, GraphEdge>(
                                cloneAssociateCIWithPropertyValuesRes.left().value().getLeft(),
                                capabilityInstPair.getRight()),
                        cloneAssociateCIWithPropertyValuesRes.left().value().getRight());
            }
        }
    }
    log.debug("After cloning of capability instance of resource instance {}. Status is {}", resourceInstanceId,
            error);
    if (error == null) {
        return Either.left(result);
    }
    return Either.right(error);
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java

private Either<List<ImmutablePair<TitanVertex, GraphEdge>>, TitanOperationStatus> cloneCapabilityInstancesOfResourceInstance(
        TitanVertex componentInstanceVertex, ComponentInstance resourceInstance) {
    TitanOperationStatus error = null;/* w  ww  . j ava 2 s.  c  om*/
    String resourceInstanceId = resourceInstance.getUniqueId();
    log.debug("Before cloning of capability instances of resource instance {}.", resourceInstanceId);

    Either<TitanVertex, TitanOperationStatus> cloneAssociateCIWithPropertyValuesRes = null;
    Either<List<ImmutablePair<CapabilityInstData, GraphEdge>>, TitanOperationStatus> getAllCapabilityInstancesRes = capabilityInstanceOperation
            .getAllCapabilityInstancesOfResourceInstance(resourceInstanceId);
    if (getAllCapabilityInstancesRes.isRight()
            && !getAllCapabilityInstancesRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
        error = getAllCapabilityInstancesRes.right().value();
        log.debug("Failed to get capability instances of component instance {}. status is {}",
                resourceInstanceId, error);
    }
    List<ImmutablePair<TitanVertex, GraphEdge>> list = new ArrayList<>();
    if (getAllCapabilityInstancesRes.isLeft()) {
        List<ImmutablePair<CapabilityInstData, GraphEdge>> capabilityInstances = getAllCapabilityInstancesRes
                .left().value();
        Map<String, List<CapabilityDefinition>> allCapabilitiesMap = resourceInstance.getCapabilities();
        List<CapabilityDefinition> allCapabilitiesList = new ArrayList<>();
        for (List<CapabilityDefinition> curList : allCapabilitiesMap.values()) {
            allCapabilitiesList.addAll(curList);
        }
        Map<String, CapabilityDefinition> capabilities = allCapabilitiesList.stream()
                .collect(Collectors.toMap(CapabilityDefinition::getUniqueId, Function.identity()));
        String propertyName = GraphPropertiesDictionary.CAPABILITY_ID.getProperty();
        for (ImmutablePair<CapabilityInstData, GraphEdge> capabilityInstPair : capabilityInstances) {
            String capabilityId = (String) capabilityInstPair.getRight().getProperties().get(propertyName);
            CapabilityDefinition relatedCapability = capabilities.get(capabilityId);
            cloneAssociateCIWithPropertyValuesRes = capabilityInstanceOperation
                    .cloneAssociateCapabilityInstanceWithPropertyValues(componentInstanceVertex,
                            relatedCapability, capabilityInstPair);
            if (cloneAssociateCIWithPropertyValuesRes.isRight()) {
                error = cloneAssociateCIWithPropertyValuesRes.right().value();
                log.debug("Failed to clone capability instances {} of component instance {}. status is {}",
                        capabilityInstPair.getLeft().getUniqueId(), resourceInstanceId, error);
                break;
            } else {
                list.add(new ImmutablePair<TitanVertex, GraphEdge>(
                        cloneAssociateCIWithPropertyValuesRes.left().value(), capabilityInstPair.right));
            }
        }
    }
    log.debug("After cloning of capability instance of resource instance {}. Status is {}", resourceInstanceId,
            error);
    if (error == null) {
        return Either.left(list);
    }
    return Either.right(error);
}