Biblioteca Java - Rev 18

Subversion Repositories:
Rev:
/**
 * Licensed to Neo Technology under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Neo Technology licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */


package com.linkscreens.graphsin.repository;

import java.util.Date;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.helpers.collection.IteratorUtil;


public class StatusUpdateNode
{
    private final Node underlyingNode;
    static final String TEXT = "TEXT";
    static final String DATE = "DATE";

    public StatusUpdateNode( Node underlyingNode )
    {

        this.underlyingNode = underlyingNode;
    }

    public Node getUnderlyingNode()
    {
        return underlyingNode;
    }

    public PersonNode getPerson()
    {
        return new PersonNode( getPersonNode() );
    }

    private Node getPersonNode()
    {
        TraversalDescription traversalDescription = underlyingNode.getGraphDatabase()
                .traversalDescription()
                .depthFirst()
                .relationships( RelTypes.NEXT, Direction.INCOMING )
                .relationships( RelTypes.STATUS, Direction.INCOMING )
                .evaluator( Evaluators.includeWhereLastRelationshipTypeIs( RelTypes.STATUS ) );

        Traverser traverser = traversalDescription.traverse( getUnderlyingNode() );

        return IteratorUtil.singleOrNull( traverser.iterator() ).endNode();
    }

    public String getStatusText()
    {
        return (String) underlyingNode.getProperty( TEXT );
    }

    public Date getDate()
    {
        Long l = (Long) underlyingNode.getProperty( DATE );

        return new Date( l );
    }

}