aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-11-22 10:13:46 +0200
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-11-22 11:22:22 +0200
commit532db6daf1c0d0c9b0767eb7191385ad1a709516 (patch)
tree323bdb96337b86cd8cd3eed21b53c1642423cb46
parent619adb5955870e3b03250262677eff9b83713f14 (diff)
DAO sonar fixes
Change-Id: I453fdb5f2aa1488adbf0664a624a98b239d4a927 Issue-ID: SDC-1954 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java9
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java12
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java12
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java8
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java20
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java12
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/TitanDao.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java27
8 files changed, 53 insertions, 49 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java
index f3cf5944b4..c53e343512 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java
@@ -65,7 +65,6 @@ import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
/**
@@ -80,6 +79,8 @@ import java.util.Map;
@Singleton
public class ArtifactExternalServlet extends AbstractValidationsServlet {
+ private static final String FAILED_TO_UPDATE_ARTIFACT = "failed to update artifact";
+
@Context
private HttpServletRequest request;
@@ -146,7 +147,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, componentType, uuid, artifactUUID, operationUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
@@ -452,7 +453,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
@@ -552,7 +553,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID,
artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
index 5e1efbfa06..35ab30c79a 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
@@ -34,16 +34,16 @@ public abstract class GraphNode extends GraphElement {
private NodeTypeEnum label;
+ protected GraphNode(NodeTypeEnum label) {
+ super(GraphElementTypeEnum.Node);
+
+ this.label = label;
+ }
+
protected Gson getGson() {
return gson;
}
- protected GraphNode(NodeTypeEnum label) {
- super(GraphElementTypeEnum.Node);
-
- this.label = label;
- }
-
public String getLabel() {
return label.getName();
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java
index 6a67a99fcf..26b821a3d4 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java
@@ -42,7 +42,9 @@ import java.util.Map.Entry;
@Component("auditingDao")
public class AuditingDao extends ESTimeBasedDao {
- private static final String SERVICE_INSTANCE_ID_FIELD = AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID
+ private static final String FAILED_TO_GET_DISTRIBUTION_STATUSES_FOR_ACTION = "failed to get distribution statuses for action {}";
+ private static final String GET_SERVICE_DISTRIBUTION_STATUSES_LIST = "Get Service DistributionStatuses List";
+ private static final String SERVICE_INSTANCE_ID_FIELD = AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID
.getDisplayName(); // "serviceInstanceId";
private static final String STATUS_FIELD = AuditingFieldsKey.AUDIT_STATUS.getDisplayName(); // "status";
private static final String ACTION_FIELD = AuditingFieldsKey.AUDIT_ACTION.getDisplayName(); // "action";
@@ -130,8 +132,8 @@ public class AuditingDao extends ESTimeBasedDao {
remainingElements = customFindEvent(AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
- log.debug("failed to get distribution statuses for action {}",
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
+ log.debug(FAILED_TO_GET_DISTRIBUTION_STATUSES_FOR_ACTION,
AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
}
@@ -147,7 +149,7 @@ public class AuditingDao extends ESTimeBasedDao {
dResultElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
log.debug("failed to get distribution statuses for action {}",
AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
@@ -164,7 +166,7 @@ public class AuditingDao extends ESTimeBasedDao {
dNotifyElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
log.debug("failed to get distribution statuses for action {}",
AuditingActionEnum.DISTRIBUTION_NOTIFY.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java
index c3dc886f85..8d8e0ba50c 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java
@@ -48,6 +48,9 @@ public class ESCatalogDAO extends ESGenericSearchDAO implements ICatalogDAO {
private static Logger log = Logger.getLogger(ESCatalogDAO.class.getName());
+ // Index Checking Variables
+ private boolean initCompleted = false;
+
//TODO use LoggerMetric instead
private static Logger healthCheckLogger = Logger.getLogger("elasticsearch.healthcheck");
@@ -122,11 +125,8 @@ public class ESCatalogDAO extends ESGenericSearchDAO implements ICatalogDAO {
initCompleted = true;
}
- // Index Checking Variables
- private boolean initCompleted = false;
-
@Override
- public void writeArtifact(ESArtifactData artifactData) throws ResourceDAOException {
+ public void writeArtifact(ESArtifactData artifactData) {
try {
saveResourceData(artifactData);
} catch (Exception e) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java
index dc944d016e..556f8c1381 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java
@@ -54,7 +54,12 @@ public abstract class ESTimeBasedDao {
private Map<String, String> indexPrefix2CreationPeriod;
private ConfigurationManager configurationManager;
+
+ @Resource(name = "elasticsearch-client")
+ private ElasticSearchClient esClient;
+ protected final Map<String, Class<?>> typesToClasses = new HashMap<>();
+
protected ESTimeBasedDao() {
gson = new GsonBuilder().setPrettyPrinting().create();
configurationManager = ConfigurationManager.getConfigurationManager();
@@ -65,11 +70,6 @@ public abstract class ESTimeBasedDao {
this.configurationManager = configurationManager;
}
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- protected final Map<String, Class<?>> typesToClasses = new HashMap<>();
-
public abstract String getIndexPrefix();
public ActionStatus write(String typeName, ESTimeBasedEvent data) {
@@ -240,8 +240,7 @@ public abstract class ESTimeBasedDao {
}
}
- public List<ESTimeBasedEvent> customFindEvent(String typeName, QueryBuilder query, SortBuilder sortBuilder)
- throws JSONException {
+ public List<ESTimeBasedEvent> customFindEvent(String typeName, QueryBuilder query, SortBuilder sortBuilder) {
List<ESTimeBasedEvent> results = doCustomFindForEvent(typeName, query, sortBuilder, MAX_SEARCH_SIZE);
if (results == null) {
results = new ArrayList<>();
@@ -271,11 +270,8 @@ public abstract class ESTimeBasedDao {
}
private boolean somethingFound(final SearchResponse searchResponse) {
- if (searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
- || searchResponse.getHits().getHits().length == 0) {
- return false;
- }
- return true;
+ return !(searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
+ || searchResponse.getHits().getHits().length == 0);
}
public String getEsHost() {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java
index 448b3e31a1..5b2498a531 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java
@@ -41,7 +41,9 @@ import java.util.Map;
//@Component("users-dao")
public class Neo4jUsersDAO implements IUsersDAO {
- // @Resource
+ private static final String USER_ID = "userId";
+
+ // @Resource
Neo4jClient neo4jClient;
private static Logger logger = Logger.getLogger(Neo4jUsersDAO.class.getName());
@@ -75,7 +77,7 @@ public class Neo4jUsersDAO implements IUsersDAO {
if (createIndexStatus.equals(Neo4jOperationStatus.OK)) {
logger.info("Users indexes created in Neo4j");
List<String> propertyUnique = new ArrayList<>();
- propertyUnique.add("userId");
+ propertyUnique.add(USER_ID);
logger.info("Start create Users constraints in Neo4jGraph");
Neo4jOperationStatus createUniquenessStatus = neo4jClient
@@ -100,7 +102,7 @@ public class Neo4jUsersDAO implements IUsersDAO {
@Override
public Either<UserData, ActionStatus> getUserData(String id) {
MatchFilter filter = new MatchFilter();
- filter.addToMatch("userId", id);
+ filter.addToMatch(USER_ID, id);
Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
NodeTypeEnum.User.getName(), filter);
if (status.isRight()) {
@@ -128,7 +130,7 @@ public class Neo4jUsersDAO implements IUsersDAO {
@Override
public ActionStatus updateUserData(UserData userData) {
UpdateFilter filter = new UpdateFilter();
- filter.addToMatch("userId", userData.getUserId());
+ filter.addToMatch(USER_ID, userData.getUserId());
filter.setToUpdate(userData.toGraphMap());
Neo4jOperationStatus status = neo4jClient.updateElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
@@ -142,7 +144,7 @@ public class Neo4jUsersDAO implements IUsersDAO {
@Override
public ActionStatus deleteUserData(String id) {
MatchFilter filter = new MatchFilter();
- filter.addToMatch("userId", id);
+ filter.addToMatch(USER_ID, id);
Neo4jOperationStatus status = neo4jClient.deleteElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
if (status.equals(Neo4jOperationStatus.OK)) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/TitanDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/TitanDao.java
index ab95cdbba9..e01cddceb0 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/TitanDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/TitanDao.java
@@ -253,7 +253,7 @@ public class TitanDao {
}
}
- public void setVertexProperties(Vertex vertex, Map<String, Object> properties) throws IOException {
+ public void setVertexProperties(Vertex vertex, Map<String, Object> properties) {
for (Map.Entry<String, Object> entry : properties.entrySet()) {
if (entry.getValue() != null) {
vertex.property(entry.getKey(), entry.getValue());
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java
index 459e98379b..3c502ffccb 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java
@@ -44,7 +44,10 @@ import java.util.stream.StreamSupport;
@Component("titan-generic-dao")
public class TitanGenericDao {
- private TitanGraphClient titanClient;
+ private static final String FAILED_TO_RETRIEVE_GRAPH_STATUS_IS = "Failed to retrieve graph. status is {}";
+ private static final String NO_EDGES_IN_GRAPH_FOR_CRITERIA = "No edges in graph for criteria";
+ private static final String FAILED_TO_CREATE_EDGE_FROM_TO = "Failed to create edge from [{}] to [{}]";
+ private TitanGraphClient titanClient;
private static Logger log = Logger.getLogger(TitanGenericDao.class.getName());
private static final String LOCK_NODE_PREFIX = "lock_";
@@ -210,7 +213,7 @@ public class TitanGenericDao {
return Either.left(newRelation);
} catch (Exception e) {
- log.debug("Failed to create edge from [{}] to [{}]", from, to, e);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, from, to, e);
return Either.right(TitanGraphClient.handleTitanException(e));
}
} else {
@@ -223,7 +226,7 @@ public class TitanGenericDao {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
} catch (Exception e) {
- log.debug("Failed to create edge from [{}] to [{}]", vertexOut, vertexIn, e);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
return TitanGraphClient.handleTitanException(e);
}
return TitanOperationStatus.OK;
@@ -260,7 +263,7 @@ public class TitanGenericDao {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
return Either.left(edge);
} catch (Exception e) {
- log.debug("Failed to create edge from [{}] to [{}]", vertexOut, vertexIn, e);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
return Either.right(TitanGraphClient.handleTitanException(e));
}
@@ -452,7 +455,7 @@ public class TitanGenericDao {
Edge matchingEdge = null;
Iterable<TitanEdge> edges = query.edges();
if (edges == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
@@ -461,7 +464,7 @@ public class TitanGenericDao {
}
if (matchingEdge == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
@@ -476,7 +479,7 @@ public class TitanGenericDao {
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
- Iterable<TitanEdge> edges = ((TitanVertex) vertexFrom.left().value()).query().labels(label).edges();
+ Iterable<TitanEdge> edges = vertexFrom.left().value().query().labels(label).edges();
Iterator<TitanEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
@@ -1295,7 +1298,7 @@ public class TitanGenericDao {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
- log.error("Failed to retrieve graph. status is {}", graphRes);
+ log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
@@ -1343,7 +1346,7 @@ public class TitanGenericDao {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
- log.error("Failed to retrieve graph. status is {}", graphRes);
+ log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
@@ -1467,7 +1470,7 @@ public class TitanGenericDao {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
- log.error("Failed to retrieve graph. status is {}", graphRes);
+ log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
@@ -1590,7 +1593,7 @@ public class TitanGenericDao {
Edge matchingEdge = null;
Iterable<TitanEdge> edges = query.edges();
if (edges == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
@@ -1599,7 +1602,7 @@ public class TitanGenericDao {
}
if (matchingEdge == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);