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

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

Introduction

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

Prototype

@Override
public L getLeft() 

Source Link

Usage

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  w w.ja  v a2  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);
}

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

public Either<List<CapabilityDefinition>, TitanOperationStatus> updateCapDefPropertyValues(
        ComponentInstance componentInstance, List<CapabilityDefinition> capabilityDefList) {
    String componentInstanceId = componentInstance.getUniqueId();
    log.debug("Before updating property values of capabilities of component istance {}.", componentInstanceId);
    TitanOperationStatus error = null;//  w w  w .  j a  v  a2  s  .c  om
    NodeTypeEnum nodeType = NodeTypeEnum
            .getByNameIgnoreCase(componentInstance.getOriginType().getInstanceType().trim());

    log.debug("Before getting all capability instances of component istance {}.", componentInstanceId);
    Either<List<ImmutablePair<CapabilityInstData, GraphEdge>>, TitanOperationStatus> getCapabilityInstancesRes = titanGenericDao
            .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(nodeType), componentInstanceId,
                    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 {}",
                componentInstance.getName(), error);
    }
    log.debug("After getting all capability instances of component istance {}. Status is {}",
            componentInstanceId, error);
    Map<String, Map<String, PropertyValueData>> overridedCapabilitiesHM = new HashMap<>();
    if (getCapabilityInstancesRes.isLeft()) {
        List<ImmutablePair<CapabilityInstData, GraphEdge>> capabilityInstDataPair = getCapabilityInstancesRes
                .left().value();

        for (ImmutablePair<CapabilityInstData, GraphEdge> curCapabilityPair : capabilityInstDataPair) {
            CapabilityInstData curCapabilityInst = curCapabilityPair.getLeft();
            String curCapInstUid = curCapabilityInst.getUniqueId();

            log.debug("Before getting all property values of capability instance {} of component istance {}.",
                    curCapInstUid, componentInstanceId);
            Either<List<ImmutablePair<PropertyValueData, GraphEdge>>, TitanOperationStatus> getOverridedPropertyValuesRes = titanGenericDao
                    .getChildrenNodes(
                            UniqueIdBuilder
                                    .getKeyByNodeType(NodeTypeEnum.getByName(curCapabilityInst.getLabel())),
                            curCapInstUid, GraphEdgeLabels.PROPERTY_VALUE, NodeTypeEnum.PropertyValue,
                            PropertyValueData.class);
            if (getOverridedPropertyValuesRes.isRight()) {
                error = getOverridedPropertyValuesRes.right().value();
                log.debug("Failed to retrieve property values of capability instance {}. Status is {}",
                        curCapInstUid, error);
            }

            log.debug(
                    "After getting all property values of capability instance {} of component istance {}. Status is {}",
                    curCapInstUid, componentInstanceId, error);
            Map<String, PropertyValueData> overridedPropertyValuesHM = new HashMap<>();
            List<ImmutablePair<PropertyValueData, GraphEdge>> overridedPropertyValues = getOverridedPropertyValuesRes
                    .left().value();
            for (ImmutablePair<PropertyValueData, GraphEdge> curPropertyValuePair : overridedPropertyValues) {
                PropertyValueData curPropertyValue = curPropertyValuePair.getLeft();
                String propertyValueUid = curPropertyValue.getUniqueId();
                log.debug(
                        "Before getting property related to property value {} of capability instance {} of component istance {}.",
                        propertyValueUid, curCapInstUid, componentInstanceId);
                Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> getPropertyDataRes = titanGenericDao
                        .getChild(
                                UniqueIdBuilder.getKeyByNodeType(
                                        NodeTypeEnum.getByName(curPropertyValue.getLabel())),
                                propertyValueUid, GraphEdgeLabels.PROPERTY_IMPL, NodeTypeEnum.Property,
                                PropertyData.class);
                if (getPropertyDataRes.isRight()) {
                    error = getOverridedPropertyValuesRes.right().value();
                    log.debug("Failed to retrieve property of property value {} Status is {}", propertyValueUid,
                            error);
                }

                if (log.isDebugEnabled()) {
                    log.debug(
                            "After getting property related to property value {} of capability instance {} of component istance {}. Status is {}",
                            propertyValueUid, curCapInstUid, componentInstanceId, error);
                }
                PropertyData propertyData = getPropertyDataRes.left().value().getLeft();
                overridedPropertyValuesHM.put((String) propertyData.getUniqueId(), curPropertyValue);
            }
            overridedCapabilitiesHM.put(
                    (String) curCapabilityPair.getRight().getProperties()
                            .get(GraphPropertiesDictionary.CAPABILITY_ID.getProperty()),
                    overridedPropertyValuesHM);
        }
    }
    if (error == null && !overridedCapabilitiesHM.isEmpty()) {
        updateCapabilityPropertyValues(componentInstance.getCapabilities(), capabilityDefList,
                overridedCapabilitiesHM);
    }
    log.debug("After updating property values of capabilities of component istance {}. Status is {}",
            componentInstanceId, error);
    if (error == null) {
        return Either.left(capabilityDefList);
    }
    return Either.right(error);
}

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

