2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.datarouter.entity;
25 import java.io.IOException;
26 import java.io.Serializable;
27 import java.security.MessageDigest;
28 import java.security.NoSuchAlgorithmException;
29 import java.util.List;
31 import javax.json.Json;
32 import javax.json.JsonObject;
34 public class TopographicalEntity implements DocumentStoreDataEntity, Serializable {
36 private static final long serialVersionUID = -5188479658230319058L;
38 protected String entityType;
39 protected String entityPrimaryKeyValue;
40 protected String entityPrimaryKeyName;
41 protected String latitude;
42 protected String longitude;
43 protected String selfLink;
45 // generated, SHA-256 digest
48 private static String convertBytesToHexString(byte[] bytesToConvert) {
49 StringBuilder hexString = new StringBuilder();
50 for (int i = 0; i < bytesToConvert.length; i++) {
51 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
53 return hexString.toString();
56 private static String concatArray(List<String> list, char delimiter) {
58 if (list == null || list.isEmpty()) {
62 StringBuilder result = new StringBuilder(64);
64 boolean firstValue = true;
66 for (String item : list) {
72 result.append(delimiter).append(item);
76 return result.toString();
80 * We'll try and create a unique identity key that we can use for
81 * differencing the previously imported record sets as we won't have granular
82 * control of what is created/removed and when. The best we can hope for is
83 * identification of resources by generated Id until the Identity-Service
84 * UUID is tagged against all resources, then we can use that instead.
86 public static String generateUniqueShaDigest(String entityType, String fieldName,
87 String fieldValue) throws NoSuchAlgorithmException {
90 * Basically SHA-256 will result in an identity with a guaranteed
91 * uniqueness compared to just a java hashcode value.
93 MessageDigest digest = MessageDigest.getInstance("SHA-256");
94 digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
95 return convertBytesToHexString(digest.digest());
98 public TopographicalEntity() {}
103 * @see org.onap.aai.datarouter.entity.TopographicalEntity#getAsJson()
106 public String getAsJson() throws IOException {
109 Json.createObjectBuilder().add("entityType", entityType)
110 .add("pkey", entityPrimaryKeyValue)
111 .add("location", Json.createObjectBuilder()
112 .add("lat", latitude)
113 .add("lon", longitude))
114 .add("selfLink", selfLink).build();
116 return obj.toString();
121 public String toString() {
122 return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
123 + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
124 + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ")
125 + ("ID=" + id + ", ")
126 + ("selfLink=" + selfLink) + "]";
130 public String getId() {
134 public String getEntityType() {
138 public void setEntityType(String entityType) {
139 this.entityType = entityType;
142 public String getEntityPrimaryKeyValue() {
143 return entityPrimaryKeyValue;
146 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
147 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
150 public String getEntityPrimaryKeyName() {
151 return entityPrimaryKeyName;
154 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
155 this.entityPrimaryKeyName = entityPrimaryKeyName;
158 public String getLatitude() {
162 public void setLatitude(String latitude) {
163 this.latitude = latitude;
166 public String getLongitude() {
170 public void setLongitude(String longitude) {
171 this.longitude = longitude;
174 public String getSelfLink() {
178 public void setSelfLink(String selfLink) {
179 this.selfLink = selfLink;
182 public static long getSerialversionuid() {
183 return serialVersionUID;
186 public void setId(String id) {