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

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

Introduction

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

Prototype

@Override
public R getRight() 

Source Link

Usage

From source file:org.openecomp.sdc.be.dao.titan.TitanGenericDao.java

public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteria(NodeTypeEnum type,
        Class<T> clazz, List<ImmutableTriple<QueryType, String, Object>> props) {
    Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
    if (graph.isLeft()) {
        try {//from www  . jav  a2  s .c o  m
            TitanGraph tGraph = graph.left().value();

            TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
            query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
            for (ImmutableTriple<QueryType, String, Object> prop : props) {
                if (QueryType.HAS.equals(prop.getLeft())) {
                    query = query.has(prop.getMiddle(), prop.getRight());
                } else {
                    query = query.hasNot(prop.getMiddle(), prop.getRight());
                }
            }
            Iterable<TitanVertex> vertices = query.vertices();
            if (vertices == null) {
                return Either.right(TitanOperationStatus.NOT_FOUND);
            }

            Iterator<TitanVertex> iterator = vertices.iterator();
            List<T> result = new ArrayList<T>();

            while (iterator.hasNext()) {
                Vertex vertex = iterator.next();

                Map<String, Object> newProp = getProperties(vertex);

                T element = GraphElementFactory.createElement(type.getName(), GraphElementTypeEnum.Node,
                        newProp, clazz);
                result.add(element);
            }
            if (result.size() == 0) {
                return Either.right(TitanOperationStatus.NOT_FOUND);
            }

            return Either.left(result);
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed  get by  criteria for type = {}", type, e);
            }
            return Either.right(TitanGraphClient.handleTitanException(e));
        }

    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed  get by  criteria for type ={}  error : {}", type, graph.right().value());
        }
        return Either.right(graph.right().value());
    }
}

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

@Deprecated
public Either<List<Component>, ActionStatus> getComponentsFromCacheForCatalog(Set<String> components,
        ComponentTypeEnum componentType) {

    Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> componentsForCatalog = componentCache
            .getComponentsForCatalog(components, componentType);
    if (componentsForCatalog.isLeft()) {
        ImmutableTriple<List<Component>, List<Component>, Set<String>> immutableTriple = componentsForCatalog
                .left().value();//from   www.j  av  a  2s .c o  m
        List<Component> foundComponents = immutableTriple.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());

        }
        List<Component> foundDirtyComponents = immutableTriple.getMiddle();
        Set<String> nonCachedComponents = immutableTriple.getRight();
        int numberDirtyResources = foundDirtyComponents == null ? 0 : foundDirtyComponents.size();
        int numberNonCached = nonCachedComponents == null ? 0 : nonCachedComponents.size();
        log.debug("The number of left {}s for catalog is {}", componentType.name().toLowerCase(),
                numberDirtyResources + numberNonCached);
        return Either.left(foundComponents);
    }

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

From source file:org.openecomp.sdc.ci.tests.api.ComponentBaseTest.java