private <T, S extends ComponentMetadataData> Either<List<T>, StorageOperationStatus> collectComponents(
        TitanGraph graph, NodeTypeEnum neededType, String categoryUid, NodeTypeEnum categoryType,
        Class<S> clazz) {/*w w  w . j  a v  a2s  . c om*/
    List<T> components = new ArrayList<>();
    Either<List<ImmutablePair<S, GraphEdge>>, TitanOperationStatus> parentNodes = titanGenericDao
            .getParentNodes(UniqueIdBuilder.getKeyByNodeType(categoryType), categoryUid,
                    GraphEdgeLabels.CATEGORY, neededType, clazz);
    if (parentNodes.isLeft()) {
        for (ImmutablePair<S, GraphEdge> component : parentNodes.left().value()) {
            ComponentMetadataDataDefinition componentData = component.getLeft().getMetadataDataDefinition();
            Boolean isHighest = componentData.isHighestVersion();
            Boolean isComplex = neededType == NodeTypeEnum.Resource
                    ? ResourceTypeEnum.VF
                            .equals(((ResourceMetadataDataDefinition) componentData).getResourceType())
                    : true;
            if (isHighest && isComplex) {
                Either<T, StorageOperationStatus> result = getLightComponent(componentData.getUniqueId(), true);
                if (result.isRight()) {
                    return Either.right(result.right().value());
                }
                components.add(result.left().value());
            }
        }
    }
    return Either.left(components);
}

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

public Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> getComponentsFromCacheForCatalog(
        Map<String, Long> components, ComponentTypeEnum componentType) {

    Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> componentsForCatalog = componentCache
            .getComponentsForCatalog(components, componentType);
    if (componentsForCatalog.isLeft()) {
        ImmutablePair<List<Component>, Set<String>> immutablePair = componentsForCatalog.left().value();
        List<Component> foundComponents = immutablePair.getLeft();

        if (foundComponents != null) {
            // foundComponents.forEach(p -> result.add((Resource)p));
            log.debug("The number of {}s added to catalog from cache is {}", componentType.name().toLowerCase(),
                    foundComponents.size());
        }/*from   w  w w  .j  av  a  2  s . c  om*/
        Set<String> leftComponents = immutablePair.getRight();
        int numberNonCached = leftComponents == null ? 0 : leftComponents.size();
        log.debug("The number of left {}s for catalog is {}", componentType.name().toLowerCase(),
                numberNonCached);

        ImmutablePair<List<Component>, Set<String>> result = new ImmutablePair<List<Component>, Set<String>>(
                foundComponents, leftComponents);
        return Either.left(result);
    }

    return Either.right(componentsForCatalog.right().value());
}

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

