2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.inventory.entity;
28 import java.io.IOException;
29 import java.io.Serializable;
30 import java.security.MessageDigest;
31 import java.security.NoSuchAlgorithmException;
32 import java.util.List;
34 import javax.json.Json;
35 import javax.json.JsonObject;
38 * The Class TopographicalEntity.
40 public class TopographicalEntity implements Serializable {
42 private static final long serialVersionUID = -5188479658230319058L;
44 protected String entityType;
45 protected String entityPrimaryKeyValue;
46 protected String entityPrimaryKeyName;
47 protected String latitude;
48 protected String longitude;
49 protected String selfLink;
51 // generated, SHA-256 digest
55 * Convert bytes to hex string.
57 * @param bytesToConvert the bytes to convert
60 private static String convertBytesToHexString(byte[] bytesToConvert) {
61 StringBuffer hexString = new StringBuffer();
62 for (int i = 0; i < bytesToConvert.length; i++) {
63 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
65 return hexString.toString();
71 * @param list the list
72 * @param delimiter the delimiter
75 private static String concatArray(List<String> list, char delimiter) {
77 if (list == null || list.size() == 0) {
81 StringBuilder result = new StringBuilder(64);
83 int listSize = list.size();
84 boolean firstValue = true;
86 for (String item : list) {
92 result.append(delimiter).append(item);
97 return result.toString();
102 * We'll try and create a unique identity key that we can use for differencing the previously
103 * imported record sets as we won't have granular control of what is created/removed and when. The
104 * best we can hope for is identification of resources by generated Id until the Identity-Service
105 * UUID is tagged against all resources, then we can use that instead.
109 * Generate unique sha digest.
111 * @param entityType the entity type
112 * @param fieldName the field name
113 * @param fieldValue the field value
115 * @throws NoSuchAlgorithmException the no such algorithm exception
117 public static String generateUniqueShaDigest(String entityType, String fieldName,
118 String fieldValue) throws NoSuchAlgorithmException {
121 * Basically SHA-256 will result in an identity with a guaranteed uniqueness compared to just a
122 * java hashcode value.
124 MessageDigest digest = MessageDigest.getInstance("SHA-256");
125 digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
126 return convertBytesToHexString(digest.digest());
130 * Instantiates a new topographical entity.
132 public TopographicalEntity() {}
137 * @see com.att.queryrouter.dao.DocumentStoreDataEntity#getAsJson()
139 public String getAsJson() throws IOException {
142 Json.createObjectBuilder().add("entityType", entityType).add("pkey", entityPrimaryKeyValue)
143 .add("location", Json.createObjectBuilder().add("lat", latitude).add("lon", longitude))
144 .add("selfLink", selfLink).build();
146 return obj.toString();
151 * @see java.lang.Object#toString()
154 public String toString() {
155 return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
156 + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
157 + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ") + ("ID=" + id + ", ")
158 + ("selfLink=" + selfLink) + "]";
161 public String getId() {
165 public String getEntityType() {
169 public void setEntityType(String entityType) {
170 this.entityType = entityType;
173 public String getEntityPrimaryKeyValue() {
174 return entityPrimaryKeyValue;
177 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
178 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
181 public String getEntityPrimaryKeyName() {
182 return entityPrimaryKeyName;
185 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
186 this.entityPrimaryKeyName = entityPrimaryKeyName;
189 public String getLatitude() {
193 public void setLatitude(String latitude) {
194 this.latitude = latitude;
197 public String getLongitude() {
201 public void setLongitude(String longitude) {
202 this.longitude = longitude;
205 public String getSelfLink() {
209 public void setSelfLink(String selfLink) {
210 this.selfLink = selfLink;
213 public static long getSerialversionuid() {
214 return serialVersionUID;
217 public void setId(String id) {