Java Code Examples for org.apache.tinkerpop.gremlin.structure.Property#value()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Property#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasJanusElement.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T getProperty(String propertyName, Class<T> clazz) {

    //add explicit logic to return null if the property does not exist
    //This is the behavior Atlas expects.  Janus throws an exception
    //in this scenario.
    Property p = getWrappedElement().property(propertyName);
    if (p.isPresent()) {
        Object propertyValue= p.value();
        if (propertyValue == null) {
            return null;
        }
        if (AtlasEdge.class == clazz) {
            return (T)graph.getEdge(propertyValue.toString());
        }
        if (AtlasVertex.class == clazz) {
            return (T)graph.getVertex(propertyValue.toString());
        }
        return (T)propertyValue;

    }
    return null;
}
 
Example 2
Source File: Titan1Element.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T getProperty(String propertyName, Class<T> clazz) {

    //add explicit logic to return null if the property does not exist
    //This is the behavior Atlas expects.  Titan 1 throws an exception
    //in this scenario.
    Property p = getWrappedElement().property(propertyName);
    if (p.isPresent()) {
        Object propertyValue= p.value();
        if (propertyValue == null) {
            return null;
        }
        if (AtlasEdge.class == clazz) {
            return (T)graph.getEdge(propertyValue.toString());
        }
        if (AtlasVertex.class == clazz) {
            return (T)graph.getVertex(propertyValue.toString());
        }
        return (T)propertyValue;

    }
    return null;
}
 
Example 3
Source File: PolymorphicTypeResolver.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Class<? extends T> resolve(final Element element, final Class<T> kind) {
    final Property<String> nodeClazzProperty = element.<String>property(this.typeResolutionKey);
    final String nodeClazz;
    if( nodeClazzProperty.isPresent() )
        nodeClazz = nodeClazzProperty.value();
    else
        return kind;

    final Class<T> nodeKind = (Class<T>) this.reflectionCache.forName(nodeClazz);

    if (kind.isAssignableFrom(nodeKind) || kind.equals(VertexFrame.class) || kind.equals(EdgeFrame.class) || kind.equals(AbstractVertexFrame.class) || kind.equals(AbstractEdgeFrame.class) || kind.
          equals(Object.class))
        return nodeKind;
    else
        return kind;
}
 
Example 4
Source File: LogEntryFactory.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
public LogEntry createForEdge(Edge edge) throws IllegalArgumentException {
  Property<Integer> revProp = edge.property("rev");
  if (!revProp.isPresent()) {
    String id = edge.value("tim_id");
    throw new IllegalArgumentException(
      String.format("Edge with id '%s' has no property 'rev'. This edge will be ignored.", id)
    );
  }
  Integer rev = revProp.value();

  if (rev > 1) {
    Edge prevEdge = edgeRetriever.getPreviousVersion(edge);

    return new UpdateEdgeLogEntry(edge, prevEdge);
  }
  return new CreateEdgeLogEntry(edge);

}
 
Example 5
Source File: ClassificationService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided {@link FileModel}.
 */
public int getMigrationEffortPoints(FileModel fileModel)
{
    GraphTraversal<Vertex, Vertex> classificationPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement());
    classificationPipeline.in(ClassificationModel.FILE_MODEL);
    classificationPipeline.has(EffortReportModel.EFFORT, P.gt(0));
    classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE));

    int classificationEffort = 0;
    for (Vertex v : classificationPipeline.toList())
    {
        Property<Integer> migrationEffort = v.property(ClassificationModel.EFFORT);
        if (migrationEffort.isPresent())
        {
            classificationEffort += migrationEffort.value();
        }
    }
    return classificationEffort;
}
 
Example 6
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static boolean testProperty(Property<?> prop, Object expected) {
    Object actual = prop.value();
    P<Object> predicate;
    if (expected instanceof String &&
        ((String) expected).startsWith(TraversalUtil.P_CALL)) {
        predicate = TraversalUtil.parsePredicate(((String) expected));
    } else {
        predicate = ConditionP.eq(expected);
    }
    updatePredicateValue(predicate, ((HugeProperty<?>) prop).propertyKey());
    return predicate.test(actual);
}
 
Example 7
Source File: GraphOMRSRelationshipMapper.java    From egeria with Apache License 2.0 5 votes vote down vote up
private Object getEdgeProperty(Edge edge, String propName)
{
    Property ep = edge.property(propName);
    if (ep == null || !ep.isPresent())
        return null;
    else
        return ep.value();
}
 
Example 8
Source File: AtlasJanusElement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void removePropertyValue(String propertyName, Object propertyValue) {
    Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);

    while (it.hasNext()) {
        Property currentProperty      = it.next();
        Object   currentPropertyValue = currentProperty.value();

        if (Objects.equals(currentPropertyValue, propertyValue)) {
            currentProperty.remove();
            break;
        }
    }
}
 
Example 9
Source File: AtlasJanusElement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void removeAllPropertyValue(String propertyName, Object propertyValue) {
    Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);

    while (it.hasNext()) {
        Property currentProperty      = it.next();
        Object   currentPropertyValue = currentProperty.value();

        if (Objects.equals(currentPropertyValue, propertyValue)) {
            currentProperty.remove();
        }
    }
}
 