private TitanOperationStatus setSubCategories(NodeTypeEnum parentNodeType, CategoryDefinition parentCategory) {
    NodeTypeEnum childNodeType = getChildNodeType(parentNodeType);
    if (childNodeType != null) {
        String categoryName = parentCategory.getName();
        log.trace("Getting sub-categories for category {}, category type {}", categoryName, parentNodeType);
        Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao
                .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType),
                        parentCategory.getUniqueId(), GraphEdgeLabels.SUB_CATEGORY, childNodeType,
                        SubCategoryData.class);
        if (parentNode.isRight()) {
            TitanOperationStatus titanOperationStatus = parentNode.right().value();
            if (titanOperationStatus == TitanOperationStatus.NOT_FOUND) {
                log.trace("Didn't find subcategories for category {}, category type {}", categoryName,
                        parentNodeType);
                titanOperationStatus = TitanOperationStatus.OK;
            }//from w  w w. j a va 2s  .co m
            return titanOperationStatus;
        }
        List<ImmutablePair<SubCategoryData, GraphEdge>> subsCategoriesData = parentNode.left().value();
        List<SubCategoryDefinition> subCategoriesDefinitions = new ArrayList<>();
        for (ImmutablePair<SubCategoryData, GraphEdge> subCatPair : subsCategoriesData) {
            SubCategoryDataDefinition subCategoryDataDefinition = subCatPair.getLeft()
                    .getSubCategoryDataDefinition();
            SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(subCategoryDataDefinition);

            log.trace("Found sub-category {} for category {}, category type {}",
                    subCategoryDataDefinition.getName(), categoryName, parentNodeType);
            TitanOperationStatus setGroupings = setGroupings(childNodeType, subCategoryDefinition);
            if (setGroupings != TitanOperationStatus.OK) {
                log.debug("Failed to set groupings for sub-category {}, sub-category type {}, error {}",
                        subCategoryDataDefinition.getName(), childNodeType, setGroupings);
                return TitanOperationStatus.GENERAL_ERROR;
            }
            subCategoriesDefinitions.add(subCategoryDefinition);
        }
        parentCategory.setSubcategories(subCategoriesDefinitions);
    }
    return TitanOperationStatus.OK;
}

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

private TitanOperationStatus setGroupings(NodeTypeEnum parentNodeType,
        SubCategoryDefinition parentSubCategory) {
    NodeTypeEnum childNodeType = getChildNodeType(parentNodeType);
    if (childNodeType != null) {
        String subCategoryName = parentSubCategory.getName();
        log.trace("Getting groupings for subcategory {}, subcategory type {}", subCategoryName, parentNodeType);
        Either<List<ImmutablePair<GroupingData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao
                .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType),
                        parentSubCategory.getUniqueId(), GraphEdgeLabels.GROUPING, childNodeType,
                        GroupingData.class);
        if (parentNode.isRight()) {
            TitanOperationStatus titanOperationStatus = parentNode.right().value();
            if (titanOperationStatus == TitanOperationStatus.NOT_FOUND) {
                log.trace("Didn't find groupings for subcategory {}, subcategory type {}", subCategoryName,
                        parentNodeType);
                titanOperationStatus = TitanOperationStatus.OK;
            }/*from  w ww.ja  v a 2  s  .co m*/
            return titanOperationStatus;
        }
        List<ImmutablePair<GroupingData, GraphEdge>> groupingData = parentNode.left().value();
        List<GroupingDefinition> groupingDefinitions = new ArrayList<>();
        for (ImmutablePair<GroupingData, GraphEdge> groupPair : groupingData) {
            GroupingDataDefinition groupingDataDefinition = groupPair.getLeft().getGroupingDataDefinition();
            log.trace("Found grouping {} for sub-category {}, sub-category type {}",
                    groupingDataDefinition.getName(), subCategoryName, parentNodeType);
            groupingDefinitions.add(new GroupingDefinition(groupingDataDefinition));
        }
        parentSubCategory.setGroupings(groupingDefinitions);
    }
    return TitanOperationStatus.OK;
}

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

