org.nuiton.wikitty
Class WikittyUtil

java.lang.Object
  extended by org.nuiton.wikitty.WikittyUtil
All Implemented Interfaces:
WikittyConstants

public class WikittyUtil
extends Object
implements WikittyConstants

Util static method for wikitty.

Version:
$Revision: 1394 $ Last update: $Date: 2012-01-30 19:21:23 +0100 (lun, 30 jan 2012) $ by : $Author: bpoussin $
Author:
poussin

Field Summary
protected static Locale CANONICAL_LOCALE
           
protected static TimeZone CANONICAL_TZ
          used to format date for solr
static String DATE_FORMAT
           
static String[] DATE_FORMAT_ALLOWED
           
static org.nuiton.wikitty.WikittyUtil.WikittyDateConverter dateConverter
           
static String DEFAULT_MAJOR_VERSION
           
static String DEFAULT_MAJOR_VERSION_PREFIX
           
static String DEFAULT_MINOR_VERSION
           
static String DEFAULT_VERSION
           
static String extensionFieldNamePattern
          Pattern que doivent respecter les noms des champs des extensions
static String extensionNamePattern
          Pattern que doivent respecter les noms des extensions
protected static Pattern fieldPattern
          Field pattern parser group 1: type (string) group 2: name (string) group 3: lower bound (number) can be null group 4: upper bound (number) can be null, mutually exclusive with group 5 group 5: upper bound (n or *) can be null group 6: unique can be null (legacy configuration, prefer use of unique="true" group 7: not null can be null (legacy configuration, prefer use of notNull="true" group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")
protected static Pattern formatMatcher
          Pattern de recherche des field dans les chaines de formatage
static Map<Class<?>,Class<?>> interfaceToClass
          contains mapping between interface and concret class that must be used
static String SOLR_DATE_FORMAT
           
protected static org.apache.commons.lang.time.FastDateFormat solrDateFormat
           
protected static Pattern tagValuesPattern
           
protected static String tagValuesPatternString
          Pattern for tag value: tag="value" or tag=value. value can contains '"'
 
Fields inherited from interface org.nuiton.wikitty.WikittyConstants
FQ_FIELD_NAME_SEPARATOR, FQ_FIELD_NAME_SEPARATOR_REGEX, FQ_META_EXTENSION_SEPARATOR, FQ_META_EXTENSION_SEPARATOR_REGEX
 
Constructor Summary
WikittyUtil()
           
 
Method Summary
static LinkedHashMap<String,FieldType> buildFieldMapExtension(String... definitions)
          Create map from string representation.
static
<E> E
cast(Object obj, Class<E> clazz)
          Try to cast obj to class passed in argument.
static Wikitty checkExtensionVersion(String securityToken, WikittyService wikittyService, Wikitty wikitty, BusinessEntityImpl entity)
          Check extension default, i.e. if bean contain a extension with a great version as in wikitty.
static Wikitty clone(Wikitty wikittyToClone, boolean genId)
          Clone wikitty with new id if genId is true
static void copyBean(Object source, Object dest)
          Copy all properties (get/set) from source to destination, except wikitty property
static String format(String formatWikitty, Wikitty w)
          Format wikitty for string representation.
static String formatDate(Date date)
           
static Object fromString(FieldType field, String s)
          Convert string field representation to correct value type.
static String genSecurityTokenId()
          SecurityToken is used like wikitty id and must begin with UUID_
static String genUID()
           
static Class<?> getClass(Object value)
          Return class of argument, if argument is null, return null.
static String getExtensionNameFromFQFieldName(String fqFieldName)
          given a fully qualified field name, return the name of the extension TODO poussin 20101208 redondant code with WikittyExtension.extractExtensionName(java.lang.String)
static String getExtensionNameFromFQMetaExtensionName(String fqFieldName)
          given a fully qualified meta-extension name, return the name of the extension
static String getFieldNameFromFQFieldName(String fqFieldName)
          given a fully qualified field name, return the name of the field TODO poussin 20101208 redondant code with WikittyExtension.extractFieldName(java.lang.String)
static
<E> E
getFieldValueFromFQFieldName(String fqField, BusinessEntity entity)
          Extract field value corresponding of fqField in entity
static
<E> List<E>
getFieldValuesFromFQFieldName(String fqField, Iterable<? extends BusinessEntity> entities)
          Extract all field values corresponding of fqField in list of entities
static String getFQFieldName(String extensionName, String fieldName)
          given names of extension and field, return a fully qualified field name
static String getFQMetaExtensionName(String metaExtensionName, String extensionName)
          given names of meta-extension and extension, return a fully qualified meta-extension name
static List<String> getIds(Iterable<? extends BusinessEntity> entities)
          Extract all id for beans
static String getMetaExtensionNameFromFQMetaExtensionName(String fqFieldName)
          given a fully qualified meta-extension name, return the name of the meta-extension.
static String getMetaFieldName(String metaExtensionName, String extensionName, String fieldName)
          Get the FQN of a metaExtension field.
static String getUniqueLoginName()
          Recherche le meilleur nom a utiliser comme pseudo pour cette machine.
static Wikitty getWikitty(WikittyService service, String securityToken, BusinessEntity entity)
          Deprecated. since 3.3 use WikittyClient.getWikitty(org.nuiton.wikitty.entities.BusinessEntity)
static String incrementMajorRevision(String v)
          increment major version.
static String incrementMinorRevision(String v)
          Increment minor version.
static
<E extends BusinessEntity>
E
newInstance(Class<E> clazz)
          Create new instance of WikittyDto without Wikitty object passed in argument.
<E extends BusinessEntity>
E
newInstance(Class<E> target, BusinessEntityImpl source)
          Cast Business object to another Business Object If source don't have target extension, this extension is added
static
<E extends BusinessEntity>
List<E>
newInstance(Class<E> target, List<Wikitty> wikitties)
          Create new Business Entity List from wikitties
static
<E extends BusinessEntity>
E
newInstance(Class<E> target, Wikitty w)
          Create new Business Entity with specified Wikitty
static
<E extends BusinessEntity>
E
newInstance(String securityToken, WikittyService wikittyService, Class<E> clazz, Wikitty w)
          Deprecated. since 3.3 il n'est pas coherent d'acceder au serveur lorsqu'on instancie un objet. La verification de la securite de toute facon ne se fait qu'au moment de la sauvegarde.
static String normalizeVersion(String version)
          if version if null return 0 else version If version is not in format .
static Date parseDate(String dateAsString)
           
static String parseField(String def, FieldType fieldType)
          parse FieldType definition and return field name.
static Map<String,String> tagValuesToMap(String tagValues)
          Deserialize tagValues to map
static String tagValuesToString(Map<String,String> tagValues)
          Serialize tagValues to string
static BigDecimal toBigDecimal(Object value)
          Get value as BigDecimal.
static byte[] toBinary(Object value)
          Get value as Binary.
static boolean toBoolean(Object value)
          Convert object to boolean: - null => false - 0 => false - numeric => true - object.toString() == false => false - other => true
static Date toDate(Object value)
           
static
<E> List<E>
toList(Object value, Class<E> clazz)
          Convert value to list.
static String toString(Object value)
          Convert Object to String representation if value is not null Wikitty is converted to id, and Date to SolrDateFormat
static String toStringForExport(FieldType field, Object o)
          Convert object o for export CSV/XML.
static String toStringForSearchEngine(FieldType field, Object o)
          Convert object o for indexation
static String toWikitty(Object value)
          Return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller
static boolean versionEquals(String v1, String v2)
          Return true if v1 and v2 are equals. 1.2.0 et 1.2 ne sont pas egaux
static boolean versionGreaterThan(String v1, String v2)
          Return true if v1 greater than v2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extensionNamePattern

public static final String extensionNamePattern
Pattern que doivent respecter les noms des extensions

See Also:
Constant Field Values

extensionFieldNamePattern

public static final String extensionFieldNamePattern
Pattern que doivent respecter les noms des champs des extensions

See Also:
Constant Field Values

DEFAULT_MAJOR_VERSION

public static final String DEFAULT_MAJOR_VERSION
See Also:
Constant Field Values

DEFAULT_MINOR_VERSION

public static final String DEFAULT_MINOR_VERSION
See Also:
Constant Field Values

DEFAULT_MAJOR_VERSION_PREFIX

public static final String DEFAULT_MAJOR_VERSION_PREFIX
See Also:
Constant Field Values

DEFAULT_VERSION

public static final String DEFAULT_VERSION
See Also:
Constant Field Values

DATE_FORMAT

public static final String DATE_FORMAT
See Also:
Constant Field Values

SOLR_DATE_FORMAT

public static final String SOLR_DATE_FORMAT
See Also:
Constant Field Values

CANONICAL_TZ

protected static final TimeZone CANONICAL_TZ
used to format date for solr


CANONICAL_LOCALE

protected static final Locale CANONICAL_LOCALE

solrDateFormat

protected static final org.apache.commons.lang.time.FastDateFormat solrDateFormat

DATE_FORMAT_ALLOWED

public static final String[] DATE_FORMAT_ALLOWED

interfaceToClass

public static Map<Class<?>,Class<?>> interfaceToClass
contains mapping between interface and concret class that must be used


tagValuesPatternString

protected static String tagValuesPatternString
Pattern for tag value: tag="value" or tag=value. value can contains '"'


tagValuesPattern

protected static Pattern tagValuesPattern

fieldPattern

protected static Pattern fieldPattern
Field pattern parser
  • group 1: type (string)
  • group 2: name (string)
  • group 3: lower bound (number) can be null
  • group 4: upper bound (number) can be null, mutually exclusive with group 5
  • group 5: upper bound (n or *) can be null
  • group 6: unique can be null (legacy configuration, prefer use of unique="true"
  • group 7: not null can be null (legacy configuration, prefer use of notNull="true"
  • group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")


  • formatMatcher

    protected static Pattern formatMatcher
    Pattern de recherche des field dans les chaines de formatage


    dateConverter

    public static org.nuiton.wikitty.WikittyUtil.WikittyDateConverter dateConverter
    Constructor Detail

    WikittyUtil

    public WikittyUtil()
    Method Detail

    parseDate

    public static Date parseDate(String dateAsString)
                          throws ParseException
    Throws:
    ParseException

    formatDate

    public static String formatDate(Date date)
                             throws ParseException
    Throws:
    ParseException

    parseField

    public static String parseField(String def,
                                    FieldType fieldType)
    parse FieldType definition and return field name. All field information are stored in fieldType object passed in argument

    Parameters:
    def - string field definition
    fieldType - object used to put parsed information
    Returns:
    field name parsed in definition

    tagValuesToString

    public static String tagValuesToString(Map<String,String> tagValues)
    Serialize tagValues to string

    Parameters:
    tagValues - tagValues as map
    Returns:
    string represent tagValues

    tagValuesToMap

    public static Map<String,String> tagValuesToMap(String tagValues)
    Deserialize tagValues to map

    Parameters:
    tagValues - tagValues as string
    Returns:
    map represent tagValues

    buildFieldMapExtension

    public static LinkedHashMap<String,FieldType> buildFieldMapExtension(String... definitions)
    Create map from string representation. ex: "String name", "Wikitty attachment[0-*]"

    Parameters:
    definitions - extension definition
    Returns:
    extensions map

    normalizeVersion

    public static String normalizeVersion(String version)
    if version if null return 0 else version If version is not in format ., ".0" is added to the version

    Parameters:
    version - version
    Returns:
    the normalized version

    versionEquals

    public static boolean versionEquals(String v1,
                                        String v2)
    Return true if v1 and v2 are equals. 1.2.0 et 1.2 ne sont pas egaux

    Parameters:
    v1 - version
    v2 - version
    Returns:
    true if v1 == v2

    versionGreaterThan

    public static boolean versionGreaterThan(String v1,
                                             String v2)
    Return true if v1 greater than v2.

    Parameters:
    v1 - version
    v2 - version
    Returns:
    true if v1 > v2

    incrementMinorRevision

    public static String incrementMinorRevision(String v)
    Increment minor version.

    Parameters:
    v - version as 3.1 where 1 is minor and 3 major
    Returns:
    incremented minor number (3.1 -> 3.2)

    incrementMajorRevision

    public static String incrementMajorRevision(String v)
    increment major version.

    Parameters:
    v - version as 3.2 where 2 is minor and 3 major
    Returns:
    incremented major number and reset minor number (3.2 -> 4.0)

    format

    public static String format(String formatWikitty,
                                Wikitty w)
    Format wikitty for string representation. exemple:
  • "%Person.lastName$s %Person.firstName$s: %Person.birthday$tm %Person.birthday$te,%Person.birthday$tY"
  • "Hello %Person.firstName|unknow$s" if firstName field doesn't exist, unknow is used

    Parameters:
    format - format as http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax execpt that position is replace with fq field name.
    w - wikitty to format
    Returns:
    String that represent the wikitty

  • toBinary

    public static byte[] toBinary(Object value)
    Get value as Binary.

    Parameters:
    value - null and empty return empty byte[]
    Returns:
    value as byte[]

    toBigDecimal

    public static BigDecimal toBigDecimal(Object value)
    Get value as BigDecimal.

    Parameters:
    value - null and empty string are casted to '0' value.
    Returns:
    value as BigDecimal
    Throws:
    WikittyException - on NumberFormatException or if value object can't be casted to number.

    toBoolean

    public static boolean toBoolean(Object value)
    Convert object to boolean:

    Parameters:
    value - value
    Returns:
    value as boolean

    toString

    public static String toString(Object value)
    Convert Object to String representation if value is not null Wikitty is converted to id, and Date to SolrDateFormat

    Parameters:
    value - value to convert
    Returns:
    String representation or null

    toDate

    public static Date toDate(Object value)

    toWikitty

    public static String toWikitty(Object value)
    Return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller

    Parameters:
    value -
    Returns:
    id of wikitty object or null

    toList

    public static <E> List<E> toList(Object value,
                                     Class<E> clazz)
    Convert value to list.

    Type Parameters:
    E - elements type
    Parameters:
    value - value to convert
    clazz - element class
    Returns:
    unmodifiable list

    toStringForExport

    public static String toStringForExport(FieldType field,
                                           Object o)
    Convert object o for export CSV/XML.

    Parameters:
    field - field description
    o - field value
    Returns:
    solr representation

    toStringForSearchEngine

    public static String toStringForSearchEngine(FieldType field,
                                                 Object o)
    Convert object o for indexation

    Parameters:
    field - field description
    o - field value
    Returns:
    solr representation

    fromString

    public static Object fromString(FieldType field,
                                    String s)
    Convert string field representation to correct value type.

    Parameters:
    field - field description
    s - string value
    Returns:
    object in type of field

    getClass

    public static Class<?> getClass(Object value)
    Return class of argument, if argument is null, return null.

    Parameters:
    value -
    Returns:
    class of value or null

    newInstance

    public static <E extends BusinessEntity> E newInstance(Class<E> clazz)
    Create new instance of WikittyDto without Wikitty object passed in argument. If arguement is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of WikittyDto or business interface

    Type Parameters:
    E - element type
    Parameters:
    clazz - class of the new instance
    Returns:
    new instance of clazz

    newInstance

    public static <E extends BusinessEntity> E newInstance(Class<E> target,
                                                           Wikitty w)
    Create new Business Entity with specified Wikitty

    Parameters:
    target - Business Entity class
    w - wikitty to used
    Returns:

    newInstance

    public <E extends BusinessEntity> E newInstance(Class<E> target,
                                                    BusinessEntityImpl source)
    Cast Business object to another Business Object If source don't have target extension, this extension is added

    Parameters:
    source - business entity source
    target - business entity class wanted
    Returns:
    new instance of object wanted

    newInstance

    public static <E extends BusinessEntity> List<E> newInstance(Class<E> target,
                                                                 List<Wikitty> wikitties)
    Create new Business Entity List from wikitties

    Parameters:
    target - Business Entity class
    wikitties - list of wikitties
    Returns:
    new list of Business Entity

    newInstance

    @Deprecated
    public static <E extends BusinessEntity> E newInstance(String securityToken,
                                                                      WikittyService wikittyService,
                                                                      Class<E> clazz,
                                                                      Wikitty w)
    Deprecated. since 3.3 il n'est pas coherent d'acceder au serveur lorsqu'on instancie un objet. La verification de la securite de toute facon ne se fait qu'au moment de la sauvegarde.

    Create new instance of BusinessEntity from Wikitty object passed in argument. If argument is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of Business interface

    Type Parameters:
    E - entity type
    Parameters:
    wikittyService - wikitty service
    clazz - class of the new instance
    w - wikitty object to use internaly for in new instance
    Returns:
    new instance

    checkExtensionVersion

    public static Wikitty checkExtensionVersion(String securityToken,
                                                WikittyService wikittyService,
                                                Wikitty wikitty,
                                                BusinessEntityImpl entity)
    Check extension default, i.e. if bean contain a extension with a great version as in wikitty. In this case the extension is stored in last version and wikitty it is restored again. The upgrade data is during the restoration.

    Parameters:
    wikittyService -
    wikitty -
    entity -
    Returns:

    cast

    public static <E> E cast(Object obj,
                             Class<E> clazz)
    Try to cast obj to class passed in argument.

    Type Parameters:
    E - element type
    Parameters:
    obj - object to cast
    clazz - new type of object
    Returns:
    the same object but casted to class wanted, except for primitive where is new object if obj BigDecimal

    clone

    public static Wikitty clone(Wikitty wikittyToClone,
                                boolean genId)
                         throws CloneNotSupportedException
    Clone wikitty with new id if genId is true

    Parameters:
    wikittyToClone - concerned
    genId - true to generate new id
    Returns:
    cloned wikitty
    Throws:
    CloneNotSupportedException - if exception is thrown

    genSecurityTokenId

    public static String genSecurityTokenId()
    SecurityToken is used like wikitty id and must begin with UUID_

    Returns:
    SecurityToken that can be used like wikitty id

    genUID

    public static String genUID()

    getExtensionNameFromFQFieldName

    public static String getExtensionNameFromFQFieldName(String fqFieldName)
    given a fully qualified field name, return the name of the extension TODO poussin 20101208 redondant code with WikittyExtension.extractExtensionName(java.lang.String)


    getFieldNameFromFQFieldName

    public static String getFieldNameFromFQFieldName(String fqFieldName)
    given a fully qualified field name, return the name of the field TODO poussin 20101208 redondant code with WikittyExtension.extractFieldName(java.lang.String)


    getFQFieldName

    public static String getFQFieldName(String extensionName,
                                        String fieldName)
    given names of extension and field, return a fully qualified field name


    getMetaExtensionNameFromFQMetaExtensionName

    public static String getMetaExtensionNameFromFQMetaExtensionName(String fqFieldName)
    given a fully qualified meta-extension name, return the name of the meta-extension.

    Returns:
    null if fqFieldName doesn't contains a meta extension

    getExtensionNameFromFQMetaExtensionName

    public static String getExtensionNameFromFQMetaExtensionName(String fqFieldName)
    given a fully qualified meta-extension name, return the name of the extension


    getFQMetaExtensionName

    public static String getFQMetaExtensionName(String metaExtensionName,
                                                String extensionName)
    given names of meta-extension and extension, return a fully qualified meta-extension name


    getMetaFieldName

    public static String getMetaFieldName(String metaExtensionName,
                                          String extensionName,
                                          String fieldName)
    Get the FQN of a metaExtension field. The FQN may depend of an extension getMetaFieldName(metaExt, ext, field) returns "ext:metaExt.field" getMetaFieldName(metaExt, null, field) returns "metaExt.field"


    getIds

    public static List<String> getIds(Iterable<? extends BusinessEntity> entities)
    Extract all id for beans

    Parameters:
    entities - to extract ids
    Returns:
    ids of entities

    getFieldValueFromFQFieldName

    public static <E> E getFieldValueFromFQFieldName(String fqField,
                                                     BusinessEntity entity)
    Extract field value corresponding of fqField in entity

    Type Parameters:
    E - return type
    Parameters:
    fqField - fqField concerned
    entity - entity concerned
    Returns:
    value of field

    getFieldValuesFromFQFieldName

    public static <E> List<E> getFieldValuesFromFQFieldName(String fqField,
                                                            Iterable<? extends BusinessEntity> entities)
    Extract all field values corresponding of fqField in list of entities

    Type Parameters:
    E - return type
    Parameters:
    fqField - fqField concerned
    entities - entities concerned
    Returns:
    value of field

    getUniqueLoginName

    public static String getUniqueLoginName()
    Recherche le meilleur nom a utiliser comme pseudo pour cette machine. Un UUID est toujours ajouter en debut, pour potentiellement lancer plusieurs application en meme temps sur la meme machine et etre sur que le pseudo soit bien unique. Le pseudo, n'est pas seulement un UUID, pour pouvoir facilement faire du debug en entrant dans le channel et voir les ip des machiens connectees

    Returns:

    getWikitty

    @Deprecated
    public static Wikitty getWikitty(WikittyService service,
                                                String securityToken,
                                                BusinessEntity entity)
    Deprecated. since 3.3 use WikittyClient.getWikitty(org.nuiton.wikitty.entities.BusinessEntity)

    Parameters:
    service -
    securityToken -
    entity -
    Returns:

    copyBean

    public static void copyBean(Object source,
                                Object dest)
                         throws Exception
    Copy all properties (get/set) from source to destination, except wikitty property

    Parameters:
    source -
    dest -
    Throws:
    Exception


    Copyright © 2009-2012 CodeLutin. All Rights Reserved.