3ae8266f84b4c38b52f219e312ffef9a3efbacbf
[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.HashSet;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.onap.crud.entity.Edge;
31
32 import org.onap.crud.entity.Vertex;
33 import org.onap.crud.exception.CrudException;
34
35 public interface GraphDao {
36
37   public Vertex getVertex(String id, String version) throws CrudException;
38
39   public Vertex getVertex(String id, String type, String version, Map<String, String> queryParams) throws CrudException;
40
41   /**
42    * Retrieve all of the edges which are incident to the vertex with the
43    * specified identifier.
44    *
45    * @param id
46    *          - The unique identifier of the vertex to retrieve the edges for.
47    * @param queryParams
48    *              - query parameters to be passed         
49    * @return - A collection of edges.
50    * @throws CrudException
51    */
52   public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException;
53
54   /**
55    * Retrieve a collection of {@link Vertex} objects which match the supplied
56    * type label and filter properties.
57    *
58    * @param type
59    *          - The vertex type that we want to retrieve.
60    * @param filter
61    *          - The parameters to filter our results by.
62    * @return - A collection of vertices.
63    * @throws CrudException
64    */
65   public List<Vertex> getVertices(String type, Map<String, Object> filter, String version) throws CrudException;
66
67   /**
68    * Retrieve a collection of {@link Vertex} objects which match the supplied
69    * type label and filter properties.
70    *
71    * @param type
72    *          - The vertex type that we want to retrieve.
73    * @param filter
74    *          - The parameters to filter our results by.
75    * @param properties
76    *          - The properties to retrieve with the vertex
77    * @return - A collection of vertices.
78    * @throws CrudException
79    */
80   public List<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version) throws CrudException;
81
82   /**
83    * Retrieve an {@link Edge} from the graph database by specifying its unique
84    * identifier.
85    *
86    * @param id
87    *          - The unique identifier for the Edge to be retrieved.
88    * @param type
89    *          - The type that we want to retrieve.
90    * @param queryParams
91    *              - query parameters to be passed                
92    * @return - The Edge corresponding to the specified identifier.
93    * @throws CrudException
94    */
95   public Edge getEdge(String id, String type, Map<String, String> queryParams) throws CrudException;
96
97   /**
98    * Retrieve a collection of {@link Edge} objects with a given type and which
99    * match a set of supplied filter parameters.
100    *
101    * @param type
102    *          - The type of edges that we are interested in.
103    * @param filter
104    *          - The parameters that we want to filter our edges by.
105    * @return - A collection of edges which match the supplied filter parameters.
106    * @throws CrudException
107    */
108   public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException;
109
110   /**
111    * Insert a new {@link Vertex} into the graph data store.
112    *
113    * @param type
114    *          - The type label to assign to the vertex.
115    * @param properties
116    *          - The properties to associated with this vertex.
117    * @return - The {@link Vertex} object that was created.
118    * @throws CrudException
119    */
120   public Vertex addVertex(String type, Map<String, Object> properties, String version) throws CrudException;
121
122   /**
123    * Updates an existing {@link Vertex}.
124    *
125    * @param id
126    *          - The unique identifier of the vertex to be updated.
127    * @param properties
128    *          - The properties to associate with the vertex.
129    * @return - The udpated vertex.
130    * @throws CrudException
131    */
132   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version) throws CrudException;
133
134   /**
135    * Removes the specified vertex from the graph data base.
136    *
137    * <p>
138    * NOTE: The vertex MUST contain NO incident edges before it can be deleted.
139    *
140    * @param id
141    *          - The unique identifier of the vertex to be deleted.
142    * @throws CrudException
143    */
144   public void deleteVertex(String id, String type) throws CrudException;
145
146   /**
147    * Adds an edge to the graph database.
148    *
149    * @param type
150    *          - The 'type' label to apply to the edge.
151    * @param source
152    *          - The source vertex for this edge.
153    * @param target
154    *          - The target vertex for this edge.
155    * @param properties
156    *          - The properties map to associate with this edge.
157    * @return - The {@link Edge} object that was created.
158    * @throws CrudException
159    */
160   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version) throws CrudException;
161
162   /**
163    * Updates an existing {@link Edge}.
164    *
165    * @param id
166    *          - The unique identifier of the edge to be updated.
167    * @param properties
168    *          - The properties to associate with the edge.
169    * @return - The update edge.
170    * @throws CrudException
171    */
172   public Edge updateEdge(Edge edge) throws CrudException;
173
174   /**
175    * Remove the specified edge from the graph data base.
176    *
177    * @param id
178    *          - The unique identifier of the edge to be deleted.
179    * @throws CrudException
180    */
181   public void deleteEdge(String id, String type) throws CrudException;
182
183   public String openTransaction();
184
185   public void commitTransaction(String id) throws CrudException;
186
187   public void rollbackTransaction(String id) throws CrudException;
188
189   public boolean transactionExists(String id) throws CrudException;
190
191   public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId) throws CrudException;
192
193   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version, String txId)
194       throws CrudException;
195
196   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version, String txId) throws CrudException;
197
198   public Edge updateEdge(Edge edge, String txId) throws CrudException;
199
200   public void deleteVertex(String id, String type, String txId) throws CrudException;
201
202   public void deleteEdge(String id, String type, String txId) throws CrudException;
203
204   public Edge getEdge(String id, String type, String txId) throws CrudException;
205 }