/**
 * get all properties of the group./*w w  w  . jav a 2  s.  c o  m*/
 * 
 * the propert definition is taken from the group type.
 * 
 * @param groupUid
 * @return
 */
public Either<List<GroupProperty>, TitanOperationStatus> getGroupProperties(String groupUid) {

    List<GroupProperty> groupPropertiesList = new ArrayList<>();

    Either<GroupTypeDefinition, TitanOperationStatus> groupTypeOfGroupRes = getGroupTypeOfGroup(groupUid);

    if (groupTypeOfGroupRes.isRight()) {
        TitanOperationStatus status = groupTypeOfGroupRes.right().value();
        return Either.right(status);
    }

    GroupTypeDefinition groupTypeDefinition = groupTypeOfGroupRes.left().value();

    // Get the properties on the group type of this group
    List<PropertyDefinition> groupTypeProperties = groupTypeDefinition.getProperties();

    if (groupTypeProperties == null || true == groupTypeProperties.isEmpty()) {
        return Either.right(TitanOperationStatus.OK);
    }

    Map<String, PropertyDefinition> uidToPropDefMap = groupTypeProperties.stream()
            .collect(Collectors.toMap(p -> p.getUniqueId(), p -> p));

    // Find all properties values on the group
    Either<List<ImmutablePair<PropertyValueData, GraphEdge>>, TitanOperationStatus> propertyImplNodes = titanGenericDao
            .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Group), groupUid,
                    GraphEdgeLabels.PROPERTY_VALUE, NodeTypeEnum.PropertyValue, PropertyValueData.class);

    if (propertyImplNodes.isRight()) {
        TitanOperationStatus status = propertyImplNodes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            groupPropertiesList = groupTypeProperties.stream()
                    .map(p -> new GroupProperty(p, p.getDefaultValue(), null)).collect(Collectors.toList());
            return Either.left(groupPropertiesList);
        } else {
            return Either.right(status);
        }
    }

    List<ImmutablePair<PropertyValueData, GraphEdge>> list = propertyImplNodes.left().value();
    if (list == null || true == list.isEmpty()) {
        return Either.right(TitanOperationStatus.OK);
    }

    List<String> processedProps = new ArrayList<>();

    for (ImmutablePair<PropertyValueData, GraphEdge> propertyValue : list) {

        PropertyValueData propertyValueData = propertyValue.getLeft();
        String propertyValueUid = propertyValueData.getUniqueId();
        String value = propertyValueData.getValue();

        Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> propertyDefRes = titanGenericDao
                .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PropertyValue), propertyValueUid,
                        GraphEdgeLabels.PROPERTY_IMPL, NodeTypeEnum.Property, PropertyData.class);
        if (propertyDefRes.isRight()) {
            TitanOperationStatus status = propertyDefRes.right().value();
            if (status == TitanOperationStatus.NOT_FOUND) {
                status = TitanOperationStatus.INVALID_ID;
            }
            return Either.right(status);
        }

        ImmutablePair<PropertyData, GraphEdge> propertyDefPair = propertyDefRes.left().value();

        PropertyData propertyData = propertyDefPair.left;
        String propertyUniqueId = propertyData.getPropertyDataDefinition().getUniqueId();

        PropertyDefinition propertyDefinition = uidToPropDefMap.get(propertyUniqueId);
        GroupProperty groupProperty = new GroupProperty(propertyDefinition, value, propertyValueUid);

        processedProps.add(propertyUniqueId);

        groupPropertiesList.add(groupProperty);

    }

    // Find all properties which does not have property value on the group.
    List<GroupProperty> leftProps = groupTypeProperties.stream()
            // filter out the group type properties which already processed
            .filter(p -> false == processedProps.contains(p.getUniqueId()))
            .map(p -> new GroupProperty(p, p.getDefaultValue(), null)).collect(Collectors.toList());
    if (leftProps != null) {
        groupPropertiesList.addAll(leftProps);
    }

    return Either.left(groupPropertiesList);
}

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

private Either<InputDefinition, TitanOperationStatus> getInputFromGraph(String uniqueId, boolean skipProperties,
        boolean skipInputsValue) {

    Either<InputDefinition, TitanOperationStatus> result = null;

    Either<InputsData, TitanOperationStatus> inputRes = titanGenericDao
            .getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Input), uniqueId, InputsData.class);
    if (inputRes.isRight()) {
        TitanOperationStatus status = inputRes.right().value();
        log.debug("Failed to retrieve group {}  from graph. Status is {}", uniqueId, status);
        BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError("Fetch Group", uniqueId,
                String.valueOf(status));
        result = Either.right(status);/*w ww. j  a  v  a  2 s  . c  om*/
        return result;
    }

    InputsData inputData = inputRes.left().value();

    InputDefinition groupDefinition = this.convertInputDataToInputDefinition(inputData);

    if (false == skipInputsValue) {
        List<ComponentInstanceInput> propsList = new ArrayList<ComponentInstanceInput>();

        Either<List<ImmutablePair<InputValueData, GraphEdge>>, TitanOperationStatus> propertyImplNodes = titanGenericDao
                .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Input), uniqueId,
                        GraphEdgeLabels.GET_INPUT, NodeTypeEnum.InputValue, InputValueData.class);

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

        }
        if (propertyImplNodes.isLeft()) {
            List<ImmutablePair<InputValueData, GraphEdge>> propertyDataPairList = propertyImplNodes.left()
                    .value();
            for (ImmutablePair<InputValueData, GraphEdge> propertyValue : propertyDataPairList) {

                InputValueData propertyValueData = propertyValue.getLeft();
                String propertyValueUid = propertyValueData.getUniqueId();
                String value = propertyValueData.getValue();

                Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> propertyDefRes = titanGenericDao
                        .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.InputValue), propertyValueUid,
                                GraphEdgeLabels.INPUT_IMPL, NodeTypeEnum.Property, PropertyData.class);
                if (propertyDefRes.isRight()) {
                    TitanOperationStatus status = propertyDefRes.right().value();
                    if (status == TitanOperationStatus.NOT_FOUND) {
                        status = TitanOperationStatus.INVALID_ID;
                    }
                    return Either.right(status);
                }

                ImmutablePair<PropertyData, GraphEdge> propertyDefPair = propertyDefRes.left().value();
                String propertyUniqueId = (String) propertyDefPair.left.getUniqueId();

                ComponentInstanceInput resourceInstanceProperty = new ComponentInstanceInput();
                // set property original unique id
                resourceInstanceProperty.setUniqueId(propertyUniqueId);
                // set resource id
                // TODO: esofer add resource id
                resourceInstanceProperty.setParentUniqueId(null);
                // set value
                resourceInstanceProperty.setValue(value);
                // set property value unique id
                resourceInstanceProperty.setValueUniqueUid(propertyValueUid);
                // set rules
                // resourceInstanceProperty.setRules(propertyValueData.getRules());

                propsList.add(resourceInstanceProperty);

            }

            groupDefinition.setInputsValue(propsList);
        }

    }

    if (false == skipProperties) {
        Either<List<ImmutablePair<PropertyValueData, GraphEdge>>, TitanOperationStatus> propertyImplNodes = titanGenericDao
                .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), uniqueId,
                        GraphEdgeLabels.GET_INPUT, NodeTypeEnum.PropertyValue, PropertyValueData.class);

        if (propertyImplNodes.isRight()) {
            TitanOperationStatus status = propertyImplNodes.right().value();
            return Either.right(status);
        }

        List<ImmutablePair<PropertyValueData, GraphEdge>> list = propertyImplNodes.left().value();

        if (list == null || true == list.isEmpty()) {
            return Either.right(TitanOperationStatus.NOT_FOUND);
        }

        List<ComponentInstanceProperty> propsRresult = new ArrayList<>();
        for (ImmutablePair<PropertyValueData, GraphEdge> propertyValueDataPair : list) {
            PropertyValueData propertyValueData = propertyValueDataPair.left;
            String propertyValueUid = propertyValueData.getUniqueId();
            String value = propertyValueData.getValue();

            Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> propertyDefRes = titanGenericDao
                    .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PropertyValue), propertyValueUid,
                            GraphEdgeLabels.PROPERTY_IMPL, NodeTypeEnum.Property, PropertyData.class);
            if (propertyDefRes.isRight()) {
                TitanOperationStatus status = propertyDefRes.right().value();
                if (status != TitanOperationStatus.NOT_FOUND) {
                    status = TitanOperationStatus.INVALID_ID;
                    return Either.right(status);
                }

            }
            if (propertyDefRes.isLeft()) {

                ImmutablePair<PropertyData, GraphEdge> propertyDefPair = propertyDefRes.left().value();
                PropertyData propertyData = propertyDefPair.left;
                String propertyUniqueId = (String) propertyData.getPropertyDataDefinition().getUniqueId();

                ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
                // set property original unique id
                resourceInstanceProperty.setUniqueId(propertyUniqueId);
                // set resource id
                // TODO: esofer add resource id
                resourceInstanceProperty.setParentUniqueId(null);
                // set value
                resourceInstanceProperty.setValue(value);
                // set property value unique id
                resourceInstanceProperty.setValueUniqueUid(propertyValueData.getUniqueId());
                // set rules
                resourceInstanceProperty.setRules(propertyValueData.getRules());
                resourceInstanceProperty.setType(propertyData.getPropertyDataDefinition().getType());
                resourceInstanceProperty.setSchema(propertyData.getPropertyDataDefinition().getSchema());
                resourceInstanceProperty.setName((String) propertyValueDataPair.right.getProperties()
                        .get(GraphPropertiesDictionary.NAME.getProperty()));

                propsRresult.add(resourceInstanceProperty);
            }

            groupDefinition.setProperties(propsRresult);
        }

    }

    result = Either.left(groupDefinition);

    return result;

}

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

