From 60f7f5e11d7d0d7870a4650956921bd1afa309fd Mon Sep 17 00:00:00 2001 From: abatos Date: Fri, 12 May 2017 14:11:30 -0400 Subject: Initial ONAP Synapse commit Change-Id: I3a0ed659dbb8f8faeeb54093b5d6f10414cd886e Signed-off-by: abatos --- .../datarouter/entity/AaiEventEntity.java | 315 +++++++++++++++++++++ .../datarouter/entity/AggregationEntity.java | 124 ++++++++ .../datarouter/entity/DocumentStoreDataEntity.java | 35 +++ .../datarouter/entity/OxmEntityDescriptor.java | 126 +++++++++ .../datarouter/entity/PolicyResponse.java | 72 +++++ .../datarouter/entity/SuggestionSearchEntity.java | 281 ++++++++++++++++++ .../datarouter/entity/TopographicalEntity.java | 191 +++++++++++++ .../datarouter/entity/UebEventHeader.java | 169 +++++++++++ 8 files changed, 1313 insertions(+) create mode 100644 src/main/java/org/openecomp/datarouter/entity/AaiEventEntity.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/AggregationEntity.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/DocumentStoreDataEntity.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/OxmEntityDescriptor.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/PolicyResponse.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/SuggestionSearchEntity.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/TopographicalEntity.java create mode 100644 src/main/java/org/openecomp/datarouter/entity/UebEventHeader.java (limited to 'src/main/java/org/openecomp/datarouter/entity') diff --git a/src/main/java/org/openecomp/datarouter/entity/AaiEventEntity.java b/src/main/java/org/openecomp/datarouter/entity/AaiEventEntity.java new file mode 100644 index 0000000..418c0d3 --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/AaiEventEntity.java @@ -0,0 +1,315 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +/* +* ============LICENSE_START======================================================= +* DataRouter +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.datarouter.entity; + +import java.io.IOException; +import java.io.Serializable; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.json.Json; +import javax.json.JsonObject; + +/** + * Note: AAIEventEntity is a port forward of IndexDocument Has been renamed here to move forward + * with abstraction of document store technology. + */ +public class AaiEventEntity implements DocumentStoreDataEntity, Serializable { + + private static final long serialVersionUID = -5188479658230319058L; + + protected String entityType; + protected String entityPrimaryKeyName; + protected String entityPrimaryKeyValue; + protected ArrayList searchTagCollection = new ArrayList(); + protected ArrayList searchTagIdCollection = new ArrayList(); + protected ArrayList crossEntityReferenceCollection = new ArrayList(); + protected String lastmodTimestamp; + protected String link; + + private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + /* + * Generated fields, leave the settings for junit overrides + */ + + // generated, SHA-256 digest + protected String id; + + /* + * generated based on searchTagCollection values + */ + protected String searchTags; + protected String searchTagIds; + protected String crossReferenceEntityValues; + + + private static String convertBytesToHexString(byte[] bytesToConvert) { + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < bytesToConvert.length; i++) { + hexString.append(Integer.toHexString(0xFF & bytesToConvert[i])); + } + return hexString.toString(); + } + + private static String concatArray(List list, char delimiter) { + + if (list == null || list.size() == 0) { + return ""; + } + + StringBuilder result = new StringBuilder(64); + + int listSize = list.size(); + boolean firstValue = true; + + for (String item : list) { + + if (firstValue) { + result.append(item); + firstValue = false; + } else { + result.append(delimiter).append(item); + } + + } + + return result.toString(); + + } + + /* + * We'll try and create a unique identity key that we can use for differencing the previously + * imported record sets as we won't have granular control of what is created/removed and when. The + * best we can hope for is identification of resources by generated Id until the Identity-Service + * UUID is tagged against all resources, then we can use that instead. + */ + + private static String generateUniqueShaDigest(String entityType, String fieldName, + String fieldValue) throws NoSuchAlgorithmException { + + /* + * Basically SHA-256 will result in an identity with a guaranteed uniqueness compared to just a + * java hashcode value. + */ + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes()); + return convertBytesToHexString(digest.digest()); + } + + + public AaiEventEntity() { + SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT); + Timestamp timestamp = new Timestamp(System.currentTimeMillis()); + String currentFormattedTimeStamp = dateFormat.format(timestamp); + this.lastmodTimestamp = currentFormattedTimeStamp; + } + + public void deriveFields() throws NoSuchAlgorithmException { + this.id = generateUniqueShaDigest(entityType, entityPrimaryKeyName, entityPrimaryKeyValue); + this.searchTags = concatArray(searchTagCollection, ';'); + this.searchTagIds = concatArray(searchTagIdCollection, ';'); + this.crossReferenceEntityValues = concatArray(crossEntityReferenceCollection, ';'); + } + + + /* + * (non-Javadoc) + * + * @see org.openecomp.datarouter.entity.AAIEventEntity#getAsJson() + */ + @Override + public String getAsJson() throws IOException { + + JsonObject obj = Json.createObjectBuilder().add("entityType", entityType) + .add("entityPrimaryKeyValue", entityPrimaryKeyValue).add("searchTagIDs", searchTagIds) + .add("searchTags", searchTags).add("crossEntityReferenceValues", crossReferenceEntityValues) + .add("lastmodTimestamp", lastmodTimestamp).add("link", link).build(); + + return obj.toString(); + } + + + public void addSearchTagWithKey(String searchTag, String key) { + searchTagIdCollection.add(key); + searchTagCollection.add(searchTag); + } + + public void addCrossEntityReferenceValue(String crossEntityReferenceValue) { + if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) { + crossEntityReferenceCollection.add(crossEntityReferenceValue); + } + } + + public String getEntityType() { + return entityType; + } + + public String getEntityPrimaryKeyName() { + return entityPrimaryKeyName; + } + + public String getEntityPrimaryKeyValue() { + return entityPrimaryKeyValue; + } + + + /* + * (non-Javadoc) + * + * @see org.openecomp.datarouter.entity.AAIEventEntity#getId() + */ + @Override + public String getId() { + return id; + } + + public ArrayList getSearchTagCollection() { + return searchTagCollection; + } + + public String getSearchTags() { + return searchTags; + } + + public String getSearchTagIDs() { + return searchTagIds; + } + + public void setSearchTagIDs(String searchTagIDs) { + this.searchTagIds = searchTagIDs; + } + + public void setEntityType(String entityType) { + this.entityType = entityType; + } + + public void setId(String id) { + this.id = id; + } + + public void setSearchTagCollection(ArrayList searchTagCollection) { + this.searchTagCollection = searchTagCollection; + } + + public void setSearchTags(String searchTags) { + this.searchTags = searchTags; + } + + public ArrayList getSearchTagIdCollection() { + return searchTagIdCollection; + } + + public void setSearchTagIdCollection(ArrayList searchTagIdCollection) { + this.searchTagIdCollection = searchTagIdCollection; + } + + public String getLastmodTimestamp() { + return lastmodTimestamp; + } + + public void setLastmodTimestamp(String lastmodTimestamp) { + this.lastmodTimestamp = lastmodTimestamp; + } + + public void setEntityPrimaryKeyName(String entityPrimaryKeyName) { + this.entityPrimaryKeyName = entityPrimaryKeyName; + } + + public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) { + this.entityPrimaryKeyValue = entityPrimaryKeyValue; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + /* + * public void mergeEntity(AAIEventEntity entityToMergeIn) { + * + * if ( entityToMergeIn == null ) { return; } + * + * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType = + * entityToMergeIn.getEntityType(); } + * + * if ( !entityToMergeIn.getEntityType().equals( entityType )) { entityType = + * entityToMergeIn.getEntityType(); } + * + * } + */ + + @Override + public String toString() { + return "AAIEventEntity [" + (entityType != null ? "entityType=" + entityType + ", " : "") + + (entityPrimaryKeyName != null ? "entityPrimaryKeyName=" + entityPrimaryKeyName + ", " + : "") + + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", " + : "") + + (searchTagCollection != null ? "searchTagCollection=" + searchTagCollection + ", " : "") + + (searchTagIdCollection != null ? "searchTagIDCollection=" + searchTagIdCollection + ", " + : "") + + (crossEntityReferenceCollection != null + ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "") + + "lastmodTimestamp=" + lastmodTimestamp + ", " + (id != null ? "id=" + id + ", " : "") + + (searchTags != null ? "searchTags=" + searchTags + ", " : "") + + (searchTagIds != null ? "searchTagIDs=" + searchTagIds + ", " : "") + + (crossReferenceEntityValues != null + ? "crossReferenceEntityValues=" + crossReferenceEntityValues : "") + + "]"; + } + +} diff --git a/src/main/java/org/openecomp/datarouter/entity/AggregationEntity.java b/src/main/java/org/openecomp/datarouter/entity/AggregationEntity.java new file mode 100644 index 0000000..4830d67 --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/AggregationEntity.java @@ -0,0 +1,124 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.openecomp.datarouter.util.NodeUtils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * The Class AggregationEntity. Mimics functionality of AAIUI's AggregationEntity + */ +public class AggregationEntity implements DocumentStoreDataEntity, Serializable { + private String id; + private String link; + private String lastmodTimestamp; + + public String getLink() { + return link; + } + public void setLink(String link) { + this.link = link; + } + public String getId() { + // make sure that deliveFields() is called before getting the id + return id; + } + public void setId(String id) { + this.id = id; + } + + + public String getLastmodTimestamp() { + return lastmodTimestamp; + } + public void setLastmodTimestamp(String lastmodTimestamp) { + this.lastmodTimestamp = lastmodTimestamp; + } + + + Map attributes = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + + /** + * Instantiates a new aggregation entity. + */ + public AggregationEntity() { } + + public void deriveFields(JsonNode uebPayload) { + + this.setId(NodeUtils.generateUniqueShaDigest(link)); + + this.setLastmodTimestamp(Long.toString(System.currentTimeMillis())); + + JsonNode entityNode = uebPayload.get("entity"); + + Iterator> nodes = entityNode.fields(); + + while (nodes.hasNext()) { + Map.Entry entry = (Map.Entry) nodes.next(); + if (!entry.getKey().equalsIgnoreCase("relationship-list")){ + attributes.put(entry.getKey(), entry.getValue().asText()); + } + } + } + + public void copyAttributeKeyValuePair(Map map){ + for(String key: map.keySet()){ + if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation + this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value + } + } + } + + public void addAttributeKeyValuePair(String key, String value){ + this.attributes.put(key, value); + } + + public String getAsJson() { + ObjectNode rootNode = mapper.createObjectNode(); + rootNode.put("link", this.getLink()); + rootNode.put("lastmodTimestamp", lastmodTimestamp); + for (String key: this.attributes.keySet()){ + rootNode.put(key, this.attributes.get(key)); + } + return rootNode.toString(); + } + + @Override + public String toString() { + return "AggregationEntity [id=" + id + ", link=" + link + ", attributes=" + attributes + + ", mapper=" + mapper + "]"; + } +} diff --git a/src/main/java/org/openecomp/datarouter/entity/DocumentStoreDataEntity.java b/src/main/java/org/openecomp/datarouter/entity/DocumentStoreDataEntity.java new file mode 100644 index 0000000..61df316 --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/DocumentStoreDataEntity.java @@ -0,0 +1,35 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import java.io.IOException; + +public interface DocumentStoreDataEntity { + + public String getId(); + + public String getAsJson() throws IOException; + +} diff --git a/src/main/java/org/openecomp/datarouter/entity/OxmEntityDescriptor.java b/src/main/java/org/openecomp/datarouter/entity/OxmEntityDescriptor.java new file mode 100644 index 0000000..9f486e4 --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/OxmEntityDescriptor.java @@ -0,0 +1,126 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import java.util.List; + +import org.openecomp.datarouter.util.CrossEntityReference; + + +public class OxmEntityDescriptor { + + private String entityName; + + private List primaryKeyAttributeName; + + private List searchableAttributes; + + private CrossEntityReference crossEntityReference; + + private List alias; + + private List suggestableAttributes; + + boolean isSuggestableEntity; + + public String getEntityName() { + return entityName; + } + + public void setEntityName(String entityName) { + this.entityName = entityName; + } + + public List getPrimaryKeyAttributeName() { + return primaryKeyAttributeName; + } + + public void setPrimaryKeyAttributeName(List primaryKeyAttributeName) { + this.primaryKeyAttributeName = primaryKeyAttributeName; + } + + public List getSearchableAttributes() { + return searchableAttributes; + } + + public void setSearchableAttributes(List searchableAttributes) { + this.searchableAttributes = searchableAttributes; + } + + public boolean hasSearchableAttributes() { + + if ( this.searchableAttributes == null) { + return false; + } + + if ( this.searchableAttributes.size() > 0 ) { + return true; + } + + return false; + + } + + public CrossEntityReference getCrossEntityReference() { + return crossEntityReference; + } + + public void setCrossEntityReference(CrossEntityReference crossEntityReference) { + this.crossEntityReference = crossEntityReference; + } + + public List getAlias() { + return alias; + } + + public void setAlias(List alias) { + this.alias = alias; + } + + public List getSuggestableAttributes() { + return suggestableAttributes; + } + + public void setSuggestableAttributes(List suggestableAttributes) { + this.suggestableAttributes = suggestableAttributes; + } + + public boolean isSuggestableEntity() { + return isSuggestableEntity; + } + + public void setSuggestableEntity(boolean isSuggestableEntity) { + this.isSuggestableEntity = isSuggestableEntity; + } + + @Override + public String toString() { + return "OxmEntityDescriptor [entityName=" + entityName + ", primaryKeyAttributeName=" + + primaryKeyAttributeName + ", searchableAttributes=" + searchableAttributes + + ", crossEntityReference=" + crossEntityReference + ", alias=" + alias + + ", suggestableAttributes=" + suggestableAttributes + ", isSuggestableEntity=" + + isSuggestableEntity + "]"; + } +} \ No newline at end of file diff --git a/src/main/java/org/openecomp/datarouter/entity/PolicyResponse.java b/src/main/java/org/openecomp/datarouter/entity/PolicyResponse.java new file mode 100644 index 0000000..fd577fa --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/PolicyResponse.java @@ -0,0 +1,72 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +/** + * Provides information about the level of success of a policy execution against a routed query. + */ +public class PolicyResponse { + + private ResponseType responseType; + + private String responseData; + + private int httpResponseCode; + + public PolicyResponse(ResponseType responseType, String responseData) { + super(); + this.responseType = responseType; + this.responseData = responseData; + } + + public ResponseType getResponseType() { + return responseType; + } + + public String getResponseData() { + return responseData; + } + + + public int getHttpResponseCode() { + return httpResponseCode; + } + + public void setHttpResponseCode(int httpResponseCode) { + this.httpResponseCode = httpResponseCode; + } + + @Override + public String toString() { + return "PolicyResponse [responseType=" + responseType + ", responseData=" + responseData + + ", httpResponseCode=" + httpResponseCode + "]"; + } + + + + public enum ResponseType { + SUCCESS, PARTIAL_SUCCESS, FAILURE; + } +} diff --git a/src/main/java/org/openecomp/datarouter/entity/SuggestionSearchEntity.java b/src/main/java/org/openecomp/datarouter/entity/SuggestionSearchEntity.java new file mode 100644 index 0000000..ae2711b --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/SuggestionSearchEntity.java @@ -0,0 +1,281 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import java.io.IOException; +import java.io.Serializable; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.openecomp.datarouter.util.NodeUtils; + +import com.fasterxml.jackson.databind.JsonNode; + +public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializable { + private static final long serialVersionUID = -3636393943669310760L; + + protected String id; // generated SHA-256 digest + private String entityType; + private List entityTypeAliases; + private List suggestionInputPermutations = new ArrayList<>(); + private List statusPermutations = new ArrayList<>(); + private List suggestableAttr = new ArrayList<>(); + private Map payload = new HashMap<>(); + private JSONObject payloadJsonNode = new JSONObject(); + private StringBuffer outputString = new StringBuffer(); + + public void deriveFields() throws NoSuchAlgorithmException { + int payloadEntryCounter = 1; + + for (Map.Entry payload : getPayload().entrySet()) { + if (payload.getValue() != null && payload.getValue().length() > 0) { + this.getPayloadJsonNode().put(payload.getKey(), payload.getValue()); + this.outputString.append(payload.getValue()); + + if (payloadEntryCounter < getPayload().entrySet().size()) { + this.outputString.append(" and "); + } else { + this.outputString.append(" "); + } + } + + payloadEntryCounter++; + } + + this.outputString.append(getEntityTypeAliases().get(0)); + this.id = NodeUtils.generateUniqueShaDigest(outputString.toString()); + } + + /** + * Launch pad for performing permutations of the entity type, aliases, prov status and orchestration status. + * SHA-256 will result in an ID with a guaranteed uniqueness compared to just a java hashcode value. + * @return + */ + public List generateSuggestionInputPermutations() { + List entityNames = new ArrayList<>(); + entityNames.add(entityType); + + if ((entityTypeAliases != null) && !(entityTypeAliases.isEmpty())) { + for (String alias : entityTypeAliases) { + entityNames.add(alias); + } + } + + ArrayList listToPermutate = new ArrayList<>(statusPermutations); + ArrayList listOfSearchSuggestionPermutations = new ArrayList<>(); + + for (String entityName : entityNames) { + listToPermutate.add(entityName); + permutateList(listToPermutate, new ArrayList(), listToPermutate.size(), listOfSearchSuggestionPermutations); + listToPermutate.remove(entityName); + } + + return listOfSearchSuggestionPermutations; + } + + public boolean isSuggestableDoc() { + return this.getPayload().size() != 0; + } + + /** + * Generate all permutations of Entity Type and (Prov Status and/or Orchestration Status) + * @param list The list of unique elements to create permutations of + * @param permutation A list to hold the current permutation used during + * @param size To keep track of the original size of the number of unique elements + * @param listOfSearchSuggestionPermutationList The list to hold all of the different permutations + */ + private void permutateList(List list, List permutation, int size, + List listOfSearchSuggestionPermutationList) { + if (permutation.size() == size) { + StringBuilder newPermutation = new StringBuilder(); + + for (int i = 0; i < permutation.size(); i++) { + newPermutation.append(permutation.get(i)).append(" "); + } + + listOfSearchSuggestionPermutationList.add(newPermutation.toString().trim()); + + return; + } + + String[] availableItems = list.toArray(new String[0]); + + for (String i : availableItems) { + permutation.add(i); + list.remove(i); + permutateList(list, permutation, size, listOfSearchSuggestionPermutationList); + list.add(i); + permutation.remove(i); + } + } + + /** + * return Custom-built JSON representation of this class + */ + @Override + public String getAsJson() throws IOException { + if (entityType == null || suggestionInputPermutations == null) { + return null; + } + + JSONObject rootNode = new JSONObject(); + JSONArray inputArray = new JSONArray(); + JSONObject payloadNode = new JSONObject(); + StringBuffer outputString = new StringBuffer(); + + int payloadEntryCounter = 1; + + // Add prov and orchestration status to search suggestion string + for (Map.Entry payload : getPayload().entrySet()) { + payloadNode.put(payload.getKey(), payload.getValue()); + outputString.append(payload.getValue()); + + if (payloadEntryCounter < getPayload().entrySet().size()) { + // Add the word "and" between prov and orchestration statuses, if both are present + outputString.append(" and "); + payloadEntryCounter++; + } + } + + // Add entity type to search suggestion string. We've decided to use the first entity type alias from the OXM + outputString.append(" ").append(getEntityTypeAliases().get(0)); + + for (String permutation : suggestionInputPermutations) { + inputArray.put(permutation); + } + + // Build up the search suggestion as JSON + JSONObject entitySuggest = new JSONObject(); + entitySuggest.put("input", inputArray); + entitySuggest.put("output", outputString); + entitySuggest.put("payload", payloadNode); + rootNode.put("entity_suggest", entitySuggest); + + return rootNode.toString(); + } + + public String getEntityType() { + return entityType; + } + + public void setEntityType(String entityType) { + this.entityType = entityType; + } + + public List getEntityTypeAliases() { + return entityTypeAliases; + } + + public void setEntityTypeAliases(List entityTypeAliases) { + this.entityTypeAliases = entityTypeAliases; + } + + @Override + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public StringBuffer getOutputString() { + return outputString; + } + + public void setOutputString(StringBuffer outputString) { + this.outputString = outputString; + } + + public Map getPayload() { + return payload; + } + + public void setPayloadFromResponse(JsonNode node) { + Map nodePayload = new HashMap<>(); + JsonNode entityNode = node.get("entity"); + if (suggestableAttr != null) { + for (String attribute : suggestableAttr) { + if (entityNode.get(attribute) != null && !entityNode.get(attribute).asText().trim().isEmpty()) { + nodePayload.put(attribute, entityNode.get(attribute).asText()); + this.statusPermutations.add(entityNode.get(attribute).asText()); + } + } + this.setPayload(nodePayload); + } + } + + public void setPayload(Map payload) { + this.payload = payload; + } + + public JSONObject getPayloadJsonNode() { + return payloadJsonNode; + } + + public void setPayloadJsonNode(JSONObject payloadJsonNode) { + this.payloadJsonNode = payloadJsonNode; + } + + public List getStatusPermutations() { + return statusPermutations; + } + + public List getSuggestableAttr() { + return suggestableAttr; + } + + public List getSuggestionInputPermutations() { + return this.suggestionInputPermutations; + } + + public void setStatusPermutations(List statusPermutations) { + this.statusPermutations = statusPermutations; + } + + public void setSuggestableAttr(ArrayList attributes) { + for (String attribute : attributes) { + this.suggestableAttr.add(attribute); + } + } + + public void setSuggestionInputPermutations(List permutations) { + this.suggestionInputPermutations = permutations; + } + + @Override + public String toString() { + return "SuggestionSearchEntity [id=" + id + ", entityType=" + entityType + + ", entityTypeAliases=" + entityTypeAliases + ", suggestionInputPermutations=" + + suggestionInputPermutations + ", statusPermutations=" + statusPermutations + + ", suggestableAttr=" + suggestableAttr + ", payload=" + payload + ", payloadJsonNode=" + + payloadJsonNode + ", outputString=" + outputString + "]"; + } +} diff --git a/src/main/java/org/openecomp/datarouter/entity/TopographicalEntity.java b/src/main/java/org/openecomp/datarouter/entity/TopographicalEntity.java new file mode 100644 index 0000000..79cdfcd --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/TopographicalEntity.java @@ -0,0 +1,191 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import java.io.IOException; +import java.io.Serializable; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.List; + +import javax.json.Json; +import javax.json.JsonObject; + +public class TopographicalEntity implements DocumentStoreDataEntity, Serializable { + + private static final long serialVersionUID = -5188479658230319058L; + + protected String entityType; + protected String entityPrimaryKeyValue; + protected String entityPrimaryKeyName; + protected String latitude; + protected String longitude; + protected String selfLink; + + // generated, SHA-256 digest + protected String id; + + private static String convertBytesToHexString(byte[] bytesToConvert) { + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < bytesToConvert.length; i++) { + hexString.append(Integer.toHexString(0xFF & bytesToConvert[i])); + } + return hexString.toString(); + } + + private static String concatArray(List list, char delimiter) { + + if (list == null || list.size() == 0) { + return ""; + } + + StringBuilder result = new StringBuilder(64); + + int listSize = list.size(); + boolean firstValue = true; + + for (String item : list) { + + if (firstValue) { + result.append(item); + firstValue = false; + } else { + result.append(delimiter).append(item); + } + } + + return result.toString(); + } + + /* + * We'll try and create a unique identity key that we can use for + * differencing the previously imported record sets as we won't have granular + * control of what is created/removed and when. The best we can hope for is + * identification of resources by generated Id until the Identity-Service + * UUID is tagged against all resources, then we can use that instead. + */ + public static String generateUniqueShaDigest(String entityType, String fieldName, + String fieldValue) throws NoSuchAlgorithmException { + + /* + * Basically SHA-256 will result in an identity with a guaranteed + * uniqueness compared to just a java hashcode value. + */ + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + digest.update(String.format("%s.%s.%s", entityType, fieldName, fieldValue).getBytes()); + return convertBytesToHexString(digest.digest()); + } + + public TopographicalEntity() {} + + /* + * (non-Javadoc) + * + * @see org.openecomp.datarouter.entity.TopographicalEntity#getAsJson() + */ + public String getAsJson() throws IOException { + + JsonObject obj = + Json.createObjectBuilder().add("entityType", entityType) + .add("pkey", entityPrimaryKeyValue) + .add("location", Json.createObjectBuilder() + .add("lat", latitude) + .add("lon", longitude)) + .add("selfLink", selfLink).build(); + + return obj.toString(); + } + + + @Override + public String toString() { + return "TopographicalEntity [" + ("entityType=" + entityType + ", ") + + ("entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", ") + + ("latitude=" + latitude + ", ") + ("longitude=" + longitude + ", ") + + ("ID=" + id + ", ") + + ("selfLink=" + selfLink) + "]"; + } + + @Override + public String getId() { + return this.id; + } + + public String getEntityType() { + return entityType; + } + + public void setEntityType(String entityType) { + this.entityType = entityType; + } + + public String getEntityPrimaryKeyValue() { + return entityPrimaryKeyValue; + } + + public void setEntityPrimaryKeyValue(String entityPrimaryKeyValue) { + this.entityPrimaryKeyValue = entityPrimaryKeyValue; + } + + public String getEntityPrimaryKeyName() { + return entityPrimaryKeyName; + } + + public void setEntityPrimaryKeyName(String entityPrimaryKeyName) { + this.entityPrimaryKeyName = entityPrimaryKeyName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getSelfLink() { + return selfLink; + } + + public void setSelfLink(String selfLink) { + this.selfLink = selfLink; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/main/java/org/openecomp/datarouter/entity/UebEventHeader.java b/src/main/java/org/openecomp/datarouter/entity/UebEventHeader.java new file mode 100644 index 0000000..5eab97f --- /dev/null +++ b/src/main/java/org/openecomp/datarouter/entity/UebEventHeader.java @@ -0,0 +1,169 @@ +/** + * ============LICENSE_START======================================================= + * DataRouter + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.datarouter.entity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A convenience POJO for mapping the UebEventHeader from a UEB Event. + * + * @author davea + */ + +@JsonIgnoreProperties(ignoreUnknown = true) +public class UebEventHeader { + + private String timestamp; + + private String id; + + private String action; + + private String domain; + + private String sourceName; + + private String entityLink; + + private String entityType; + + private String topEntityType; + + private String sequenceNumber; + + private String eventType; + + private String version; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getSourceName() { + return sourceName; + } + + @JsonProperty("source-name") + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + public String getEntityLink() { + return entityLink; + } + + @JsonProperty("entity-link") + public void setEntityLink(String entityLink) { + this.entityLink = entityLink; + } + + public String getEntityType() { + return entityType; + } + + @JsonProperty("entity-type") + public void setEntityType(String entityType) { + this.entityType = entityType; + } + + public String getTopEntityType() { + return topEntityType; + } + + @JsonProperty("top-entity-type") + public void setTopEntityType(String topEntityType) { + this.topEntityType = topEntityType; + } + + public String getSequenceNumber() { + return sequenceNumber; + } + + @JsonProperty("sequence-number") + public void setSequenceNumber(String sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } + + public String getEventType() { + return eventType; + } + + @JsonProperty("event-type") + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + return "UebEventHeader [" + (timestamp != null ? "timestamp=" + timestamp + ", " : "") + + (id != null ? "id=" + id + ", " : "") + (action != null ? "action=" + action + ", " : "") + + (domain != null ? "domain=" + domain + ", " : "") + + (sourceName != null ? "sourceName=" + sourceName + ", " : "") + + (entityLink != null ? "entityLink=" + entityLink + ", " : "") + + (entityType != null ? "entityType=" + entityType + ", " : "") + + (topEntityType != null ? "topEntityType=" + topEntityType + ", " : "") + + (sequenceNumber != null ? "sequenceNumber=" + sequenceNumber + ", " : "") + + (eventType != null ? "eventType=" + eventType + ", " : "") + + (version != null ? "version=" + version : "") + "]"; + } + +} -- cgit 1.2.3-korg