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

java.lang.Object
org.cxbox.core.crudma.impl.AbstractResponseService<T,E>
All Implemented Interfaces:
ResponseService<T,E>
Direct Known Subclasses:
VersionAwareResponseService

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

    • typeOfDTO

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

      protected final Class<E extends BaseEntity> typeOfEntity
    • parentSpec

      protected final jakarta.persistence.metamodel.SingularAttribute<? super E extends BaseEntity,? extends BaseEntity> parentSpec
    • preActionConditionHolderDataResponse

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

      protected Class<? extends PreActionConditionHolderAssoc> preActionConditionHolderAssoc
    • baseDAO

      @Autowired protected BaseDAO baseDAO
    • applicationContext

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

    • AbstractResponseService

      public AbstractResponseService()
  • Method Details

    • 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 ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
    • isDeferredCreationSupported

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

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

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

      protected T doGetOne(BusinessComponent bc)
    • deleteEntity

      public ActionResultDTO<T> deleteEntity(BusinessComponent bc)
      Description copied from interface: ResponseService
      Deletes an entity based on a business component
      Specified by:
      deleteEntity in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Returns a list of matched objects based on a business component
      Specified by:
      getList in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      Parameters:
      bc - businessComponent
      Returns:
      list of matched objects
    • getList

      protected org.cxbox.api.data.ResultPage<T> getList(BaseDAO dao, BusinessComponent bc)
    • getList

      protected final org.cxbox.api.data.ResultPage<T> getList(BaseDAO dao, BusinessComponent bc, Class<E> typeOfEntity, Class<T> typeOfDTO)
    • getPageEntities

      protected final org.cxbox.api.data.ResultPage<E> getPageEntities(BusinessComponent bc, QueryParameters queryParameters)
    • getFetchGraphName

      protected String getFetchGraphName(BusinessComponent bc)
    • getFetchGraph

      protected jakarta.persistence.EntityGraph<? super E> getFetchGraph(BusinessComponent bc)
    • getAvailableActions

      public ActionsDTO getAvailableActions(RowMetaType metaType, org.cxbox.api.data.dto.DataResponseDTO data, BusinessComponent bc)
      Description copied from interface: ResponseService
      Returns actions for entity with conditions of their availability invoke method getActions
      Specified by:
      getAvailableActions in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Returns actions invoked with cancel
      Specified by:
      onCancel in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Invokes action with given name, add preactions, loads or updates entity if necessary
      Specified by:
      invokeAction in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Returns the number of matching entities
      Specified by:
      count in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      Parameters:
      bc - businessComponent
      Returns:
      count
    • count

      protected long count(BaseDAO dao, BusinessComponent bc)
    • count

      protected final long count(BaseDAO dao, BusinessComponent bc, Class<E> typeOfEntity, Class<T> typeOfDTO)
    • validate

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

      public Actions<T> getActions()
      Description copied from interface: ResponseService
      Returns actions for entity with conditions of their availability invoked by method getAvailableActions
      Specified by:
      getActions in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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

      protected T entityToDto(BusinessComponent bc, E entity)
    • 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)
    • getParentSpecification

      protected org.springframework.data.jpa.domain.Specification<E> getParentSpecification(BusinessComponent bc)
    • getParentField

      protected <P extends org.cxbox.api.data.dto.DataResponseDTO, F> F getParentField(DtoField<P,F> dtoField, BusinessComponent bc)
      Type Parameters:
      P - parent DTO type
      F - parent DTO field type
      Parameters:
      dtoField - parent bc DTO field
      bc - current bc (parent will be taken from it automatically)
      Returns:
      parent DTO In this DTO you'll get parent state including not persisted yet changes. Cases:
      1) parent is saved to persistence storage - it will be mapped to DTO with entityToDTO method and returned as DTO
      2) parent is saved to persistence storage and have new not yet persisted changes that backend already knows about (for example parent have force active field that was changed and this change is stored in BcStateAware). In this case entity will be fetched from persistence storage and then changes from BcStateAware will be applied with doUpdate method, so you'll get parent DTO with ALL CHANGES backend already knows about
      3) parent is in creation process and have new not yet persisted changes - result will be same as in 2), e.g. you'll get parent DTO with ALL CHANGES backend already knows about

      CREATE new row directly in popup: One MUST use this method, when service is used to CREATE new row directly in popup, because in this case the only way to get data from parent is this method Why behaviour is different? Why you cannot not get parent with repository findById(bc.getParentIdAsLong())? Because commiting changes to new child in popup, would have to commit not yet persisted changes in parent TOO which is wrong and breaks parent creation cancellation, so parent not persisted changes is not available in DB at all when child action is not readonly (e.g. changes will not be rolled back)!

      Other, then CREATE new row directly in popup cases: Fill free to use this method, or as usually get parent with repository findById(bc.getParentIdAsLong())
    • isExist

      protected final E isExist(Long id)
    • loadEntity

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

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

      public ActionResultDTO<T> updateEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
      Description copied from interface: ResponseService
      Updates an entity based on a business component by DTO
      Specified by:
      updateEntity in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Updates an entity based on a business component by DTO Used in forceactive fields
      Specified by:
      preview in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Creates an entity based on a business component
      Specified by:
      createEntity in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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: ResponseService
      Сreates links between entities
      Specified by:
      associate in interface ResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
      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)
    • getSpecification

      protected org.springframework.data.jpa.domain.Specification<E> getSpecification(BusinessComponent bc)
    • getActionType

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

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