All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.weaverplatform.protocol.model.WriteOperation Maven / Gradle / Ivy

package com.weaverplatform.protocol.model;

import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;

/**
 * @author Mohamad Alamili
 */
public abstract class WriteOperation {
  private WriteOperationAction action;
  private String user, id, graph;
  private long timestamp;
  private transient String payload;
  private Boolean upsert;

  public WriteOperation(String user, String id) {
    this.user = user;
    this.id = id;
    this.timestamp = System.currentTimeMillis();
    this.action = this.getAction();
  }

  public WriteOperation(String user, String id, Boolean upsert) {
    this.user = user;
    this.id = id;
    this.timestamp = System.currentTimeMillis();
    this.action = this.getAction();
    this.upsert = upsert;
  }

  public abstract WriteOperationAction getAction();

  public String toJson() {
    return new GsonBuilder()
    .registerTypeAdapter(AttributeValue.class, new AttributeValue.AttributeValueSerializer())
    .create().toJson(this);
  }

  public String getUser() {
    return user;
  }

  public void setTimestamp(long timestamp) {
    this.timestamp = timestamp;
  }

  public String getGraph() {
    return graph;
  }

  public void setGraph(String graph) {
    this.graph = graph;
  }

  public void setUser(String user) {
    this.user = user;
  }

  public String getId() {
    return id;
  }

  public long getTimestamp() {
    return timestamp;
  }

  public void setPayload(String payload) {
    this.payload = payload;
  }

  public String getPayload() {
    return payload;
  }

  public Boolean getUpsert() {
    return upsert;
  }

  public void setUpsert(Boolean upsert) {
    this.upsert = upsert;
  }

  public enum WriteOperationAction {
    @SerializedName("create-node")                CREATE_NODE("create-node"),
    @SerializedName("change-node-id")             CHANGE_NODE_ID("change-node-id"),
    @SerializedName("change-node-graph")          CHANGE_NODE_GRAPH("change-node-graph"),
    @SerializedName("create-relation")            CREATE_RELATION("create-relation"),
    @SerializedName("change-relation-key")        CHANGE_RELATION_KEY("change-relation-key"),
    @SerializedName("create-attribute")           CREATE_ATTRIBUTE("create-attribute"),
    @SerializedName("change-attribute-key")       CHANGE_ATTRIBUTE_KEY("change-attribute-key"),
    @SerializedName("remove-node")                REMOVE_NODE("remove-node"),
    @SerializedName("remove-node-unrecoverable")  REMOVE_NODE_UNRECOVERABLE("remove-node-unrecoverable"),
    @SerializedName("remove-relation")            REMOVE_RELATION("remove-relation"),
    @SerializedName("remove-attribute")           REMOVE_ATTRIBUTE("remove-attribute"),
    @SerializedName("truncate-graph")             TRUNCATE_GRAPH("truncate-graph"),
    @SerializedName("add-to-set")                 ADD_TO_SET("add-to-set"),
    @SerializedName("remove-from-set")            REMOVE_FROM_SET("remove-from-set");

    private String value;

    WriteOperationAction(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy