X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fdatarouter%2Fpolicy%2FEntityEventPolicy.java;h=152baf33f285c0709ca43b9907240ba456020077;hb=06576aee86306e15f01796b50f323939a6d1b531;hp=3ba8547e14c9060cf2af21942bd8e61015a4ba5b;hpb=a70a4453adadcb4c96b47c17a8ba15e6afc760fe;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 3ba8547..152baf3 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,8 @@ * ============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 * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,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 +37,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 +76,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<>(); @@ -130,6 +130,7 @@ public class EntityEventPolicy implements Processor { entitySearchIndex = config.getSearchEntitySearchIndex(); topographicalSearchIndex = config.getSearchTopographySearchIndex(); aggregateGenericVnfIndex = config.getSearchAggregationVnfIndex(); + autosuggestIndex = config.getSearchEntityAutoSuggestIndex(); // Instantiate the agent that we will use for interacting with the Search Service. searchAgent = new SearchServiceAgent(config.getSearchCertName(), @@ -143,7 +144,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(); } @@ -173,8 +174,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); } @@ -203,8 +204,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); } @@ -215,7 +216,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); @@ -243,19 +244,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); @@ -264,9 +265,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); @@ -275,9 +276,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); @@ -286,9 +287,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); @@ -297,9 +298,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); @@ -307,25 +308,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); @@ -337,9 +334,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); @@ -358,9 +355,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); @@ -372,9 +369,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); @@ -390,7 +387,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: @@ -507,7 +504,7 @@ public class EntityEventPolicy implements Processor { updateCerInEntity(entityToSync); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + logger.debug(e.getMessage()); } } } else { @@ -814,9 +811,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; } @@ -824,8 +821,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; } @@ -847,8 +843,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()); } @@ -902,7 +896,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<>(); @@ -913,7 +907,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 @@ -926,7 +920,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); } @@ -967,8 +961,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)) { @@ -1006,6 +998,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 {