Class EntityItem

java.lang.Object
com.priint.pubserver.plugin.entitydata.EntityItem
All Implemented Interfaces:
Serializable

public class EntityItem extends Object implements Serializable
Serialization class for all types of entity data for insert, update or removal.

An item is described by an entityClass, entityIdentifier and identifier like "Bucket#product#0815".

An operation for the item is defined as a ConnectorPersistRemote.PushCommand with field values meaning "insert", "update", "upsert", "delete", etc..

Data can be attached as full item, e.g. a Bucket or a TableData object (for insert).

Data can be attached as patch (or "diff") (for update). A patch is actually a hash map of field values.

The result of an operation can be provided as a EntityItem.Status (like "processing", "updated", "failed", etc.). The status can be detailed by a textual message.

Create EntityItems through one of the provided factory methods.

See Also:
  • Constructor Details

    • EntityItem

      public EntityItem()
      Empty default constructor for JAXB
  • Method Details

    • createPatch

      public static Map<String,Object> createPatch(EntityData item1, EntityData item2)
      Create a map of all fields where values differ between item 1 and item 2.

      This compares only fields that are listed in the @XmlType propOrder attribute of the class.

      Parameters:
      item1 -
      item2 -
      Returns:
      Map of differences or empty map.
      Throws:
      IllegalArgumentException - if a property cannot be read in item1 or item2.
    • instanceForDelete

      public static EntityItem instanceForDelete(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Context context)
      Create a new instance to delete an entity item.
      Parameters:
      entityClass -
      entityIdentifier -
      identifier -
      context -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if any of the arguments is null.
    • instanceForDelete

      public static EntityItem instanceForDelete(Entity.DataClass dataClass, String entityIdentifier, String identifier, Context context)
      Create a new instance to delete an entity item.
      Parameters:
      dataClass -
      entityIdentifier -
      identifier -
      context -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if any of the arguments is null.
    • instanceForDelete

      public static EntityItem instanceForDelete(EntityData value)
      Create a new instance to delete an entity item.
      Parameters:
      value -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if the value argument or its entityIdentifier or identifier is null.
    • instanceForInsert

      public static EntityItem instanceForInsert(EntityData value)
      Create a new instance to insert an entity item.
      Parameters:
      value - Bucket, text, etc. to be inserted.
      Returns:
      new EntityItem for INSERT
      Throws:
      IllegalArgumentException - if value or type is not supported for this operation.
    • instanceForUpdate

      public static EntityItem instanceForUpdate(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Map<String,Object> patch, Context context)
      Create a new instance to update an entity item.
      Parameters:
      entityClass -
      entityIdentifier -
      identifier -
      patch -
      context -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if any of the arguments is null.
    • instanceForUpdate

      public static EntityItem instanceForUpdate(Entity.DataClass dataClass, String entityIdentifier, String identifier, Map<String,Object> patch, Context context)
      Create a new instance to update an entity item.
      Parameters:
      dataClass -
      entityIdentifier -
      identifier -
      patch -
      context -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if any of the arguments is null.
    • instanceForUpdate

      public static EntityItem instanceForUpdate(EntityData oldValue, EntityData newValue)
      Create a new instance to update an entity item.

      OldValue and newValue will be compared to create a patch.

      Parameters:
      oldValue -
      newValue -
      Returns:
      EntityItem
      Throws:
      IllegalArgumentException - if oldValue or newValue are empty of types do not match.
    • getCommand

      Operation that should be executed on this item.
      Returns:
      command
    • getConnectorEntity

      public ConnectorEntity getConnectorEntity()
      Get connector entity for this item.

      This will NOT read the connector entity from the embedded value in INSERT operations.

      Normally, connectorEntity will be automatically handled by the entity manager.

      Use this method only if you are directly dealing with a connector.

      Returns:
      connectorEntity
    • getDataClass

      public Entity.DataClass getDataClass()
      Data class value for this item. It is preferred to use the getEntityClass() instead.
      Returns:
      dataClass
    • getEntityClass

      public Class<? extends EntityData> getEntityClass()
      EntityData class of this item
      Returns:
      class
    • getEntityIdentifier

      public String getEntityIdentifier()
      Identifier of the entity type in its entityModel.

      Should never be null.

      Returns:
      entityIdentifier
    • getIdentifier

      public String getIdentifier()
      Identifier of the entity item in its data source.

      Should never be null.

      Returns:
      identifier
    • getMessage

      public String getMessage()
      Returns:
      status message of the operation defined in getCommand(). This may contain reasons in case of failure or exception.
    • getPatch

      public Map<String,Object> getPatch()
      Retrieve a map of patch values for an update. A field patch is defined as an entry with key=fieldName and value=someObject. This makes-up a DIFF between old and new values for the item.

      Values can be of any object type here. But during real update process the type must match the actual type of the target field. Otherwise an exception will be raised or the field is silently skipped. Please read the documentation of the update method you are calling.

      Returns:
      patch
    • getStatus

      public EntityItem.Status getStatus()
      Returns:
      status value of the operation defined in getCommand().
    • getValue

      public EntityData getValue()
      Retrieve EntityData value for the item. This MUST be set for INSERT operations. It will normally be null for UPDATE and DELETE.
      Returns:
      value
    • getContext

      public Context getContext()
      Returns:
      The context of the entity
    • setConnectorEntity

      public void setConnectorEntity(ConnectorEntity connectorEntity)
      Set connector entity for this item.

      This is only needed for update actions, where ConnectorEntity cannot be attached to the item itself.

      Normally, connectorEntity will be automatically handled by the entity manager.

      Use this method only if you are directly dealing with a connector.

      Parameters:
      connectorEntity -
    • setMessage

      public void setMessage(String message)
      Parameters:
      message -
      See Also:
    • setStatus

      public void setStatus(EntityItem.Status status)
      Parameters:
      status -
      See Also:
    • setValue

      public void setValue(EntityData value)
      Set EntityData value for the item.
      Parameters:
      value -
    • toString

      public String toString()
      Overrides:
      toString in class Object