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