2 * ============LICENSE_START=======================================================
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.
25 package org.openecomp.datarouter.entity;
27 import java.io.IOException;
28 import java.io.Serializable;
29 import java.security.MessageDigest;
30 import java.security.NoSuchAlgorithmException;
31 import java.util.List;
33 import javax.json.Json;
34 import javax.json.JsonObject;
36 public class TopographicalEntity implements DocumentStoreDataEntity, Serializable {
38 private static final long serialVersionUID = -5188479658230319058L;
40 protected String entityType;
41 protected String entityPrimaryKeyValue;
42 protected String entityPrimaryKeyName;
43 protected String latitude;
44 protected String longitude;
45 protected String selfLink;
47 // generated, SHA-256 digest
50 private static String convertBytesToHexString(byte[] bytesToConvert) {
51 StringBuffer hexString = new StringBuffer();
52 for (int i = 0; i < bytesToConvert.length; i++) {
53 hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
55 return hexString.toString();
58 private static String concatArray(List<String> list, char delimiter) {
60 if (list == null || list.size() == 0) {
64 StringBuilder result = new StringBuilder(64);
66 int listSize = list.size();
67 boolean firstValue = true;
69 for (String item : list) {
75 result.append(delimiter).append(item);
79 return result.toString();
83 * We'll try and create a unique identity key that we can use for
84 * differencing the previously imported record sets as we won't have granular
85 * control of what is created/removed and when. The best we can hope for is
86 * identification of resources by generated Id until the Identity-Service
87 * UUID is tagged against all resources, then we can use that instead.
89 public static String generateUniqueShaDigest(String entityType, String fieldName,
90 String fieldValue) throws NoSuchAlgorithmException {
93 * Basically SHA-256 will result in an identity with a guaranteed
94 * uniqueness compared to just a java hashcode value.
96 MessageDigest digest = MessageDigest.getInstance("SHA-256");
97 digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes());
98 return convertBytesToHexString(digest.digest());
101 public TopographicalEntity() {}
106 * @see org.openecomp.datarouter.entity.TopographicalEntity#getAsJson()
108 public String getAsJson() throws IOException {
111 Json.createObjectBuilder().add("entityType", entityType)
112 .add("pkey", entityPrimaryKeyValue)
113 .add("location", Json.createObjectBuilder()
114 .add("lat", latitude)
115 .add("lon", longitude))
116 .add("selfLink", selfLink).build();
118 return obj.toString();
123 public String toString() {
124 return "TopographicalEntity [" + ("entityType=" + entityType + ", ")
125 + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ")
126 + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ")
127 + ("ID=" + id + ", ")
128 + ("selfLink=" + selfLink) + "]";
132 public String getId() {
136 public String getEntityType() {
140 public void setEntityType(String entityType) {
141 this.entityType = entityType;
144 public String getEntityPrimaryKeyValue() {
145 return entityPrimaryKeyValue;
148 public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) {
149 this.entityPrimaryKeyValue = entityPrimaryKeyValue;
152 public String getEntityPrimaryKeyName() {
153 return entityPrimaryKeyName;
156 public void setEntityPrimaryKeyName(String entityPrimaryKeyName) {
157 this.entityPrimaryKeyName = entityPrimaryKeyName;
160 public String getLatitude() {
164 public void setLatitude(String latitude) {
165 this.latitude = latitude;
168 public String getLongitude() {
172 public void setLongitude(String longitude) {
173 this.longitude = longitude;
176 public String getSelfLink() {
180 public void setSelfLink(String selfLink) {
181 this.selfLink = selfLink;
184 public static long getSerialversionuid() {
185 return serialVersionUID;
188 public void setId(String id) {