e627def46f19c2403144f2c368c9c352b79ff53e
[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 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;
37
38 public abstract class AbstractGraphDataService {
39   protected GraphDao dao;
40   
41   public AbstractGraphDataService(GraphDao dao) throws CrudException {
42     this.dao = dao;
43
44     CrudServiceUtil.loadModels();
45   }
46   
47   public String getEdge(String version, String id, String type) throws CrudException {
48     RelationshipSchemaValidator.validateType(version, type);
49     Edge edge = dao.getEdge(id, type);
50
51     return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
52   }
53   
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);
58   }
59   
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,
65         version);
66   }
67
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);
72   }
73   
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;
83 }