From 00fca27997c4a4a473823c4dc0123c074dac7b50 Mon Sep 17 00:00:00 2001 From: Yuli Shlosberg Date: Sun, 22 Oct 2017 14:27:51 +0300 Subject: remove neo4j classes Change-Id: I7a9b781c30d4eb269c19dfdaa5d230807a97f08b Issue-Id: SDC-487 Signed-off-by: Yuli Shlosberg --- .../org/openecomp/sdc/be/dao/api/BasicDao.java | 183 ---- .../org/openecomp/sdc/be/dao/api/IBasicDAO.java | 65 -- .../org/openecomp/sdc/be/dao/api/IPropertyDAO.java | 28 - .../org/openecomp/sdc/be/dao/api/IResourceDAO.java | 57 -- .../openecomp/sdc/be/dao/impl/Neo4jElementDAO.java | 112 --- .../sdc/be/dao/impl/Neo4jPropertyDAO.java | 52 - .../sdc/be/dao/impl/Neo4jResourceDAO.java | 229 ----- .../openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java | 169 ---- .../openecomp/sdc/be/dao/neo4j/BatchBuilder.java | 83 -- .../sdc/be/dao/neo4j/CypherTemplates.java | 52 - .../sdc/be/dao/neo4j/CypherTranslator.java | 251 ----- .../sdc/be/dao/neo4j/GraphNeighbourTable.java | 64 -- .../openecomp/sdc/be/dao/neo4j/Neo4jClient.java | 1003 -------------------- .../org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java | 69 -- .../sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java | 189 ---- .../sdc/be/dao/neo4j/Neo4jOperationStatus.java | 77 -- .../openecomp/sdc/be/dao/neo4j/NodeRelation.java | 65 -- .../sdc/be/dao/neo4j/filters/MatchFilter.java | 51 - .../neo4j/filters/RecursiveByRelationFilter.java | 81 -- .../sdc/be/dao/neo4j/filters/RecursiveFilter.java | 68 -- .../sdc/be/dao/neo4j/filters/UpdateFilter.java | 56 -- 21 files changed, 3004 deletions(-) delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java delete mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java (limited to 'catalog-dao/src/main') diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java deleted file mode 100644 index 3e6e7706cb..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java +++ /dev/null @@ -1,183 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.api; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.impl.Neo4jResourceDAO; -import org.openecomp.sdc.be.dao.neo4j.BatchBuilder; -import org.openecomp.sdc.be.dao.neo4j.GraphNeighbourTable; -import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jGraphBatchBuilder; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fj.data.Either; - -public abstract class BasicDao implements IBasicDAO { - - Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder(); - - Neo4jClient neo4jClient; - - private static Logger logger = LoggerFactory.getLogger(Neo4jResourceDAO.class.getName()); - - public Either create(GraphNeighbourTable graphNeighbourTable, - Class clazz, NodeTypeEnum nodeType) { - - if (graphNeighbourTable != null) { - - Either bbResult = graphBatchBuilder - .buildBatchBuilderFromTable(graphNeighbourTable); - - if (bbResult.isLeft()) { - - BatchBuilder batchBuilder = bbResult.left().value(); - // Neo4jOperationStatus neo4jOperationStatus = - // neo4jClient.execute(batchBuilder); - Either>, Neo4jOperationStatus> executeResult = neo4jClient - .execute(batchBuilder); - - if (executeResult.isRight()) { - return Either.right(executeResult.right().value()); - } - - T result = null; - List> listOfResults = executeResult.left().value(); - if (listOfResults != null) { - for (List listOfElements : listOfResults) { - if (listOfElements != null && false == listOfElements.isEmpty()) { - for (GraphElement element : listOfElements) { - logger.debug("element {} was returned after running batch operation {}", - element, batchBuilder); - if (element instanceof GraphNode) { - GraphNode neo4jNode = (GraphNode) element; - if (NodeTypeEnum.getByName(neo4jNode.getLabel()) == nodeType) { - result = clazz.cast(neo4jNode); - } - } - } - } - } - } - - return Either.left(result); - - } else { - return Either.right(bbResult.right().value()); - } - - } else { - logger.error("The table sent in order to create resource is empty."); - return Either.right(Neo4jOperationStatus.BAD_REQUEST); - } - - } - - @Override - public Either getNodeData(String uniqueid, Class clazz, - NodeTypeEnum nodeTypeEnum) { - - MatchFilter filter = new MatchFilter(); - filter.addToMatch(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), uniqueid); - - return getNodeData(filter, clazz, nodeTypeEnum); - - } - - @Override - public Either getNodeData(String keyName, String uniqueid, - Class clazz, NodeTypeEnum nodeTypeEnum) { - - MatchFilter filter = new MatchFilter(); - filter.addToMatch(keyName, uniqueid); - - return getNodeData(filter, clazz, nodeTypeEnum); - - } - - private Either getNodeData(MatchFilter filter, Class clazz, - NodeTypeEnum nodeTypeEnum) { - - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - nodeTypeEnum.getName(), filter); - - if (status.isRight()) { - return Either.right(status.right().value()); - } else { - List value = status.left().value(); - if (value == null || value.isEmpty()) { - return Either.right(Neo4jOperationStatus.NOT_FOUND); - } else { - return Either.left(clazz.cast(value.get(0))); - } - } - } - - @Override - public Either, Neo4jOperationStatus> getNodesData( - Map propertiesToMatch, Class clazz, NodeTypeEnum nodeTypeEnum) { - - MatchFilter filter = new MatchFilter(); - if (propertiesToMatch != null) { - for (Entry property : propertiesToMatch.entrySet()) { - filter.addToMatch(property.getKey(), property.getValue()); - } - } - - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - nodeTypeEnum.getName(), filter); - - if (status.isRight()) { - return Either.right(status.right().value()); - } else { - List value = status.left().value(); - if (value == null || value.isEmpty()) { - return Either.right(Neo4jOperationStatus.NOT_FOUND); - } else { - List list = new ArrayList(); - for (GraphElement element : value) { - list.add(clazz.cast(element)); - } - return Either.left(list); - } - } - } - - public Neo4jClient getNeo4jClient() { - return neo4jClient; - } - - public void setNeo4jClient(Neo4jClient neo4jClient) { - this.neo4jClient = neo4jClient; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java deleted file mode 100644 index 3a2bfb34e8..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.api; - -import java.util.List; -import java.util.Map; - -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.neo4j.GraphNeighbourTable; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; - -import fj.data.Either; - -public interface IBasicDAO { - - /** - * add the content of the graph neighbour table to the graph. - * - * @param graphNeighbourTable - * @param clazz - * - the type of the object to be returned - * @param nodeType - * - label of the node - * @return Neo4jNode implementation - */ - public Either create(GraphNeighbourTable graphNeighbourTable, - Class clazz, NodeTypeEnum nodeType); - - /** - * return the node data by unique id. - * - * @param id - * - unique id of the node - * @param clazz - * @param nodeType - * @return - */ - public Either getNodeData(String id, Class clazz, - NodeTypeEnum nodeType); - - public Either getNodeData(String keyName, String id, Class clazz, - NodeTypeEnum nodeType); - - public Either, Neo4jOperationStatus> getNodesData( - Map propertiesToMatch, Class clazz, NodeTypeEnum nodeTypeEnum); -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java deleted file mode 100644 index 17bded535c..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.api; - -public interface IPropertyDAO extends IBasicDAO { - - // Either - // createPropertyData(GraphNeighbourTable graphNeighbourTable); - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java deleted file mode 100644 index 47bbcbcb11..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.api; - -import java.util.List; -import java.util.Map; - -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.resources.data.ResourceMetadataData; - -import fj.data.Either; - -public interface IResourceDAO extends IBasicDAO { - - Either getResourceData(String id); - - // Either - // createResourceData(GraphNeighbourTable graphNeighbourTable); - - /** - * the method retrieves all the resources according to the supplied - * properties, if none or null is supplied all the resources will be - * returned. - * - * @param propertiesToMatch - * a map of properties to match. - * @return - */ - Either, Neo4jOperationStatus> getAllResourcesData(Map propertiesToMatch); - - // ActionStatus updateUserData(UserData userData); - // - // ActionStatus deleteUserData(String id); - - void setNeo4jClient(Neo4jClient client); - - Either getNumberOfResourcesByName(String name); -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java deleted file mode 100644 index d6b8d2eed8..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.impl; - -import java.util.List; - -import javax.annotation.Resource; - -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.api.IElementDAO; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; -import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import fj.data.Either; - -//@Component("elements-dao") -public class Neo4jElementDAO implements IElementDAO { - - // @Resource - Neo4jClient neo4jClient; - - private static Logger logger = LoggerFactory.getLogger(Neo4jElementDAO.class.getName()); - - @Override - public Either, ActionStatus> getAllCategories() { - MatchFilter filter = new MatchFilter(); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.ResourceCategory.getName(), filter); - if (status.isRight()) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - List value = status.left().value(); - if (value == null || value.isEmpty()) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - return Either.left(value); - } - } - } - - @Override - public Either, ActionStatus> getAllTags() { - MatchFilter filter = new MatchFilter(); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.Tag.getName(), filter); - if (status.isRight()) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - List value = status.left().value(); - if (value == null) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - return Either.left(value); - } - } - } - - @Override - public Either getCategory(String name) { - MatchFilter filter = new MatchFilter(); - filter.addToMatch(GraphPropertiesDictionary.NAME.getProperty(), name); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.ResourceCategory.getName(), filter); - if (status.isRight()) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - List value = status.left().value(); - if (value == null) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - return Either.left(value.get(0)); - } - } - - } - - /** - * FOR TEST ONLY - * - * @param neo4jClient - */ - public void setNeo4jClient(Neo4jClient neo4jClient) { - this.neo4jClient = neo4jClient; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java deleted file mode 100644 index c9fcbab0de..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.impl; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; - -import org.openecomp.sdc.be.dao.api.BasicDao; -import org.openecomp.sdc.be.dao.api.IPropertyDAO; -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jGraphBatchBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -//@Component("neo4j-property-dao") -public class Neo4jPropertyDAO extends BasicDao implements IPropertyDAO { - - // @Resource - Neo4jClient neo4jClient; - - private static Logger logger = LoggerFactory.getLogger(Neo4jPropertyDAO.class.getName()); - - Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder(); - - public Neo4jPropertyDAO() { - - } - - @PostConstruct - public void init() { - setNeo4jClient(neo4jClient); - } -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java deleted file mode 100644 index 8d961b10ec..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java +++ /dev/null @@ -1,229 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.impl; - -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; - -import org.openecomp.sdc.be.dao.api.BasicDao; -import org.openecomp.sdc.be.dao.api.IResourceDAO; -import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; -import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint; -import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; -import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jGraphBatchBuilder; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.resources.data.ResourceMetadataData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fj.data.Either; - -//@Component("neo4j-resource-dao") -public class Neo4jResourceDAO extends BasicDao implements IResourceDAO { - - // @Resource - Neo4jClient neo4jClient; - - private static Logger logger = LoggerFactory.getLogger(Neo4jResourceDAO.class.getName()); - - Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder(); - - public Neo4jResourceDAO() { - - } - - @PostConstruct - public void init() { - super.setNeo4jClient(neo4jClient); - } - - private String findResourceDataIdFromNodes(List nodes) { - - if (nodes != null) { - - for (GraphNode neo4jNode : nodes) { - String label = neo4jNode.getLabel(); - if (label.equals(NodeTypeEnum.Resource.getName())) { - return neo4jNode.getUniqueId().toString(); - } - } - } - - return null; - } - - private GraphRelation addStateRelation(RelationEndPoint from, RelationEndPoint to, GraphEdgeLabels edgeLabel, - String value) { - - GraphRelation relationState = new GraphRelation(); - relationState.setFrom(from); - relationState.setTo(to); - relationState.setType(edgeLabel.name()); - relationState.setAction(ActionEnum.Create); - return relationState; - } - - // private ActionStatus convertNeo4jOperationStatusToActionStatus( - // Neo4jOperationStatus value) { - // - // if (value == null) { - // return ActionStatus.GENERAL_ERROR; - // } - // - // switch (value) { - // case NOT_FOUND: - // return ActionStatus.RESOURCE_NOT_FOUND; - // case ERROR: - // return ActionStatus.GENERAL_ERROR; - // case NOT_SUPPORTED: - // return ActionStatus.INVALID_CONTENT; - // case WRONG_INPUT: - // return ActionStatus.INVALID_CONTENT; - // case OK: - // return ActionStatus.OK; - // default: - // return ActionStatus.GENERAL_ERROR; - // } - // - // } - - @Override - public Either getResourceData(String id) { - - MatchFilter filter = new MatchFilter(); - filter.addToMatch(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), id); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.Resource.getName(), filter); - - if (status.isRight()) { - return Either.right(status.right().value()); - } else { - List value = status.left().value(); - if (value == null || value.isEmpty()) { - return Either.right(Neo4jOperationStatus.NOT_FOUND); - } else { - return Either.left((ResourceMetadataData) value.get(0)); - } - } - } - - @Override - public Either getNumberOfResourcesByName(String name) { - - MatchFilter filter = new MatchFilter(); - filter.addToMatch(GraphPropertiesDictionary.NAME.getProperty(), name); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.Resource.getName(), filter); - - if (status.isRight() || (status.left().value() == null)) { - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } else { - List value = status.left().value(); - return Either.left(value.size()); - } - } - - @Override - public void setNeo4jClient(Neo4jClient client) { - this.neo4jClient = client; - super.setNeo4jClient(client); - } - - @Override - public Either, Neo4jOperationStatus> getAllResourcesData( - Map propertiesToMatch) { - - RecursiveFilter filter = new RecursiveFilter(NodeTypeEnum.Resource); - // filter.addRelationType("typeof").addRelationType("belong").setProperties(propertiesToMatch); - - Either>, Neo4jOperationStatus> ret = neo4jClient.executeGet(filter); - if (ret.isRight()) { - return Either.right(ret.right().value()); - } - List> listOfListOfNeo4jElement = ret.left().value(); - - for (List row : listOfListOfNeo4jElement) { - - for (GraphElement elem : row) { - - } - } - return Either.right(null); - - /* - * MatchFilter filter = new MatchFilter(); if(propertiesToMatch != - * null){ for (Entry propertie : - * propertiesToMatch.entrySet()){ filter.addToMatch(propertie.getKey(), - * propertie.getValue()); } } Either, - * Neo4jOperationStatus> status = - * neo4jClient.getByFilter(GraphElementTypeEnum.Node, - * NodeTypeEnum.Resource.getName(), filter); if (status.isRight()) { - * return Either.right(status.right().value()); } else { - * List value = status.left().value(); if (value == null - * || value.isEmpty()) { return - * Either.right(Neo4jOperationStatus.NOT_FOUND); } else { - * List result=new ArrayList<>(); for(GraphElement element - * : value ){ result.add((ResourceData)element); } return - * Either.left(result); } } - */ - } - - // @Override - // public ActionStatus updateUserData(UserData userData) { - // UpdateFilter filter = new UpdateFilter(); - // filter.addToMatch("userId", userData.getUserId()); - // filter.setToUpdate(userData.toMap()); - // Neo4jOperationStatus status = - // neo4jClient.updateElement(Neo4JElementTypeEnum.Node, - // NodeTypeEnum.User.getName(), filter); - // if (status.equals(Neo4jOperationStatus.OK)) { - // return ActionStatus.OK; - // } else { - // return ActionStatus.GENERAL_ERROR; - // } - // } - // - // @Override - // public ActionStatus deleteUserData(String id) { - // MatchFilter filter = new MatchFilter(); - // filter.addToMatch("userId", id); - // Neo4jOperationStatus status = - // neo4jClient.deleteElement(Neo4JElementTypeEnum.Node, - // NodeTypeEnum.User.getName(), filter); - // if (status.equals(Neo4jOperationStatus.OK)) { - // return ActionStatus.OK; - // } else { - // return ActionStatus.GENERAL_ERROR; - // } - // } - -} 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 deleted file mode 100644 index 14489ef04b..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; - -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.api.IUsersDAO; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; -import org.openecomp.sdc.be.dao.neo4j.Neo4jClient; -import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.UpdateFilter; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.resources.data.UserData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import fj.data.Either; - -//@Component("users-dao") -public class Neo4jUsersDAO implements IUsersDAO { - - // @Resource - Neo4jClient neo4jClient; - - private static Logger logger = LoggerFactory.getLogger(Neo4jUsersDAO.class.getName()); - - public Neo4jUsersDAO() { - - } - - @PostConstruct - public void init() { - } - - private void createIndexesAndConstraints() { - Either>, Neo4jOperationStatus> statusInd = neo4jClient - .getIndexes(NodeTypeEnum.User.getName()); - if (statusInd.isRight()) { - logger.error("Failed to get indexes from Neo4j graph"); - throw new RuntimeException("Failed to initialize Neo4jUsersDAO - Failed to get indexes from Neo4j graph"); - } - Map> indexes = statusInd.left().value(); - if (indexes == null || indexes.isEmpty()) { - logger.info("Define users indexes in Neo4j"); - List propertyNames = new ArrayList(); - propertyNames.add("firstName"); - propertyNames.add("lastName"); - propertyNames.add("email"); - propertyNames.add("role"); - logger.info("Start create Users indexes in Neo4jGraph"); - Neo4jOperationStatus createIndexStatus = neo4jClient.createIndex(NodeTypeEnum.User.getName(), - propertyNames); - if (createIndexStatus.equals(Neo4jOperationStatus.OK)) { - logger.info("Users indexes created in Neo4j"); - List propertyUnique = new ArrayList(); - propertyUnique.add("userId"); - - logger.info("Start create Users constraints in Neo4jGraph"); - Neo4jOperationStatus createUniquenessStatus = neo4jClient - .createUniquenessConstraints(NodeTypeEnum.User.getName(), propertyUnique); - if (createUniquenessStatus.equals(Neo4jOperationStatus.OK)) { - logger.info("Users constraints creatyed in Neo4j"); - } else { - logger.error("Failed to create constraints in Neo4j graph [{}]", createUniquenessStatus); - throw new RuntimeException( - "Failed to initialize Neo4jUsersDAO - Failed to create constraints in Neo4j graph"); - } - } else { - logger.error("Failed to create indexes in Neo4j graph [{}]", createIndexStatus); - throw new RuntimeException( - "Failed to initialize Neo4jUsersDAO - Failed to create indexes in Neo4j graph"); - } - } else { - logger.info("Users indexes already defined in Neo4j"); - } - } - - @Override - public Either getUserData(String id) { - MatchFilter filter = new MatchFilter(); - filter.addToMatch("userId", id); - Either, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node, - NodeTypeEnum.User.getName(), filter); - if (status.isRight()) { - return Either.right(ActionStatus.GENERAL_ERROR); - } else { - List value = status.left().value(); - if (value == null || value.isEmpty()) { - return Either.right(ActionStatus.USER_NOT_FOUND); - } else { - return Either.left((UserData) value.get(0)); - } - } - } - - @Override - public ActionStatus saveUserData(UserData userData) { - Neo4jOperationStatus status = neo4jClient.createElement(userData); - if (status.equals(Neo4jOperationStatus.OK)) { - return ActionStatus.OK; - } else { - return ActionStatus.GENERAL_ERROR; - } - } - - @Override - public ActionStatus updateUserData(UserData userData) { - UpdateFilter filter = new UpdateFilter(); - filter.addToMatch("userId", userData.getUserId()); - filter.setToUpdate(userData.toGraphMap()); - Neo4jOperationStatus status = neo4jClient.updateElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(), - filter); - if (status.equals(Neo4jOperationStatus.OK)) { - return ActionStatus.OK; - } else { - return ActionStatus.GENERAL_ERROR; - } - } - - @Override - public ActionStatus deleteUserData(String id) { - MatchFilter filter = new MatchFilter(); - filter.addToMatch("userId", id); - Neo4jOperationStatus status = neo4jClient.deleteElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(), - filter); - if (status.equals(Neo4jOperationStatus.OK)) { - return ActionStatus.OK; - } else { - return ActionStatus.GENERAL_ERROR; - } - } - - public Neo4jClient getNeo4jClient() { - return neo4jClient; - } - - public void setNeo4jClient(Neo4jClient neo4jClient) { - this.neo4jClient = neo4jClient; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java deleted file mode 100644 index 0177d0bd70..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; - -public class BatchBuilder { - // private Map> nodes; - // private List relations; - // - private List elements; - - // TODO add filter - - protected BatchBuilder() { - // nodes = new HashMap>(); - // relations = new ArrayList(); - elements = new ArrayList(); - } - - public static BatchBuilder getBuilder() { - return new BatchBuilder(); - } - - public BatchBuilder add(GraphElement element) { - elements.add(element); - return this; - } - - public List getElements() { - return elements; - } - - // public BatchBuilder add( Neo4jNode element ){ - // String label = element.getLabel(); - // List list = nodes.get(label); - // if ( list == null ){ - // list = new ArrayList(); - // } - // list.add(element); - // nodes.put(label, list); - - // return this; - // } - // public BatchBuilder add( Neo4jRelation relation ){ - // relations.add(relation); - // return this; - // } - // - // public Map> getNodes() { - // return nodes; - // } - // - // public List getRelations() { - // return relations; - // } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java deleted file mode 100644 index b0b2cc20bb..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -public interface CypherTemplates { - - public static final String CypherUrlTemplate = "http://$host$:$port$/db/data/transaction/commit"; - public static final String batchTemplate = "http://$host$:$port$/db/data/batch"; - public static final String getAllIndexsTemplate = "http://$host$:$port$/db/data/schema/index"; - - public static final String CypherCreateNodeTemplate = "{\n\"statements\" : [ {\n \"statement\" : \"CREATE (n:$label$ { props } ) RETURN n\",\n \"parameters\" : { \n \"props\" : $props$ \n } } ] }"; - - public static final String CypherMatchTemplate = "{\"statements\": [{\"statement\": \"MATCH (n:$label$ {$filter$}) RETURN ($type$) \" }]}"; - - public static final String CypherUpdateTemplate = "{\"statements\": [{\"statement\": \"MATCH (n:$label$ {$filter$}) SET n += {props} RETURN ($type$) \",\"parameters\" : {\"props\" : {$props$}}}]}"; - public static final String CypherDeleteNodeTemplate = "{\"statements\": [{\"statement\": \"MATCH ( n:$label$ {$filter$} ) DELETE n \" }]}"; - - public static final String BatchTemplate = "{ \"statements\" : [ $statementList$ ] }"; - - public static final String RegularStatementTemplate = "{ \"statement\" : $statement$ }"; - - public static final String CreateSingleNodeTemplate = " \"CREATE (n:$label$ { props } ) RETURN n, labels(n)\", \"parameters\" : { \"props\" : $props$ }"; - - public static final String CreateRelationTemplate = "\"MATCH (a:$labelFrom$),(b:$labelTo$) WHERE a.$idNameFrom$ = '$idValueFrom$' AND b.$idNameTo$ = '$idvalueTo$' CREATE (a)-[r:$type$ { props } ]->(b) RETURN a, labels(a), b, labels(b), r, type(r)\", \"parameters\": {\"props\": $props$ } "; - - public static final String CreateRelationTemplateNoProps = "\"MATCH (a:$labelFrom$),(b:$labelTo$) WHERE a.$idNameFrom$ = '$idValueFrom$' AND b.$idNameTo$ = '$idvalueTo$' CREATE (a)-[r:$type$ ]->(b) RETURN a,labels(a), b, labels(b), r, type(r)\""; - - public static final String UpdateNodeStatementTemplate = "\"MATCH (n:$label$ {$filter$}) SET n += {props} \",\"parameters\" : {\"props\" : $props$}"; - - public static final String GetNodeRecursiveTemplate = "\"MATCH (m:$label$ {$filter$} )-[f$typesList$]->l RETURN m, labels(m), l, labels(l),f, type(f)\""; - - public static final String GetByRelationNodeRecursiveTemplate = "\"MATCH (n:$labelNode$ ($propsNode$} )-[r:$type$ {$propsRel$}]->(m:$labelSrc$)-[f$typesList$]->l RETURN n, labels(n), r, type(r), m, labels(m), l, labels(l),f, type(f)\""; - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java deleted file mode 100644 index e1409b3bb1..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java +++ /dev/null @@ -1,251 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; -import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveByRelationFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter; -import org.openecomp.sdc.be.dao.utils.DaoUtils; - -public class CypherTranslator { - - public String translate(BatchBuilder builder) { - String json = null; - StringBuilder statementList = new StringBuilder(); - - List elements = builder.getElements(); - int statementCounter = 0; - for (GraphElement element : elements) { - String singleStatementBody = null; - switch (element.getElementType()) { - case Node: - singleStatementBody = prepareNodeStatement(element); - break; - case Relationship: - singleStatementBody = prepareRelationStatement(element); - break; - } - if (singleStatementBody != null && !singleStatementBody.isEmpty()) { - - String singleStatement = CypherTemplates.RegularStatementTemplate.replace("$statement$", - singleStatementBody); - - statementList.append(singleStatement); - } - ++statementCounter; - if (statementCounter < elements.size() && singleStatementBody != null) { - statementList.append(","); - } - - } - json = CypherTemplates.BatchTemplate.replace("$statementList$", statementList.toString()); - return json; - } - - private String prepareNodeStatement(GraphElement element) { - if (element instanceof GraphNode) { - GraphNode node = (GraphNode) element; - - switch (node.getAction()) { - case Create: - return createNodeStatement(node); - case Update: - return updateNodeStatement(node); - case Delete: - // TODO - break; - default: - break; - } - } - return null; - } - - private String updateNodeStatement(GraphNode node) { - String singleStatement = CypherTemplates.UpdateNodeStatementTemplate.replace("$label$", node.getLabel()); - String filter = prepareKeyValueFilter(node); - - singleStatement = singleStatement.replace("$filter$", filter); - - singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(node.toGraphMap())); - - return singleStatement; - } - - private String createNodeStatement(GraphNode node) { - String singleStatement = CypherTemplates.CreateSingleNodeTemplate.replace("$label$", node.getLabel()); - - singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(node.toGraphMap())); - return singleStatement; - } - - private String prepareRelationStatement(GraphElement element) { - if (element instanceof GraphRelation) { - - GraphRelation relation = (GraphRelation) element; - - switch (relation.getAction()) { - case Create: - return createRelationStatement(relation); - case Update: - return updateRelationStatement(relation); - case Delete: - // TODO - break; - default: - break; - } - } - return null; - } - - private String createRelationStatement(GraphRelation relation) { - RelationEndPoint from = relation.getFrom(); - String singleStatement; - - Map props = relation.toGraphMap(); - if (props == null || props.isEmpty()) { - singleStatement = CypherTemplates.CreateRelationTemplateNoProps.replace("$labelFrom$", - from.getLabel().getName()); - } else { - singleStatement = CypherTemplates.CreateRelationTemplate.replace("$labelFrom$", from.getLabel().getName()); - singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(props)); - } - - singleStatement = singleStatement.replace("$idNameFrom$", from.getIdName()); - singleStatement = singleStatement.replace("$idValueFrom$", from.getIdValue().toString()); - - RelationEndPoint to = relation.getTo(); - singleStatement = singleStatement.replace("$labelTo$", to.getLabel().getName()); - singleStatement = singleStatement.replace("$idNameTo$", to.getIdName()); - singleStatement = singleStatement.replace("$idvalueTo$", to.getIdValue().toString()); - - singleStatement = singleStatement.replace("$type$", relation.getType()); - return singleStatement; - } - - private String updateRelationStatement(GraphRelation relation) { - // TODO - return null; - } - - private String prepareKeyValueFilter(GraphNode node) { - StringBuilder sb = new StringBuilder(); - - ImmutablePair keyValueId = node.getKeyValueId(); - - sb.append(keyValueId.getKey()).append(":"); - if (keyValueId.getValue() instanceof String) { - sb.append("'"); - } - sb.append(keyValueId.getValue()); - - if (keyValueId.getValue() instanceof String) { - sb.append("'"); - } - - return sb.toString(); - } - - public String translateGet(RecursiveFilter filter) { - String requestJson = null; - String statement; - - if (filter instanceof RecursiveByRelationFilter) { - RecursiveByRelationFilter byRelationFilter = (RecursiveByRelationFilter) filter; - - statement = CypherTemplates.GetByRelationNodeRecursiveTemplate.replace("$labelNode$", - byRelationFilter.getNode().getLabel()); - String keyValueId = prepareKeyValueFilter(byRelationFilter.getNode()); - - statement = statement.replace("$propsNode$", keyValueId); - - statement = statement.replace("$type$", byRelationFilter.getRelationType()); - - String relationProps = prepareFilterBody(filter); - statement = statement.replace("$propsRel$", relationProps); - statement = statement.replace("$labelSrc$", filter.getNodeType().getName()); - - } else { - - statement = CypherTemplates.GetNodeRecursiveTemplate.replace("$label$", filter.getNodeType().getName()); - - // replace filter - if (filter.getProperties().isEmpty()) { - // get all records by label - statement = statement.replace("{$filter$}", ""); - } else { - String filterStr = prepareFilterBody(filter); - statement = statement.replace("$filter$", filterStr); - } - } - - if (filter.getChildRelationTypes() == null || filter.getChildRelationTypes().isEmpty()) { - statement = statement.replace("$typesList$", ""); - - } else { - StringBuilder typesList = new StringBuilder(); - int count = 0; - for (String type : filter.getChildRelationTypes()) { - typesList.append(":").append(type); - ++count; - if (count < filter.getChildRelationTypes().size()) { - typesList.append("|"); - } - } - statement = statement.replace("$typesList$", typesList.toString()); - } - String singleStatement = CypherTemplates.RegularStatementTemplate.replace("$statement$", statement); - requestJson = CypherTemplates.BatchTemplate.replace("$statementList$", singleStatement); - - return requestJson; - } - - public static String prepareFilterBody(MatchFilter filter) { - StringBuilder sb = new StringBuilder(); - int count = 0; - int size = filter.getProperties().entrySet().size(); - for (Map.Entry entry : filter.getProperties().entrySet()) { - sb.append(entry.getKey()).append(":"); - if (entry.getValue() instanceof String) { - sb.append("'"); - } - sb.append(entry.getValue()); - if (entry.getValue() instanceof String) { - sb.append("'"); - } - ++count; - if (count < size) { - sb.append(","); - } - } - return sb.toString(); - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java deleted file mode 100644 index ccfb57b145..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.util.ArrayList; -import java.util.List; - -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; - -public class GraphNeighbourTable { - - List nodes = new ArrayList(); - - List directedEdges = new ArrayList(); - - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } - - public List getDirectedEdges() { - return directedEdges; - } - - public void setDirectedEdges(List directedEdges) { - this.directedEdges = directedEdges; - } - - public int addNode(GraphNode node) { - this.nodes.add(node); - return this.nodes.size() - 1; - } - - public void addEdge(NodeRelation directedEdge) { - this.directedEdges.add(directedEdge); - } - - @Override - public String toString() { - return "GraphNeighbourTable [nodes=" + nodes + ", directedEdges=" + directedEdges + "]"; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java deleted file mode 100644 index eb279cda3d..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java +++ /dev/null @@ -1,1003 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.AuthCache; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.util.EntityUtils; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.graph.GraphElementFactory; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter; -import org.openecomp.sdc.be.dao.neo4j.filters.UpdateFilter; -import org.openecomp.sdc.be.dao.utils.DaoUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import fj.data.Either; - -//@Component("neo4j-client") -public class Neo4jClient { - private CloseableHttpClient httpClient; - private JSONParser jsonParser; - - private CypherTranslator cypherTranslator; - - private static Logger logger = LoggerFactory.getLogger(Neo4jClient.class.getName()); - - private static final String getServiceRoot = "http://$host$:$port$/db/data/"; - // Error's Classification templates - private static final String ClientError = "ClientError"; - private static final String DatabaseError = "DatabaseError"; - private static final String TransientError = "TransientError"; - - // Error's Category templates - private static final String General = "General"; - private static final String LegacyIndex = "LegacyIndex"; - private static final String Request = "Request"; - private static final String Schema = "Schema"; - private static final String Security = "Security"; - private static final String Statement = "Statement"; - private static final String Transaction = "Transaction"; - - // Error's Title templates - private static final String EntityNotFound = "EntityNotFound"; - private static final String ConstraintViolation = "ConstraintViolation"; - - @PostConstruct - public void init() { - - PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); - connectionManager.setMaxTotal(100); - connectionManager.setDefaultMaxPerRoute(20); - connectionManager.setValidateAfterInactivity(15000); - this.httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); - jsonParser = new JSONParser(); - cypherTranslator = new CypherTranslator(); - - } - - @PreDestroy - public void shutdown() { - try { - httpClient.close(); - logger.debug("Http client to Neo4j Graph closed"); - } catch (Exception e) { - logger.info("Failed to close http client", e); - } - } - - /** - * - * @param builder - * @return - */ - public Either>, Neo4jOperationStatus> execute(BatchBuilder builder) { - - String json = cypherTranslator.translate(builder); - logger.debug("Try to execute cypher request [{}]", json); - - Either result = sendPostCypher(json); - if (result.isRight()) { - return Either.right(result.right().value()); - } - List> batchResult; - try { - batchResult = parseResult(result.left().value(), false); - } catch (ParseException e) { - logger.error("Failed to parse batchresponse", e); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - - return Either.left(batchResult); - } - - public Either>, Neo4jOperationStatus> executeGet(RecursiveFilter filter) { - String json = cypherTranslator.translateGet(filter); - logger.debug("Try to execute cypher request [{}]", json); - - Either result = sendPostCypher(json); - if (result.isRight()) { - return Either.right(result.right().value()); - } - List> batchResult; - try { - batchResult = parseResult(result.left().value(), true); - } catch (ParseException e) { - logger.error("Failed to parse batchresponse", e); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - - return Either.left(batchResult); - - } - - /** - * - * @param element - * @param ip - * @param user - * @param password - * @return - */ - public Neo4jOperationStatus createElement(GraphElement element) { - Neo4jOperationStatus result = Neo4jOperationStatus.OK; - switch (element.getElementType()) { - case Node: - Either status = createNode(element); - if (status.isRight()) { - result = status.right().value(); - } - break; - case Relationship: - // TODO - break; - - default: - break; - } - - return result; - } - - public Either createSingleElement(GraphElement element) { - switch (element.getElementType()) { - case Node: - Either status = createNode(element); - if (status.isRight()) { - return Either.right(status.right().value()); - } - // parse response - String response = status.left().value(); - try { - List listElements = parseGetResponse(element.getElementType(), - ((GraphNode) element).getLabel(), response); - if (listElements == null || listElements.isEmpty()) { - return Either.right(Neo4jOperationStatus.NOT_FOUND); - } else { - return Either.left(listElements.get(0)); - } - } catch (Exception e) { - logger.error("Failed to parse fetched data from graph", e); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - case Relationship: - // TODO - break; - - default: - break; - } - - return Either.right(Neo4jOperationStatus.NOT_SUPPORTED); - } - - /** - * - * @param type - * @param label - * @param filter - * @param ip - * @param user - * @param password - * @return - */ - public Either, Neo4jOperationStatus> getByFilter(GraphElementTypeEnum type, String label, - MatchFilter filter) { - - List result = null; - - String requestJson; - // replace return type - if (type.equals(GraphElementTypeEnum.Node)) { - requestJson = CypherTemplates.CypherMatchTemplate.replace("$type$", "n"); - } else { - requestJson = CypherTemplates.CypherMatchTemplate.replace("$type$", "r"); - } - // replace label - if (label != null && !label.isEmpty()) { - requestJson = requestJson.replace("$label$", label); - } else { - requestJson = requestJson.replace("$label$", ""); - } - - // replace filter - if (filter.getProperties().isEmpty()) { - // get all records by label - requestJson = requestJson.replace("{$filter$}", ""); - } else { - String filterStr = CypherTranslator.prepareFilterBody(filter); - requestJson = requestJson.replace("$filter$", filterStr); - } - logger.debug("Try to perform request []", requestJson); - - Either status = sendPostCypher(requestJson); - if (status.isRight()) { - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - // parse response - String response = status.left().value(); - try { - result = parseGetResponse(type, label, response); - } catch (Exception e) { - logger.error("Failed to parse fetched data from graph", e); - Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - - return Either.left(result); - } - - /** - * - * @param type - * @param label - * @param toMatch - * @param toUpdate - * @param ip - * @param user - * @param password - * @return - */ - public Neo4jOperationStatus updateElement(GraphElementTypeEnum type, String label, UpdateFilter toUpdate) { - - String requestJson; - // replace return type - if (type.equals(GraphElementTypeEnum.Node)) { - requestJson = CypherTemplates.CypherUpdateTemplate.replace("$type$", "n"); - } else { - requestJson = CypherTemplates.CypherUpdateTemplate.replace("$type$", "r"); - } - // replace label - if (label != null && !label.isEmpty()) { - requestJson = requestJson.replace("$label$", label); - } else { - requestJson = requestJson.replace("$label$", ""); - } - - // replace filter - if (toUpdate.getProperties().isEmpty()) { - // get all records by label - requestJson = requestJson.replace("{$filter$}", ""); - } else { - String filterStr = CypherTranslator.prepareFilterBody(toUpdate); - requestJson = requestJson.replace("$filter$", filterStr); - } - String props = preparePropertiesInStatement(toUpdate.getToUpdate()); - requestJson = requestJson.replace("$props$", props); - - logger.debug("Try to perform request [{}]", requestJson); - - Either result = sendPostCypher(requestJson); - if (result.isRight()) { - return Neo4jOperationStatus.GENERAL_ERROR; - } - return Neo4jOperationStatus.OK; - } - - /** - * - * @param type - * @param label - * @param response - * @return - * @throws ParseException - */ - - private List parseGetResponse(GraphElementTypeEnum type, String label, String response) - throws ParseException { - List result = new ArrayList(); - JSONObject responseData = (JSONObject) jsonParser.parse(response); - JSONArray results = (JSONArray) responseData.get("results"); - Iterator iteratorResults = results.iterator(); - while (iteratorResults.hasNext()) { - JSONObject elementResult = iteratorResults.next(); - // JSONArray data = (JSONArray) elementResult.get("row"); - JSONArray data = (JSONArray) elementResult.get("data"); - - Iterator iterator = data.iterator(); - JSONObject element; - while (iterator.hasNext()) { - element = (JSONObject) iterator.next(); - JSONArray row = (JSONArray) element.get("row"); - - Iterator iteratorRow = row.iterator(); - while (iteratorRow.hasNext()) { - JSONObject rowElement = iteratorRow.next(); - - Map props = new HashMap(); - - for (Map.Entry entry : (Set>) rowElement.entrySet()) { - // props.put(entry.getKey(), - // rowElement.get(entry.getValue())); - props.put(entry.getKey(), entry.getValue()); - } - GraphElement newElement = GraphElementFactory.createElement(label, type, props); - result.add(newElement); - } - } - } - return result; - } - - private List> parseResult(String response, boolean storeRelationNode) throws ParseException { - - List> batchList = new ArrayList>(); - - JSONObject responseData = (JSONObject) jsonParser.parse(response); - JSONArray results = (JSONArray) responseData.get("results"); - Iterator iteratorResults = results.iterator(); - - while (iteratorResults.hasNext()) { - JSONObject elementResult = iteratorResults.next(); - JSONArray data = (JSONArray) elementResult.get("data"); - JSONArray columns = (JSONArray) elementResult.get("columns"); - Iterator iteratorData = data.iterator(); - List singleDataList = new ArrayList(); - while (iteratorData.hasNext()) { - - JSONObject singleData = iteratorData.next(); - JSONArray row = (JSONArray) singleData.get("row"); - if (columns.size() == 2) { - // node - JSONArray labelArray = (JSONArray) row.get(1); - JSONObject node = (JSONObject) row.get(0); - - Map props = jsonObjectToMap(node); - // get only first label on node. Now single label supported - GraphElement newElement = GraphElementFactory.createElement((String) labelArray.get(0), - GraphElementTypeEnum.Node, props); - singleDataList.add(newElement); - } - if (columns.size() == 10) { - // relation - JSONObject startNode = (JSONObject) row.get(0); - JSONArray startNodeArray = (JSONArray) row.get(1); - - JSONObject relationFromStart = (JSONObject) row.get(2); - String relationFromStartType = (String) row.get(3); - - JSONObject nodeFrom = (JSONObject) row.get(4); - JSONArray labelFromArray = (JSONArray) row.get(5); - - JSONObject nodeTo = (JSONObject) row.get(6); - JSONArray labelToArray = (JSONArray) row.get(7); - - JSONObject relation = (JSONObject) row.get(8); - String type = (String) row.get(9); - - Map propsStartNode = jsonObjectToMap(startNode); - Map propsRelationStartNode = jsonObjectToMap(relationFromStart); - - Map propsFrom = jsonObjectToMap(nodeFrom); - Map propsTo = jsonObjectToMap(nodeTo); - Map propsRelation = jsonObjectToMap(relation); - - GraphNode startN = (GraphNode) GraphElementFactory.createElement((String) startNodeArray.get(0), - GraphElementTypeEnum.Node, propsStartNode); - - GraphNode from = (GraphNode) GraphElementFactory.createElement((String) labelFromArray.get(0), - GraphElementTypeEnum.Node, propsFrom); - GraphNode to = (GraphNode) GraphElementFactory.createElement((String) labelToArray.get(0), - GraphElementTypeEnum.Node, propsTo); - - singleDataList.add(startN); - - GraphElement relationFromStartNode = GraphElementFactory.createRelation(type, - propsRelationStartNode, startN, from); - singleDataList.add(relationFromStartNode); - - singleDataList.add(from); - singleDataList.add(to); - // get only first type on relationship. Now single type - // supported - GraphElement newElement = GraphElementFactory.createRelation(type, propsRelation, from, to); - singleDataList.add(newElement); - } - if (columns.size() == 8) { - - } - } - batchList.add(singleDataList); - } - return batchList; - } - - private Map jsonObjectToMap(JSONObject node) { - Map props = new HashMap(); - - for (Map.Entry entry : (Set>) node.entrySet()) { - props.put(entry.getKey(), entry.getValue()); - } - return props; - } - - private String preparePropertiesInStatement(Map properties) { - StringBuilder sb = new StringBuilder(); - int count = 0; - int size = properties.entrySet().size(); - for (Map.Entry entry : properties.entrySet()) { - sb.append("\"").append(entry.getKey()).append("\"").append(":"); - if (entry.getValue() instanceof String) { - sb.append("\""); - } - sb.append(entry.getValue()); - if (entry.getValue() instanceof String) { - sb.append("\""); - } - ++count; - if (count < size) { - sb.append(","); - } - } - return sb.toString(); - } - - private Either createNode(GraphElement element) { - Either status; - if (element instanceof GraphNode) { - GraphNode node = (GraphNode) element; - String json = prepareCreateNodeBody(node); - - logger.debug("Try to save Node [{}] on graph", json); - - status = sendPostCypher(json); - - return status; - - } else { - return Either.right(Neo4jOperationStatus.WRONG_INPUT); - } - } - - private Either sendPostCypher(String json) { - Map neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j(); - String host = (String) neo4jParams.get("host"); - Integer port = (Integer) neo4jParams.get("port"); - String user = (String) neo4jParams.get("user"); - String password = (String) neo4jParams.get("password"); - - String uri = CypherTemplates.CypherUrlTemplate.replace("$host$", host); - uri = uri.replace("$port$", port.toString()); - - HttpClientContext context = creatClientContext(host, user, password); - CloseableHttpResponse response = null; - - HttpPost post = new HttpPost(uri); - try { - StringEntity input = new StringEntity(json); - input.setContentType("application/json"); - post.setEntity(input); - - response = httpClient.execute(post, context); - - int status = response.getStatusLine().getStatusCode(); - String responseString; - responseString = new BasicResponseHandler().handleResponse(response); - logger.debug("response [{}]", responseString); - - if (status == 200 || status == 201) { - logger.debug("cypher request [{}] was succeeded", json); - Neo4jOperationStatus responseStatus = checkResponse(responseString); - if (Neo4jOperationStatus.OK.equals(responseStatus)) { - return Either.left(responseString); - } else { - return Either.right(responseStatus); - } - } else { - logger.debug("cypher request [{}] was failed : [{}]", json, responseString); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - - } catch (HttpResponseException e) { - logger.debug("failed to perform cypher request [{}]", json, e); - if (e.getStatusCode() == 401) { - return Either.right(Neo4jOperationStatus.NOT_AUTHORIZED); - } else { - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } - } catch (ClientProtocolException e) { - logger.debug("failed to perform cypher request [{}]", json, e); - return Either.right(Neo4jOperationStatus.HTTP_PROTOCOL_ERROR); - } catch (IOException e) { - logger.debug("failed to perform cypher request [{}]", json, e); - return Either.right(Neo4jOperationStatus.NOT_CONNECTED); - } finally { - releaseResource(response); - } - } - - private Neo4jOperationStatus checkResponse(String responseString) { - try { - JSONObject response = (JSONObject) jsonParser.parse(responseString); - JSONArray errors = (JSONArray) response.get("errors"); - if (errors.size() == 0) { - return Neo4jOperationStatus.OK; - } else { - Iterator iterator = errors.iterator(); - JSONObject error; - while (iterator.hasNext()) { - error = (JSONObject) iterator.next(); - String code = (String) error.get("code"); - String message = (String) error.get("message"); - - Neo4jOperationStatus neoError = mapToNeoError(code, message); - return neoError; - } - return Neo4jOperationStatus.GENERAL_ERROR; - } - } catch (ParseException e) { - logger.error("Failed to parse response", e); - return Neo4jOperationStatus.GENERAL_ERROR; - } - } - - private Neo4jOperationStatus mapToNeoError(String code, String message) { - Neo4jOperationStatus error; - - String[] errorCode = code.split("\\."); - if (errorCode.length < 4) { - error = Neo4jOperationStatus.GENERAL_ERROR; - } else { - // by Classification - switch (errorCode[1]) { - case ClientError: - // by Category - switch (errorCode[2]) { - case General: - error = Neo4jOperationStatus.DB_READ_ONLY; - break; - case LegacyIndex: - error = Neo4jOperationStatus.LEGACY_INDEX_ERROR; - break; - case Request: - error = Neo4jOperationStatus.BAD_REQUEST; - break; - case Schema: - if (errorCode[3].equals(ConstraintViolation)) { - error = Neo4jOperationStatus.ENTITY_ALREADY_EXIST; - } else { - error = Neo4jOperationStatus.SCHEMA_ERROR; - } - break; - case Security: - error = Neo4jOperationStatus.NOT_AUTHORIZED; - break; - case Statement: - // by Title - if (errorCode[3].equals(EntityNotFound)) { - error = Neo4jOperationStatus.NOT_FOUND; - } else { - if (errorCode[3].equals(ConstraintViolation)) { - error = Neo4jOperationStatus.ENTITY_ALREADY_EXIST; - } else { - error = Neo4jOperationStatus.BAD_REQUEST; - } - } - break; - case Transaction: - error = Neo4jOperationStatus.TRANSACTION_ERROR; - break; - default: - error = Neo4jOperationStatus.GENERAL_ERROR; - break; - } - break; - case DatabaseError: - // by Category - switch (errorCode[2]) { - case General: - error = Neo4jOperationStatus.GENERAL_ERROR; - break; - case Schema: - error = Neo4jOperationStatus.SCHEMA_ERROR; - break; - case Statement: - error = Neo4jOperationStatus.EXECUTION_FAILED; - break; - case Transaction: - error = Neo4jOperationStatus.TRANSACTION_ERROR; - break; - default: - error = Neo4jOperationStatus.GENERAL_ERROR; - break; - } - break; - case TransientError: - error = Neo4jOperationStatus.DB_NOT_AVAILABLE; - break; - default: - error = Neo4jOperationStatus.GENERAL_ERROR; - break; - } - error.setOriginError(code).setMessage(message); - String errorFromCfg = code.replace(".", "_"); - String helpMessage = ConfigurationManager.getConfigurationManager().getNeo4jErrorsConfiguration() - .getErrorMessage(errorFromCfg); - if (helpMessage != null && !helpMessage.isEmpty()) { - error.setHelpErrorMsg(helpMessage); - } - } - return error; - } - - private String prepareCreateNodeBody(GraphNode node) { - - String body = CypherTemplates.CypherCreateNodeTemplate.replace("$label$", node.getLabel()); - - body = body.replace("$props$", DaoUtils.convertToJson(node.toGraphMap())); - - return body; - } - - /** - * the method returns all the indexes for the given label if no label is - * supplied ( null or "") all indexes will be returned - * - * @param label - * the name of the label - * @param ip - * @param user - * @param password - * @return a map of labels and there properties - */ - public Either>, Neo4jOperationStatus> getIndexes(String label) { - Map neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j(); - String host = (String) neo4jParams.get("host"); - Integer port = (Integer) neo4jParams.get("port"); - String user = (String) neo4jParams.get("user"); - String password = (String) neo4jParams.get("password"); - - String uri = null; - if (label == null || "".equals(label)) { - uri = CypherTemplates.getAllIndexsTemplate.replace("$host$", host); - } else { - uri = CypherTemplates.getAllIndexsTemplate.replace("$host$", host) + "/" + label; - } - uri = uri.replace("$port$", port.toString()); - - HttpClientContext context = creatClientContext(host, user, password); - CloseableHttpResponse response = null; - - HttpGet get = new HttpGet(uri); - get.setHeader("Content-Type", "application/json"); - get.setHeader("Accept", "application/json; charset=UTF-8"); - - try { - - response = httpClient.execute(get, context); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode != 200) { - logger.error("failed to get indexes requeste returned {}", statusCode); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } else { - Map> labels = getLeablesFromJson(response); - return Either.left(labels); - } - } catch (Exception e) { - logger.debug("failed to get indexes ", e); - return Either.right(Neo4jOperationStatus.GENERAL_ERROR); - } finally { - releaseResource(response); - - } - - } - - private Map> getLeablesFromJson(CloseableHttpResponse response) - throws HttpResponseException, IOException, ParseException { - Map> labels = new HashMap<>(); - String responseString = new BasicResponseHandler().handleResponse(response); - JSONArray results = (JSONArray) jsonParser.parse(responseString); - Iterator iteratorResults = results.iterator(); - while (iteratorResults.hasNext()) { - JSONObject elementResult = iteratorResults.next(); - String label = (String) elementResult.get("label"); - List props = labels.get(label); - if (props == null) { - props = new ArrayList<>(); - labels.put(label, props); - } - JSONArray properties = (JSONArray) elementResult.get("property_keys"); - Iterator iterator = properties.iterator(); - while (iterator.hasNext()) { - props.add(iterator.next()); - } - } - return labels; - } - - public Neo4jOperationStatus createIndex(String label, List propertyNames) { - - Neo4jOperationStatus result = Neo4jOperationStatus.OK; - if (propertyNames != null && !propertyNames.isEmpty()) { - - Map neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration() - .getNeo4j(); - String host = (String) neo4jParams.get("host"); - Integer port = (Integer) neo4jParams.get("port"); - String user = (String) neo4jParams.get("user"); - String password = (String) neo4jParams.get("password"); - - String uri = CypherTemplates.batchTemplate.replace("$host$", host); - uri = uri.replace("$port$", port.toString()); - - String opertionUri = "/schema/index/" + label; - - HttpClientContext context = creatClientContext(host, user, password); - - CloseableHttpResponse response = null; - - HttpPost post = new HttpPost(uri); - - String json = createBatchJson(HttpMethod.POST, opertionUri, propertyNames); - - try { - StringEntity input = new StringEntity(json); - input.setContentType("application/json"); - post.setEntity(input); - response = httpClient.execute(post, context); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode != 200) { - logger.error("failed to create index for label [{}] with properties:{} requeste returned {}",label,propertyNames,statusCode); - result = Neo4jOperationStatus.GENERAL_ERROR; - } else { - logger.debug("index for label [{}] with properties: {} created", label, propertyNames); - } - } catch (Exception e) { - logger.debug("failed to create index for label [{}] with properties: {}", label, propertyNames); - result = Neo4jOperationStatus.GENERAL_ERROR; - } finally { - - releaseResource(response); - - } - - } - - else { - logger.debug("no index was created for label :{} the recived propertyNames list: {} is invalide",label,propertyNames); - return Neo4jOperationStatus.WRONG_INPUT; - } - - return result; - } - - public Neo4jOperationStatus createUniquenessConstraints(String label, List propertyNames) { - Neo4jOperationStatus result = Neo4jOperationStatus.OK; - if (propertyNames != null && !propertyNames.isEmpty()) { - - Map neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration() - .getNeo4j(); - String host = (String) neo4jParams.get("host"); - Integer port = (Integer) neo4jParams.get("port"); - String user = (String) neo4jParams.get("user"); - String password = (String) neo4jParams.get("password"); - - String uri = CypherTemplates.batchTemplate.replace("$host$", host); - uri = uri.replace("$port$", port.toString()); - - String opertionUri = "/schema/constraint/" + label + "/uniqueness/"; - - HttpClientContext context = creatClientContext(host, user, password); - - CloseableHttpResponse response = null; - - HttpPost post = new HttpPost(uri); - - String json = createBatchJson(HttpMethod.POST, opertionUri, propertyNames); - - try { - StringEntity input = new StringEntity(json); - input.setContentType("application/json"); - post.setEntity(input); - response = httpClient.execute(post, context); - - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode != 200) { - logger.error("failed to create uniqueness constraint for label [{}] on properties:{}. request returned ", - label,propertyNames,statusCode); - result = Neo4jOperationStatus.GENERAL_ERROR; - } else { - logger.debug("uniqueness constraint for label [{}] on properties:{} created",label,propertyNames); - } - } catch (Exception e) { - logger.error("failed to create uniqueness constraint [{}] with properties:{}",label,propertyNames,e); - result = Neo4jOperationStatus.GENERAL_ERROR; - } finally { - releaseResource(response); - } - - } - - else { - logger.debug("no index was created for label :{} the recived propertyNames list: {} is invalide",label,propertyNames); - return Neo4jOperationStatus.WRONG_INPUT; - } - - return result; - } - - public Neo4jOperationStatus deleteElement(GraphElementTypeEnum type, String label, MatchFilter filter) { - - String requestJson; - // replace return type - if (type.equals(GraphElementTypeEnum.Node)) { - logger.debug("removing node label: {}", label); - requestJson = createDeleteNodeStatment(label, filter); - - } else { - logger.error(" delete on type {} is not yet supported", type); - throw new RuntimeException(" delete on type " + type + " is not yet supported"); - } - - logger.debug("Try to perform request [{}]", requestJson); - - Either status = sendPostCypher(requestJson); - if (status.isRight()) { - logger.error(" delete request failed with: {}", status.right()); - return Neo4jOperationStatus.GENERAL_ERROR; - } else { - return Neo4jOperationStatus.OK; - } - } - - public String getNeo4jVersion() throws Exception { - Map neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j(); - String host = (String) neo4jParams.get("host"); - Integer port = (Integer) neo4jParams.get("port"); - String user = (String) neo4jParams.get("user"); - String password = (String) neo4jParams.get("password"); - - String uri = getServiceRoot.replace("$host$", host).replace("$port$", port.toString()); - - HttpClientContext context = creatClientContext(host, user, password); - CloseableHttpResponse response = null; - String result = null; - - HttpGet get = new HttpGet(uri); - get.setHeader("Content-Type", "application/json"); - get.setHeader("Accept", "application/json; charset=UTF-8"); - - try { - response = httpClient.execute(get, context); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode != 200) { - throw new Exception("Couldn't get Neo4j service root, HTTP status " + statusCode); - } else { - // Parse response - String responseString = new BasicResponseHandler().handleResponse(response); - JSONObject responseData = (JSONObject) jsonParser.parse(responseString); - Object obj = responseData.get("neo4j_version"); - if (obj != null) { - result = (String) obj; - } - return result; - } - } finally { - releaseResource(response); - } - } - - private String createDeleteNodeStatment(String label, MatchFilter filter) { - String requestJson; - requestJson = CypherTemplates.CypherDeleteNodeTemplate; - - if (label != null && !label.isEmpty()) { - requestJson = requestJson.replace("$label$", label); - } else { - requestJson = requestJson.replace("$label$", ""); - } - - // replace filter - if (filter.getProperties().isEmpty()) { - // get all records by label - requestJson = requestJson.replace("{$filter$}", ""); - } else { - String filterStr = CypherTranslator.prepareFilterBody(filter); - requestJson = requestJson.replace("$filter$", filterStr); - } - return requestJson; - } - - /* - * removed do to fortify scan CredentialsProvider cp = new - * BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new - * UsernamePasswordCredentials(user, password)); AuthCache authCache = new - * BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); - * authCache.put(new HttpHost(ip, 7474, "http"), basicAuth); - * context.setAuthCache(authCache); context.setCredentialsProvider(cp); - * - */ - private HttpClientContext creatClientContext(String ip, String user, String password) { - HttpClientContext context = HttpClientContext.create(); - - return context; - } - - private void releaseResource(CloseableHttpResponse response) { - if (response != null) { - try { - HttpEntity entity = response.getEntity(); - EntityUtils.consume(entity); - response.close(); - } catch (Exception e) { - logger.error("failed to close connection exception", e); - } - } - } - - private String createBatchJson(HttpMethod method, String opertionUri, List propertyNames) { - StringBuilder sb = new StringBuilder(); - sb.append("[ "); - for (int i = 0; i < propertyNames.size(); i++) { - sb.append("{ \"method\" : \"" + method + "\" , \"to\" : \"" + opertionUri - + "\" , \"body\" : { \"property_keys\" : [ \"" + propertyNames.get(i) + "\" ] } }"); - if (i + 1 < propertyNames.size()) { - sb.append(","); - } - } - sb.append(" ]"); - String json = sb.toString(); - return json; - } - - enum HttpMethod { - GET, PUT, POST, DELETE - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java deleted file mode 100644 index e8278a9a3e..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.util.Map; - -import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum; - -public class Neo4jEdge { - - private GraphEdgeLabels edgeType; - private Map properties; - private ActionEnum action; - - public Neo4jEdge(GraphEdgeLabels edgeType, Map properties, ActionEnum actionEnum) { - super(); - this.edgeType = edgeType; - this.properties = properties; - this.action = actionEnum; - } - - public GraphEdgeLabels getEdgeType() { - return edgeType; - } - - public void setEdgeType(GraphEdgeLabels edgeType) { - this.edgeType = edgeType; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public ActionEnum getAction() { - return action; - } - - public void setAction(ActionEnum action) { - this.action = action; - } - - @Override - public String toString() { - return "Neo4jEdge [edgeType=" + edgeType + ", properties=" + properties + ", action=" + action + "]"; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java deleted file mode 100644 index 5a6a8fdade..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum; -import org.openecomp.sdc.be.dao.graph.datatype.GraphElement; -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; -import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fj.data.Either; - -public class Neo4jGraphBatchBuilder { - - private static Logger logger = LoggerFactory.getLogger(Neo4jGraphBatchBuilder.class.getName()); - - public Either buildBatchBuilderFromTable( - GraphNeighbourTable graphNeighbourTable) { - - logger.debug("The table sent in order to build BatchBuilder is {}", graphNeighbourTable); - - List nodes = graphNeighbourTable.getNodes(); - if (nodes != null && nodes.size() > 0) { - List directedEdges = graphNeighbourTable.getDirectedEdges(); - - List relationEndPoints = new ArrayList(nodes.size()); - Set nodesInRelations = findDistinctNodesIndex(directedEdges); - - buildRelationEndPoints(nodes, nodesInRelations, relationEndPoints); - - BatchBuilder batchBuilder = BatchBuilder.getBuilder(); - - for (GraphElement neo4jElement : nodes) { - if (neo4jElement.getAction() != ActionEnum.Delete) { - logger.debug("Goint to add node {} to batch builder.", neo4jElement); - batchBuilder.add(neo4jElement); - } - } - - if (directedEdges != null) { - for (NodeRelation nodeRelation : directedEdges) { - GraphRelation relation = buildNeo4jRelation(relationEndPoints, nodeRelation); - logger.debug("Goint to add relation {} to batch builder.", relation); - batchBuilder.add(relation); - } - } - - for (GraphElement neo4jElement : nodes) { - if (neo4jElement.getAction() == ActionEnum.Delete) { - logger.debug("Goint to add node {} to batch builder.", neo4jElement); - batchBuilder.add(neo4jElement); - } - } - - return Either.left(batchBuilder); - - } else { - logger.error("No node was sent in order to create the resource."); - return Either.right(Neo4jOperationStatus.BAD_REQUEST); - } - } - - private Pair getUniqueIdKeyValue(GraphNode neo4jNode) { - - // String label = neo4jNode.getLabel(); - // NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getByName(label); - // - return Pair.createPair(neo4jNode.getUniqueIdKey(), neo4jNode.getUniqueId().toString()); - } - - private Set findDistinctNodesIndex(List directedEdges) { - - HashSet nodesIndex = new HashSet(); - - if (directedEdges != null) { - for (NodeRelation nodeRelation : directedEdges) { - nodesIndex.add(nodeRelation.getFromIndex()); - nodesIndex.add(nodeRelation.getToIndex()); - } - } - - return nodesIndex; - } - - private String findResourceDataIdFromNodes(List nodes) { - - if (nodes != null) { - - for (GraphNode neo4jNode : nodes) { - String label = neo4jNode.getLabel(); - if (label.equals(NodeTypeEnum.Resource.getName())) { - return neo4jNode.getUniqueId().toString(); - } - } - } - - return null; - } - - private GraphRelation buildNeo4jRelation(List relationEndPoints, NodeRelation nodeRelation) { - GraphRelation relation = new GraphRelation(); - int fromIndex = nodeRelation.getFromIndex(); - int toIndex = nodeRelation.getToIndex(); - Neo4jEdge neo4jEdge = nodeRelation.getEdge(); - relation.setFrom(relationEndPoints.get(fromIndex)); - relation.setTo(relationEndPoints.get(toIndex)); - relation.setType(neo4jEdge.getEdgeType().getProperty()); - - // TODO: fix it after change - Map edgeProps = neo4jEdge.getProperties(); - if (edgeProps != null && false == edgeProps.isEmpty()) { - relation.addPropertis(edgeProps); - } - - relation.setAction(neo4jEdge.getAction()); - return relation; - } - - private void buildRelationEndPoints(List nodes, Set nodesInRelations, - List relationEndPoints) { - - if (nodesInRelations != null) { - for (Integer nodeIndex : nodesInRelations) { - - GraphElement neo4jElement = nodes.get(nodeIndex); - GraphNode neo4jNode = (GraphNode) neo4jElement; - String label = neo4jNode.getLabel(); - Pair uniqueKeyValue = getUniqueIdKeyValue(neo4jNode); - - RelationEndPoint endPoint = new RelationEndPoint(NodeTypeEnum.getByName(label), uniqueKeyValue.getKey(), - uniqueKeyValue.getValue()); - relationEndPoints.add(nodeIndex, endPoint); - - } - } - - } - - public static class Pair { - - private final K key; - private final V value; - - public static Pair createPair(K key, V value) { - return new Pair(key, value); - } - - public Pair(K key, V value) { - this.key = key; - this.value = value; - } - - public K getKey() { - return key; - } - - public V getValue() { - return value; - } - - } -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java deleted file mode 100644 index 154449b521..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -public enum Neo4jOperationStatus { - - OK, NOT_CONNECTED, NOT_AUTHORIZED, HTTP_PROTOCOL_ERROR, DB_NOT_AVAILABLE, DB_READ_ONLY, BAD_REQUEST, LEGACY_INDEX_ERROR, SCHEMA_ERROR, TRANSACTION_ERROR, EXECUTION_FAILED, ENTITY_ALREADY_EXIST, - - WRONG_INPUT, GENERAL_ERROR, NOT_SUPPORTED, NOT_FOUND; - - private String originError; - private String message; - private String helpErrorMsg; - - private static final String NA = "NA"; - - Neo4jOperationStatus() { - originError = NA; - message = NA; - helpErrorMsg = NA; - } - - public Neo4jOperationStatus setOriginError(String originError) { - this.originError = originError; - return this; - } - - public Neo4jOperationStatus setMessage(String message) { - if (message != null && !message.isEmpty()) { - this.message = message; - } - return this; - } - - public Neo4jOperationStatus setHelpErrorMsg(String helpErrorMsg) { - this.helpErrorMsg = helpErrorMsg; - return this; - } - - public String getOriginError() { - return originError; - } - - public String getMessage() { - return message; - } - - public String getHelpErrorMsg() { - return helpErrorMsg; - } - - public String printError() { - StringBuilder sb = new StringBuilder(); - sb.append("[").append(toString()).append("-").append(originError).append("-").append(helpErrorMsg).append("-") - .append(message).append("]"); - return sb.toString(); - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java deleted file mode 100644 index c1402f402f..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j; - -public class NodeRelation { - - private int fromIndex; - private int toIndex; - private Neo4jEdge edge; - - public NodeRelation(int fromIndex, int toIndex, Neo4jEdge edge) { - super(); - this.fromIndex = fromIndex; - this.toIndex = toIndex; - this.edge = edge; - } - - public int getFromIndex() { - return fromIndex; - } - - public void setFromIndex(int fromIndex) { - this.fromIndex = fromIndex; - } - - public int getToIndex() { - return toIndex; - } - - public void setToIndex(int toIndex) { - this.toIndex = toIndex; - } - - public Neo4jEdge getEdge() { - return edge; - } - - public void setEdge(Neo4jEdge edge) { - this.edge = edge; - } - - @Override - public String toString() { - return "NodeRelation [fromIndex=" + fromIndex + ", toIndex=" + toIndex + ", edge=" + edge + "]"; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java deleted file mode 100644 index 10e93c1f56..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j.filters; - -import java.util.HashMap; -import java.util.Map; - -public class MatchFilter { - private Map toMatchProperties; - - public MatchFilter() { - toMatchProperties = new HashMap(); - } - - public MatchFilter(Map toMatchProperties) { - super(); - this.toMatchProperties = toMatchProperties; - } - - public Map getProperties() { - return toMatchProperties; - } - - public void setProperties(Map properties) { - this.toMatchProperties = properties; - } - - public MatchFilter addToMatch(String propName, Object value) { - toMatchProperties.put(propName, value); - return this; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java deleted file mode 100644 index 698077d45b..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j.filters; - -import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; - -public class RecursiveByRelationFilter extends RecursiveFilter { - - private GraphNode node; - private String relationType; - - public RecursiveByRelationFilter() { - super(); - } - - public RecursiveByRelationFilter(NodeTypeEnum nodeType, GraphNode node) { - super(nodeType); - this.node = node; - } - - public RecursiveByRelationFilter(NodeTypeEnum nodeType) { - super(nodeType); - } - - public RecursiveByRelationFilter(NodeTypeEnum nodeType, GraphNode node, String relationType) { - super(nodeType); - this.node = node; - this.relationType = relationType; - } - - public RecursiveByRelationFilter addNode(GraphNode node) { - this.node = node; - return this; - } - - public RecursiveByRelationFilter addRelation(String relationType) { - this.relationType = relationType; - return this; - } - - public GraphNode getNode() { - return node; - } - - public void setNode(GraphNode node) { - this.node = node; - } - - public String getRelationType() { - return relationType; - } - - public void setRelationType(String relationType) { - this.relationType = relationType; - } - - @Override - public String toString() { - return "RecursiveByRelationFilter [node=" + node + ", relationType=" + relationType + "]"; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java deleted file mode 100644 index fa78539f8f..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j.filters; - -import java.util.ArrayList; -import java.util.List; - -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; - -public class RecursiveFilter extends MatchFilter { - - private List childRelationTypes; - NodeTypeEnum nodeType; - - public RecursiveFilter() { - childRelationTypes = new ArrayList(); - } - - public RecursiveFilter(NodeTypeEnum nodeType) { - childRelationTypes = new ArrayList(); - this.nodeType = nodeType; - } - - public RecursiveFilter addChildRelationType(String type) { - childRelationTypes.add(type); - return this; - } - - public List getChildRelationTypes() { - return childRelationTypes; - } - - public void setChildRelationTypes(List childRelationTypes) { - this.childRelationTypes = childRelationTypes; - } - - public NodeTypeEnum getNodeType() { - return nodeType; - } - - public void setNodeType(NodeTypeEnum nodeType) { - this.nodeType = nodeType; - } - - @Override - public String toString() { - return "RecursiveFilter [childRelationTypes=" + childRelationTypes + ", nodeType=" + nodeType + "]"; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java deleted file mode 100644 index 3abfdeb70e..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.be.dao.neo4j.filters; - -import java.util.HashMap; -import java.util.Map; - -public class UpdateFilter extends MatchFilter { - - private Map toUpdate; - - public UpdateFilter(Map toUpdate) { - super(); - this.toUpdate = toUpdate; - } - - public UpdateFilter() { - super(); - toUpdate = new HashMap(); - } - - public UpdateFilter(Map toMatch, Map toUpdate) { - super(toMatch); - this.toUpdate = toUpdate; - } - - public Map getToUpdate() { - return toUpdate; - } - - public void setToUpdate(Map toUpdate) { - this.toUpdate = toUpdate; - } - - public void addToUpdate(String property, Object value) { - toUpdate.put(property, value); - } -} -- cgit 1.2.3-korg