Java Code Examples for org.apache.tinkerpop.gremlin.structure.Element#property()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Element#property() . 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: ElementHelper.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Assign key/value pairs as properties to an {@link Element}.  If the value of {@link T#id} or
 * {@link T#label} is in the set of pairs, then they are ignored.
 *
 * @param element           the graph element to assign the {@code propertyKeyValues}
 * @param propertyKeyValues the key/value pairs to assign to the {@code element}
 * @throws ClassCastException       if the value of the key is not a {@link String}
 * @throws IllegalArgumentException if the value of {@code element} is null
 */
public static void attachProperties(final Element element, final Object... propertyKeyValues) {
    if (null == element)
        throw Graph.Exceptions.argumentCanNotBeNull("element");

    final boolean allowNullPropertyValues = element instanceof Vertex ?
            element.graph().features().vertex().supportsNullPropertyValues() : element instanceof Edge ?
            element.graph().features().edge().supportsNullPropertyValues() :
            element.graph().features().vertex().properties().supportsNullPropertyValues();

    for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
        if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label))
            if (!allowNullPropertyValues && null == propertyKeyValues[i + 1])
                element.properties(((String) propertyKeyValues[i])).forEachRemaining(Property::remove);
            else
                element.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]);
    }
}
 
Example 2
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 3
Source File: UpdateBy.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
@Override
public Element property(Element element, Update update) {
  if (update.getKeyValues() != null) {
    ((Vertex) element).property(update.getCardinality(),
        update.getKey(),
        update.getValue(),
        update.getKeyValues());
  } else {
    element.property(update.getKey(), update.getValue());
  }
  return element;
}
 
Example 4
Source File: GraphTypeManager.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private static Set<String> getTypeProperties(Element abstractElement)
{
    Set<String> results = new HashSet<>();
    Iterator<? extends Property> properties = null;
    if (abstractElement instanceof Vertex)
    {
        // LOG.info("Getting from standardvertex as properties method");
        properties = ((Vertex) abstractElement).properties(WindupFrame.TYPE_PROP);
    }
    else if (abstractElement instanceof JanusGraphEdge)
    {
        Property<String> typeProperty = abstractElement.property(WindupFrame.TYPE_PROP);
        if (typeProperty.isPresent())
        {
            List<String> all = Arrays.asList(((String) typeProperty.value()).split("\\|"));
            results.addAll(all);
            return results;
        }
    }
    else
    {
        // LOG.info("Using the old style properties method");
        properties = Collections.singleton(abstractElement.property(WindupFrame.TYPE_PROP)).iterator();
    }

    if (properties == null)
        return results;

    properties.forEachRemaining(property -> {
        if (property.isPresent())
            results.add((String) property.value());
    });
    return results;
}
 
Example 5
Source File: DefaultValueInitializer.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void setupDefaults(Element element, LinkedList<PropertyDefaultValue> values)
{
    for (PropertyDefaultValue pValue : values)
    {
        element.property(pValue.key, pValue.value);
    }
}
 
Example 6
Source File: GraphTypeManager.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void addTokenProperty(Element el, String propertyName, String propertyValue)
{
    Property<String> val = el.property(propertyName);
    if (!val.isPresent())
        el.property(propertyName, propertyValue);
    else
        el.property(propertyName, val.value() + "|" + propertyValue);
}
 
Example 7
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void setModified(Element element, Change modified) {
  final String value = jsnO(
    "timeStamp", jsn(modified.getTimeStamp()),
    "userId", jsn(modified.getUserId())
  ).toString();
  element.property("modified", value);
}
 
Example 8
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void setModified(Element element, String userId, Instant instant) {
  final String value = jsnO(
    "timeStamp", jsn(instant.toEpochMilli()),
    "userId", jsn(userId)
  ).toString();
  element.property("modified", value);
}
 
Example 9
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void setCreated(Element element, String userId, Instant instant) {
  final String value = jsnO(
    "timeStamp", jsn(instant.toEpochMilli()),
    "userId", jsn(userId)
  ).toString();
  element.property("created", value);
  element.property("modified", value);
}
 
Example 10
Source File: PolymorphicTypeResolver.java    From Ferma with Apache License 2.0 5 votes vote down vote up
@Override
public Class<?> resolve(final Element element) {
    final Property<String> typeResolutionName = element.<String>property(this.typeResolutionKey);

    if( typeResolutionName.isPresent() )
        return this.reflectionCache.forName(typeResolutionName.value());
    else
        return null;
}
 
Example 11
Source File: JsonNodeParsers.java    From atlas with Apache License 2.0 5 votes vote down vote up
public Element update(Graph gr, Object id, Map<String,Object> schema) {
    Element el = get(gr, id);

    for (Map.Entry<String, Object> entry : schema.entrySet()) {
        el.property(entry.getKey(), entry.getValue());
    }

    return el;
}
 
Example 12
Source File: PolymorphicTypeResolver.java    From Ferma with Apache License 2.0 4 votes vote down vote up
@Override
public void init(final Element element, final Class<?> kind) {
    element.property(this.typeResolutionKey, kind.getName());
}
 
Example 13
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setCreated(Element element, String userId) {
  String value = getFormattedUpdateString(userId);
  element.property("created", value);
  element.property("modified", value);
}
 
Example 14
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setModified(Element element, String userId) {
  String value = getFormattedUpdateString(userId);
  element.property("modified", value);
}
 
Example 15
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setTimId(Element element) {
  element.property("tim_id", UUID.randomUUID().toString());
}
 
Example 16
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setTimId(Element element, String timId) {
  element.property("tim_id", timId);
}
 
Example 17
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setRev(Element element, int rev) {
  element.property("rev", rev);
}
 
Example 18
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setIsLatest(Element element, boolean isLatest) {
  element.property("isLatest", isLatest);
}
 
Example 19
Source File: SystemPropertyModifier.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public void setIsDeleted(Element element, boolean isDeleted) {
  element.property("deleted", isDeleted);
}
 
Example 20
Source File: DocumentGraphFactory.java    From baleen with Apache License 2.0 4 votes vote down vote up
protected Object setProperty(Element v, String key, Object value) {
  return v.property(key, coerce(value));
}