public Either<List<ComponentInstanceInput>, TitanOperationStatus> getAllInputsOfResourceInstanceOnlyInputDefId(
        String resourceInstanceUid, NodeTypeEnum instanceNodeType) {

    Either<ComponentInstanceData, TitanOperationStatus> findResInstanceRes = titanGenericDao.getNode(
            UniqueIdBuilder.getKeyByNodeType(instanceNodeType), resourceInstanceUid,
            ComponentInstanceData.class);

    if (findResInstanceRes.isRight()) {
        TitanOperationStatus status = findResInstanceRes.right().value();
        if (status == TitanOperationStatus.NOT_FOUND) {
            status = TitanOperationStatus.INVALID_ID;
        }//from  w  w  w  .  j a v a2s  .c o m
        return Either.right(status);
    }

    Either<List<ImmutablePair<InputValueData, GraphEdge>>, TitanOperationStatus> propertyImplNodes = titanGenericDao
            .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(instanceNodeType), resourceInstanceUid,
                    GraphEdgeLabels.INPUT_VALUE, NodeTypeEnum.InputValue, InputValueData.class);

    if (propertyImplNodes.isRight()) {
        TitanOperationStatus status = propertyImplNodes.right().value();
        return Either.right(status);
    }

    List<ImmutablePair<InputValueData, GraphEdge>> list = propertyImplNodes.left().value();
    if (list == null || true == list.isEmpty()) {
        return Either.right(TitanOperationStatus.NOT_FOUND);
    }

    List<ComponentInstanceInput> result = new ArrayList<>();

    for (ImmutablePair<InputValueData, GraphEdge> propertyValueDataPair : list) {

        InputValueData propertyValueData = propertyValueDataPair.getLeft();
        String propertyValueUid = propertyValueData.getUniqueId();
        String value = propertyValueData.getValue();

        Either<ImmutablePair<InputsData, GraphEdge>, TitanOperationStatus> inputNodes = titanGenericDao
                .getParentNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(),
                        propertyValueData.getUniqueId(), GraphEdgeLabels.GET_INPUT, NodeTypeEnum.Input,
                        InputsData.class);

        if (inputNodes.isRight()) {

            return Either.right(inputNodes.right().value());
        }

        InputsData input = inputNodes.left().value().left;
        String inputId = input.getPropertyDataDefinition().getUniqueId();

        Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> propertyDefRes = titanGenericDao
                .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.InputValue), propertyValueUid,
                        GraphEdgeLabels.INPUT_IMPL, NodeTypeEnum.Property, PropertyData.class);
        if (propertyDefRes.isRight()) {
            TitanOperationStatus status = propertyDefRes.right().value();
            if (status == TitanOperationStatus.NOT_FOUND) {
                status = TitanOperationStatus.INVALID_ID;
            }
            return Either.right(status);
        }

        ImmutablePair<PropertyData, GraphEdge> propertyDefPair = propertyDefRes.left().value();
        PropertyData propertyData = propertyDefPair.left;
        Either<Edge, TitanOperationStatus> inputsEges = titanGenericDao.getIncomingEdgeByCriteria(propertyData,
                GraphEdgeLabels.INPUT, null);
        if (inputsEges.isRight()) {
            TitanOperationStatus status = inputsEges.right().value();

            return Either.right(status);
        }
        Edge edge = inputsEges.left().value();
        String inputName = (String) titanGenericDao.getProperty(edge,
                GraphEdgePropertiesDictionary.NAME.getProperty());

        String propertyUniqueId = (String) propertyData.getPropertyDataDefinition().getUniqueId();

        ComponentInstanceInput resourceInstanceProperty = new ComponentInstanceInput(
                propertyData.getPropertyDataDefinition(), inputId, value, propertyValueUid);

        //resourceInstanceProperty.setName(inputName);
        // set resource id
        // TODO: esofer add resource id
        resourceInstanceProperty.setName(inputName);
        resourceInstanceProperty.setParentUniqueId(inputId);
        // set value
        resourceInstanceProperty.setValue(value);
        // set property value unique id
        resourceInstanceProperty.setValueUniqueUid(propertyValueData.getUniqueId());
        // set rules
        // resourceInstanceProperty.setRules(propertyValueData.getRules());
        resourceInstanceProperty.setType(propertyData.getPropertyDataDefinition().getType());
        resourceInstanceProperty.setSchema(propertyData.getPropertyDataDefinition().getSchema());
        //resourceInstanceProperty.setComponentInstanceName(componentInsName);
        resourceInstanceProperty.setComponentInstanceId(resourceInstanceUid);

        result.add(resourceInstanceProperty);
    }

    return Either.left(result);
}

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

