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 org.apache.tinkerpop.gremlin.structure.Vertex;
24 import org.janusgraph.core.JanusGraph;
25 import org.janusgraph.core.JanusGraphFactory;
26 import org.janusgraph.core.JanusGraphVertex;
27 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import java.util.ArrayList;
32 import java.util.Iterator;
33 import java.util.List;
36 * Created by mlando on 2/23/2016.
38 public class ProductLogic {
40 private static Logger log = Logger.getLogger(ProductLogic.class.getName());
42 public boolean deleteAllProducts(String janusGraphFile, String beHost, String bePort, String adminUser) {
43 log.debug("retrieving all products from graph");
44 RestUtils restUtils = null;
45 List<String> productList = getAllProducts(janusGraphFile);
46 restUtils = new RestUtils();
47 if (productList != null) {
48 for (String productUid : productList) {
49 restUtils.deleteProduct(productUid, beHost, bePort, adminUser);
54 log.error("failed to get products from graph");
59 private List<String> getAllProducts(String janusGraphFile) {
60 JanusGraph graph = null;
62 graph = openGraph(janusGraphFile);
63 List<String> productsToDelete = new ArrayList<String>();
64 Iterable vertices = graph.query()
65 .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices();
66 if (vertices != null) {
67 Iterator<JanusGraphVertex> iter = vertices.iterator();
68 while (iter.hasNext()) {
69 Vertex vertex = iter.next();
70 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
71 productsToDelete.add(id);
76 return productsToDelete;
77 } catch (Exception e) {
79 log.info("get All Products failed - {}" , e);
81 graph.tx().rollback();
92 private JanusGraph openGraph(String janusGraphFileLocation) {
94 return JanusGraphFactory.open(janusGraphFileLocation);