Class AbstractAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>

java.lang.Object
org.cxbox.core.crudma.impl.AbstractAnySourceResponseService<T,E>
All Implemented Interfaces:
AnySourceResponseServiceMarker, AnySourceResponseService<T,E>
Direct Known Subclasses:
AnySourceVersionAwareResponseService

@Transactional public abstract class AbstractAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> extends Object implements AnySourceResponseService<T,E>
  • Field Details

    • typeOfDTO

      protected final Class<T extends org.cxbox.api.data.dto.DataResponseDTO> typeOfDTO
    • typeOfEntity

      protected final Class<E> typeOfEntity
    • anySourceBaseDAOClass

      protected final Class<? extends AnySourceBaseDAO<E>> anySourceBaseDAOClass
    • preActionConditionHolderDataResponse

      protected Class<? extends PreActionConditionHolderDataResponse<T extends org.cxbox.api.data.dto.DataResponseDTO>> preActionConditionHolderDataResponse
    • preActionConditionHolderAssoc

      protected Class<? extends PreActionConditionHolderAssoc> preActionConditionHolderAssoc
    • applicationContext

      @Autowired protected org.springframework.context.ApplicationContext applicationContext
  • Constructor Details

    • AbstractAnySourceResponseService

      public AbstractAnySourceResponseService()
  • Method Details

    • getBaseDao

      public AnySourceBaseDAO<E> getBaseDao()
      Specified by:
      getBaseDao in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
    • cast

      public static <T> T cast(Object o, Class<T> clazz)
    • setMappedIfChanged

      public final <D, V> void setMappedIfChanged(T dto, DtoField<? super T,D> dtoField, Consumer<V> entitySetter, Supplier<D> dtoGetter, Function<D,V> mapper)
      Saving the value of the DTO field (when it changes) in the entity field (using the custom DTO-getter).
      Type Parameters:
      D - type of DTO field value to be saved in the entity field
      V - type of entity field to the value is to be saved
      Parameters:
      dto - DTO-object, which value to be saved to the entity field
      dtoField - the DTO-object field, which value to be saved to the entity field
      entitySetter - method for saving a value (when it changes) to an entity
      dtoGetter - method for retrieving a value (when it changes) from the DTO
      mapper - converts the saving value into the corresponding entity field type
    • setIfChanged

      public final <V> void setIfChanged(T dto, DtoField<? super T,V> dtoField, Consumer<V> entitySetter, Supplier<V> dtoGetter)
      Saving the value of the DTO field (when it changes) in the entity field (using the custom DTO-getter).
      Type Parameters:
      V - type of entity field to the value is to be saved
      Parameters:
      dto - DTO-object, which value to be saved to the entity field
      dtoField - the DTO-object field, which value to be saved to the entity field
      entitySetter - method for saving a value (when it changes) to an entity
      dtoGetter - method for retrieving a value (when it changes) from the DTO
    • setMappedIfChanged

      public final <D, V> void setMappedIfChanged(T dto, DtoField<? super T,D> dtoField, Consumer<V> entitySetter, Function<D,V> mapper)
      Saving the value of the DTO field (when it changes) in the entity field.
      Type Parameters:
      D - type of DTO field value to be saved in the entity field
      V - type of entity field to the value is to be saved
      Parameters:
      dto - DTO-object, which value to be saved to the entity field
      dtoField - the DTO-object field, which value to be saved to the entity field
      entitySetter - method for saving a value (when it changes) to an entity
      mapper - converts the saving value into the corresponding entity field type
    • setIfChanged

      public final <V> void setIfChanged(T dto, DtoField<? super T,V> dtoField, Consumer<V> entitySetter)
      Saving the value of the DTO field (when it changes) in the entity field.
      Type Parameters:
      V - type of entity field to the value is to be saved
      Parameters:
      dto - DTO-object, which value to be saved to the entity field
      dtoField - the DTO-object field, which value to be saved to the entity field
      entitySetter - method for saving a value (when it changes) to an entity
    • unwrap

      public <V> V unwrap(Class<V> cls)
      Specified by:
      unwrap in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
    • isDeferredCreationSupported

      public boolean isDeferredCreationSupported(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Determines is deferred saving of new objects supported
      Specified by:
      isDeferredCreationSupported in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
    • hasPersister

      public boolean hasPersister()
      Description copied from interface: AnySourceResponseService
      Determines whether the service interacts with an entity from the database
      Specified by:
      hasPersister in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Returns:
      true/false
    • getOneAsEntity

      public E getOneAsEntity(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns an entity based on a business component
      Specified by:
      getOneAsEntity in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      entity
    • getOne

      @Cacheable(cacheResolver="cxboxCacheResolver", cacheNames="requestCache", key="{#root.targetClass, #root.methodName, #bc.name, #bc.id}") public T getOne(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns object based on a business component
      Specified by:
      getOne in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      object
    • doGetOne

      protected T doGetOne(BusinessComponent bc)
    • deleteEntity

      public ActionResultDTO<T> deleteEntity(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Deletes an entity based on a business component
      Specified by:
      deleteEntity in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      ActionResultDTO class with DataResponseDTO and postactions
    • getList

      public org.cxbox.api.data.ResultPage<T> getList(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns a list of matched objects based on a business component
      Specified by:
      getList in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      list of matched objects
    • getAvailableActions

      public ActionsDTO getAvailableActions(RowMetaType metaType, org.cxbox.api.data.dto.DataResponseDTO data, BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns actions for entity with conditions of their availability invoke method getActions
      Specified by:
      getAvailableActions in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      metaType - type of meta
      data - information about entity, it's changed fields, errors
      bc - businessComponent
      Returns:
      AssociateResultDTO class with DataResponseDTO and postactions
    • onCancel

      public ActionResultDTO onCancel(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns actions invoked with cancel
      Specified by:
      onCancel in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      AssociateResultDTO class with DataResponseDTO and postactions
    • invokeAction

      public ActionResultDTO<T> invokeAction(BusinessComponent bc, String actionName, org.cxbox.api.data.dto.DataResponseDTO data)
      Description copied from interface: AnySourceResponseService
      Invokes action with given name, add preactions, loads or updates entity if necessary
      Specified by:
      invokeAction in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      actionName - name of action
      data - information about entity, it's changed fields, errors
      Returns:
      ActionResultDTO class with DataResponseDTO and postactions
    • count

      public long count(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Returns the number of matching entities
      Specified by:
      count in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      count
    • validate

      public void validate(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
      Description copied from interface: AnySourceResponseService
      Validates the entry on save
      Specified by:
      validate in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      data - information about entity, it's changed fields, errors
    • getActions

      public Actions<T> getActions()
      Description copied from interface: AnySourceResponseService
      Returns actions for entity with conditions of their availability invoked by method getAvailableActions
      Specified by:
      getActions in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Returns:
      AssociateResultDTO class with DataResponseDTO and postactions
    • getPreActionsForSave

      protected List<PreActionEvent> getPreActionsForSave()
    • entitiesToDtos

      protected org.cxbox.api.data.ResultPage<T> entitiesToDtos(BusinessComponent bc, org.cxbox.api.data.ResultPage<E> entities)
    • entityToDto

      public T entityToDto(BusinessComponent bc, E entity)
      Specified by:
      entityToDto in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
    • entityListToResultPage

      @Deprecated protected org.cxbox.api.data.ResultPage<E> entityListToResultPage(List<E> entities, int limit)
      Deprecated.
      deprecated, the hasNext formation logic has been moved to the DAO layer Left for custom DAOs that return List instead of ResultPage
    • dtoListToResultPage

      protected org.cxbox.api.data.ResultPage<T> dtoListToResultPage(List<T> dtos, int limit)
    • getParentField

      protected <P extends org.cxbox.api.data.dto.DataResponseDTO, F> F getParentField(DtoField<P,F> dtoField, BusinessComponent bc)
      see AbstractResponseService.getParentField(org.cxbox.constgen.DtoField, org.cxbox.core.crudma.bc.BusinessComponent)
      Note! AnySource api do not restore bc state with insert/update to DB and 'rollback'/'commit' changes if user 'did not complete'/'completed' process, but restores state in fully independent custom cache, so all any source bc's can be fetched with baseDao.getById()

      But you can use AnySource service as child and VersionAware as parent, so when CREATING ROW directly in child popup, then parent can again be fetched only with this method see AbstractResponseService.getParentField(org.cxbox.constgen.DtoField, org.cxbox.core.crudma.bc.BusinessComponent))
    • isExist

      protected final E isExist(BusinessComponent bc)
    • loadEntity

      protected E loadEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
    • getAnySourceFieldMetaBuilder

      public Class<? extends AnySourceFieldMetaBuilder<T>> getAnySourceFieldMetaBuilder()
      Description copied from interface: AnySourceResponseService
      Returns AnySourceFieldMetaBuilder for class
      Specified by:
      getAnySourceFieldMetaBuilder in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Returns:
      AnySourceFieldMetaBuilder class for building field meta
    • updateEntity

      public ActionResultDTO<T> updateEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
      Description copied from interface: AnySourceResponseService
      Updates an entity based on a business component by DTO
      Specified by:
      updateEntity in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      data - information about entity, it's changed fields, errors
      Returns:
      ActionResultDTO class with DataResponseDTO and postactions
    • preview

      public ActionResultDTO<T> preview(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
      Description copied from interface: AnySourceResponseService
      Updates an entity based on a business component by DTO Used in forceactive fields
      Specified by:
      preview in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      data - information about entity, it's changed fields, errors
      Returns:
      ActionResultDTO class with DataResponseDTO and postactions
    • createEntity

      public CreateResult<T> createEntity(BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Creates an entity based on a business component
      Specified by:
      createEntity in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      bc - businessComponent
      Returns:
      CreateResult class with DataResponseDTO and postactions
    • associate

      public AssociateResultDTO associate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc)
      Description copied from interface: AnySourceResponseService
      Creates links between entities
      Specified by:
      associate in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
      Parameters:
      data - information about an entity, whether the entity was associated
      bc - businessComponent
      Returns:
      AssociateResultDTO class with DataResponseDTO and postactions
    • doAssociate

      protected AssociateResultDTO doAssociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc)
    • getActionType

      public CrudmaActionType getActionType()
      Specified by:
      getActionType in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
    • getBc

      public BusinessComponent getBc()
      Specified by:
      getBc in interface AnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>