2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.datarouter.entity;
23 import java.io.IOException;
24 import java.io.Serializable;
25 import java.security.MessageDigest;
26 import java.security.NoSuchAlgorithmException;
27 import java.util.List;
29 import javax.json.Json;
30 import javax.json.JsonObject;
32 public class TopographicalEntity implements DocumentStoreDataEntity, Serializable {
34 private static final long serialVersionUID = -5188479658230319058L;
36 protected String entityType;
37 protected String entityPrimaryKeyValue;
38 protected String entityPrimaryKeyName;
39 protected String latitude;
40 protected String longitude;
41 protected String selfLink;
43 // generated, SHA-256 digest
46 private static String convertBytesToHexString(byte[] bytesToConvert) {
47 StringBuilder hexString = new StringBuilder();
48 for (int i = 0; i < bytesToConvert.length; i++) {
49 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
51 return hexString.toString();
54 private static String concatArray(List<String> list, char delimiter) {
56 if (list == null || list.isEmpty()) {
60 StringBuilder result = new StringBuilder(64);
62 boolean firstValue = true;
64 for (String item : list) {
70 result.append(delimiter).append(item);
74 return result.toString();
78 * We'll try and create a unique identity key that we can use for
79 * differencing the previously imported record sets as we won't have granular
80 * control of what is created/removed and when. The best we can hope for is
81 * identification of resources by generated Id until the Identity-Service
82 * UUID is tagged against all resources, then we can use that instead.
84 public static String generateUniqueShaDigest(String entityType, String fieldName,
85 String fieldValue) throws NoSuchAlgorithmException {
88 * Basically SHA-256 will result in an identity with a guaranteed
89 * uniqueness compared to just a java hashcode value.
91 MessageDigest digest = MessageDigest.getInstance("SHA-256");
92 digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
93 return convertBytesToHexString(digest.digest());
96 public TopographicalEntity() {}
101 * @see org.onap.aai.datarouter.entity.TopographicalEntity#getAsJson()
104 public String getAsJson() throws IOException {
107 Json.createObjectBuilder().add("entityType", entityType)
108 .add("pkey", entityPrimaryKeyValue)
109 .add("location", Json.createObjectBuilder()
110 .add("lat", latitude)
111 .add("lon", longitude))
112 .add("selfLink", selfLink).build();
114 return obj.toString();
119 public String toString() {
120 return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
121 + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
122 + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ")
123 + ("ID=" + id + ", ")
124 + ("selfLink=" + selfLink) + "]";
128 public String getId() {
132 public String getEntityType() {
136 public void setEntityType(String entityType) {
137 this.entityType = entityType;
140 public String getEntityPrimaryKeyValue() {
141 return entityPrimaryKeyValue;
144 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
145 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
148 public String getEntityPrimaryKeyName() {
149 return entityPrimaryKeyName;
152 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
153 this.entityPrimaryKeyName = entityPrimaryKeyName;
156 public String getLatitude() {
160 public void setLatitude(String latitude) {
161 this.latitude = latitude;
164 public String getLongitude() {
168 public void setLongitude(String longitude) {
169 this.longitude = longitude;
172 public String getSelfLink() {
176 public void setSelfLink(String selfLink) {
177 this.selfLink = selfLink;
180 public static long getSerialversionuid() {
181 return serialVersionUID;
184 public void setId(String id) {