Merge "Fix sonar violations"
authorTian Lee <TianL@amdocs.com>
Mon, 9 Jul 2018 09:08:59 +0000 (09:08 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 9 Jul 2018 09:08:59 +0000 (09:08 +0000)
1  2 
src/main/java/org/onap/crud/service/AaiResourceService.java

@@@ -22,6 -22,7 +22,7 @@@ package org.onap.crud.service
  \r
  import java.security.cert.X509Certificate;\r
  import java.util.AbstractMap;\r
+ import java.util.Arrays;\r
  import java.util.HashSet;\r
  import java.util.Map;\r
  import java.util.Map.Entry;\r
@@@ -54,11 -55,10 +55,11 @@@ import org.onap.aaiauth.auth.Auth
  import org.onap.crud.exception.CrudException;\r
  import org.onap.crud.logging.CrudServiceMsgs;\r
  import org.onap.crud.logging.LoggingUtil;\r
 +import org.onap.crud.parser.EdgePayload;\r
 +import org.onap.crud.parser.util.EdgePayloadUtil;\r
  import org.onap.crud.service.CrudRestService.Action;\r
  import org.onap.crud.util.CrudServiceConstants;\r
  import org.onap.schema.EdgeRulesLoader;\r
 -import org.onap.schema.RelationshipSchemaValidator;\r
  import org.slf4j.MDC;\r
  import com.google.gson.Gson;\r
  import com.google.gson.JsonElement;\r
@@@ -398,15 -398,16 +399,15 @@@ public class AaiResourceService 
    public EdgePayload applyEdgeRulesToPayload(EdgePayload payload) throws CrudException {\r
  \r
      // Extract the types for both the source and target vertices.\r
 -    String srcType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getSource());\r
 -    String tgtType = RelationshipSchemaValidator.vertexTypeFromUri(payload.getTarget());\r
 +    String srcType = EdgePayloadUtil.getVertexNodeType(payload.getSource());\r
 +    String tgtType = EdgePayloadUtil.getVertexNodeType(payload.getTarget());\r
  \r
 -      // Now, get the default properties for this edge based on the edge rules definition...\r
 -      Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);\r
 -\r
 -      // ...and merge them with any custom properties provided in the request.\r
 -      JsonElement mergedProperties = mergeProperties(payload.getProperties(), props);\r
 -      payload.setProperties(mergedProperties);\r
 +    // Now, get the default properties for this edge based on the edge rules definition...\r
 +    Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);\r
  \r
 +    // ...and merge them with any custom properties provided in the request.\r
 +    JsonElement mergedProperties = mergeProperties(payload.getProperties(), props);\r
 +    payload.setProperties(mergedProperties);\r
  \r
      if(logger.isDebugEnabled()) {\r
        logger.debug("Edge properties after applying rules for '" + srcType + " -> " + tgtType + "': " + mergedProperties);\r
     *\r
     * @throws CrudException\r
     */\r
 +  @SuppressWarnings("unchecked")\r
    public JsonElement mergeProperties(JsonElement propertiesFromRequest, Map<EdgeProperty, String> propertyDefaults) throws CrudException {\r
  \r
      // Convert the properties from the edge payload into something we can\r
          authUser = subjectDn.toString();\r
        }\r
  \r
-       return this.auth.validateRequest(authUser.toLowerCase(), action.toString() + ":" + authPolicyFunctionName);\r
+       return this.auth.validateRequest(authUser!=null ? authUser.toLowerCase():"", action.toString() + ":" + authPolicyFunctionName);\r
  \r
      } catch (Exception e) {\r
        logResult(action, uri, e);\r
  \r
      logger.error(CrudServiceMsgs.EXCEPTION_DURING_METHOD_CALL,\r
                   op.toString(),\r
-                  uri,\r
-                  e.getStackTrace().toString());\r
+                  uri, Arrays.toString(e.getStackTrace()));\r
  \r
      // Clear the MDC context so that no other transaction inadvertently\r
      // uses our transaction id.\r