Class AbstractBaseDO<T extends IBaseEntity>

java.lang.Object
mc.core.system.base.BaseBean
mc.core.domain.base.dobj.AbstractBaseDO<T>
All Implemented Interfaces:
IBaseDO<T>
Direct Known Subclasses:
AbstractEntityBaseDO, BaseDO, CSSystemPropertyDO, MemoDO, NotificationDO, TextSetDO, WorkflowDataDO

public abstract class AbstractBaseDO<T extends IBaseEntity> extends mc.core.system.base.BaseBean implements IBaseDO<T>
common abstract base class for DOs and aspects. TX demarcation if not already active through the @Transactional interceptor. the interceptor binding is derived to all subclasses
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    helper class for framework to avoid a setEntityClass method in public DO API
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addDefaultSearchCriteria(List<mc.core.system.search.BaseSearchCriteria<?>> critList, String param)
    add entity specific default search criteria to list for search by given param
    copy(T source)
     
    void
    delete(T entity)
    WARNING: this method must not be overridden, only override delete(IBaseEntity, boolean)! It cannot be final because J2EE-container does not allow final on methods that require transactional interceptor.
    void
    delete(T entity, boolean force)
    NOTE: when overriding this method and you delete any other objects you need to call validateNotUsed before in case flag force is false!
    getAll(mc.core.system.search.SearchFilter filter)
     
    get all active entities.
    getEntityDisplay(T entity, Locale locale)
     
    getFromId(long entityId)
     
    get entity by key through entity specific property matching
    getOne(mc.core.system.search.SearchFilter filter)
     
    get at least needed user base role for the entity class
    void
    map(List<T> entities, MapContext context, OutputStream os)
    map list of entities to output stream through reader, filter and renderer.
    map(T entity, DataMap dataMap)
    IN mapping: map data to entity through writer and handler
    mc.core.system.search.SearchFilter
    prepareSearchFilter(mc.core.system.search.SearchFilter sf)
    prepare searchFilter for (paged) SearchService search() methods.
    save(T entity)
     
    save(T entity, DataMap dataMap)
    map data to entity if any, validate and save
    AbstractBaseDO<T>.mc.core.domain.base.dobj.AbstractBaseDO.Validator
    validator(T entity, DataMap map)
    for persistent entity copy constructor be used, the copy of entity be mapped and validated
    WARNING: in error case param map be changed! non valid fields be deleted from it
    all error be collect as ValidationResults in ValidationException and throw only by validate() call
    Examples to use:
    1.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractBaseDO

      public AbstractBaseDO()
  • Method Details

    • getUserRole

      public User.UserBaseRole getUserRole()
      Description copied from interface: IBaseDO
      get at least needed user base role for the entity class
      Specified by:
      getUserRole in interface IBaseDO<T extends IBaseEntity>
    • getFromId

      public T getFromId(long entityId) throws EntityNotFoundException
      Parameters:
      entityId -
      Returns:
      the attached entity if found, otherwise throws EntityNotFoundException
      Throws:
      EntityNotFoundException - if no entity of this DO's entity class and given id could be found in persistence context.
    • getFromKey

      public T getFromKey(Object key) throws EntityNotFoundException, NotUniqueResultException
      Description copied from interface: IBaseDO
      get entity by key through entity specific property matching
      Specified by:
      getFromKey in interface IBaseDO<T extends IBaseEntity>
      Returns:
      entity if found and unique
      Throws:
      EntityNotFoundException
      NotUniqueResultException
    • getOne

      public T getOne(mc.core.system.search.SearchFilter filter) throws EntityNotFoundException, NotUniqueResultException
      Throws:
      EntityNotFoundException
      NotUniqueResultException
    • getAll

      public List<T> getAll(mc.core.system.search.SearchFilter filter)
    • addDefaultSearchCriteria

      public void addDefaultSearchCriteria(List<mc.core.system.search.BaseSearchCriteria<?>> critList, String param)
      Description copied from interface: IBaseDO
      add entity specific default search criteria to list for search by given param
      Specified by:
      addDefaultSearchCriteria in interface IBaseDO<T extends IBaseEntity>
      param - mandatory
    • prepareSearchFilter

      public mc.core.system.search.SearchFilter prepareSearchFilter(mc.core.system.search.SearchFilter sf)
      prepare searchFilter for (paged) SearchService search() methods. override to add type specific criteria or ordering. always call super first when overriding and use returned filter
      Returns:
      prepared SearchFilter. never null
    • getAllActive

      public List<T> getAllActive()
      Description copied from interface: IBaseDO
      get all active entities. method is not implemented for all entity classes:
      • Principal: get all with active flag true and isSystem flag false
      • SimpleEntity: get all with isActive flag true and isSystem flag false
      • TypeEntity: get all with isActive flag true
      • all other: throws UnsupportedOperationException cause result may be too large
      Specified by:
      getAllActive in interface IBaseDO<T extends IBaseEntity>
      Returns:
      list of entities matching the above rules
    • delete

      public void delete(T entity) throws ApplicationException
      WARNING: this method must not be overridden, only override delete(IBaseEntity, boolean)! It cannot be final because J2EE-container does not allow final on methods that require transactional interceptor.
      Specified by:
      delete in interface IBaseDO<T extends IBaseEntity>
      Parameters:
      entity - mandatory
      Throws:
      ApplicationException
    • delete

      public void delete(T entity, boolean force) throws ApplicationException
      NOTE: when overriding this method and you delete any other objects you need to call validateNotUsed before in case flag force is false!
      Parameters:
      entity - mandatory
      force - if true delete without usage check, which can result in db constraints error unless references are taken care of
      Throws:
      ApplicationException
    • save

      public T save(T entity) throws ApplicationException
      Throws:
      ApplicationException
    • save

      public T save(T entity, DataMap dataMap) throws ApplicationException
      Description copied from interface: IBaseDO
      map data to entity if any, validate and save
      Specified by:
      save in interface IBaseDO<T extends IBaseEntity>
      Parameters:
      entity - mandatory
      dataMap - optional
      Returns:
      mapped entity
      Throws:
      ApplicationException
    • copy

      public T copy(T source) throws ApplicationException
      Throws:
      ApplicationException
    • map

      public T map(T entity, DataMap dataMap) throws ApplicationException
      IN mapping: map data to entity through writer and handler
      Throws:
      ApplicationException
    • map

      public void map(List<T> entities, MapContext context, OutputStream os) throws ApplicationException
      Description copied from interface: IBaseDO
      map list of entities to output stream through reader, filter and renderer. optionally using settings in publish context.
      Specified by:
      map in interface IBaseDO<T extends IBaseEntity>
      Parameters:
      entities - mandatory, may be empty
      context - optional, if null suitable defaults are used
      os - mandatory
      Throws:
      ApplicationException
    • getEntityDisplay

      public String getEntityDisplay(T entity, Locale locale)
      Specified by:
      getEntityDisplay in interface IBaseDO<T extends IBaseEntity>
      Parameters:
      entity - Attached entity to render as text. Must not be null.
      locale - Language of desired output. If null, master locale is used.
      Returns:
      Entity display according to DO classes or empty string. Never null.
    • validator

      public AbstractBaseDO<T>.mc.core.domain.base.dobj.AbstractBaseDO.Validator validator(T entity, DataMap map) throws ApplicationException
      for persistent entity copy constructor be used, the copy of entity be mapped and validated
      WARNING: in error case param map be changed! non valid fields be deleted from it
      all error be collect as ValidationResults in ValidationException and throw only by validate() call
      Examples to use:
      1. validator( navigationHrc, dataMap).thatValidField( NavigationHrc.Field.navigationHrcType).validate(); 2. validator( navigation, dataMap).thatValidField( Navigation.Field.navigationType, Navigation.Field.navigationHrc) .thatNotNullIf( HrcEntity.Field.parent, n -> n.getNavigationType().getParentNavigationType() != null).validate(); 3. validator( entity, dataMap).thatValidField( Country.Field.iso2Code, "message.validate.Country.iso2Code.missing").thatUnique( Country.Field.iso2Code).validate();
      Parameters:
      entity - mandatory
      map - optional
      Returns:
      the validator
      Throws:
      ApplicationException - the application exception