diff options
author | sebdet <sebastien.determe@intl.att.com> | 2020-06-24 11:32:27 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-07-05 08:46:33 +0000 |
commit | 3d6e3667d00c45585421dade93b00de174144cca (patch) | |
tree | e2df7cb848e5efddfdc79ab045119cfc505f59ad /asdctool | |
parent | 0bea1a6770a361820e7332766e10683a86687698 (diff) |
Fix sonar issues
Fix sonar/checkstyle issues in sdc code
Issue-ID: SDC-3158
Change-Id: Ic29f9233838e25c195d2b349bfac8e6d56888609
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'asdctool')
3 files changed, 45 insertions, 63 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java index e60640fa26..d757d81744 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,79 +20,56 @@ package org.openecomp.sdc.asdctool.impl; +import java.util.ArrayList; +import java.util.List; +import org.apache.tinkerpop.gremlin.structure.Transaction; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphFactory; -import org.janusgraph.core.JanusGraphVertex; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.common.log.wrappers.Logger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * Created by mlando on 2/23/2016. */ public class ProductLogic { - private static Logger log = Logger.getLogger(ProductLogic.class.getName()); + private static final Logger log = Logger.getLogger(ProductLogic.class.getName()); - public boolean deleteAllProducts(String janusGraphFile, String beHost, String bePort, String adminUser) { - log.debug("retrieving all products from graph"); - RestUtils restUtils = null; + public boolean deleteAllProducts(String janusGraphFile, String beHost, String bePort, String adminUser) { + log.debug("retrieving all products from graph"); List<String> productList = getAllProducts(janusGraphFile); - restUtils = new RestUtils(); - if (productList != null) { - for (String productUid : productList) { - restUtils.deleteProduct(productUid, beHost, bePort, adminUser); - } - return true; - } - else { + if (productList.isEmpty()) { log.error("failed to get products from graph"); return false; } - } - - private List<String> getAllProducts(String janusGraphFile) { - JanusGraph graph = null; - try { - graph = openGraph(janusGraphFile); - List<String> productsToDelete = new ArrayList<String>(); - Iterable vertices = graph.query() - .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices(); - if (vertices != null) { - Iterator<JanusGraphVertex> iter = vertices.iterator(); - while (iter.hasNext()) { - Vertex vertex = iter.next(); - String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); - productsToDelete.add(id); - } - } - - graph.tx().commit(); - return productsToDelete; - } catch (Exception e) { - e.printStackTrace(); - log.info("get All Products failed - {}" , e); - if(graph != null) { - graph.tx().rollback(); - } - return null; - - } finally { - if (graph != null) { - graph.close(); - } - } - } - - private JanusGraph openGraph(String janusGraphFileLocation) { - - return JanusGraphFactory.open(janusGraphFileLocation); - - } + for (String productUid : productList) { + new RestUtils().deleteProduct(productUid, beHost, bePort, adminUser); + } + return true; + } + private List<String> getAllProducts(String janusGraphFile) { + List<String> productsToDelete = new ArrayList<>(); + Transaction transac = null; + try (JanusGraph graph = JanusGraphFactory.open(janusGraphFile)) { + transac = graph.tx(); + Iterable vertices = graph.query() + .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices(); + if (vertices != null) { + for (Vertex vertex : (Iterable<Vertex>) vertices) { + String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); + productsToDelete.add(id); + } + } + transac.commit(); + } catch (Exception e) { + log.error("get All Products failed", e); + if (transac != null) { + transac.rollback(); + } + } + return productsToDelete; + } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java index aaafdd2367..3332131e79 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java @@ -51,8 +51,7 @@ public class RestUtils { return status; } catch (Exception e) { log.error("Product uid:{} delete failed with exception", productUid, e); + return HttpStatus.SC_INTERNAL_SERVER_ERROR; } - return null; } - } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/RestUtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/RestUtilsTest.java index 90672734bd..4afa3a1df2 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/RestUtilsTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/RestUtilsTest.java @@ -20,7 +20,10 @@ package org.openecomp.sdc.asdctool.impl; -import org.junit.Test; + +import org.apache.http.HttpStatus; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class RestUtilsTest { @@ -39,6 +42,9 @@ public class RestUtilsTest { // default test testSubject = createTestSubject(); - result = testSubject.deleteProduct(productUid, beHost, bePort, adminUser); + assertEquals(Integer.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), testSubject.deleteProduct(productUid, + beHost, + bePort, + adminUser)); } } |