streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eponvert <...@git.apache.org>
Subject [GitHub] incubator-streams pull request: found and fixed a bug with GraphHt...
Date Mon, 06 Jul 2015 16:03:20 GMT
Github user eponvert commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/240#discussion_r33950499
  
    --- Diff: streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHttpPersistWriter.java
---
    @@ -84,54 +86,79 @@ else if( configuration.getType().equals(GraphHttpConfiguration.Type.REXSTER))
{
         protected ObjectNode preparePayload(StreamsDatum entry) {
     
             Activity activity = null;
    +        ActivityObject activityObject = null;
     
             if (entry.getDocument() instanceof Activity) {
                 activity = (Activity) entry.getDocument();
    -        } else if (entry.getDocument() instanceof ObjectNode) {
    -            activity = mapper.convertValue(entry.getDocument(), Activity.class);
    -        } else if (entry.getDocument() instanceof String) {
    -            try {
    -                activity = mapper.readValue((String) entry.getDocument(), Activity.class);
    -            } catch (Throwable e) {
    -                LOGGER.warn(e.getMessage());
    +        } else if (entry.getDocument() instanceof ActivityObject) {
    +            activityObject = (ActivityObject) entry.getDocument();
    +        } else {
    +            ObjectNode objectNode;
    +            if (entry.getDocument() instanceof ObjectNode) {
    +                objectNode = (ObjectNode) entry.getDocument();
    +            } else if( entry.getDocument() instanceof String) {
    +                try {
    +                    objectNode = mapper.readValue((String) entry.getDocument(), ObjectNode.class);
    +                } catch (IOException e) {
    +                    LOGGER.error("Can't handle input: ", entry);
    +                    return mapper.createObjectNode();
    +                }
    +            } else {
    +                LOGGER.error("Can't handle input: ", entry);
    +                return mapper.createObjectNode();
    +            }
    +
    +            if( objectNode.get("verb") != null ) {
    +                try {
    +                    activity = mapper.convertValue(objectNode, Activity.class);
    +                } catch (Exception e) {
    +                    activityObject = mapper.convertValue(objectNode, ActivityObject.class);
    +                }
    +            } else {
    +                activityObject = mapper.convertValue(objectNode, ActivityObject.class);
                 }
             }
     
    -        Preconditions.checkNotNull(activity);
    +        Preconditions.checkArgument(activity != null || activityObject != null);
     
             ObjectNode request = mapper.createObjectNode();
             ArrayNode statements = mapper.createArrayNode();
     
    -        activity.getActor().setObjectType("page");
    -
             // always add vertices first
     
    -        List<String> labels = Lists.newArrayList();
    -        if( activity.getProvider() != null &&
    -                !Strings.isNullOrEmpty(activity.getProvider().getId()) ) {
    -            labels.add(activity.getProvider().getId());
    -        }
    +        List<String> labels = Lists.newArrayList("streams");
     
    -        if( activity.getActor() != null &&
    -                !Strings.isNullOrEmpty(activity.getActor().getId()) ) {
    -            if( activity.getActor().getObjectType() != null )
    -                labels.add(activity.getActor().getObjectType());
    -            statements.add(httpGraphHelper.createHttpRequest(queryGraphHelper.mergeVertexRequest(activity.getActor())));
    +        if( activityObject != null ) {
    +            if (activityObject.getObjectType() != null)
    +                labels.add(activityObject.getObjectType());
    +            statements.add(httpGraphHelper.createHttpRequest(queryGraphHelper.mergeVertexRequest(activityObject)));
             }
     
    -        if( activity.getObject() != null &&
    -                !Strings.isNullOrEmpty(activity.getObject().getId()) ) {
    -            if( activity.getObject().getObjectType() != null )
    -                labels.add(activity.getObject().getObjectType());
    -            statements.add(httpGraphHelper.createHttpRequest(queryGraphHelper.mergeVertexRequest(activity.getObject())));
    -        }
    +        if( activity != null ) {
    +            if( activity.getProvider() != null &&
    --- End diff --
    
    More style points, similar comment as before, basically -- I'd save `provider`, `actor`,
`object` variables here, I think would be more readable than calling `activity.getProvider()`
etc in what follows.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message