013845e799ef7c9b17dc1be923819e4c087bb88a
[aai/gizmo.git] / src / main / java / org / onap / crud / service / AbstractGraphDataService.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Gizmo
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.crud.service;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.ws.rs.core.HttpHeaders;
30
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;
39
40 public abstract class AbstractGraphDataService {
41   protected GraphDao dao;
42   
43   public AbstractGraphDataService(GraphDao dao) throws CrudException {
44     this.dao = dao;
45
46     CrudServiceUtil.loadModels();
47   }
48   
49   public String getEdge(String version, String id, String type) throws CrudException {
50     RelationshipSchemaValidator.validateType(version, type);
51     Edge edge = dao.getEdge(id, type);
52
53     return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
54   }
55   
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);
60   }
61   
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,
67         version);
68   }
69
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);
74   }
75   
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;
85 }