private void cleanComponents() throws Exception {

    // Components to delete
    List<String> vfResourcesToDelete = new ArrayList<String>();
    List<String> nonVfResourcesToDelete = new ArrayList<String>();
    List<String> servicesToDelete = new ArrayList<String>();
    List<String> productsToDelete = new ArrayList<String>();

    // Categories to delete
    List<ImmutableTriple<String, String, String>> productGroupingsToDelete = new ArrayList<>();
    List<ImmutablePair<String, String>> productSubsToDelete = new ArrayList<>();
    List<ImmutablePair<String, String>> resourceSubsToDelete = new ArrayList<>();
    List<String> productCategoriesToDelete = new ArrayList<>();
    List<String> resourceCategoriesToDelete = new ArrayList<String>();
    List<String> serviceCategoriesToDelete = new ArrayList<String>();

    List<String> resourcesNotToDelete = config.getResourcesNotToDelete();
    List<String> resourceCategoriesNotToDelete = config.getResourceCategoriesNotToDelete();
    List<String> serviceCategoriesNotToDelete = config.getServiceCategoriesNotToDelete();
    TitanGraphQuery<? extends TitanGraphQuery> query = titanGraph.query();
    query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName());
    Iterable<TitanVertex> vertices = query.vertices();
    //      Iterable<TitanVertex> vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName()).vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex vertex = iter.next();
            Boolean isAbstract = vertex.value(GraphPropertiesDictionary.IS_ABSTRACT.getProperty());
            // if (!isAbstract) {
            String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
            String version = vertex.value(GraphPropertiesDictionary.VERSION.getProperty());

            if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name))
                    || (version != null && !version.equals("1.0"))) {
                String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                String resourceType = vertex.value(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty());
                // if (name.startsWith("ci")) {
                if (resourceType.equals(ResourceTypeEnum.VF.name())) {
                    vfResourcesToDelete.add(id);
                } else {
                    nonVfResourcesToDelete.add(id);
                }//w  w w  .java2 s . c  om
                // }
            } else if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name))
                    || (version != null && version.equals("1.0"))) {
                if ((boolean) vertex
                        .value(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) == false) {
                    vertex.property(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
                }
            }
            // }
        }
    }
    vertices = titanGraph.query()
            .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Service.getName()).vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex vertex = iter.next();
            String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
            String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
            // if (name.startsWith("ci")){
            servicesToDelete.add(id);
            // }
        }
    }

    vertices = titanGraph.query()
            .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex vertex = iter.next();
            String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
            String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
            //if (name.startsWith("ci")) {
            productsToDelete.add(id);
            //}
        }
    }

    // Getting categories

    vertices = titanGraph.query()
            .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ResourceNewCategory.getName())
            .vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex category = iter.next();
            String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
            if (!resourceCategoriesNotToDelete.contains(name)) {
                String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                resourceCategoriesToDelete.add(catId);
                Iterator<Vertex> subs = category.vertices(Direction.OUT,
                        GraphEdgeLabels.SUB_CATEGORY.getProperty());
                while (subs.hasNext()) {
                    Vertex sub = subs.next();
                    String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                    resourceSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
                }
            }
        }
    }

    vertices = titanGraph.query()
            .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ServiceNewCategory.getName())
            .vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex category = iter.next();
            String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
            if (!serviceCategoriesNotToDelete.contains(name)) {
                String id = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                serviceCategoriesToDelete.add(id);
            }
        }
    }

    vertices = titanGraph.query()
            .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ProductCategory.getName())
            .vertices();
    if (vertices != null) {
        Iterator<TitanVertex> iter = vertices.iterator();
        while (iter.hasNext()) {
            Vertex category = iter.next();
            String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
            productCategoriesToDelete.add(catId);
            Iterator<Vertex> subs = category.vertices(Direction.OUT,
                    GraphEdgeLabels.SUB_CATEGORY.getProperty());
            while (subs.hasNext()) {
                Vertex sub = subs.next();
                String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                productSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
                Iterator<Vertex> groupings = sub.vertices(Direction.OUT,
                        GraphEdgeLabels.GROUPING.getProperty());
                while (groupings.hasNext()) {
                    Vertex grouping = groupings.next();
                    String groupId = grouping.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
                    productGroupingsToDelete
                            .add(new ImmutableTriple<String, String, String>(catId, subCatId, groupId));
                }
            }

        }
    }

    titanGraph.tx().commit();

    String adminId = UserRoleEnum.ADMIN.getUserId();
    String productStrategistId = UserRoleEnum.PRODUCT_STRATEGIST1.getUserId();

    // Component delete
    for (String id : productsToDelete) {
        RestResponse deleteProduct = ProductRestUtils.deleteProduct(id, productStrategistId);

    }
    for (String id : servicesToDelete) {
        RestResponse deleteServiceById = ServiceRestUtils.deleteServiceById(id, adminId);

    }
    for (String id : vfResourcesToDelete) {
        RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);

    }

    for (String id : nonVfResourcesToDelete) {
        RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);

    }

    // Categories delete - product
    String componentType = BaseRestUtils.PRODUCT_COMPONENT_TYPE;
    for (ImmutableTriple<String, String, String> triple : productGroupingsToDelete) {
        CategoryRestUtils.deleteGrouping(triple.getRight(), triple.getMiddle(), triple.getLeft(),
                productStrategistId, componentType);
    }
    for (ImmutablePair<String, String> pair : productSubsToDelete) {
        CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), productStrategistId,
                componentType);
    }
    for (String id : productCategoriesToDelete) {
        CategoryRestUtils.deleteCategory(id, productStrategistId, componentType);
    }

    // Categories delete - resource
    componentType = BaseRestUtils.RESOURCE_COMPONENT_TYPE;
    for (ImmutablePair<String, String> pair : resourceSubsToDelete) {
        CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), adminId, componentType);
    }
    for (String id : resourceCategoriesToDelete) {
        CategoryRestUtils.deleteCategory(id, adminId, componentType);
    }
    // Categories delete - resource
    componentType = BaseRestUtils.SERVICE_COMPONENT_TYPE;
    for (String id : serviceCategoriesToDelete) {
        CategoryRestUtils.deleteCategory(id, adminId, componentType);
    }

}