Class EntityModelFactoryImpl

  • All Implemented Interfaces:
    EntityModelFactory

    public class EntityModelFactoryImpl
    extends Object
    implements EntityModelFactory
    Implementation of the entity model factory - creates models that hold metadata about an entity
    Author:
    bas.rutten
    • Constructor Detail

      • EntityModelFactoryImpl

        public EntityModelFactoryImpl()
        Default constructor without the use of delegated model factories
      • EntityModelFactoryImpl

        public EntityModelFactoryImpl​(EntityModelFactory... delegatedModelFactories)
        Use this constructor when one needs to delegate creation of models to other model factories
        Parameters:
        delegatedModelFactories -
    • Method Detail

      • canProvideModel

        public <T> boolean canProvideModel​(String reference,
                                           Class<T> entityClass)
        Indicates whether this factory can provide the model for the specified combination of reference and entity class
        Specified by:
        canProvideModel in interface EntityModelFactory
        Parameters:
        reference - the reference
      • checkWeekSettingAllowed

        protected void checkWeekSettingAllowed​(AttributeModel model)
        Check that the"week" setting is only allowed for java.time.LocalDate
        Parameters:
        model - the attribute model
      • constructAttributeModel

        protected <T> List<AttributeModel> constructAttributeModel​(PropertyDescriptor descriptor,
                                                                   EntityModelImpl<T> entityModel,
                                                                   Class<?> parentClass,
                                                                   boolean nested,
                                                                   String prefix)
        Constructs an attribute model for a property
        Parameters:
        descriptor - the property descriptor
        entityModel - the entity model
        parentClass - the type of the direct parent of the attribute (relevant in case of embedded attributes)
        nested - whether this is a nested attribute
        prefix - the prefix to apply to the attribute name
        Returns:
      • constructModel

        protected <T> EntityModelImpl<T> constructModel​(Class<T> entityClass,
                                                        String reference,
                                                        EntityModelImpl<T> entityModel)
        Constructs a model
        Parameters:
        entityClass - the entity class
        reference - the unique reference
        entityModel - the base (?) entity model
        Returns:
      • constructModel

        protected <T> EntityModel<T> constructModel​(String reference,
                                                    Class<T> entityClass)
        Constructs the model for an entity
        Parameters:
        entityClass - the class of the entity
        Returns:
      • determineAttributeGroupMapping

        protected <T> Map<String,​String> determineAttributeGroupMapping​(EntityModel<T> model,
                                                                              Class<T> entityClass)
        Constructs the attribute group mapping - from attribute name to the group it belongs to
        Parameters:
        model - the entity model
        entityClass - the entity class
        Returns:
      • determineAttributeOrder

        protected <T> void determineAttributeOrder​(Class<T> entityClass,
                                                   String reference,
                                                   List<AttributeModel> attributeModels)
        Determines the order of the attributes - this will first pick up any attributes that are mentioned in the @AttributeOrder annotation (in the order in which they occur) and then add any attributes that are not explicitly mentioned
        Parameters:
        entityClass -
        reference -
        attributeModels -
      • determineAttributeType

        protected AttributeType determineAttributeType​(Class<?> parentClass,
                                                       AttributeModelImpl model)
        Determines the attribute type of an attribute
        Parameters:
        model - the model representation of the attribute
        Returns:
      • determineDateType

        protected <T> AttributeDateType determineDateType​(Class<?> modelType,
                                                          Class<T> entityClass,
                                                          String fieldName)
        Determines the "dateType" for an attribute
        Parameters:
        modelType - the type of the attribute. Can be a java 8 LocalX type
        entityClass - the class of the entity
        fieldName - the name of the attribute
        Returns:
      • determineDefaultDisplayFormat

        protected String determineDefaultDisplayFormat​(Class<?> type,
                                                       AttributeDateType dateType)
        Determines the default format to use for a date or time property
        Parameters:
        type - the type of the property
        dateType - the date type
        Returns:
      • findModelFactory

        protected <T> EntityModelFactory findModelFactory​(String reference,
                                                          Class<T> entityClass)
        Parameters:
        reference -
        entityClass -
        Returns:
      • getAttributeMessage

        protected <T> String getAttributeMessage​(EntityModel<T> model,
                                                 AttributeModel attributeModel,
                                                 String propertyName)
        Retrieves a message relating to an attribute from the message bundle
        Parameters:
        model - the entity model
        attributeModel - the attribute model
        propertyName - the name of the property
        Returns:
      • getEntityMessage

        protected String getEntityMessage​(String reference,
                                          String propertyName)
        Retrieves a message relating to an entity from the message bundle
        Parameters:
        reference -
        propertyName -
        Returns:
      • getLocale

        protected Locale getLocale()
      • hasEntityModel

        protected boolean hasEntityModel​(Class<?> type,
                                         String reference)
        Check if a certain entity model has already been processed
        Parameters:
        type - the type of the entity
        reference - the reference to the entity
        Returns:
      • hasModel

        public boolean hasModel​(String reference)
      • isVisible

        protected boolean isVisible​(String msg)
        Check whether a message contains a value that marks the attribute as "visible"
        Parameters:
        msg - the message
        Returns:
      • setAnnotationOverrides

        protected void setAnnotationOverrides​(Class<?> parentClass,
                                              AttributeModelImpl model,
                                              PropertyDescriptor descriptor,
                                              boolean nested)
        Overwrite the default values with annotation values
        Parameters:
        parentClass -
        model -
        descriptor -
      • setDefaultValue

        protected void setDefaultValue​(AttributeModelImpl model,
                                       String defaultValue)
        Sets the default value on the attribute model (translates a String to the appropriate type)
        Parameters:
        model - the attribute model
        defaultValue - the default value to set
      • setNestedEntityModel

        protected void setNestedEntityModel​(AttributeModelImpl model)
        Calculates the entity model for a nested property, recursively up until a certain depth
        Parameters:
        model - the attribute model
      • setSortOrder

        protected <T> void setSortOrder​(EntityModel<T> model,
                                        String sortOrderMsg)
        Sets the sort order on an entity model
        Parameters:
        model - the entity model
        sortOrderMsg - the sort order from the message bundle
      • skipAttribute

        protected boolean skipAttribute​(String name)
        Indicates whether to skip an attribute since it does not constitute an actual property but rather a generic or technical field that all entities have
        Parameters:
        name - the name of the attribute
        Returns: