Class TopiaTemplateHelper

java.lang.Object
org.nuiton.topia.templates.TopiaTemplateHelper

public class TopiaTemplateHelper extends Object
Classe regroupant divers méthodes utiles pour la génération des entités. Remplace TopiageneratorUtil car on ne veut plus utiliser de méthodes statiques (par exemple pour avoir les valeurs par défaut des tagValues,...). Created on 7/6/14.
Since:
3.0
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

    • PERSISTENCE_TYPE_HIBERNATE

      public final String PERSISTENCE_TYPE_HIBERNATE
      Type de persistence Hibernate
      See Also:
    • PERSISTENCE_TYPE_DEFAULT

      public final String PERSISTENCE_TYPE_DEFAULT
      Type de persistence par défaut (si aucun précisé)
      See Also:
    • PROPERTY_DEFAULT_PACKAGE

      public final String PROPERTY_DEFAULT_PACKAGE
      Propriété des générateurs indiquant le package par défaut
      See Also:
    • DEFAULT_PACKAGE

      public final String DEFAULT_PACKAGE
      Le package par défaut si aucun n'est spécifié
      See Also:
    • DEFAULT_INHERITANCE_STRATEGY

      public final String DEFAULT_INHERITANCE_STRATEGY
      Stratégie d'heritage par defaut.
      See Also:
    • model

      protected final org.nuiton.eugene.models.object.ObjectModel model
    • eugeneTagValues

      protected final org.nuiton.eugene.EugeneCoreTagValues eugeneTagValues
    • topiaCoreTagValues

      protected final TopiaCoreTagValues topiaCoreTagValues
    • topiaHibernateTagValues

      protected final TopiaHibernateTagValues topiaHibernateTagValues
    • OBJECT_MODEL_CLASS_COMPARATOR

      public final Comparator<org.nuiton.eugene.models.object.ObjectModelClass> OBJECT_MODEL_CLASS_COMPARATOR
  • Constructor Details

    • TopiaTemplateHelper

      public TopiaTemplateHelper(org.nuiton.eugene.models.object.ObjectModel model)
  • Method Details

    • getTopiaCoreTagValues

      @Deprecated public TopiaCoreTagValues getTopiaCoreTagValues()
      Deprecated.
    • getTopiaHibernateTagValues

      @Deprecated public TopiaHibernateTagValues getTopiaHibernateTagValues()
      Deprecated.
    • getPersistenceType

      public String getPersistenceType(org.nuiton.eugene.models.object.ObjectModelClassifier classifier)
      Renvoie le type de persistence pour le classifier donné. Si aucun n'est trouvé, le type par défaut est utilisé
      Parameters:
      classifier - l'élément à tester
      Returns:
      le type de persitence pour l'élément donné.
      Since:
      2.5
    • getDefaultPackage

      public String getDefaultPackage(org.nuiton.eugene.AbstractGenerator<?> generator)
      Renvoie le package par défaut pour le générateur donné
      Parameters:
      generator - le générateur donné
      Returns:
      le package par défaut du générator donné
    • getApplicationContextPackage

      public String getApplicationContextPackage(org.nuiton.eugene.java.ObjectModelTransformerToJava transformer, org.nuiton.eugene.models.object.ObjectModel model)
    • getPersistenceContextPackage

      public String getPersistenceContextPackage(org.nuiton.eugene.java.ObjectModelTransformerToJava transformer, org.nuiton.eugene.models.object.ObjectModel model)
    • getDaoPackage

      public String getDaoPackage(org.nuiton.eugene.java.ObjectModelTransformerToJava transformer, org.nuiton.eugene.models.object.ObjectModel model)
    • getParentDaoName

      public String getParentDaoName(org.nuiton.eugene.models.object.ObjectModel model)
    • getParentDaoFqn

      public String getParentDaoFqn(org.nuiton.eugene.java.ObjectModelTransformerToJava transformer, org.nuiton.eugene.models.object.ObjectModel model)
    • getApplicationContextInterfaceName

      public String getApplicationContextInterfaceName(org.nuiton.eugene.models.object.ObjectModel model)
    • getApplicationContextAbstractName

      public String getApplicationContextAbstractName(org.nuiton.eugene.models.object.ObjectModel model)
    • getApplicationContextConcreteName

      public String getApplicationContextConcreteName(org.nuiton.eugene.models.object.ObjectModel model)
    • getPersistenceContextAbstractName

      public String getPersistenceContextAbstractName(org.nuiton.eugene.models.object.ObjectModel model)
    • getPersistenceContextConcreteName

      public String getPersistenceContextConcreteName(org.nuiton.eugene.models.object.ObjectModel model)
    • getPersistenceContextInterfaceName

      public String getPersistenceContextInterfaceName(org.nuiton.eugene.models.object.ObjectModel model)
    • getDaoSupplierInterfaceName

      public String getDaoSupplierInterfaceName(org.nuiton.eugene.models.object.ObjectModel model)
    • getDaoSupplierName

      public String getDaoSupplierName(org.nuiton.eugene.models.object.ObjectModel model)
    • getEntityEnumName

      public String getEntityEnumName(org.nuiton.eugene.models.object.ObjectModel model)
    • getEntityAbstractName

      public String getEntityAbstractName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getEntityConcreteName

      public String getEntityConcreteName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getAbstractDaoName

      public String getAbstractDaoName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getGeneratedDaoName

      public String getGeneratedDaoName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getConcreteDaoName

      public String getConcreteDaoName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getContractDaoName

      public String getContractDaoName(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getAbstractDaoFqn

      public String getAbstractDaoFqn(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getGeneratedDaoFqn

      public String getGeneratedDaoFqn(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getConcreteDaoFqn

      public String getConcreteDaoFqn(org.nuiton.eugene.models.object.ObjectModelClass input)
    • getEntityPackage

      public String getEntityPackage(org.nuiton.eugene.java.ObjectModelTransformerToJava transformer, org.nuiton.eugene.models.object.ObjectModel model, org.nuiton.eugene.models.object.ObjectModelClassifier input)
    • getReverseDbName

      public String getReverseDbName(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
      Obtain the reverse db name of an attribute. Try first to get the reverse db Name from the reverseDbname tag-value, then if attribute has a specific reverse attribute, use his db name, otherwise suffix the db name of the attribute by _id.
      Parameters:
      attr - the attribute to seek
      Returns:
      the value of the reverse name
      Since:
      2.5
    • getDbName

      public String getDbName(org.nuiton.eugene.models.object.ObjectModelElement element)
      Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le tag associé si il existe, sinon sur le nom de l'élément
      Parameters:
      element - l'élément à tester
      Returns:
      le nom de table
    • getReverseDbNameOnReverseAttribute

      public String getReverseDbNameOnReverseAttribute(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
      Obtain the reverse db name of a reverse attribute. Note that the reverse attribute can't be null here.
      • Try first to get the reverse db Name from the ReverseDbname tag-value
      • If not found, try then the ReverseDbname tag-value on the same attribute but from this other side of the relation
      • If not found, try then just get the name of the reverse attribute
      Parameters:
      attr - the attribute to seek
      Returns:
      the value of the reverse db name on the reverse attribute
      Since:
      2.9.5.2
    • getNaturalIdAttributes

      public Set<org.nuiton.eugene.models.object.ObjectModelAttribute> getNaturalIdAttributes(org.nuiton.eugene.models.object.ObjectModelClass clazz)
      Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
      Parameters:
      clazz - la classe à tester
      Returns:
      la liste des attributs de la clef métier
    • getNotNullAttributes

      public Set<org.nuiton.eugene.models.object.ObjectModelAttribute> getNotNullAttributes(org.nuiton.eugene.models.object.ObjectModelClass clazz)
      Cherche et renvoie la liste des attributs qui ne doivent pas etre null dans une classe.
      Parameters:
      clazz - la classe à tester
      Returns:
      la liste des attributs qui ne doivent pas etre null
    • isAttributeNotNull

      public boolean isAttributeNotNull(org.nuiton.eugene.models.object.ObjectModelAttribute attribute)
      Detecte si un attribut est marqué comme non null. Les naturalId sont not null par défaut
      Parameters:
      attribute - l'attribut à tester
      Returns:
      true si l'attribut doit être non null, par défaut pour les naturalId, false sinon..
      Since:
      2.6.9
    • getDOType

      public String getDOType(org.nuiton.eugene.models.object.ObjectModelElement elem, org.nuiton.eugene.models.object.ObjectModel model)
    • getDOType

      public String getDOType(String type, org.nuiton.eugene.models.object.ObjectModel model)
    • isNumericType

      public boolean isNumericType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • isTextType

      public boolean isTextType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • isDateType

      public boolean isDateType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • isBooleanType

      public boolean isBooleanType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • isPrimitiveType

      public boolean isPrimitiveType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • getClassForPrimitiveType

      public String getClassForPrimitiveType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
    • hasUnidirectionalRelationOnAbstractType

      public boolean hasUnidirectionalRelationOnAbstractType(org.nuiton.eugene.models.object.ObjectModelAttribute attr, org.nuiton.eugene.models.object.ObjectModel model)

      Cette méthode permet de détecter si - l'attribut représente une relation 1-n - cette relation est unidirectionnelle - le type de l'attribut représente un entité - cette entité a des sous-classes dans le modèle Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a adopter un comportement particulier.

      Parameters:
      attr - l'attribut a tester
      model - le model
      Returns:
      true si et seulement si il s'agit bien de ce type de relation
    • getManyToManyTableName

      public String getManyToManyTableName(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
      Renvoie le nom unique de table pour une relation ManyToMany en fonction de l'attribut attr
      Parameters:
      attr - l'attribut servant de base au calcul du nom
      Returns:
      le nom de la table
    • getNMultiplicityHibernateType

      public String getNMultiplicityHibernateType(org.nuiton.eugene.models.object.ObjectModelAttribute attr)
      Renvoie le type d'interface à utiliser en fonction de l'attribut
      Parameters:
      attr - l'attribut a traiter
      Returns:
      String
    • getEntityClasses

      public List<org.nuiton.eugene.models.object.ObjectModelClass> getEntityClasses(org.nuiton.eugene.models.object.ObjectModel model, boolean sort)
      Obtain the list of entities classes with the possibility to sort the result.
      Parameters:
      model - the current model to scan
      sort - flag to allow sort the result
      Returns:
      the list of filtred classes by their stereotype
    • getImports

      public List<String> getImports(org.nuiton.eugene.models.object.ObjectModelClass aClass, String... incomingFqns)
      Obtain the list of fqn of object involed in the given class.
      Parameters:
      aClass - the clazz to inspect
      incomingFqns - incoming fqns
      Returns:
      the list of fqn of attributes
    • getImports

      public void getImports(org.nuiton.eugene.models.object.ObjectModelClass aClass, Set<String> fqns)
      Obtain the list of fqn of object involed in the given class.
      Parameters:
      aClass - the class to inspect
      fqns - where to store found fqns
    • getImports

      public void getImports(org.nuiton.eugene.models.object.ObjectModelInterface anInterface, Set<String> fqns)
      Obtain the list of fqn of object involed in the given interface.
      Parameters:
      anInterface - the interface to inspect
      fqns - where to store found fqns
    • getImports

      public void getImports(org.nuiton.eugene.models.object.ObjectModelOperation operation, Set<String> fqns)
      Obtain the fqn's list of all involed type in a givne operation.
      Parameters:
      operation - operation to inspect
      fqns - where to store found fqns
    • cleanImports

      public List<String> cleanImports(String packageName, Set<String> fqns)
      Clean a set of fqns, transform it into a List and sort it.
      Parameters:
      packageName - the current package name
      fqns - the dirty set of fqns
      Returns:
      the sorted cleaned list of fqns.
    • searchDirectUsages

      public Map<org.nuiton.eugene.models.object.ObjectModelClass,Set<org.nuiton.eugene.models.object.ObjectModelClass>> searchDirectUsages(org.nuiton.eugene.models.object.ObjectModel model)
    • searchDirectUsages

      public void searchDirectUsages(org.nuiton.eugene.models.object.ObjectModelClass klass, Map<String,org.nuiton.eugene.models.object.ObjectModelClass> allEntitiesByFQN, Map<org.nuiton.eugene.models.object.ObjectModelClass,Set<org.nuiton.eugene.models.object.ObjectModelClass>> usages)
    • isImportNeeded

      public boolean isImportNeeded(Collection<org.nuiton.eugene.models.object.ObjectModelOperation> operations, String importName)
    • isCollectionNeeded

      public boolean isCollectionNeeded(Collection<org.nuiton.eugene.models.object.ObjectModelOperation> operations)
    • isSetNeeded

      public boolean isSetNeeded(Collection<org.nuiton.eugene.models.object.ObjectModelOperation> operations)
    • isEntity

      public boolean isEntity(org.nuiton.eugene.models.object.ObjectModelAttribute attribute, org.nuiton.eugene.models.object.ObjectModel model)
      Check if the given attribute type is an entity.
      Parameters:
      attribute - attribute to test
      model - model containing the attribute
      Returns:
      true if type of attribute is an entity, false otherwise
      Since:
      2.7
      See Also:
    • isEntity

      public boolean isEntity(org.nuiton.eugene.models.object.ObjectModelClassifier classifier)
      Check if the given classifier has the TopiaCoreTagValues.Store.entity and is not an enumeration
      Parameters:
      classifier - classifier to test
      Returns:
      true if stereotype was found and classifier is not enumeration, false otherwise
      Since:
      2.5
      See Also:
    • isAbstract

      public boolean isAbstract(org.nuiton.eugene.models.object.ObjectModelClassifier classifier)
      Check if the given classifier is an abstract class
      Parameters:
      classifier - classifier to test
      Returns:
      true if the classifier is abstract, false otherwise
    • getInheritanceStrategy

      public String getInheritanceStrategy(org.nuiton.eugene.models.object.ObjectModelClassifier classifier)
      Obtain the value of the TopiaHibernateTagValues.Store.inheritanceStrategy tag value on the given classifier.
      Parameters:
      classifier - classifier to seek
      Returns:
      the none empty value of the found tag value or null if not found nor empty.
      Since:
      3.0
      See Also:
    • getCollectionType

      public Class<?> getCollectionType(org.nuiton.eugene.models.object.ObjectModelAttribute attribute)
    • getCollectionInstanceType

      public Class<?> getCollectionInstanceType(org.nuiton.eugene.models.object.ObjectModelAttribute attribute)
    • getLegacyDaoName

      @Deprecated public static String getLegacyDaoName(org.nuiton.eugene.models.object.ObjectModelClass input)
      Deprecated.
      only used for warn to help migration to 3.0, should be deleted
      dependency to add extra operations for entity dao.
      Parameters:
      input - FIXME
      Returns:
      FIXME
      Since:
      2.3.4