Class ItemCollection

java.lang.Object
org.imixs.workflow.ItemCollection
All Implemented Interfaces:
Cloneable

public class ItemCollection extends Object implements Cloneable
This Class defines a ValueObject to be used to exchange data structures used by the org.imixs.workflow Framework. Most components of this framework use this wrapper class to easy transport workflow data between the different workflow modules. ValueObjects, particular in J2EE Applications, have the advantage to improve performance of remote method calls. The Imixs ItemCcollection enables a very flexibly and easy to use data structure.

A ItemCollection contains various Items (attributes). Every Item exist of a Name (String) and a list of values (List of Object). Internal every Value is stored inside a Vector Class. All values are stored internally in a Map containing key values pairs.

NOTE: An ItemCollection is not serializable and can not be stored into another ItemCollection. To serialize a ItemCollection use the XMLItemCollection. @see XMLItemCollectionAdapter.

Version:
2.1
Author:
Ralph Soika
See Also:
  • Constructor Details

    • ItemCollection

      public ItemCollection()
      Creates a new empty ItemCollection
    • ItemCollection

      public ItemCollection(Map<String,List<Object>> map)
      Creates a new ItemCollection and makes a deep copy from a given value Map
      Parameters:
      map - - with item values
    • ItemCollection

      public ItemCollection(ItemCollection itemCol)
      Creates a new ItemCollection and makes a deep copy from a given ItemCollection
      Parameters:
      itemCol - - ItemCollection with values
  • Method Details

    • createByReference

      public static ItemCollection createByReference(Map<String,List<Object>> map)
      Creates a new ItemCollection by a reference to a given value Map. This method does not make a deep copy of the given map and sets the value map by reference. This method can be used in cases where values are only read. In all other cases, the constructor method 'ItemCollection(map)' should be used.
      Parameters:
      map - - reference with item values
      Returns:
      new reference
    • clone

      public Object clone()
      This method clones the current ItemCollection. The method makes a deep copy of the current instance.
      Overrides:
      clone in class Object
    • clone

      public ItemCollection clone(List<String> itemNames)
      This method clones the current ItemCollection with a subset of items. The method makes a deep copy of the current instance and removes items not defined by the list of itemNames.

      The list of itemNames can contain exact names or a regular expression.

      A itemName can also be mapped into a new itemName by separating the target name with a | (e.g. name|parentName)

      Parameters:
      itemNames - - list of items to be copied into the clone
      Returns:
      new ItemCollection
    • cloneItem

      public void cloneItem(String itemName, ItemCollection source)
      This method makes a deep copy of a single item value from a given source ItemCollection. The method can be used in cases the item to copy represents a complex data structure and can not be copied by reference. See also deepCopyOfMap.
      Parameters:
      itemvalue -
    • equals

      public boolean equals(Object o)
      This method compares the values of two item collections by comparing the hash maps. This did not garantie that also embedded arrays are equal.
      Overrides:
      equals in class Object
    • setItemValue

      public ItemCollection setItemValue(String itemName, Object itemValue)
      Set the value of an item. If the ItemCollection does not contain an item with the specified name, the method creates a new item and adds it to the ItemCollection. The ItemName is not case sensitive. Use hasItem to verify the existence of an item. All item names will be lower cased.

      Each item can contain a list of values (multivalue item). If a single value is provided the method creates a List with one single value (singlevalue item).

      If the value is null the method will remove the item. This is equal to the method call removeItem()

      If the ItemValue is not serializable the item will be removed.

      Parameters:
      itemName - The name of the item or items you want to replace.
      itemValue - The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.
      Returns:
      current instance
    • setItemValueUnique

      public ItemCollection setItemValueUnique(String itemName, Object itemValue)
      Set the value of an item. If the ItemCollection does not contain an item with the specified name, the method creates a new item and adds it to the ItemCollection. The ItemName is not case sensitive. Use hasItem to verify the existence of an item. All item names will be lower cased.

      Each item can contain a list of values (multivalue item). If a single value is provided the method creates a List with one single value (singlevalue item).

      If the value is null the method will remove the item. This is equal to the method call removeItem()

      If the ItemValue is not serializable the item will be removed.

      This method ensures that all values are unique and null or empty values will be removed

      Parameters:
      itemName - The name of the item or items you want to replace.
      itemValue - The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.
      Returns:
      current instance
    • appendItemValue

      public ItemCollection appendItemValue(String itemName, Object itemValue)
      Appends a value to an existing item. If the ItemCollection does not contain an item with the specified name, the method creates a new item and adds it to the ItemCollection. The ItemName is not case sensitive. Use hasItem to verify the existence of an item. All item names will be lower cased.

      If a value list is provided the method appends each single value.

      If the value is null the method will remove the item. This is equal to the method call removeItem()

      If the ItemValue is not serializable the item will be removed.

      Parameters:
      itemName - The name of the item or items you want to replace.
      itemValue - The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.
      Returns:
      current instance
    • appendItemValueUnique

      public ItemCollection appendItemValueUnique(String itemName, Object itemValue)
      Appends a value to an existing item. If the ItemCollection does not contain an item with the specified name, the method creates a new item and adds it to the ItemCollection. The ItemName is not case sensitive. Use hasItem to verify the existence of an item. All item names will be lower cased.

      If a value list is provided the method appends each single value.

      If the value is null the method will remove the item. This is equal to the method call removeItem()

      If the ItemValue is not serializable the item will be removed.

      This method ensures that all values are unique and null or empty values will be removed

      Parameters:
      itemName - The name of the item or items you want to replace.
      itemValue - The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.
      Returns:
      current instance
    • getItemValue

      public List getItemValue(String itemName)
      Returns the value list for the specified Item. The returned list is untyped and the values contained in the list are not converted to a specific type. The values have the same object type as set by calling the method setItemValue(String itemName, Object itemValue). To get a typed value list, see the method getItemValue(itemName, itemType) .

      If the item does not exist or has no values, the method returns an empty List.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      an untyped list of values contained by the item.
    • getItemValue

      public <T> T getItemValue(String itemName, Class<T> itemType)
      Returns the resolved item value of the specified type. The method converts the value to the specified type if possible, otherwise the method returns null. If the item has multiple values, this method returns the first value.

      If the item isn't present in the itemCollection the method returns null.

      If the specified type is int, float, long, double, Integer, Float, Long or Double, the method returns 0 instead of null

      If the item contains no value with the specified type, the method returns null. The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The item Name.
      itemType - The type into which the resolve item value should get converted
      Returns:
      the resolved item value as an object of the requested type.
    • getItemValueList

      public <T> List<T> getItemValueList(String itemName, Class<T> itemType)
      Returns the resolved list of item values of the specified type. The method converts the values of the list to the specified type if possible.

      If the item isn't present in the itemCollection the method returns an empty list.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The item Name.
      itemType - The type into which the resolved item values should get converted
      Returns:
      the resolved list of item values of the requested type.
    • removeItem

      public void removeItem(String name)
      removes a attribute from the item collection
      Parameters:
      name - - item name
    • hasItem

      public boolean hasItem(String aName)
      Indicates whether an item exists in the document.
      Parameters:
      aName - - item name
      Returns:
      true if an item with name exists in the document, false if no item with name exists in the document
    • isItemEmpty

      public boolean isItemEmpty(String itemName)
      Returns true if the given itemname does not exist or no value is assigned to. This includes empty strings.
      Parameters:
      itemName - - the item to be verified
      Returns:
      - true if no value is assigned.
    • isItemValueInteger

      public boolean isItemValueInteger(String aName)
      Returns true if the value of an item with a single numeric value is from type 'Integer'
      Parameters:
      aName - - item name
      Returns:
      boolean true if object is from type Double
    • isItemValueLong

      public boolean isItemValueLong(String aName)
      Returns true if the value of an item with a single numeric value is from type 'Long'
      Parameters:
      aName - - item name
      Returns:
      boolean true if object is from type Double
    • isItemValueDouble

      public boolean isItemValueDouble(String aName)
      Returns true if the value of an item with a single numeric value is from type 'Double'
      Parameters:
      aName - - item name
      Returns:
      boolean true if object is from type Double
    • isItemValueFloat

      public boolean isItemValueFloat(String aName)
      Returns true if the value of an item with a single numeric value is from type 'Float'
      Parameters:
      aName - - item name
      Returns:
      boolean true if object is from type Double
    • isItemValueNumeric

      public boolean isItemValueNumeric(String aName)
      Returns true if the value of an item is a numeric value (e.g. float,double,int,long)
      Parameters:
      aName -
      Returns:
    • isItemValueDate

      public boolean isItemValueDate(String aName)
      Returns true if the value of an item is from type 'Date'
      Parameters:
      aName - - item name
      Returns:
      boolean true if object is from type Double
    • getAllItems

      public Map<String,List<Object>> getAllItems()
      returns all Items of the Collection as a Map
      Returns:
      Map with all Items
    • setAllItems

      public void setAllItems(Map<String,List<Object>> aHash)
      replaces the current map object. In different to the method replaceAllItems this method overwrites the hash object and did not copy the values
      Parameters:
      aHash -
    • getItemNames

      public List<String> getItemNames()
      Returns a sorted list of all item names stored in the current ItemCollection.
      Returns:
      sorted list of item names
    • replaceItemValue

      public void replaceItemValue(String itemName, Object itemValue)
      Replaces the value of an item. If the ItemCollection does not contain an item with the specified name, the method creates a new item and adds it to the ItemCollection. The ItemName is not case sensitive. Use hasItem to verify the existence of an item. All item names will be lower cased.

      Each item can contain a list of values (multivalue item). If a single value is provided the method creates a List with one single value (singlevalue item).

      If the value is null the method will remove the item. This is equal to the method call removeItem()

      If the ItemValue is not serializable the item will be removed. This method is deprecated and should be replaced by the method setItemvValue.

      Parameters:
      itemName - The name of the item or items you want to replace.
      itemValue - The value of the new item. The data type of the item depends upon the data type of value, and does not need to match the data type of the old item.
      See Also:
      • setItemValue.
    • getItemValueString

      public String getItemValueString(String itemName)
      Returns the resolved String value of the specified item. The method converts the stored value to a String. If the item has no value, the method returns an empty String. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the String value of the item
    • getItemValueInteger

      public int getItemValueInteger(String itemName)
      Returns the resolved Integer value of the specified item. The method converts the stored value to an Integer. If the item has no value or the value is not convertible to an Integer, the method returns 0. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the integer value of the item
    • getItemValueLong

      public long getItemValueLong(String itemName)
      Returns the resolved Long value of the specified item. The method converts the stored value to long. If the item has no value or the value is not convertible to a Long, the method returns 0. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the Long value of the item
    • getItemValueDate

      public Date getItemValueDate(String aName)
      Returns the resolved Date value of the specified item. If the item has no value or the value is not of the type Date, the method returns null. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the Date value of the item
    • getItemValueLocalDateTime

      public LocalDateTime getItemValueLocalDateTime(String aName)
      Returns the resolved LocalDateTime value of the specified item. The method converts a Date object into a LocalDateTime object using the ZoneId.systemDefault().

      Note: internally the ItemCollection store LocalDateTime values as Date objects!

      If the item has no value or the value is not of the type Date, the method returns null. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the Date value of the item
    • getItemValueLocalDate

      public LocalDate getItemValueLocalDate(String aName)
      Returns the resolved LocalDate value of the specified item. The method converts a Date object into a LocalDate object using the ZoneId.systemDefault().

      Note: internally the ItemCollection store LocalDateTime values as Date objects!

      If the item has no value or the value is not of the type Date, the method returns null. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the Date value of the item
    • getItemValueDouble

      public double getItemValueDouble(String itemName)
      Returns the resolved Double value of the specified item. The method converts the stored value to double. If the item has no value or the value is not convertible to a Double, the method returns 0.0. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the double value of the item
    • getItemValueFloat

      public float getItemValueFloat(String itemName)
      Returns the resolved Float value of the specified item. The method converts the stored value to float. If the item has no value or the value is not convertible to a Float, the method returns 0.0. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the float value of the item
    • getItemValueBoolean

      public boolean getItemValueBoolean(String itemName)
      Returns the resolved Boolean value of the specified item. The method converts the stored value to Boolean. If the item has no value or the value is not convertible to a Boolean, the method returns false. If the item has multiple values, this method returns the first value.

      The ItemName is not case sensitive. Use hasItem to verify the existence of an item.

      Parameters:
      itemName - The name of an item.
      Returns:
      the boolean value of the item
    • replaceAllItems

      public void replaceAllItems(Map<String,List<Object>> map)
      Replaces all items specified in the map with new items, which are assigned to the specified values inside the map. The method makes a deep copy of the source map using serialization. This is to make sure, that no object reference is copied. Other wise for example embedded arrays are not cloned. This is also important for JPA to avoid changes of attached entity beans with references in the data of an ItemCollection.
      Parameters:
      map -
      See Also:
      • deepCopyOfMap(java.util.Map<java.lang.String,java.util.List<java.lang.Object>>)
    • copy

      public void copy(ItemCollection source)
      Copies all items of a source ItemCollection.

      The method makes a deep copy of the source map using serialization. This is to make sure, that no object reference is copied. Other wise for example embedded arrays are not cloned. This is also important for JPA to avoid changes of attached entity beans with references in the data of an ItemCollection.

      Parameters:
      map -
      See Also:
      • deepCopyOfMap(java.util.Map<java.lang.String,java.util.List<java.lang.Object>>)
    • mergeItems

      public void mergeItems(Map<String,List<Object>> map)
      Merges all items from a source map into the current instance. Only Items will be copied if the current instance does not have an item with the same name. If you want to copy all item values, use the method replaceAllItems instead.

      The method makes a deep copy of the source map using serialization. This is to make sure, that no object reference is copied. Other wise for example embedded arrays are not cloned. This is also important for JPA to avoid changes of attached entity beans with references in the data of an ItemCollection.

      Parameters:
      map -
      See Also:
      • deepCopyOfMap(java.util.Map<java.lang.String,java.util.List<java.lang.Object>>)
    • purgeItemValue

      public void purgeItemValue(String itemName)
      This method removes duplicates and null or empty values from an item list
      Parameters:
      itemName - - item to be processed
    • addFileData

      public void addFileData(FileData filedata)
      This method adds a fileData object to the ItemCollection. The item '$file' stores all data objects.
      Parameters:
      filedata - - a file data object
      See Also:
    • addFile

      @Deprecated public void addFile(byte[] data, String fileName, String contentType)
      Deprecated.
      This method adds a single file to the ItemCollection. files will be stored into the property $file.
      Parameters:
      data - - byte array with file data
      fileName - - name of the file attachment
      contentType - - the contenttype (e.g. 'Text/HTML')
    • getFile

      @Deprecated public List<Object> getFile(String filename)
      Deprecated.
      Returns a data object for an attached file. The data object is a list containing the contentType (String) and the content (byte[])
      Parameters:
      filename -
      Returns:
      file data contentType (String) and the content (byte[])
    • getFileData

      public FileData getFileData(String filename)
      Returns a FileData object for an attached file.
      Parameters:
      filename -
      Returns:
      FileData object
    • getFileData

      public List<FileData> getFileData()
      Returns a list of all FileData objects.

      FileData objects are stored in the attribute '$file'.

      Returns:
      list of FileData objects
    • removeFile

      public void removeFile(String aFilename)
      This method removes a single file attachment from the workitem
    • getFiles

      @Deprecated public Map<String,List<Object>> getFiles()
      Deprecated.
      Returns files stored in the property '$file'. The files are returned in a Map interface where the key is the filename and the value is a list with two elements - the ContenType and the file content (byte[]). s Files can be added into a ItemCollection using the method addFile().
      Returns:
    • getFileNames

      public List<String> getFileNames()
      Returns a list of file names attached to the current workitem. File Attachments can be added using the method addFile().
      Returns:
    • getItem

      public Map<String,?> getItem()
      Returns an ItemAdapter for this instance.
      Returns:
    • getItemList

      public Map<String,?> getItemList()
      Returns an ItemListAdapter for this instance.
      Returns:
    • getItemListArray

      public Map<String,?> getItemListArray()
      Returns an ItemListArrayAdapter for this instance.
      Returns:
    • getType

      public String getType()
      Returns:
      current type
    • setType

      public void setType(String type)
      set type
      Parameters:
      type -
    • getTaskID

      public int getTaskID()
      Returns:
      current $TaskID
    • setTaskID

      public void setTaskID(int taskID)
      set $taskID
      Parameters:
      taskID -
    • task

      public ItemCollection task(int taskID)
    • getEventID

      public int getEventID()
      Returns:
      current $EventID
    • setEventID

      public void setEventID(int eventID)
      set $eventID
      Parameters:
      eventID -
    • event

      public ItemCollection event(int eventID)
      Set the event id for a workitem. If a event id is already set, the method appends the event to the ACTIVITYIDLIST
      Parameters:
      eventID -
      Returns:
    • getModelVersion

      public String getModelVersion()
      Returns:
      current $ModelVersion
    • setModelVersion

      public void setModelVersion(String modelversion)
      set the $ModelVersion
    • model

      public ItemCollection model(String modelversion)
    • getWorkflowGroup

      public String getWorkflowGroup()
      Returns:
      current $ModelVersion
    • setWorkflowGroup

      public void setWorkflowGroup(String group)
      set the $ModelVersion
    • workflowGroup

      public ItemCollection workflowGroup(String group)
    • getUniqueID

      public String getUniqueID()
      Returns:
      $UniqueID
    • getProcessID

      @Deprecated public int getProcessID()
      Deprecated.
      This method is deprecated. Use instead getTaskID()
      Returns:
      current $processID
    • getActivityID

      @Deprecated public int getActivityID()
      Deprecated.
      This method is deprecated. Use instead getEventID()
      Returns:
      current $ActivityID
    • setActivityID

      @Deprecated public void setActivityID(int activityID)
      Deprecated.
      set $ActivityID. This method is deprecated. Use instead setEventID()
      Parameters:
      activityID -