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