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/AaiResourceService.java19
-rw-r--r--src/main/java/org/onap/crud/service/AbstractGraphDataService.java33
-rw-r--r--src/main/java/org/onap/crud/service/BulkPayload.java80
-rw-r--r--src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java10
-rw-r--r--src/main/java/org/onap/crud/service/CrudGraphDataService.java40
-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
8 files changed, 79 insertions, 328 deletions
diff --git a/src/main/java/org/onap/crud/service/AaiResourceService.java b/src/main/java/org/onap/crud/service/AaiResourceService.java
index afabe7e..c0375b4 100644
--- a/src/main/java/org/onap/crud/service/AaiResourceService.java
+++ b/src/main/java/org/onap/crud/service/AaiResourceService.java
@@ -54,10 +54,11 @@ 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.EdgePayload;
+import org.onap.crud.parser.util.EdgePayloadUtil;
import org.onap.crud.service.CrudRestService.Action;
import org.onap.crud.util.CrudServiceConstants;
import org.onap.schema.EdgeRulesLoader;
-import org.onap.schema.RelationshipSchemaValidator;
import org.slf4j.MDC;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
@@ -397,16 +398,15 @@ public class AaiResourceService {
public EdgePayload applyEdgeRulesToPayload(EdgePayload payload) throws CrudException {
// Extract the types for both the source and target vertices.
- String srcType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getSource());
- String tgtType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getTarget());
+ String srcType = EdgePayloadUtil.getVertexNodeType(payload.getSource());
+ String tgtType = EdgePayloadUtil.getVertexNodeType(payload.getTarget());
- // Now, get the default properties for this edge based on the edge rules definition...
- Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);
-
- // ...and merge them with any custom properties provided in the request.
- JsonElement mergedProperties = mergeProperties(payload.getProperties(), props);
- payload.setProperties(mergedProperties);
+ // Now, get the default properties for this edge based on the edge rules definition...
+ Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);
+ // ...and merge them with any custom properties provided in the request.
+ JsonElement mergedProperties = mergeProperties(payload.getProperties(), props);
+ payload.setProperties(mergedProperties);
if(logger.isDebugEnabled()) {
logger.debug("Edge properties after applying rules for '" + srcType + " -> " + tgtType + "': " + mergedProperties);
@@ -430,6 +430,7 @@ public class AaiResourceService {
*
* @throws CrudException
*/
+ @SuppressWarnings("unchecked")
public JsonElement mergeProperties(JsonElement propertiesFromRequest, Map<EdgeProperty, String> propertyDefaults) throws CrudException {
// Convert the properties from the edge payload into something we can
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
index 7c1168e..fed12fd 100644
--- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
@@ -36,10 +36,14 @@ 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.OxmModelValidator;
-import org.onap.schema.RelationshipSchemaValidator;
+import org.onap.schema.validation.OxmModelValidator;
+import org.onap.schema.validation.RelationshipSchemaValidator;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
@@ -228,12 +232,31 @@ public abstract class AbstractGraphDataService {
edgePayload
.setTarget("services/inventory/" + version + "/" + target.getType() + "/" + target.getId().get());
}
- validatedEdge = RelationshipSchemaValidator.validateIncomingAddPayload(version, edgePayload.getType(),
- edgePayload);
+
+ List<Edge> sourceVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getSource()), edgePayload.getType(),
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getSource()), null));
+
+ List<Edge> targetVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getTarget()), edgePayload.getType(),
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getTarget()), null));
+
+ validatedEdge = RelationshipSchemaValidator.validateIncomingAddPayload(version, edgePayload.getType(), edgePayload, sourceVertexEdges,
+ targetVertexEdges);
persistedEdge = addBulkEdge(validatedEdge, version, txId);
} else if (opr.getValue().getAsString().equalsIgnoreCase("modify")) {
Edge edge = dao.getEdge(edgePayload.getId(), edgePayload.getType(), txId);
- validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, edgePayload);
+
+ // load source and target vertex relationships for validation
+ List<Edge> sourceVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getSource()), edgePayload.getType(),
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getSource()), null));
+
+ List<Edge> targetVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(edgePayload.getTarget()), edgePayload.getType(),
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(edgePayload.getTarget()), null));
+
+ validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, edgePayload, edgePayload.getType(), sourceVertexEdges, targetVertexEdges);
persistedEdge = updateBulkEdge(validatedEdge, version, txId);
} else {
if ( (edgePayload.getId() == null) || (edgePayload.getType() == null) ) {
diff --git a/src/main/java/org/onap/crud/service/BulkPayload.java b/src/main/java/org/onap/crud/service/BulkPayload.java
deleted file mode 100644
index 8dc99c4..0000000
--- a/src/main/java/org/onap/crud/service/BulkPayload.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * ============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 6b447a1..c2d2591 100644
--- a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
@@ -56,11 +56,13 @@ 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.OxmModelValidator;
-import org.onap.schema.RelationshipSchemaValidator;
+import org.onap.schema.validation.OxmModelValidator;
+import org.onap.schema.validation.RelationshipSchemaValidator;
public class CrudAsyncGraphDataService extends AbstractGraphDataService {
@@ -211,7 +213,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
throws CrudException {
// Validate the incoming payload
Vertex vertex = OxmModelValidator.validateIncomingUpsertPayload(null, version, type, payload.getProperties());
- vertex.getProperties().put(org.onap.schema.OxmModelValidator.Metadata.NODE_TYPE.propertyName(), type);
+ vertex.getProperties().put(OxmModelValidator.Metadata.NODE_TYPE.propertyName(), type);
// Create graph request event
GraphEvent event = GraphEvent.builder(GraphEventOperation.CREATE)
.vertex(GraphEventVertex.fromVertex(vertex, version)).build();
@@ -233,6 +235,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
public ImmutablePair<EntityTag, String> addEdge(String version, String type, EdgePayload payload)
throws CrudException {
Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload);
+
// Create graph request event
GraphEvent event =
GraphEvent.builder(GraphEventOperation.CREATE).edge(GraphEventEdge.fromEdge(edge, version)).build();
@@ -320,6 +323,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
OperationResult operationResult = dao.getEdge(id, type, new HashMap<String, String>());
Edge edge = Edge.fromJson(operationResult.getResult());
Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, payload);
+
GraphEvent event = GraphEvent.builder(GraphEventOperation.UPDATE)
.edge(GraphEventEdge.fromEdge(validatedEdge, version)).build();
diff --git a/src/main/java/org/onap/crud/service/CrudGraphDataService.java b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
index 5b1c2dd..2888ace 100644
--- a/src/main/java/org/onap/crud/service/CrudGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
@@ -22,6 +22,7 @@ package org.onap.crud.service;
import java.util.HashMap;
+import java.util.List;
import javax.ws.rs.core.EntityTag;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.onap.aai.restclient.client.OperationResult;
@@ -30,9 +31,12 @@ 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.OxmModelValidator;
-import org.onap.schema.RelationshipSchemaValidator;
+import org.onap.schema.validation.OxmModelValidator;
+import org.onap.schema.validation.RelationshipSchemaValidator;
public class CrudGraphDataService extends AbstractGraphDataService {
@@ -70,7 +74,17 @@ public class CrudGraphDataService extends AbstractGraphDataService {
@Override
public ImmutablePair<EntityTag, String> addEdge(String version, String type, EdgePayload payload)
throws CrudException {
- Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload);
+ // 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));
+
+ List<Edge> targetVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getTarget()), type,
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getTarget()), null));
+
+ Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload, sourceVertexEdges, targetVertexEdges);
+
return addEdge(version, edge);
}
@@ -133,7 +147,20 @@ public class CrudGraphDataService extends AbstractGraphDataService {
@Override
public ImmutablePair<EntityTag, String> updateEdge(String version, String id, String type, EdgePayload payload)
throws CrudException {
- Edge validatedEdge = getValidatedEdge(version, id, type, payload);
+ 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));
+
+ List<Edge> targetVertexEdges =
+ EdgePayloadUtil.filterEdgesByRelatedVertexAndType(EdgePayloadUtil.getVertexNodeType(payload.getTarget()), type,
+ daoForGet.getVertexEdges(EdgePayloadUtil.getVertexNodeId(payload.getTarget()), null));
+
+ Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, payload, type, sourceVertexEdges, targetVertexEdges);
+
return updateEdge(version, validatedEdge);
}
@@ -152,11 +179,6 @@ 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 583fee6..a43d7e5 100644
--- a/src/main/java/org/onap/crud/service/CrudRestService.java
+++ b/src/main/java/org/onap/crud/service/CrudRestService.java
@@ -52,6 +52,9 @@ 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
deleted file mode 100644
index a670b54..0000000
--- a/src/main/java/org/onap/crud/service/EdgePayload.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * ============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
deleted file mode 100644
index 172d03b..0000000
--- a/src/main/java/org/onap/crud/service/VertexPayload.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * ============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