private Either<Operation, StorageOperationStatus> updateExistingOperation(String resourceId,
        Operation operation, String interfaceName, String operationName,
        Either<List<ImmutablePair<InterfaceData, GraphEdge>>, TitanOperationStatus> childrenNodes) {
    Operation newOperation = null;
    StorageOperationStatus storageOperationStatus = StorageOperationStatus.GENERAL_ERROR;

    for (ImmutablePair<InterfaceData, GraphEdge> interfaceDataNode : childrenNodes.left().value()) {

        GraphEdge interfaceEdge = interfaceDataNode.getRight();
        Map<String, Object> interfaceEdgeProp = interfaceEdge.getProperties();
        InterfaceData interfaceData = interfaceDataNode.getKey();

        if (interfaceEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(interfaceName)) {
            Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> operationRes = titanGenericDao
                    .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(),
                            (String) interfaceDataNode.getLeft().getUniqueId(),
                            GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation,
                            OperationData.class);
            if (operationRes.isRight()) {
                log.error("Failed to find operation {} on interface {}", operationName, interfaceName);
                return Either.right(
                        DaoStatusConverter.convertTitanStatusToStorageStatus(operationRes.right().value()));
            } else {
                List<ImmutablePair<OperationData, GraphEdge>> operations = operationRes.left().value();
                for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : operations) {
                    GraphEdge opEdge = operationPairEdge.getRight();
                    OperationData opData = operationPairEdge.getLeft();
                    Map<String, Object> opEdgeProp = opEdge.getProperties();
                    if (opEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(operationName)) {
                        ArtifactDefinition artifact = operation.getImplementation();
                        Either<ImmutablePair<ArtifactData, GraphEdge>, TitanOperationStatus> artifactRes = titanGenericDao
                                .getChild(GraphPropertiesDictionary.UNIQUE_ID.getProperty(),
                                        (String) opData.getUniqueId(), GraphEdgeLabels.ARTIFACT_REF,
                                        NodeTypeEnum.ArtifactRef, ArtifactData.class);
                        Either<ArtifactDefinition, StorageOperationStatus> artStatus;
                        if (artifactRes.isRight()) {
                            artStatus = artifactOperation.addArifactToComponent(artifact,
                                    (String) operationPairEdge.getLeft().getUniqueId(),
                                    NodeTypeEnum.InterfaceOperation, true, true);
                        } else {
                            artStatus = artifactOperation.updateArifactOnResource(artifact,
                                    (String) operationPairEdge.getLeft().getUniqueId(),
                                    (String) artifactRes.left().value().getLeft().getUniqueId(),
                                    NodeTypeEnum.InterfaceOperation, true);
                        }/*from   www  . j  a  v  a2 s.  com*/
                        if (artStatus.isRight()) {
                            titanGenericDao.rollback();
                            log.error("Failed to add artifact {}", operationName, interfaceName);
                            return Either.right(artStatus.right().value());
                        } else {
                            newOperation = this.convertOperationDataToOperation(opData);
                            newOperation.setImplementation(artStatus.left().value());

                        }

                    }

                }
                if (newOperation == null) {
                    Either<InterfaceData, TitanOperationStatus> parentInterfaceStatus = findInterfaceOnParentNode(
                            resourceId, interfaceName);
                    if (parentInterfaceStatus.isRight()) {
                        log.debug("Interface {} not exist", interfaceName);
                        return Either.right(DaoStatusConverter
                                .convertTitanStatusToStorageStatus(parentInterfaceStatus.right().value()));
                    }

                    InterfaceData parentInterfaceData = parentInterfaceStatus.left().value();
                    Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> opRes = titanGenericDao
                            .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(),
                                    (String) parentInterfaceData.getUniqueId(),
                                    GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation,
                                    OperationData.class);
                    if (opRes.isRight()) {
                        log.error("Failed to find operation {} on interface", operationName, interfaceName);
                        return Either.right(DaoStatusConverter
                                .convertTitanStatusToStorageStatus(operationRes.right().value()));

                    } else {
                        List<ImmutablePair<OperationData, GraphEdge>> parentOperations = opRes.left().value();
                        for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : parentOperations) {
                            GraphEdge opEdge = operationPairEdge.getRight();
                            OperationData opData = operationPairEdge.getLeft();
                            Map<String, Object> opEdgeProp = opEdge.getProperties();
                            if (opEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty())
                                    .equals(operationName)) {
                                return copyAndCreateNewOperation(operation, interfaceName, operationName, null,
                                        interfaceData, operationRes, opData);
                            }
                        }
                    }

                }

            }

        } else {
            // not found
            storageOperationStatus = StorageOperationStatus.ARTIFACT_NOT_FOUND;
        }

    }
    if (newOperation == null)
        return Either.right(storageOperationStatus);
    else
        return Either.left(newOperation);
}