[AAI-26] Adding gizmo data to the repository.
[aai/gizmo.git] / src / main / java / org / openecomp / crud / entity / Vertex.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.openecomp.crud.entity;
25
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
28
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Optional;
32
33 public class Vertex {
34   private static final Gson gson = new GsonBuilder().create();
35
36   private final Optional<String> id;
37   private final String type;
38   private final Map<String, Object> properties;
39
40
41   private Vertex(Builder builder) {
42     this.id = builder.id;
43     this.type = builder.type;
44     this.properties = builder.properties;
45   }
46
47   public static class Builder {
48     private Optional<String> id = Optional.empty();
49     private final String type;
50     private final Map<String, Object> properties = new HashMap<String, Object>();
51
52     public Builder(String type) {
53       if (type == null) {
54         throw new IllegalArgumentException("Type cannot be null");
55       }
56       this.type = type;
57     }
58
59     public Builder id(String id) {
60       if (id == null) {
61         throw new IllegalArgumentException("id cannot be null");
62       }
63
64       this.id = Optional.of(id);
65       return this;
66     }
67
68     public Builder property(String key, Object value) {
69       if (key == null || value == null) {
70         throw new IllegalArgumentException("Property key/value cannot be null");
71       }
72       properties.put(key, value);
73       return this;
74     }
75
76     public Vertex build() {
77       return new Vertex(this);
78     }
79   }
80
81   public String toJson() {
82     return gson.toJson(this);
83   }
84
85   @Override
86   public String toString() {
87     return "Vertex [id=" + id + ", type=" + type + ", properties=" + properties + "]";
88   }
89
90   public Optional<String> getId() {
91     return id;
92   }
93
94   public String getType() {
95     return type;
96   }
97
98   public Map<String, Object> getProperties() {
99     return properties;
100   }
101
102 }