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

    • Constructor Detail

      • AbstractResponseService

        public AbstractResponseService()
    • Method Detail

      • 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
      • 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
      • 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
      • 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
      • getFetchGraph

        protected javax.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
      • 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
      • 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
      • entitiesToDtos

        protected org.cxbox.api.data.ResultPage<T> entitiesToDtos​(BusinessComponent bc,
                                                                  org.cxbox.api.data.ResultPage<E> entities)
      • 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)
      • isExist

        protected final E isExist​(Long id)
      • loadEntity

        protected E loadEntity​(BusinessComponent bc,
                               org.cxbox.api.data.dto.DataResponseDTO data)
      • 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
      • getSpecification

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

        protected org.springframework.data.jpa.domain.Specification<E> getSecuritySpecification​(InnerBcDescription bcDescription)
      • getBcSpecification

        protected org.springframework.data.jpa.domain.Specification<E> getBcSpecification​(InnerBcDescription bcDescription)
      • getLinkSpecification

        protected org.springframework.data.jpa.domain.Specification<E> getLinkSpecification​(BusinessComponent bc)
      • getAssociatedSsNames

        public List<String> getAssociatedSsNames()