aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/crud/dao
diff options
context:
space:
mode:
authorsblimkie <steven.blimkie@amdocs.com>2018-07-19 16:03:44 -0400
committersblimkie <steven.blimkie@amdocs.com>2018-07-19 16:08:20 -0400
commit3bc6a702f2d3d8710c7aaa94cdc8c0ccf3deb759 (patch)
tree9703ebe15777acc73ad118520f6b1a219f60e107 /src/main/java/org/onap/crud/dao
parent194adee686ebb90488f739f2c637f6cb3def94d5 (diff)
Auto-resolve edge type
Auto-resolve edge type based on EdgeRules file. Change-Id: Ic6de47f5172bc410efcdd5f08c1ea5c4f822610e Issue-ID: AAI-1396 Signed-off-by: sblimkie <steven.blimkie@amdocs.com>
Diffstat (limited to 'src/main/java/org/onap/crud/dao')
-rw-r--r--src/main/java/org/onap/crud/dao/GraphDao.java14
-rw-r--r--src/main/java/org/onap/crud/dao/champ/ChampDao.java76
2 files changed, 57 insertions, 33 deletions
diff --git a/src/main/java/org/onap/crud/dao/GraphDao.java b/src/main/java/org/onap/crud/dao/GraphDao.java
index 6c1bca9..7cb3d4c 100644
--- a/src/main/java/org/onap/crud/dao/GraphDao.java
+++ b/src/main/java/org/onap/crud/dao/GraphDao.java
@@ -42,10 +42,12 @@ public interface GraphDao {
* - The unique identifier of the vertex to retrieve the edges for.
* @param queryParams
* - query parameters to be passed
+ * @param txid
+ * - a DB transaction ID to use (if null, no transactionId is used)
* @return - A collection of edges.
* @throws CrudException
*/
- public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException;
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams, String txId) throws CrudException;
/**
* Retrieve a collection of {@link Vertex} objects which match the supplied
@@ -89,7 +91,7 @@ public interface GraphDao {
* @throws CrudException
*/
public OperationResult getEdge(String id, String type, Map<String, String> queryParams) throws CrudException;
-
+
/**
* Retrieve a collection of {@link Edge} objects with a given type and which
* match a set of supplied filter parameters.
@@ -172,7 +174,7 @@ public interface GraphDao {
* - The unique identifier of the edge to be deleted.
* @throws CrudException
*/
- public void deleteEdge(String id, String type) throws CrudException;
+ public void deleteEdge(String id) throws CrudException;
public String openTransaction();
@@ -193,7 +195,9 @@ public interface GraphDao {
public void deleteVertex(String id, String type, String txId) throws CrudException;
- public void deleteEdge(String id, String type, String txId) throws CrudException;
+ public void deleteEdge(String id, String txId) throws CrudException;
- public Edge getEdge(String id, String type, String txId) throws CrudException;
+ public Edge getEdge(String id, String txId) throws CrudException;
+
+ public Edge getEdge(String id) throws CrudException;
}
diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
index fd5de57..81980cc 100644
--- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java
+++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
@@ -141,26 +141,39 @@ public class ChampDao implements GraphDao {
}
@Override
- public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException {
- StringBuilder strBuild = new StringBuilder(baseObjectUrl);
- strBuild.append("/relationships/");
- strBuild.append(id);
- if(queryParams != null && !queryParams.isEmpty())
- {
- strBuild.append("?");
- strBuild.append(URLEncodedUtils.format(convertToNameValuePair(queryParams), Charset.defaultCharset()));
- }
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams, String txId) throws CrudException {
+ StringBuilder strBuild = new StringBuilder(baseObjectUrl);
+ strBuild.append("/relationships/");
+ strBuild.append(id);
+
+ Map<String,String> queryParamsCopy = null;
+ if (queryParams != null) {
+ queryParamsCopy = new HashMap<String,String>(queryParams);
+ }
+ else {
+ queryParamsCopy = new HashMap<String,String>();
+ }
- OperationResult getResult = client.get(strBuild.toString(), createHeader(), MediaType.APPLICATION_JSON_TYPE);
+ if (txId != null) {
+ queryParamsCopy.put("transactionId", txId);
+ }
- if (getResult.getResultCode() == 200) {
- return champGson.fromJson(getResult.getResult(), new TypeToken<List<Edge>>() {
- }.getType());
- } else {
- // We didn't find a vertex with the supplied id, so just throw an
- // exception.
- throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
- }
+ if (!queryParamsCopy.isEmpty())
+ {
+ strBuild.append("?");
+ strBuild.append(URLEncodedUtils.format(convertToNameValuePair(queryParamsCopy), Charset.defaultCharset()));
+ }
+
+ OperationResult getResult = client.get(strBuild.toString(), createHeader(), MediaType.APPLICATION_JSON_TYPE);
+
+ if (getResult.getResultCode() == 200) {
+ return champGson.fromJson(getResult.getResult(), new TypeToken<List<Edge>>() {
+ }.getType());
+ } else {
+ // We didn't find a vertex with the supplied id, so just throw an
+ // exception.
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No vertex with id " + id + " found in graph");
+ }
}
@Override
@@ -343,7 +356,7 @@ public class ChampDao implements GraphDao {
}
@Override
- public void deleteEdge(String id, String type) throws CrudException {
+ public void deleteEdge(String id) throws CrudException {
String url = baseRelationshipUrl + "/" + id;
OperationResult getResult = client.delete(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
@@ -512,7 +525,7 @@ public class ChampDao implements GraphDao {
}
@Override
- public void deleteEdge(String id, String type, String txId) throws CrudException {
+ public void deleteEdge(String id, String txId) throws CrudException {
String url = baseRelationshipUrl + "/" + id + "?transactionId=" + txId;
OperationResult getResult = client.delete(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
@@ -524,19 +537,12 @@ public class ChampDao implements GraphDao {
}
@Override
- public Edge getEdge(String id, String type, String txId) throws CrudException {
+ public Edge getEdge(String id, String txId) throws CrudException {
String url = baseRelationshipUrl + "/" + id + "?transactionId=" + txId;
OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
if (getResult.getResultCode() == 200) {
Edge edge = Edge.fromJson(getResult.getResult());
-
- if (!edge.getType().equalsIgnoreCase(type)) {
- // We didn't find an edge with the supplied type, so just throw an
- // exception.
- throw new CrudException("No edge with id " + id + " and type " + type + " found in graph",
- javax.ws.rs.core.Response.Status.NOT_FOUND);
- }
return edge;
} else {
// We didn't find an edge with the supplied id, so just throw an
@@ -544,6 +550,20 @@ public class ChampDao implements GraphDao {
throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
+
+ @Override
+ public Edge getEdge(String id) throws CrudException {
+ String url = baseRelationshipUrl + "/" + id;
+ OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
+
+ if (getResult.getResultCode() == 200) {
+ Edge edge = Edge.fromJson(getResult.getResult());
+ return edge;
+ } else {
+ // We didn't find an edge with the supplied id, so just throw an exception.
+ throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
+ }
+ }
public Vertex getVertex(String id, String type, String version, String txId) throws CrudException {
String url = baseObjectUrl + "/" + id + "?transactionId=" + txId;