2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.asdctool.impl;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.thinkaurelius.titan.core.TitanFactory;
34 import com.thinkaurelius.titan.core.TitanGraph;
35 import com.thinkaurelius.titan.core.TitanVertex;
38 * Created by mlando on 2/23/2016.
40 public class ProductLogic {
42 private static Logger log = LoggerFactory.getLogger(ProductLogic.class.getName());
44 public boolean deleteAllProducts(String titanFile, String beHost, String bePort, String adminUser) {
45 log.debug("retrieving all products from graph");
46 RestUtils restUtils = null;
47 List<String> productList = getAllProducts(titanFile);
48 restUtils = new RestUtils();
49 if (productList != null) {
50 for (String productUid : productList) {
51 restUtils.deleteProduct(productUid, beHost, bePort, adminUser);
56 log.error("failed to get products from graph");
61 private List<String> getAllProducts(String titanFile) {
62 TitanGraph graph = null;
64 graph = openGraph(titanFile);
65 List<String> productsToDelete = new ArrayList<String>();
66 Iterable vertices = graph.query()
67 .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices();
68 if (vertices != null) {
69 Iterator<TitanVertex> iter = vertices.iterator();
70 while (iter.hasNext()) {
71 Vertex vertex = iter.next();
72 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
73 productsToDelete.add(id);
78 return productsToDelete;
79 } catch (Exception e) {
81 graph.tx().rollback();
91 private TitanGraph openGraph(String titanFileLocation) {
93 TitanGraph graph = TitanFactory.open(titanFileLocation);