Refactor to move from openecomp to onap
[aai/gizmo.git] / src / main / java / org / onap / crud / dao / GraphDao.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Gizmo
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.crud.dao;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import org.onap.crud.entity.Edge;
30
31 import org.onap.crud.entity.Vertex;
32 import org.onap.crud.exception.CrudException;
33
34 public interface GraphDao {
35
36   public Vertex getVertex(String id) throws CrudException;
37
38   public Vertex getVertex(String id, String type) throws CrudException;
39
40   /**
41    * Retrieve all of the edges which are incident to the vertex with the
42    * specified identifier.
43    *
44    * @param id
45    *          - The unique identifier of the vertex to retrieve the edges for.
46    * @return - A collection of edges.
47    * @throws CrudException
48    */
49   public List<Edge> getVertexEdges(String id) throws CrudException;
50
51   /**
52    * Retrieve a collection of {@link Vertex} objects which match the supplied
53    * type label and filter properties.
54    *
55    * @param type
56    *          - The vertex type that we want to retrieve.
57    * @param filter
58    *          - The parameters to filter our results by.
59    * @return - A collection of vertices.
60    * @throws CrudException
61    */
62   public List<Vertex> getVertices(String type, Map<String, Object> filter) throws CrudException;
63
64   /**
65    * Retrieve an {@link Edge} from the graph database by specifying its unique
66    * identifier.
67    *
68    * @param id
69    *          - The unique identifier for the Edge to be retrieved.
70    * @return - The Edge corresponding to the specified identifier.
71    * @throws CrudException
72    */
73   public Edge getEdge(String id, String type) throws CrudException;
74
75   /**
76    * Retrieve a collection of {@link Edge} objects with a given type and which
77    * match a set of supplied filter parameters.
78    *
79    * @param type
80    *          - The type of edges that we are interested in.
81    * @param filter
82    *          - The parameters that we want to filter our edges by.
83    * @return - A collection of edges which match the supplied filter parameters.
84    * @throws CrudException
85    */
86   public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException;
87
88   /**
89    * Insert a new {@link Vertex} into the graph data store.
90    *
91    * @param type
92    *          - The type label to assign to the vertex.
93    * @param properties
94    *          - The properties to associated with this vertex.
95    * @return - The {@link Vertex} object that was created.
96    * @throws CrudException
97    */
98   public Vertex addVertex(String type, Map<String, Object> properties) throws CrudException;
99
100   /**
101    * Updates an existing {@link Vertex}.
102    *
103    * @param id
104    *          - The unique identifier of the vertex to be updated.
105    * @param properties
106    *          - The properties to associate with the vertex.
107    * @return - The udpated vertex.
108    * @throws CrudException
109    */
110   public Vertex updateVertex(String id, String type, Map<String, Object> properties) throws CrudException;
111
112   /**
113    * Removes the specified vertex from the graph data base.
114    *
115    * <p>
116    * NOTE: The vertex MUST contain NO incident edges before it can be deleted.
117    *
118    * @param id
119    *          - The unique identifier of the vertex to be deleted.
120    * @throws CrudException
121    */
122   public void deleteVertex(String id, String type) throws CrudException;
123
124   /**
125    * Adds an edge to the graph database.
126    *
127    * @param type
128    *          - The 'type' label to apply to the edge.
129    * @param source
130    *          - The source vertex for this edge.
131    * @param target
132    *          - The target vertex for this edge.
133    * @param properties
134    *          - The properties map to associate with this edge.
135    * @return - The {@link Edge} object that was created.
136    * @throws CrudException
137    */
138   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties) throws CrudException;
139
140   /**
141    * Updates an existing {@link Edge}.
142    *
143    * @param id
144    *          - The unique identifier of the edge to be updated.
145    * @param properties
146    *          - The properties to associate with the edge.
147    * @return - The update edge.
148    * @throws CrudException
149    */
150   public Edge updateEdge(Edge edge) throws CrudException;
151
152   /**
153    * Remove the specified edge from the graph data base.
154    *
155    * @param id
156    *          - The unique identifier of the edge to be deleted.
157    * @throws CrudException
158    */
159   public void deleteEdge(String id, String type) throws CrudException;
160
161   public String openTransaction();
162
163   public void commitTransaction(String id) throws CrudException;
164
165   public void rollbackTransaction(String id) throws CrudException;
166
167   public boolean transactionExists(String id) throws CrudException;
168
169   public Vertex addVertex(String type, Map<String, Object> properties, String txId) throws CrudException;
170
171   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String txId)
172       throws CrudException;
173
174   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String txId) throws CrudException;
175
176   public Edge updateEdge(Edge edge, String txId) throws CrudException;
177
178   public void deleteVertex(String id, String type, String txId) throws CrudException;
179
180   public void deleteEdge(String id, String type, String txId) throws CrudException;
181
182   public Edge getEdge(String id, String type, String txId) throws CrudException;
183 }