2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.crud.service;
26 import java.util.List;
29 import org.onap.crud.dao.GraphDao;
30 import org.onap.crud.entity.Edge;
31 import org.onap.crud.entity.Vertex;
32 import org.onap.crud.exception.CrudException;
33 import org.onap.crud.parser.CrudResponseBuilder;
34 import org.onap.crud.util.CrudServiceUtil;
35 import org.onap.schema.OxmModelValidator;
36 import org.onap.schema.RelationshipSchemaValidator;
38 public abstract class AbstractGraphDataService {
39 protected GraphDao dao;
41 public AbstractGraphDataService(GraphDao dao) throws CrudException {
44 CrudServiceUtil.loadModels();
47 public String getEdge(String version, String id, String type) throws CrudException {
48 RelationshipSchemaValidator.validateType(version, type);
49 Edge edge = dao.getEdge(id, type);
51 return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
54 public String getEdges(String version, String type, Map<String, String> filter) throws CrudException {
55 RelationshipSchemaValidator.validateType(version, type);
56 List<Edge> items = dao.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter));
57 return CrudResponseBuilder.buildGetEdgesResponse(items, version);
60 public String getVertex(String version, String id, String type) throws CrudException {
61 type = OxmModelValidator.resolveCollectionType(version, type);
62 Vertex vertex = dao.getVertex(id, type);
63 List<Edge> edges = dao.getVertexEdges(id);
64 return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges,
68 public String getVertices(String version, String type, Map<String, String> filter) throws CrudException {
69 type = OxmModelValidator.resolveCollectionType(version, type);
70 List<Vertex> items = dao.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter));
71 return CrudResponseBuilder.buildGetVerticesResponse(items, version);
74 public abstract String addVertex(String version, String type, VertexPayload payload) throws CrudException;
75 public abstract String updateVertex(String version, String id, String type, VertexPayload payload) throws CrudException;
76 public abstract String patchVertex(String version, String id, String type, VertexPayload payload) throws CrudException;
77 public abstract String deleteVertex(String version, String id, String type) throws CrudException;
78 public abstract String addEdge(String version, String type, EdgePayload payload) throws CrudException;
79 public abstract String deleteEdge(String version, String id, String type) throws CrudException;
80 public abstract String updateEdge(String version, String id, String type, EdgePayload payload) throws CrudException;
81 public abstract String patchEdge(String version, String id, String type, EdgePayload payload) throws CrudException;
82 public abstract String addBulk(String version, BulkPayload payload) throws CrudException;