summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/crud/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/crud/service')
-rw-r--r--src/main/java/org/onap/crud/service/AbstractGraphDataService.java35
-rw-r--r--src/main/java/org/onap/crud/service/BulkPayload.java80
-rw-r--r--src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java6
-rw-r--r--src/main/java/org/onap/crud/service/CrudGraphDataService.java38
-rw-r--r--src/main/java/org/onap/crud/service/CrudRestService.java3
-rw-r--r--src/main/java/org/onap/crud/service/EdgePayload.java110
-rw-r--r--src/main/java/org/onap/crud/service/VertexPayload.java112
7 files changed, 321 insertions, 63 deletions
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
index 14ea242..8225adf 100644
--- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
@@ -41,14 +41,10 @@ import org.onap.crud.dao.champ.ChampVertexSerializer;
import org.onap.crud.entity.Edge;
import org.onap.crud.entity.Vertex;
import org.onap.crud.exception.CrudException;
-import org.onap.crud.parser.BulkPayload;
import org.onap.crud.parser.CrudResponseBuilder;
-import org.onap.crud.parser.EdgePayload;
-import org.onap.crud.parser.VertexPayload;
-import org.onap.crud.parser.util.EdgePayloadUtil;
import org.onap.crud.util.CrudServiceUtil;
-import org.onap.schema.validation.OxmModelValidator;
-import org.onap.schema.validation.RelationshipSchemaValidator;
+import org.onap.schema.OxmModelValidator;
+import org.onap.schema.RelationshipSchemaValidator;
public abstract class AbstractGraphDataService {
protected GraphDao daoForGet;
@@ -230,22 +226,14 @@ public abstract class AbstractGraphDataService {
edgePayload
.setTarget("services/inventory/" + version + "/" + target.getType() + "/" + target.getId().get());
}
-
+
// If the type isn't set, resolve it based on on the sourece and target vertex types
if (edgePayload.getType() == null || edgePayload.getType().isEmpty()) {
edgePayload.setType(CrudServiceUtil.determineEdgeType(edgePayload, version));
}
- List<Edge> sourceVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getSource()), edgePayload.getType(),
- dao.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getSource()), null, txId));
-
- List<Edge> targetVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getTarget()), edgePayload.getType(),
- dao.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getTarget()), null, txId));
-
- validatedEdge = RelationshipSchemaValidator.validateIncomingAddPayload(version, edgePayload.getType(), edgePayload, sourceVertexEdges,
- targetVertexEdges);
+ validatedEdge = RelationshipSchemaValidator.validateIncomingAddPayload(version, edgePayload.getType(),edgePayload);
+
persistedEdge = addBulkEdge(validatedEdge, version, txId);
} else if (opr.getValue().getAsString().equalsIgnoreCase("modify")) {
Edge edge = dao.getEdge(edgePayload.getId(), txId);
@@ -255,17 +243,8 @@ public abstract class AbstractGraphDataService {
edgePayload.setType(edge.getType());
}
- // load source and target vertex relationships for validation
- List<Edge> sourceVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getSource()), edgePayload.getType(),
- dao.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getSource()), null, txId));
-
- List<Edge> targetVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getTarget()), edgePayload.getType(),
- dao.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getTarget()), null, txId));
-
-
- validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, edgePayload, edgePayload.getType(), sourceVertexEdges, targetVertexEdges);
+ validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, edgePayload);
+
persistedEdge = updateBulkEdge(validatedEdge, version, txId);
} else {
if (edgePayload.getId() == null) {
diff --git a/src/main/java/org/onap/crud/service/BulkPayload.java b/src/main/java/org/onap/crud/service/BulkPayload.java
new file mode 100644
index 0000000..8dc99c4
--- /dev/null
+++ b/src/main/java/org/onap/crud/service/BulkPayload.java
@@ -0,0 +1,80 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+
+import org.onap.crud.exception.CrudException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.Response.Status;
+
+public class BulkPayload {
+ public enum OperationType {
+ CREATE, UPDATE, DELETE
+ }
+
+ private List<JsonElement> objects = new ArrayList<JsonElement>();
+ private List<JsonElement> relationships = new ArrayList<JsonElement>();
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static BulkPayload fromJson(String payload) throws CrudException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ return gson.fromJson(payload, BulkPayload.class);
+ } catch (Exception ex) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ }
+
+ public List<JsonElement> getObjects() {
+ return objects;
+ }
+
+ public void setObjects(List<JsonElement> objects) {
+ this.objects = objects;
+ }
+
+ public List<JsonElement> getRelationships() {
+ return relationships;
+ }
+
+ public void setRelationships(List<JsonElement> relationships) {
+ this.relationships = relationships;
+ }
+
+ @Override
+ public String toString() {
+ return "BulkPayload [objects=" + objects + ", relationships=" + relationships + "]";
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
index 8d147eb..14ba7f2 100644
--- a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
@@ -56,13 +56,11 @@ import org.onap.crud.event.envelope.GraphEventEnvelope;
import org.onap.crud.event.response.GraphEventResponseHandler;
import org.onap.crud.exception.CrudException;
import org.onap.crud.logging.CrudServiceMsgs;
-import org.onap.crud.parser.EdgePayload;
-import org.onap.crud.parser.VertexPayload;
import org.onap.crud.util.CrudProperties;
import org.onap.crud.util.CrudServiceConstants;
import org.onap.crud.util.etag.EtagGenerator;
-import org.onap.schema.validation.OxmModelValidator;
-import org.onap.schema.validation.RelationshipSchemaValidator;
+import org.onap.schema.OxmModelValidator;
+import org.onap.schema.RelationshipSchemaValidator;
public class CrudAsyncGraphDataService extends AbstractGraphDataService {
diff --git a/src/main/java/org/onap/crud/service/CrudGraphDataService.java b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
index ae2d294..034b0bf 100644
--- a/src/main/java/org/onap/crud/service/CrudGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
@@ -31,12 +31,9 @@ import org.onap.crud.entity.Edge;
import org.onap.crud.entity.Vertex;
import org.onap.crud.exception.CrudException;
import org.onap.crud.parser.CrudResponseBuilder;
-import org.onap.crud.parser.EdgePayload;
-import org.onap.crud.parser.VertexPayload;
-import org.onap.crud.parser.util.EdgePayloadUtil;
import org.onap.crud.util.CrudServiceUtil;
-import org.onap.schema.validation.OxmModelValidator;
-import org.onap.schema.validation.RelationshipSchemaValidator;
+import org.onap.schema.OxmModelValidator;
+import org.onap.schema.RelationshipSchemaValidator;
public class CrudGraphDataService extends AbstractGraphDataService {
@@ -74,16 +71,8 @@ public class CrudGraphDataService extends AbstractGraphDataService {
@Override
public ImmutablePair<EntityTag, String> addEdge(String version, String type, EdgePayload payload)
throws CrudException {
- // load source and target vertex relationships for validation
- List<Edge> sourceVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getSource()), type,
- daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getSource()), null, null));
-
- List<Edge> targetVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getTarget()), type,
- daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getTarget()), null, null));
-
- Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload, sourceVertexEdges, targetVertexEdges);
+
+ Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload);
return addEdge(version, edge);
}
@@ -147,19 +136,7 @@ public class CrudGraphDataService extends AbstractGraphDataService {
@Override
public ImmutablePair<EntityTag, String> updateEdge(String version, String id, String type, EdgePayload payload)
throws CrudException {
- OperationResult edgeResult = dao.getEdge(id, type, new HashMap<String, String>());
- Edge edge = Edge.fromJson(edgeResult.getResult());
-
- // load source and target vertex relationships for validation
- List<Edge> sourceVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getSource()), type,
- daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getSource()), null, null));
-
- List<Edge> targetVertexEdges =
- EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getTarget()), type,
- daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getTarget()), null, null));
-
- Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, payload, type, sourceVertexEdges, targetVertexEdges);
+ Edge validatedEdge = getValidatedEdge(version, id, type, payload);
return updateEdge(version, validatedEdge);
}
@@ -179,6 +156,11 @@ public class CrudGraphDataService extends AbstractGraphDataService {
.buildUpsertEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, updatedEdge), version);
}
+ private Edge getValidatedEdge(String version, String id, String type, EdgePayload payload) throws CrudException {
+ OperationResult operationResult = dao.getEdge(id, type, new HashMap<String, String>());
+ return RelationshipSchemaValidator.validateIncomingUpdatePayload(Edge.fromJson(operationResult.getResult()), version, payload);
+ }
+
@Override
public ImmutablePair<EntityTag, String> patchEdge(String version, String id, String type, EdgePayload payload)
throws CrudException {
diff --git a/src/main/java/org/onap/crud/service/CrudRestService.java b/src/main/java/org/onap/crud/service/CrudRestService.java
index 025f3d2..734c4d5 100644
--- a/src/main/java/org/onap/crud/service/CrudRestService.java
+++ b/src/main/java/org/onap/crud/service/CrudRestService.java
@@ -56,9 +56,6 @@ import org.onap.aaiauth.auth.Auth;
import org.onap.crud.exception.CrudException;
import org.onap.crud.logging.CrudServiceMsgs;
import org.onap.crud.logging.LoggingUtil;
-import org.onap.crud.parser.BulkPayload;
-import org.onap.crud.parser.EdgePayload;
-import org.onap.crud.parser.VertexPayload;
import org.onap.crud.util.CrudProperties;
import org.onap.crud.util.CrudServiceConstants;
import org.onap.crud.util.CrudServiceUtil;
diff --git a/src/main/java/org/onap/crud/service/EdgePayload.java b/src/main/java/org/onap/crud/service/EdgePayload.java
new file mode 100644
index 0000000..a670b54
--- /dev/null
+++ b/src/main/java/org/onap/crud/service/EdgePayload.java
@@ -0,0 +1,110 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import javax.ws.rs.core.Response.Status;
+import org.onap.crud.exception.CrudException;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+
+public class EdgePayload {
+
+ private String id;
+ private String type;
+ private String url;
+ private String source;
+ private String target;
+ private JsonElement properties;
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+
+ @Override
+ public String toString() {
+ return "EdgePayload [id=" + id + ", type=" + type + ", url=" + url + ", source="
+ + source + ", target=" + target + ", properties=" + properties + "]";
+ }
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static EdgePayload fromJson(String payload) throws CrudException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ return gson.fromJson(payload, EdgePayload.class);
+ } catch (Exception ex) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public JsonElement getProperties() {
+ return properties;
+ }
+
+ public void setProperties(JsonElement properties) {
+ this.properties = properties;
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/crud/service/VertexPayload.java b/src/main/java/org/onap/crud/service/VertexPayload.java
new file mode 100644
index 0000000..172d03b
--- /dev/null
+++ b/src/main/java/org/onap/crud/service/VertexPayload.java
@@ -0,0 +1,112 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response.Status;
+import org.onap.crud.exception.CrudException;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+
+public class VertexPayload {
+
+ private String id;
+ private String type;
+ private String url;
+ private JsonElement properties;
+ private List<EdgePayload> in = new ArrayList<EdgePayload>();
+ private List<EdgePayload> out = new ArrayList<EdgePayload>();
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static VertexPayload fromJson(String payload) throws CrudException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ return gson.fromJson(payload, VertexPayload.class);
+ } catch (Exception ex) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public JsonElement getProperties() {
+ return properties;
+ }
+
+ public void setProperties(JsonElement properties) {
+ this.properties = properties;
+ }
+
+ public List<EdgePayload> getIn() {
+ return in;
+ }
+
+ public void setIn(List<EdgePayload> in) {
+ this.in = in;
+ }
+
+ public List<EdgePayload> getOut() {
+ return out;
+ }
+
+ public void setOut(List<EdgePayload> out) {
+ this.out = out;
+ }
+
+
+ @Override
+ public String toString() {
+ return "VertexPayload [id=" + id + ", type=" + type + ", url=" + url + ", properties="
+ + properties + ", in=" + in + ", out=" + out + "]";
+ }
+
+} \ No newline at end of file