[AAI-2175] Change aai champ container processes to run as non-root on the host
[aai/champ.git] / champ-service / src / main / java / org / onap / champ / event / GraphEvent.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  */
21 package org.onap.champ.event;
22
23 import javax.ws.rs.core.Response.Status;
24
25 import com.google.gson.annotations.SerializedName;
26
27 public class GraphEvent {
28
29   public enum GraphEventOperation {
30     CREATE, UPDATE, DELETE
31   }
32
33   public enum GraphEventResult {
34     SUCCESS, FAILURE
35   }
36
37   private GraphEventOperation operation;
38
39   @SerializedName("transaction-id")
40   private String transactionId;
41
42   @SerializedName("database-transaction-id")
43   private String dbTransactionId;
44   
45   private long timestamp;
46
47   private GraphEventVertex vertex;
48
49   private GraphEventEdge edge;
50
51   private GraphEventResult result;
52
53   @SerializedName("error-message")
54   private String errorMessage;
55
56   private Status httpErrorStatus;
57
58   public static Builder builder(GraphEventOperation operation) {
59     return new Builder(operation);
60   }
61
62   public GraphEventOperation getOperation() {
63     return operation;
64   }
65
66   public String getTransactionId() {
67     return transactionId;
68   }
69   
70   public String getDbTransactionId() {
71     return dbTransactionId;
72   }
73   
74   public void setDbTransactionId(String id) {
75     dbTransactionId = id;
76   }
77   
78   public long getTimestamp() {
79     return timestamp;
80   }
81
82   public GraphEventVertex getVertex() {
83     return vertex;
84   }
85
86   public GraphEventEdge getEdge() {
87     return edge;
88   }
89
90   public GraphEventResult getResult() {
91     return result;
92   }
93
94   public String getErrorMessage() {
95     return errorMessage;
96   }
97
98   public void setResult(GraphEventResult result) {
99     this.result = result;
100   }
101
102
103   public Status getHttpErrorStatus() {
104     return httpErrorStatus;
105   }
106
107   public void setHttpErrorStatus(Status httpErrorStatus) {
108     this.httpErrorStatus = httpErrorStatus;
109   }
110
111   public void setTimestamp(long timestamp) {
112     this.timestamp = timestamp;
113   }
114
115   public void setErrorMessage(String errorMessage) {
116     this.errorMessage = errorMessage;
117   }
118
119   public void setVertex(GraphEventVertex vertex) {
120     this.vertex = vertex;
121   }
122
123   public void setEdge(GraphEventEdge edge) {
124     this.edge = edge;
125   }
126
127   public String getObjectKey() {
128     if (this.getVertex() != null) {
129       return this.getVertex().getId();
130     } else if (this.getEdge() != null) {
131       return this.getEdge().getId();
132     }
133
134     return null;
135   }
136
137   public String getObjectType() {
138     if (this.getVertex() != null) {
139       return "vertex->" + this.getVertex().getType();
140     } else if (this.getEdge() != null) {
141       return "edge->" + this.getEdge().getType();
142     }
143
144     return null;
145   }
146
147   public static class Builder {
148
149     GraphEvent event = null;
150
151     public Builder(GraphEventOperation operation) {
152       event = new GraphEvent();
153       event.operation = operation;
154     }
155
156     public Builder vertex(GraphEventVertex vertex) {
157       event.vertex = vertex;
158       return this;
159     }
160
161     public Builder edge(GraphEventEdge edge) {
162       event.edge = edge;
163       return this;
164     }
165
166     public Builder result(GraphEventResult result) {
167       event.result = result;
168       return this;
169     }
170
171     public Builder errorMessage(String errorMessage) {
172       event.errorMessage = errorMessage;
173       return this;
174     }
175
176     public Builder httpErrorStatus(Status httpErrorStatus) {
177       event.httpErrorStatus = httpErrorStatus;
178       return this;
179     }
180
181     public GraphEvent build() {
182
183       event.timestamp = System.currentTimeMillis();
184       event.transactionId = java.util.UUID.randomUUID().toString();
185
186       return event;
187     }
188   }
189
190 }