X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fdatarouter%2Fpolicy%2FEntityEventPolicy.java;h=ec76c9551ee33be20d496f7d10bd97829711535c;hb=ae6c01275cfa4e85045edb0473659789865479f3;hp=d08186813cd29256c509384e5770816bc3a1ca2e;hpb=aa6be5e9ddf87462ba5e660824a026febe68b203;p=aai%2Fdata-router.git diff --git a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java index d081868..ec76c95 100644 --- a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java +++ b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java @@ -2,8 +2,9 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * Modifications Copyright (C) 2019 IBM * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +18,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.datarouter.policy; @@ -39,26 +38,28 @@ import org.apache.camel.Processor; import org.eclipse.persistence.dynamic.DynamicType; import org.eclipse.persistence.internal.helper.DatabaseField; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; +import org.eclipse.persistence.oxm.MediaType; import org.json.JSONException; import org.json.JSONObject; import org.onap.aai.datarouter.entity.AaiEventEntity; import org.onap.aai.datarouter.entity.AggregationEntity; import org.onap.aai.datarouter.entity.DocumentStoreDataEntity; -import org.onap.aai.datarouter.entity.OxmEntityDescriptor; import org.onap.aai.datarouter.entity.SuggestionSearchEntity; import org.onap.aai.datarouter.entity.TopographicalEntity; import org.onap.aai.datarouter.entity.UebEventHeader; import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs; -import org.onap.aai.datarouter.util.CrossEntityReference; -import org.onap.aai.datarouter.util.EntityOxmReferenceHelper; -import org.onap.aai.datarouter.util.ExternalOxmModelProcessor; import org.onap.aai.datarouter.util.NodeUtils; -import org.onap.aai.datarouter.util.OxmModelLoader; import org.onap.aai.datarouter.util.RouterServiceUtil; import org.onap.aai.datarouter.util.SearchServiceAgent; import org.onap.aai.datarouter.util.SearchSuggestionPermutation; -import org.onap.aai.datarouter.util.Version; -import org.onap.aai.datarouter.util.VersionedOxmEntities; +import org.onap.aai.entity.OxmEntityDescriptor; +import org.onap.aai.util.CrossEntityReference; +import org.onap.aai.util.EntityOxmReferenceHelper; +import org.onap.aai.util.ExternalOxmModelProcessor; +import org.onap.aai.schema.OxmModelLoader; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.util.Version; +import org.onap.aai.util.VersionedOxmEntities; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.cl.mdc.MdcContext; @@ -76,20 +77,20 @@ import com.fasterxml.jackson.databind.node.ObjectNode; public class EntityEventPolicy implements Processor { public static final String additionalInfo = "Response of AAIEntityEventPolicy"; - private static final String entitySearchSchema = "entitysearch_schema.json"; - private static final String topographicalSearchSchema = "topographysearch_schema.json"; + private static final String ENTITY_SEARCH_SCHEMA = "entitysearch_schema.json"; + private static final String TOPOGRAPHICAL_SEARCH_SCHEMA = "topographysearch_schema.json"; private Collection externalOxmModelProcessors; - private final String EVENT_HEADER = "event-header"; - private final String ENTITY_HEADER = "entity"; - private final String ACTION_CREATE = "create"; - private final static String ACTION_DELETE = "delete"; - private final String ACTION_UPDATE = "update"; - private final String PROCESS_AAI_EVENT = "Process AAI Event"; - private final String TOPO_LAT = "latitude"; - private final String TOPO_LONG = "longitude"; + private static final String EVENT_HEADER = "event-header"; + private static final String ENTITY_HEADER = "entity"; + private static final String ACTION_CREATE = "create"; + private static final String ACTION_DELETE = "delete"; + private static final String ACTION_UPDATE = "update"; + private static final String PROCESS_AAI_EVENT = "Process AAI Event"; + private static final String TOPO_LAT = "latitude"; + private static final String TOPO_LONG = "longitude"; - private final List SUPPORTED_ACTIONS = + private static final List SUPPORTED_ACTIONS = Arrays.asList(ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE); Map oxmVersionContextMap = new HashMap<>(); @@ -144,7 +145,7 @@ public class EntityEventPolicy implements Processor { this.externalOxmModelProcessors = new ArrayList<>(); this.externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance()); OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors); - OxmModelLoader.loadModels(); + OxmModelLoader.loadModels(config.getSchemaVersions(), config.getSchemaLocationsBean()); oxmVersionContextMap = OxmModelLoader.getVersionContextMap(); parseLatestOxmVersion(); } @@ -174,8 +175,8 @@ public class EntityEventPolicy implements Processor { public void startup() { // Create the indexes in the search service if they do not already exist. - searchAgent.createSearchIndex(entitySearchIndex, entitySearchSchema); - searchAgent.createSearchIndex(topographicalSearchIndex, topographicalSearchSchema); + searchAgent.createSearchIndex(entitySearchIndex, ENTITY_SEARCH_SCHEMA); + searchAgent.createSearchIndex(topographicalSearchIndex, TOPOGRAPHICAL_SEARCH_SCHEMA); logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED); } @@ -204,8 +205,8 @@ public class EntityEventPolicy implements Processor { } public void returnWithError(Exchange exchange, String payload, String errorMsg){ - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, errorMsg); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, errorMsg, payload); + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, errorMsg); + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, errorMsg, payload); setResponse(exchange, ResponseType.FAILURE, additionalInfo); } @@ -216,7 +217,7 @@ public class EntityEventPolicy implements Processor { String uebPayload = exchange.getIn().getBody().toString(); - JsonNode uebAsJson =null; + JsonNode uebAsJson = null; ObjectMapper mapper = new ObjectMapper(); try{ uebAsJson = mapper.readTree(uebPayload); @@ -244,19 +245,19 @@ public class EntityEventPolicy implements Processor { // Get src domain from header; discard event if not originated from same domain String payloadSrcDomain = eventHeader.getDomain(); if (payloadSrcDomain == null || !payloadSrcDomain.equalsIgnoreCase(this.srcDomain)) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Unrecognized source domain '" + payloadSrcDomain + "'", uebPayload); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Unrecognized source domain '" + payloadSrcDomain + "'"); setResponse(exchange, ResponseType.SUCCESS, additionalInfo); return; } - DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion.toLowerCase()); + DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion); if (oxmJaxbContext == null) { logger.error(EntityEventPolicyMsgs.OXM_VERSION_NOT_SUPPORTED, oxmVersion); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, "OXM version mismatch", + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "OXM version mismatch", uebPayload); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -265,9 +266,9 @@ public class EntityEventPolicy implements Processor { String action = eventHeader.getAction(); if (action == null || !SUPPORTED_ACTIONS.contains(action.toLowerCase())) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Unrecognized action '" + action + "'", uebPayload); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Unrecognized action '" + action + "'"); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -276,9 +277,9 @@ public class EntityEventPolicy implements Processor { String entityType = eventHeader.getEntityType(); if (entityType == null) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Payload header missing entity type", uebPayload); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload header missing entity type"); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -287,9 +288,9 @@ public class EntityEventPolicy implements Processor { String topEntityType = eventHeader.getTopEntityType(); if (topEntityType == null) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Payload header missing top entity type", uebPayload); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload header top missing entity type"); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -298,9 +299,9 @@ public class EntityEventPolicy implements Processor { String entityLink = eventHeader.getEntityLink(); if (entityLink == null) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Payload header missing entity link", uebPayload); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload header missing entity link"); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -308,25 +309,21 @@ public class EntityEventPolicy implements Processor { } // log the fact that all data are in good shape - logger.info(EntityEventPolicyMsgs.PROCESS_AAI_ENTITY_EVENT_POLICY_NONVERBOSE, action, + logger.info(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_NONVERBOSE, action, entityType); - logger.debug(EntityEventPolicyMsgs.PROCESS_AAI_ENTITY_EVENT_POLICY_VERBOSE, action, entityType, + logger.debug(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_VERBOSE, action, entityType, uebPayload); // Process for building AaiEventEntity object - String[] entityTypeArr = entityType.split("-"); - String oxmEntityType = ""; - for (String entityWord : entityTypeArr) { - oxmEntityType += entityWord.substring(0, 1).toUpperCase() + entityWord.substring(1); - } + String oxmEntityType = new OxmEntityTypeConverter().convert(entityType); List searchableAttr = getOxmAttributes(uebPayload, oxmJaxbContext, oxmEntityType, entityType, "searchable"); if (searchableAttr == null) { - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Searchable attribute not found for payload entity type '" + entityType + "'"); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Searchable attribute not found for payload entity type '" + entityType + "'", uebPayload); @@ -338,9 +335,9 @@ public class EntityEventPolicy implements Processor { getEntityPrimaryKeyFieldName(oxmJaxbContext, uebPayload, oxmEntityType, entityType); String entityPrimaryKeyFieldValue = lookupValueUsingKey(uebPayload, entityPrimaryKeyFieldName); if (entityPrimaryKeyFieldValue == null || entityPrimaryKeyFieldValue.isEmpty()) { - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload missing primary key attribute"); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Payload missing primary key attribute", uebPayload); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -359,9 +356,9 @@ public class EntityEventPolicy implements Processor { aaiEventEntity.setLink(entityLink); if (!getSearchTags(aaiEventEntity, searchableAttr, uebPayload, action)) { - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload missing searchable attribute for entity type '" + entityType + "'"); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Payload missing searchable attribute for entity type '" + entityType + "'", uebPayload); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -373,9 +370,9 @@ public class EntityEventPolicy implements Processor { aaiEventEntity.deriveFields(); } catch (NoSuchAlgorithmException e) { - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Cannot create unique SHA digest"); - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "Cannot create unique SHA digest", uebPayload); setResponse(exchange, ResponseType.FAILURE, additionalInfo); @@ -391,7 +388,7 @@ public class EntityEventPolicy implements Processor { * Use the versioned OXM Entity class to get access to cross-entity reference helper collections */ VersionedOxmEntities oxmEntities = - EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion)); + EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase())); /** * NOTES: @@ -414,7 +411,8 @@ public class EntityEventPolicy implements Processor { JSONObject entityJsonObject = getUebEntity(uebPayload); - JsonNode entityJsonNode = convertToJsonNode(entityJsonObject.toString()); + JsonNode entityJsonNode = + convertToJsonNode(entityJsonObject !=null ? entityJsonObject.toString() : ""); String parentEntityType = entityType; @@ -508,7 +506,7 @@ public class EntityEventPolicy implements Processor { updateCerInEntity(entityToSync); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + logger.debug(e.getMessage()); } } } else { @@ -815,9 +813,9 @@ public class EntityEventPolicy implements Processor { try { uebJsonObj = new JSONObject(payload); } catch (JSONException e) { - logger.debug(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_VERBOSE, - "Payload has invalid JSON Format", payload.toString()); - logger.error(EntityEventPolicyMsgs.DISCARD_AAI_EVENT_NONVERBOSE, + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, + "Payload has invalid JSON Format", payload); + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, "Payload has invalid JSON Format"); return null; } @@ -825,8 +823,7 @@ public class EntityEventPolicy implements Processor { if (uebJsonObj.has(ENTITY_HEADER)) { return uebJsonObj.getJSONObject(ENTITY_HEADER); } else { - logger.debug(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing", - payload.toString()); + logger.debug(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing", payload); logger.error(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing"); return null; } @@ -848,8 +845,6 @@ public class EntityEventPolicy implements Processor { primaryKeyValues.add(pkeyValue); primaryKeyNames.add(keyName); } else { - // logger.warn("getPopulatedDocument(), pKeyValue is null for entityType = " + - // resultDescriptor.getEntityName()); logger.error(EntityEventPolicyMsgs.PRIMARY_KEY_NULL_FOR_ENTITY_TYPE, resultDescriptor.getEntityName()); } @@ -903,7 +898,7 @@ public class EntityEventPolicy implements Processor { headers.put(Headers.IF_MATCH, etag); } else { logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE, - entitySearchIndex, entityId); + entitySearchIndex, entityId); } ArrayList sourceObject = new ArrayList<>(); @@ -914,7 +909,7 @@ public class EntityEventPolicy implements Processor { if (!sourceObject.isEmpty()) { JsonNode node = sourceObject.get(0); final String sourceCer = NodeUtils.extractFieldValueFromObject(node, - "crossEntityReferenceValues"); + "crossReferenceEntityValues"); String newCer = aaiEventEntity.getCrossReferenceEntityValues(); boolean hasNewCer = true; if (sourceCer != null && sourceCer.length() > 0){ // already has CER @@ -927,7 +922,7 @@ public class EntityEventPolicy implements Processor { if (hasNewCer){ // Do the PUT with new CER - ((ObjectNode)node).put("crossEntityReferenceValues", newCer); + ((ObjectNode)node).put("crossReferenceEntityValues", newCer); jsonPayload = NodeUtils.convertObjectToJson(node, false); searchAgent.putDocument(entitySearchIndex, entityId, jsonPayload, headers); } @@ -968,8 +963,6 @@ public class EntityEventPolicy implements Processor { String entityId = eventEntity.getId(); - // System.out.println("aaiEventEntity as json = " + aaiEventEntity.getAsJson()); - if ((action.equalsIgnoreCase(ACTION_CREATE) && entityId != null) || action.equalsIgnoreCase(ACTION_UPDATE)) { @@ -1007,6 +1000,13 @@ public class EntityEventPolicy implements Processor { logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE, index, entityId); } + + /* + * The Spring-Boot version of the search-data-service rejects the DELETE operation unless + * we specify a Content-Type. + */ + + headers.put("Content-Type", Arrays.asList(MediaType.APPLICATION_JSON.getMediaType())); searchAgent.deleteDocument(index, eventEntity.getId(), headers); } else {