Class ModelHelper

    • Field Detail

      • MAX_NAME_LENGTH

        public static final int MAX_NAME_LENGTH
        The maximum length for names
        See Also:
        Constant Field Values
      • MAX_INTERNAL_NAME_LENGTH

        public static final int MAX_INTERNAL_NAME_LENGTH
        The maximum length for internal names
        See Also:
        Constant Field Values
    • Constructor Detail

      • ModelHelper

        public ModelHelper()
    • Method Detail

      • clearIds

        public static void clearIds​(Iterable<? extends EntityModel> models)
        Sets the ids of all models to null
      • copyProperties

        public static <S extends Bean,​T extends Bean> void copyProperties​(S source,
                                                                                T target)
        It copies from source to target (apply a bean over another bean) traversing all source's properties.
        If a property is not found in the target bean or has a different type then it's ignored.
        Throws:
        IllegalArgumentException - if source, target or both are null.
      • equals

        public static boolean equals​(LatLongDTO first,
                                     LatLongDTO second)
        Check if both coordinates are the same
      • escapeIdentifierIfNeeded

        public static String escapeIdentifierIfNeeded​(String value)
        When the given value is a valid Long, return it escaped with a trailing '. Otherwise return the value as is.
      • getActualInternalNameOrId

        public static String getActualInternalNameOrId​(EntityVO vo)
        Returns the internal name of the given VO if it is valid (no nested paths contains a null part). Otherwise, returns the id as string
      • getHierarchyPath

        public static <T extends BeanList<T> getHierarchyPath​(T bean,
                                                                Property<T,​T> parentProperty)
        Returns a list with the path from the hierarchy root up to the given object, having the given parent property to resolve an object's parent. For example, if the given object is A1.1.1, the result is [A, A1, A1.1, A1.1.1]
      • getLevel

        public static <T extends Bean> int getLevel​(T bean,
                                                    Property<T,​T> parentProperty)
        Returns the level of a given hierarchical bean. The given property needs to resolve the parent bean. Objects with no parent have level 1
      • getLocation

        public static LatLongDTO getLocation​(IAddress address)
        Returns the location for a given address
      • identifier

        public static String identifier​(AccountOwner owner,
                                        boolean numericValueAsLocator)
        Returns the string identifier of an account owner: SYSTEM for system, EXTERNAL for external and id for users.
      • internalNameOrId

        public static String internalNameOrId​(IEntity entity)
        For a given entity model, returns the internal name, if available, otherwise the id
      • isEmpty

        public static boolean isEmpty​(DatePeriodDTO period)
        Returns whether the given date period is empty: null or having both begin and end as null
      • isEmpty

        public static boolean isEmpty​(Range<?> range)
        Returns whether the given range is empty: null or having both min and maxas null
      • isEmpty

        @SafeVarargs
        public static <T extends Bean> boolean isEmpty​(T bean,
                                                       Property<?,​? super T>... properties)
        Parameters:
        properties - list of Properties to be checked for empty/null
        Returns:
        true if observable is null or all of the specified properties are null or empty (see ObjectHelper.isEmpty(Object)).
      • isValid

        public static boolean isValid​(DistanceDTO distance)
        Returns whether the given distance is valid
      • isValid

        public static boolean isValid​(FileSizeDTO size)
        Returns whether the given size and unit are valid
      • isValid

        public static boolean isValid​(LatLongDTO latLong)
        Returns whether the given latitude and longitude are valid
      • isValid

        public static boolean isValid​(TimeIntervalDTO interval)
        Returns whether the given time interval is valid
      • isValid

        public static boolean isValid​(UserLocatorVO user)
        Returns whether the given user locator is valid
      • latLong

        public static LatLongDTO latLong​(double latitude,
                                         double longitude)
        Creates a new LatLongDTO
      • locatorText

        public static String locatorText​(String text)
        Prepares the given text to be used as locator. Basically removes leading and trailing single quotes, if any.
      • removeId

        public static <E extends EntityModel> E removeId​(E model)
        Set null to the id property and return the same instance.
      • resolveImageNature

        public static ImageNature resolveImageNature​(ImageVO image)
        Returns the image nature for the given ImageVO
      • stringFromVO

        public static String stringFromVO​(EntityVO vo)
        Returns the locator string from the given EntityVO. For example, for UserLocatorVO, returns the principal. Will never return the id. If the VO has no representing string, returns null.
      • stringFromVO

        public static String stringFromVO​(EntityVO vo,
                                          boolean numericValueAsLocator)
        Returns the locator string from the given EntityVO. For example, for UserLocatorVO, returns the principal. Will never return the id. If the VO has no representing string, returns null. For UserLocatorVO if ´numericValueAsLocator´ is true and the principal is numeric it will be prefixed with "\'", this way it can be used as locator, otherwise it will be treated as an id and the location will fail.
      • toVOs

        public static <VO extends EntityVOSet<VO> toVOs​(Class<VO> voClass,
                                                          Collection<? extends IEntity> entities)
        Returns a set with VOs filled up only with ids
      • unqualifiedInternalNameOrId

        public static String unqualifiedInternalNameOrId​(IEntity entity)
        For a given entity model, returns the internal name, if available, otherwise the id
      • unqualifyInternalName

        public static String unqualifyInternalName​(String internalName)
        Returns the unqualified internal name, for example, "a.b.c" returns "c".
      • userLocator

        public static UserLocatorVO userLocator​(String text)
        Returns a UserLocatorVO from the given text, allowing ids
      • userLocator

        public static UserLocatorVO userLocator​(String text,
                                                boolean allowId)
        Returns a UserLocatorVO from the given text, optionally allowing ids
      • voFromString

        public static <VO extends EntityVO> VO voFromString​(Class<VO> voClass,
                                                            String value)
        Converts a textual value to a VO. If the value is null, returns null. Else, if the value is a number, use it as id. Otherwise, use it as either internal name, principal (if a userLocatorVO) or account number (if an AccountVO)