Class EntityUtil

java.lang.Object
org.apache.ofbiz.entity.util.EntityUtil

public final class EntityUtil extends Object
Helper methods when dealing with Entities, especially ones that follow certain conventions
  • Method Details

    • makeFields

      @SafeVarargs public static <V> Map<String,V> makeFields(V... args)
    • getFirst

      public static GenericValue getFirst(Collection<GenericValue> values)
    • getFirst

      public static GenericValue getFirst(List<GenericValue> values)
    • getOnly

      public static GenericValue getOnly(Collection<GenericValue> values)
    • getOnly

      public static GenericValue getOnly(List<GenericValue> values)
    • getFilterByDateExpr

      public static EntityCondition getFilterByDateExpr()
    • getFilterByDateExpr

      public static EntityCondition getFilterByDateExpr(String fromDateName, String thruDateName)
    • getFilterByDateExpr

      public static EntityCondition getFilterByDateExpr(Date moment)
    • getFilterByDateExpr

      public static EntityCondition getFilterByDateExpr(Timestamp moment)
    • getFilterByDateExpr

      public static EntityCondition getFilterByDateExpr(Timestamp moment, String fromDateName, String thruDateName)
    • filterByDate

      public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues)
      returns the values that are currently active.
      Parameters:
      datedValues - GenericValue's that have "fromDate" and "thruDate" fields
      Returns:
      List of GenericValue's that are currently active
    • filterByDate

      public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, boolean allAreSame)
      returns the values that are currently active.
      Parameters:
      datedValues - GenericValue's that have "fromDate" and "thruDate" fields
      allAreSame - Specifies whether all values in the List are of the same entity; this can help speed things up a fair amount since we only have to see if the from and thru date fields are valid once
      Returns:
      List of GenericValue's that are currently active
    • filterByDate

      public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, Date moment)
      returns the values that are active at the moment.
      Parameters:
      datedValues - GenericValue's that have "fromDate" and "thruDate" fields
      moment - the moment in question
      Returns:
      List of GenericValue's that are active at the moment
    • filterByDate

      public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, Timestamp moment)
      returns the values that are active at the moment.
      Parameters:
      datedValues - GenericValue's that have "fromDate" and "thruDate" fields
      moment - the moment in question
      Returns:
      List of GenericValue's that are active at the moment
    • filterByDate

      public static <T extends GenericEntity> List<T> filterByDate(List<T> datedValues, Timestamp moment, String fromDateName, String thruDateName, boolean allAreSame)
      returns the values that are active at the moment.
      Parameters:
      datedValues - GenericValue's that have "fromDate" and "thruDate" fields
      moment - the moment in question
      allAreSame - Specifies whether all values in the List are of the same entity; this can help speed things up a fair amount since we only have to see if the from and thru date fields are valid once
      Returns:
      List of GenericValue's that are active at the moment
    • isValueActive

      public static boolean isValueActive(GenericValue datedValue, Timestamp moment)
    • isValueActive

      public static boolean isValueActive(GenericValue datedValue, Timestamp moment, String fromDateName, String thruDateName)
    • filterByAnd

      public static <T extends GenericEntity> List<T> filterByAnd(List<T> values, Map<String,? extends Object> fields)
      returns the values that match the values in fields
      Parameters:
      values - List of GenericValues
      fields - the field-name/value pairs that must match
      Returns:
      List of GenericValue's that match the values in fields
    • filterByAnd

      public static <T extends GenericEntity> List<T> filterByAnd(List<T> values, List<? extends EntityCondition> exprs)
      returns the values that match all of the exprs in list
      Parameters:
      values - List of GenericValues
      exprs - the expressions that must validate to true
      Returns:
      List of GenericValue's that match the values in fields
    • filterByOr

      public static <T extends GenericEntity> List<T> filterByOr(List<T> values, List<? extends EntityCondition> exprs)
      returns the values that match any of the exprs in list
      Parameters:
      values - List of GenericValues
      exprs - the expressions that must validate to true
      Returns:
      List of GenericValue's that match the values in fields
    • localizedOrderBy

      public static <T extends GenericEntity> List<T> localizedOrderBy(Collection<T> values, List<String> orderBy, Locale locale)
      returns the values in the order specified after with localized value
      Parameters:
      values - List of GenericValues
      orderBy - The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
      locale - Locale use to retrieve localized value
      Returns:
      List of GenericValue's in the proper order
    • orderBy

      public static <T extends GenericEntity> List<T> orderBy(Collection<T> values, List<String> orderBy)
      returns the values in the order specified
      Parameters:
      values - List of GenericValues
      orderBy - The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
      Returns:
      List of GenericValue's in the proper order
    • getRelated

      @Deprecated public static List<GenericValue> getRelated(String relationName, List<GenericValue> values) throws GenericEntityException
      Throws:
      GenericEntityException
    • getRelated

      public static List<GenericValue> getRelated(String relationName, Map<String,? extends Object> fields, List<GenericValue> values, boolean useCache) throws GenericEntityException
      Throws:
      GenericEntityException
    • filterByCondition

      public static <T extends GenericEntity> List<T> filterByCondition(List<T> values, EntityCondition condition)
    • filterOutByCondition

      public static <T extends GenericEntity> List<T> filterOutByCondition(List<T> values, EntityCondition condition)
    • findDatedInclusionEntity

      public static List<GenericValue> findDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> search) throws GenericEntityException
      Throws:
      GenericEntityException
    • findDatedInclusionEntity

      public static List<GenericValue> findDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> search, Timestamp now) throws GenericEntityException
      Throws:
      GenericEntityException
    • newDatedInclusionEntity

      public static GenericValue newDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> search) throws GenericEntityException
      Throws:
      GenericEntityException
    • newDatedInclusionEntity

      public static GenericValue newDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> find, Timestamp now) throws GenericEntityException
      Throws:
      GenericEntityException
    • delDatedInclusionEntity

      public static void delDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> search) throws GenericEntityException
      Throws:
      GenericEntityException
    • delDatedInclusionEntity

      public static void delDatedInclusionEntity(Delegator delegator, String entityName, Map<String,? extends Object> search, Timestamp now) throws GenericEntityException
      Throws:
      GenericEntityException
    • getFieldListFromEntityList

      public static <T> List<T> getFieldListFromEntityList(List<GenericValue> genericValueList, String fieldName, boolean distinct)
    • getFieldListFromEntityListIterator

      public static <T> List<T> getFieldListFromEntityListIterator(EntityListIterator genericValueEli, String fieldName, boolean distinct)
    • getSelectedFieldValueListFromEntityList

      public static List<GenericValue> getSelectedFieldValueListFromEntityList(Delegator delegator, List<GenericValue> values, Set<String> selected)
      returns the values with the matching selected fields
      Parameters:
      delegator -
      values - List of GenericValues
      selected - the lit of selected fields
      Returns:
      List of GenericValue's with only selected fields
    • isMultiTenantEnabled

      public static boolean isMultiTenantEnabled()
      Returns true if multi-tenant has been enabled.

      Multi-tenant features are enabled by setting the multitenant property in general.properties to "Y".

    • getStartIndexFromViewIndex

      public static int getStartIndexFromViewIndex(int viewIndex, int viewSize)
      Parameters:
      viewIndex -
      viewSize -
      Returns:
      the calculated start index based on viewIndex and viewSize
      See Also:
    • getPagedList

      public static PagedList<GenericValue> getPagedList(EntityListIterator iter, int viewIndex, int viewSize) throws GenericEntityException
      Parameters:
      iter - EntityListIterator
      viewIndex -
      viewSize -
      Returns:
      PagedList object with a subset of data items from EntityListIterator based on viewIndex and viewSize
      Throws:
      GenericEntityException
      See Also:
    • entityToPath

      public static String entityToPath(Delegator delegator, String entityName, Map<String,Object> context)
      For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueN
      Parameters:
      delegator -
      entityName -
      context -
      Returns:
    • entityToPath

      public static String entityToPath(GenericValue gv)
      For a entityName return the primary keys path that identify it like entityName/pkValue1/pkValue2/../pkValueN
      Parameters:
      gv -
      Returns:
    • getPkValuesMapFromPath

      public static Map<String,Object> getPkValuesMapFromPath(ModelEntity modelEntity, String path) throws GenericEntityException
      Form a entityName and primary keys path convert it to a Map contains all pkValue : entityName/pkValue1/pkValue2/../pkValueN -> [pkName1: pkValue1, pkName2, pkValue2, ..., pkNameN: pkValueN]
      Parameters:
      modelEntity -
      path -
      Returns:
      Throws:
      GenericEntityException