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 javax.ws.rs.core.HttpHeaders;
31 import org.onap.crud.dao.GraphDao;
32 import org.onap.crud.entity.Edge;
33 import org.onap.crud.entity.Vertex;
34 import org.onap.crud.exception.CrudException;
35 import org.onap.crud.parser.CrudResponseBuilder;
36 import org.onap.crud.util.CrudServiceUtil;
37 import org.onap.schema.OxmModelValidator;
38 import org.onap.schema.RelationshipSchemaValidator;
40 public abstract class AbstractGraphDataService {
41 protected GraphDao dao;
43 public AbstractGraphDataService(GraphDao dao) throws CrudException {
46 CrudServiceUtil.loadModels();
49 public String getEdge(String version, String id, String type) throws CrudException {
50 RelationshipSchemaValidator.validateType(version, type);
51 Edge edge = dao.getEdge(id, type);
53 return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
56 public String getEdges(String version, String type, Map<String, String> filter) throws CrudException {
57 RelationshipSchemaValidator.validateType(version, type);
58 List<Edge> items = dao.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter));
59 return CrudResponseBuilder.buildGetEdgesResponse(items, version);
62 public String getVertex(String version, String id, String type) throws CrudException {
63 type = OxmModelValidator.resolveCollectionType(version, type);
64 Vertex vertex = dao.getVertex(id, type);
65 List<Edge> edges = dao.getVertexEdges(id);
66 return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges,
70 public String getVertices(String version, String type, Map<String, String> filter) throws CrudException {
71 type = OxmModelValidator.resolveCollectionType(version, type);
72 List<Vertex> items = dao.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter));
73 return CrudResponseBuilder.buildGetVerticesResponse(items, version);
76 public abstract String addVertex(String version, String type, VertexPayload payload) throws CrudException;
77 public abstract String updateVertex(String version, String id, String type, VertexPayload payload) throws CrudException;
78 public abstract String patchVertex(String version, String id, String type, VertexPayload payload) throws CrudException;
79 public abstract String deleteVertex(String version, String id, String type) throws CrudException;
80 public abstract String addEdge(String version, String type, EdgePayload payload) throws CrudException;
81 public abstract String deleteEdge(String version, String id, String type) throws CrudException;
82 public abstract String updateEdge(String version, String id, String type, EdgePayload payload) throws CrudException;
83 public abstract String patchEdge(String version, String id, String type, EdgePayload payload) throws CrudException;
84 public abstract String addBulk(String version, BulkPayload payload, HttpHeaders headers) throws CrudException;