\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
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
ImmutablePair<EntityTag, String> result = graphDataService.addEdge(EdgeRulesLoader.getLatestSchemaVersion(), type, payload);\r
response = Response.status(Status.CREATED).entity(result.getValue()).tag(result.getKey()).type(mediaType).build();\r
\r
- } catch (CrudException e) {\r
-\r
+ } catch (CrudException ce) {\r
+ response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();\r
+ } catch (Exception e) {\r
response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();\r
}\r
}\r
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
-\r
- // Now, get the default properties for this edge based on the edge rules definition...\r
- Map<EdgeProperty, String> props = getEdgeRuleProperties(srcType, tgtType);\r
+ String srcType = EdgePayloadUtil.getVertexNodeType(payload.getSource());\r
+ String tgtType = EdgePayloadUtil.getVertexNodeType(payload.getTarget());\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