Package com.ocs.dynamo.domain.model.impl
Class EntityModelFactoryImpl
- java.lang.Object
-
- com.ocs.dynamo.domain.model.impl.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 Summary
Constructors Constructor Description EntityModelFactoryImpl()Default constructor without the use of delegated model factoriesEntityModelFactoryImpl(EntityModelFactory... delegatedModelFactories)Use this constructor when one needs to delegate creation of models to other model factories
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> booleancanProvideModel(String reference, Class<T> entityClass)Indicates whether this factory can provide the model for the specified combination of reference and entity classprotected voidcheckWeekSettingAllowed(AttributeModel model)Check that the"week" setting is only allowed for java.time.LocalDateprotected <T> List<AttributeModel>constructAttributeModel(PropertyDescriptor descriptor, EntityModelImpl<T> entityModel, Class<?> parentClass, boolean nested, String prefix)Constructs an attribute model for a propertyprotected <T> EntityModelImpl<T>constructModel(Class<T> entityClass, String reference, EntityModelImpl<T> entityModel)Constructs a modelprotected <T> EntityModel<T>constructModel(String reference, Class<T> entityClass)Constructs the model for an entityEntityModel<?>constructNestedEntityModel(EntityModelFactory master, Class<?> type, String reference)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 toprotected <T> voiddetermineAttributeOrder(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 mentionedprotected AttributeTypedetermineAttributeType(Class<?> parentClass, AttributeModelImpl model)Determines the attribute type of an attributeprotected <T> AttributeDateTypedetermineDateType(Class<?> modelType, Class<T> entityClass, String fieldName)Determines the "dateType" for an attributeprotected StringdetermineDefaultDisplayFormat(Class<?> type, AttributeDateType dateType)Determines the default format to use for a date or time propertyprotected <T> EntityModelFactoryfindModelFactory(String reference, Class<T> entityClass)protected <T> StringgetAttributeMessage(EntityModel<T> model, AttributeModel attributeModel, String propertyName)Retrieves a message relating to an attribute from the message bundleprotected StringgetEntityMessage(String reference, String propertyName)Retrieves a message relating to an entity from the message bundleprotected LocalegetLocale()MessageServicegetMessageService()<T> EntityModel<T>getModel(Class<T> entityClass)<T> EntityModel<T>getModel(String reference, Class<T> entityClass)protected booleanhasEntityModel(Class<?> type, String reference)Check if a certain entity model has already been processedbooleanhasModel(String reference)protected booleanisVisible(String msg)Check whether a message contains a value that marks the attribute as "visible"protected voidsetAnnotationOverrides(Class<?> parentClass, AttributeModelImpl model, PropertyDescriptor descriptor, boolean nested)Overwrite the default values with annotation valuesprotected voidsetDefaultValue(AttributeModelImpl model, String defaultValue)Sets the default value on the attribute model (translates a String to the appropriate type)protected voidsetNestedEntityModel(AttributeModelImpl model)Calculates the entity model for a nested property, recursively up until a certain depthprotected <T> voidsetSortOrder(EntityModel<T> model, String sortOrderMsg)Sets the sort order on an entity modelprotected booleanskipAttribute(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
-
-
-
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:
canProvideModelin interfaceEntityModelFactory- 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 descriptorentityModel- the entity modelparentClass- the type of the direct parent of the attribute (relevant in case of embedded attributes)nested- whether this is a nested attributeprefix- 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 classreference- the unique referenceentityModel- 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:
-
constructNestedEntityModel
public EntityModel<?> constructNestedEntityModel(EntityModelFactory master, Class<?> type, String reference)
-
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 modelentityClass- 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 typeentityClass- the class of the entityfieldName- 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 propertydateType- 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 modelattributeModel- the attribute modelpropertyName- 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()
-
getMessageService
public MessageService getMessageService()
-
getModel
public <T> EntityModel<T> getModel(Class<T> entityClass)
- Specified by:
getModelin interfaceEntityModelFactory
-
getModel
public <T> EntityModel<T> getModel(String reference, Class<T> entityClass)
- Specified by:
getModelin interfaceEntityModelFactory
-
hasEntityModel
protected boolean hasEntityModel(Class<?> type, String reference)
Check if a certain entity model has already been processed- Parameters:
type- the type of the entityreference- 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 modeldefaultValue- 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 modelsortOrderMsg- 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:
-
-