Example 10
Source File: AbstractElementFrame.java    From Ferma with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getProperty(final String name) {
    final Property<T> property = getElement().<T>property(name);
    if( property.isPresent())
        return property.value();
    else
        return null;
}
 
Example 11
Source File: AbstractElementFrame.java    From Ferma with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getProperty(final String name, final Class<T> type) {
    final Property<T> nameProperty = getElement().property(name);
    if( !nameProperty.isPresent() )
        return null;
    final T nameValue = nameProperty.value();

    if (type.isEnum()) {
        return (T) Enum.valueOf((Class<Enum>) type, nameValue.toString());
    }
    return nameValue;
}
 
Example 12
Source File: MapInAdjacentPropertiesHandler.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Getter
 */
private static Map<String, Serializable> handleGetter(Vertex vertex, Method method, Object[] args,
            MapInAdjacentProperties ann)
{
    if (args != null && args.length != 0)
        throw new WindupException("Method must take no arguments: " + method.getName());

    // Find the map vertex.
    Map<String, Serializable> map = new HashMap<>();
    Iterator<Vertex> it = vertex.vertices(Direction.OUT, ann.label());
    Vertex mapVertex = null;
    if (!it.hasNext())
    {
        // No map yet.
        return map;
    }
    else
    {
        mapVertex = it.next();
        if (it.hasNext())
        {
            // Multiple vertices behind edges with given label.
            log.warning("Found multiple vertices for a map, using only first one; for: " + method.getName());
        }
    }

    Set<String> keys = mapVertex.keys();
    for (String key : keys)
    {
        final Property<Object> val = mapVertex.property(key);
        if (!val.isPresent() || !(val.value() instanceof String))
            log.warning("@InProperties is meant for Map<String,Serializable>, but the value was: " + val.getClass());
        map.put(key, "" + val.value());
    }
    return map;
}
 
Example 13
Source File: JoinQueryExecutor.java    From sql-gremlin with Apache License 2.0 4 votes vote down vote up
private List<Object> project(Map<String, String> fieldToTableMap, List<String> fields,
                               List<Map<String, ? extends Element>> results,
                               Map<String, TableDef> tableIdToTableDefMap) {
    final List<Object> rows = new ArrayList<>(results.size());
    Map<String, String> labelTableIdMap = new HashMap<>();
    for (Map.Entry<String, TableDef> entry : tableIdToTableDefMap.entrySet()) {
        labelTableIdMap.put(entry.getValue().label.toLowerCase(), entry.getKey());
    }
    for(Map<String, ? extends Element> result : results) {
        final Object[] row = new Object[fields.size()];
        int column = 0;
        for(String field : fields) {
            String tableId = fieldToTableMap.get(field);
            String simpleFieldName = Character.isDigit(field.charAt(field.length()-1)) ?
                    field.substring(0, field.length()-1) : field;
            simpleFieldName = Character.isDigit(field.charAt(simpleFieldName.length()-1)) ?
                    simpleFieldName.substring(0, simpleFieldName.length()-1) : simpleFieldName;
            // check for primary & fks
            final int keyIndex = simpleFieldName.toLowerCase().indexOf("_id");
            Object val = null;
            if(keyIndex > 0) {
                // is it a pk or fk?
                String key = simpleFieldName.substring(0, keyIndex);
                String tableLabel = tableIdToTableDefMap.get(tableId).label;
                if(tableLabel.toLowerCase().equals(key.toLowerCase())) {
                    val = result.get(tableId).id();
                } else {
                    String fkTableId = labelTableIdMap.get(key.toLowerCase());
                    if(result.containsKey(fkTableId)) {
                        val = result.get(fkTableId).id();
                    }
                }
            }
            final Property<Object> property = result.get(tableId).
                    property(tableIdToTableDefMap.get(tableId).getColumn(simpleFieldName.toLowerCase()).getPropertyName());
            if(!(property instanceof EmptyProperty || property instanceof EmptyVertexProperty)) {
                if(result.get(tableId).label().equals(tableIdToTableDefMap.get(tableId).label)) {
                    val = property.value();
                } else {
                    val = null;
                }
            }
            if(tableIdToTableDefMap.get(tableId).getColumn(field) != null && val != null) {
                row[column++] = TableUtil.convertType(val, tableIdToTableDefMap.get(tableId).getColumn(field));
            } else {
                row[column++] = val;
            }
        }
        rows.add(row);
    }
    return rows;
}
 
Example 14
Source File: DetachedProperty.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
protected DetachedProperty(final Property<V> property) {
    this.key = property.key();
    this.value = property.value();
    this.element = DetachedFactory.detach(property.element(), false);
}
 
Example 15
Source File: ReferenceProperty.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public ReferenceProperty(final Property<V> property) {
    this.element = null == property.element() ? null : ReferenceFactory.detach(property.element());
    this.key = property.key();
    this.value = property.value();
}
 
Example 16
Source File: InvariantsCheck.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
private boolean isAccepted(Edge edge, String edgeType) {
  String acceptedProp = String.format("%s_accepted", edgeType);
  Property<Boolean> property = edge.property(acceptedProp);
  return property.isPresent() && property.value();
}