Merge "Removed useless assignment to variables"
authorJames Forsyth <jf2512@att.com>
Thu, 28 Sep 2017 16:07:59 +0000 (16:07 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 28 Sep 2017 16:07:59 +0000 (16:07 +0000)
src/main/java/org/onap/aai/datarouter/entity/AaiEventEntity.java
src/main/java/org/onap/aai/datarouter/entity/AggregationEntity.java
src/main/java/org/onap/aai/datarouter/entity/SuggestionSearchEntity.java
src/main/java/org/onap/aai/datarouter/entity/TopographicalEntity.java
src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java
src/main/java/org/openecomp/datarouter/service/EchoService.java
src/main/java/org/openecomp/datarouter/util/CrossEntityReference.java
src/main/java/org/openecomp/datarouter/util/EntityOxmReferenceHelper.java
src/main/java/org/openecomp/datarouter/util/FileWatcher.java

index c32cd6f..0391ae3 100644 (file)
@@ -72,9 +72,9 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable {
   protected String entityType;
   protected String entityPrimaryKeyName;
   protected String entityPrimaryKeyValue;
-  protected ArrayList<String> searchTagCollection = new ArrayList<String>();
-  protected ArrayList<String> searchTagIdCollection = new ArrayList<String>();
-  protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
+  protected ArrayList<String> searchTagCollection = new ArrayList<>();
+  protected ArrayList<String> searchTagIdCollection = new ArrayList<>();
+  protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<>();
   protected String lastmodTimestamp;
   protected String link;
 
@@ -95,7 +95,7 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable {
 
 
   private static String convertBytesToHexString(byte[] bytesToConvert) {
-    StringBuffer hexString = new StringBuffer();
+    StringBuilder hexString = new StringBuilder();
     for (int i = 0; i < bytesToConvert.length; i++) {
       hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
     }
@@ -104,13 +104,12 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable {
 
   private static String concatArray(List<String> list, char delimiter) {
 
-    if (list == null || list.size() == 0) {
+    if (list == null || list.isEmpty()) {
       return "";
     }
 
     StringBuilder result = new StringBuilder(64);
 
-    int listSize = list.size();
     boolean firstValue = true;
 
     for (String item : list) {
index 44927eb..56ef6fd 100644 (file)
@@ -49,6 +49,8 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable
   public void setLink(String link) {
     this.link = link;
   }
+
+  @Override
   public String getId() {
     // make sure that deliveFields() is called before getting the id
     return id;
@@ -66,7 +68,7 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable
   }
 
 
-  Map<String, String> attributes = new HashMap<String, String>();
+  Map<String, String> attributes = new HashMap<>();
   ObjectMapper mapper = new ObjectMapper();
   
   /**
@@ -86,20 +88,22 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable
 
     while (nodes.hasNext()) {
       Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();
-      if (!entry.getKey().equalsIgnoreCase("relationship-list")){
+      if (!"relationship-list".equalsIgnoreCase(entry.getKey())){
         attributes.put(entry.getKey(), entry.getValue().asText());
       }
     }
   }
   
   public void copyAttributeKeyValuePair(Map<String, Object> 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
+    for(Map.Entry<String, Object> entry: map.entrySet()){
+      String key = entry.getKey();
+      Object value = entry.getValue();
+      if (!"relationship-list".equalsIgnoreCase(key)){   // ignore relationship data which is not required in aggregation
+        this.attributes.put(key, value.toString());    // not sure if entity attribute can contain an object as value
       }
     }
   }
-  
   public void addAttributeKeyValuePair(String key, String value){
     this.attributes.put(key, value);
   }
@@ -108,8 +112,10 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable
     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));
+    for (Map.Entry<String, String> entry: this.attributes.entrySet()){
+      String key = entry.getKey();
+      String value = entry.getValue();
+      rootNode.put(key, value);
     }
     return rootNode.toString();
   }
index a41487e..bd3c5b7 100644 (file)
@@ -57,7 +57,7 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
   private Map<String, String> inputOutputData = new HashMap<>();
   private Map<String, UiFilterConfig> filters = new HashMap<>();
   private JSONObject filterPayload = new JSONObject();
-  private StringBuffer searchSuggestionDisplayString = new StringBuffer();
+  private StringBuilder searchSuggestionDisplayString = new StringBuilder();
   private JSONArray payloadFilters = new JSONArray();
   private UiFiltersSchemaUtility filtersSchemaUtility = new UiFiltersSchemaUtility();
 
@@ -124,7 +124,7 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
       }
     }
 
-    ArrayList<String> listOfSearchSuggestionPermutations = new ArrayList<String>();
+    ArrayList<String> listOfSearchSuggestionPermutations = new ArrayList<>();
     ArrayList<String> listToPermutate = 
         new ArrayList<>(this.getInputOutputData().values());
 
@@ -152,7 +152,7 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
     JSONObject rootNode = new JSONObject();
     JSONArray inputArray = new JSONArray();
     JSONObject payloadNode = new JSONObject();
-    StringBuffer outputString = new StringBuffer();
+    StringBuilder outputString = new StringBuilder();
 
     int payloadEntryCounter = 1;
 
@@ -240,10 +240,10 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
           inputOutputData.put(attribute, entityFromUebEvent.get(attribute).asText());
 
           if(filterConfig != null) {
-            JSONObject filterPayload = new JSONObject();
-            filterPayload.put(FILTER_ID, filterConfig.getFilterId());
-            filterPayload.put(FILTER_VALUE, entityFromUebEvent.get(attribute).asText());
-            this.payloadFilters.put(filterPayload);
+            JSONObject jsonFilterPayload = new JSONObject();
+            jsonFilterPayload.put(FILTER_ID, filterConfig.getFilterId());
+            jsonFilterPayload.put(FILTER_VALUE, entityFromUebEvent.get(attribute).asText());
+            this.payloadFilters.put(jsonFilterPayload);
           } else {
             this.filterPayload.put(attribute, entityFromUebEvent.get(attribute).asText()); 
           }
@@ -292,7 +292,7 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
     return id;
   }
 
-  public StringBuffer getSearchSuggestionDisplayString() {
+  public StringBuilder getSearchSuggestionDisplayString() {
     return searchSuggestionDisplayString;
   }
 
@@ -324,7 +324,7 @@ public class SuggestionSearchEntity implements DocumentStoreDataEntity, Serializ
     return inputOutputData;
   }
 
-  public void setSearchSuggestionDisplayString(StringBuffer searchSuggestionDisplayString) {
+  public void setSearchSuggestionDisplayString(StringBuilder searchSuggestionDisplayString) {
     this.searchSuggestionDisplayString = searchSuggestionDisplayString;
   }
 
index fa25a56..1f81573 100644 (file)
@@ -46,7 +46,7 @@ public class TopographicalEntity implements DocumentStoreDataEntity, Serializabl
   protected String id;
 
   private static String convertBytesToHexString(byte[] bytesToConvert) {
-    StringBuffer hexString = new StringBuffer();
+    StringBuilder hexString = new StringBuilder();
     for (int i = 0; i < bytesToConvert.length; i++) {
       hexString.append(Integer.toHexString(0xFF & bytesToConvert[i]));
     }
@@ -55,13 +55,12 @@ public class TopographicalEntity implements DocumentStoreDataEntity, Serializabl
 
   private static String concatArray(List<String> list, char delimiter) {
 
-    if (list == null || list.size() == 0) {
+    if (list == null || list.isEmpty()) {
       return "";
     }
 
     StringBuilder result = new StringBuilder(64);
 
-    int listSize = list.size();
     boolean firstValue = true;
 
     for (String item : list) {
@@ -103,6 +102,7 @@ public class TopographicalEntity implements DocumentStoreDataEntity, Serializabl
    * 
    * @see org.onap.aai.datarouter.entity.TopographicalEntity#getAsJson()
    */
+  @Override
   public String getAsJson() throws IOException {
 
     JsonObject obj =
index a5fcbc3..402e158 100644 (file)
@@ -28,6 +28,7 @@ import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -112,7 +113,6 @@ public class EntityEventPolicy implements Processor {
 
   private Logger logger;
   private Logger metricsLogger;
-  private Logger auditLogger;
 
   public enum ResponseType {
     SUCCESS, PARTIAL_SUCCESS, FAILURE;
@@ -122,7 +122,7 @@ public class EntityEventPolicy implements Processor {
     LoggerFactory loggerFactoryInstance = LoggerFactory.getInstance();
     logger = loggerFactoryInstance.getLogger(EntityEventPolicy.class.getName());
     metricsLogger = loggerFactoryInstance.getMetricsLogger(EntityEventPolicy.class.getName());
-    auditLogger = loggerFactoryInstance.getAuditLogger(EntityEventPolicy.class.getName());
+
 
     srcDomain = config.getSourceDomain();
 
@@ -140,7 +140,7 @@ public class EntityEventPolicy implements Processor {
                                          config.getSearchEndpointDocuments(),
                                          logger);
 
-    this.externalOxmModelProcessors = new ArrayList<ExternalOxmModelProcessor>();
+    this.externalOxmModelProcessors = new ArrayList<>();
     this.externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
     OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
     OxmModelLoader.loadModels();
@@ -190,7 +190,7 @@ public class EntityEventPolicy implements Processor {
    */
   public static String convertObjectToJson(Object object, boolean pretty)
       throws JsonProcessingException {
-    ObjectWriter ow = null;
+    ObjectWriter ow;
 
     if (pretty) {
       ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
@@ -237,7 +237,7 @@ public class EntityEventPolicy implements Processor {
       return;
     }
 
-    UebEventHeader eventHeader = null;
+    UebEventHeader eventHeader;
     eventHeader = initializeUebEventHeader(uebObjHeader.toString());
 
     // Get src domain from header; discard event if not originated from same domain
@@ -419,23 +419,24 @@ public class EntityEventPolicy implements Processor {
       
       String targetEntityUrl = entityLink;
 
-      for (String key : crossEntityRefMap.keySet()) {
+      for (Map.Entry<String, CrossEntityReference> entry : crossEntityRefMap.entrySet()) {
 
         /*
          * if we know service-subscription is in the tree, then we can pull our all instances and
          * process from there.
          */
 
-        CrossEntityReference cerDescriptor = crossEntityRefMap.get(key);
+        String key = entry.getKey();
+        CrossEntityReference cerDescriptor = entry.getValue();
 
-        ArrayList<JsonNode> foundNodes = new ArrayList<JsonNode>();
+        ArrayList<JsonNode> foundNodes = new ArrayList<>();
 
         RouterServiceUtil.extractObjectsByKey(entityJsonNode, key, foundNodes);
 
-        if (foundNodes.size() > 0) {
+        if (!foundNodes.isEmpty()) {
 
           for (JsonNode n : foundNodes) {
-            if (parentEntityType.equalsIgnoreCase("customer")){  
+            if ("customer".equalsIgnoreCase(parentEntityType)){  
               /*
                * NOTES:
                * 1. prepare to hand-create url for service-instance
@@ -449,12 +450,12 @@ public class EntityEventPolicy implements Processor {
               
             }
 
-            List<String> extractedParentEntityAttributeValues = new ArrayList<String>();
+            List<String> extractedParentEntityAttributeValues = new ArrayList<>();
 
             RouterServiceUtil.extractFieldValuesFromObject(n, cerDescriptor.getAttributeNames(),
                 extractedParentEntityAttributeValues);
 
-            List<JsonNode> nestedTargetEntityInstances = new ArrayList<JsonNode>();
+            List<JsonNode> nestedTargetEntityInstances = new ArrayList<>();
             RouterServiceUtil.extractObjectsByKey(n, cerDescriptor.getTargetEntityType(),
                 nestedTargetEntityInstances);
 
@@ -472,7 +473,7 @@ public class EntityEventPolicy implements Processor {
               if (targetEntityInstance.has("link")) {   // nested SI has url mentioned
                 targetEntityUrl = RouterServiceUtil.getNodeFieldAsText(targetEntityInstance, 
                     "link");
-              } else if (parentEntityType.equalsIgnoreCase("customer") && 
+              } else if ("customer".equalsIgnoreCase(parentEntityType) && 
                   targetEntityInstance.has("service-instance-id")){
                 targetEntityUrl += "/" + RouterServiceUtil.getNodeFieldAsText(targetEntityInstance, 
                     "service-instance-id");
@@ -537,7 +538,7 @@ public class EntityEventPolicy implements Processor {
       Map<String, OxmEntityDescriptor> rootDescriptor =
           oxmEntities.getSuggestableEntityDescriptors();
       if (!rootDescriptor.isEmpty()) {
-        List<String> suggestibleAttrInPayload = new ArrayList<String>();
+        List<String> suggestibleAttrInPayload = new ArrayList<>();
         List<String> suggestibleAttrInOxm = extractSuggestableAttr(oxmEntities, entityType);
         if (suggestibleAttrInOxm != null) {
           for (String attr: suggestibleAttrInOxm){
@@ -604,17 +605,17 @@ public class EntityEventPolicy implements Processor {
   }
 
   public List<String> extractSuggestableAttr(VersionedOxmEntities oxmEntities, String entityType) {
-    // Extract suggestable attributes
+    // Extract suggestable attributeshandleTopographicalData
     Map<String, OxmEntityDescriptor> rootDescriptor = oxmEntities.getSuggestableEntityDescriptors();
 
     if (rootDescriptor == null) {
-      return null;
+      return Collections.emptyList();
     }
 
     OxmEntityDescriptor desc = rootDescriptor.get(entityType);
     
     if (desc == null) {
-      return null;
+      return Collections.emptyList();
     }
 
     return desc.getSuggestableAttributes();
@@ -627,7 +628,7 @@ public class EntityEventPolicy implements Processor {
     Map<String, OxmEntityDescriptor> rootDescriptor = oxmEntities.getEntityAliasDescriptors();
 
     if (rootDescriptor == null) {
-      return null;
+      return Collections.emptyList();
     }
 
     OxmEntityDescriptor desc = rootDescriptor.get(entityType);
@@ -744,7 +745,7 @@ public class EntityEventPolicy implements Processor {
       jsonNode = mapper.readTree(mapper.getJsonFactory().createJsonParser(payload));
     } catch (IOException e) {
       logger.debug(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing",
-          payload.toString());
+          payload);
       logger.error(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing",
           "");
     }
@@ -757,7 +758,7 @@ public class EntityEventPolicy implements Processor {
 
     boolean hasSearchableAttr = false;
     for (String searchTagField : searchableAttr) {
-      String searchTagValue = null;
+      String searchTagValue;
       if (searchTagField.equalsIgnoreCase(aaiEventEntity.getEntityPrimaryKeyName())) {
         searchTagValue = aaiEventEntity.getEntityPrimaryKeyValue();
       } else {
@@ -836,9 +837,9 @@ public class EntityEventPolicy implements Processor {
 
     d.setEntityType(resultDescriptor.getEntityName());
 
-    List<String> primaryKeyValues = new ArrayList<String>();
-    List<String> primaryKeyNames = new ArrayList<String>();
-    String pkeyValue = null;
+    List<String> primaryKeyValues = new ArrayList<>();
+    List<String> primaryKeyNames = new ArrayList<>();
+    String pkeyValue;
 
     for (String keyName : resultDescriptor.getPrimaryKeyAttributeName()) {
       pkeyValue = RouterServiceUtil.getNodeFieldAsText(entityNode, keyName);
@@ -883,7 +884,7 @@ public class EntityEventPolicy implements Processor {
       headers.put(Headers.TRANSACTION_ID, Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));
 
       String entityId = aaiEventEntity.getId();
-      String jsonPayload = aaiEventEntity.getAsJson();
+      String jsonPayload;
 
       // Run the GET to retrieve the ETAG from the search service
       OperationResult storedEntity = searchAgent.getDocument(entitySearchIndex, entityId);
@@ -897,14 +898,14 @@ public class EntityEventPolicy implements Processor {
         
         List<String> etag = storedEntity.getHeaders().get(Headers.ETAG);
 
-        if (etag != null && etag.size() > 0) {
+        if (etag != null && !etag.isEmpty()) {
           headers.put(Headers.IF_MATCH, etag);
         } else {
           logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE,
                          entitySearchIndex, entityId);
         }
         
-        ArrayList<JsonNode> sourceObject = new ArrayList<JsonNode>();
+        ArrayList<JsonNode> sourceObject = new ArrayList<>();
         NodeUtils.extractObjectsByKey(
             NodeUtils.convertJsonStrToJsonNode(storedEntity.getResult()),
             "content", sourceObject);
@@ -977,7 +978,7 @@ public class EntityEventPolicy implements Processor {
         if (HttpUtil.isHttpResponseClassSuccess(storedEntity.getResultCode())) {
           List<String> etag = storedEntity.getHeaders().get(Headers.ETAG);
 
-          if (etag != null && etag.size() > 0) {
+          if (etag != null && !etag.isEmpty()) {
             headers.put(Headers.IF_MATCH, etag);
           } else {
             logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE, index,
@@ -999,7 +1000,7 @@ public class EntityEventPolicy implements Processor {
         if (HttpUtil.isHttpResponseClassSuccess(storedEntity.getResultCode())) {
           List<String> etag = storedEntity.getHeaders().get(Headers.ETAG);
 
-          if (etag != null && etag.size() > 0) {
+          if (etag != null && !etag.isEmpty()) {
             headers.put(Headers.IF_MATCH, etag);
           } else {
             logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE, index,
@@ -1025,7 +1026,7 @@ public class EntityEventPolicy implements Processor {
       String entityPrimaryKeyFieldValue) {
 
     Map<String, String> topoData = new HashMap<>();
-    String entityLink = "";
+    String entityLink;
     List<String> topographicalAttr =
         getOxmAttributes(payload, oxmJaxbContext, oxmEntityType, entityType, "geoProps");
     if (topographicalAttr == null) {
@@ -1033,7 +1034,7 @@ public class EntityEventPolicy implements Processor {
           "Topograhical attribute not found for payload entity type '" + entityType + "'");
       logger.debug(EntityEventPolicyMsgs.DISCARD_UPDATING_TOPOGRAPHY_DATA_VERBOSE,
           "Topograhical attribute not found for payload entity type '" + entityType + "'",
-          payload.toString());
+          payload);
     } else {
       entityLink = lookupValueUsingKey(payload, "entity-link");
       for (String topoAttr : topographicalAttr) {
index 2339060..af4d490 100644 (file)
@@ -55,7 +55,7 @@ public class EchoService {
 
        String fromIp = req.getRemoteAddr();
     String fromAppId = "";
-    String transId = null;
+    String transId;
 
     if (headers.getRequestHeaders().getFirst("X-FromAppId") != null) {
       fromAppId = headers.getRequestHeaders().getFirst("X-FromAppId");
index f55d2e7..e889656 100644 (file)
@@ -38,7 +38,7 @@ public class CrossEntityReference {
 
   public CrossEntityReference() {
     this.targetEntityType = null;
-    this.attributeNames = new ArrayList<String>();
+    this.attributeNames = new ArrayList<>();
   }
 
   public String getTargetEntityType() {
index 503a069..cd5a37d 100644 (file)
@@ -33,7 +33,7 @@ public class EntityOxmReferenceHelper implements ExternalOxmModelProcessor {
    private HashMap<Version, VersionedOxmEntities> versionedModels;
    
    protected EntityOxmReferenceHelper() {
-      this.versionedModels = new HashMap<Version,VersionedOxmEntities>();
+      this.versionedModels = new HashMap<>();
    }
    
    public static EntityOxmReferenceHelper getInstance() {
@@ -57,4 +57,4 @@ public class EntityOxmReferenceHelper implements ExternalOxmModelProcessor {
       return this.versionedModels.get(version);
    }
 
-}
\ No newline at end of file
+}
index 5b04310..8ae69d3 100644 (file)
@@ -34,14 +34,15 @@ public abstract class FileWatcher extends TimerTask {
     this.timeStamp = file.lastModified();
   }
 
+  @Override
   public final void run() {
-    long timeStamp = file.lastModified();
+    long newTimeStamp = file.lastModified();
 
-    if ((timeStamp - this.timeStamp) > 500) {
-      this.timeStamp = timeStamp;
+    if ((newTimeStamp - this.timeStamp) > 500) {
+      this.timeStamp = newTimeStamp;
       onChange(file);
     }
   }
   
   protected abstract void onChange(File file);
-}
\ No newline at end of file
+}