Package org.cxbox.core.crudma.impl
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 Summary
Fields Modifier and Type Field Description protected org.springframework.context.ApplicationContextapplicationContextprotected BaseDAObaseDAOprotected Class<? extends BcSpecificationHolder<E>>bcSpecificationHolderprotected Class<? extends LinkSpecificationHolder<E>>linkSpecificationHolderprotected javax.persistence.metamodel.SingularAttribute<? super E,? extends BaseEntity>parentSpecprotected Class<? extends PreActionConditionHolderAssoc>preActionConditionHolderAssocprotected Class<? extends PreActionConditionHolderDataResponse<T>>preActionConditionHolderDataResponseprotected Class<? extends SecuritySpecificationHolder<E>>securitySpecificationHolderprotected Class<T>typeOfDTOprotected Class<E>typeOfEntity
-
Constructor Summary
Constructors Constructor Description AbstractResponseService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AssociateResultDTOassociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc)Сreates links between entitiesstatic <T> Tcast(Object o, Class<T> clazz)longcount(BusinessComponent bc)Returns the number of matching entitiesprotected longcount(BaseDAO dao, BusinessComponent bc)protected longcount(BaseDAO dao, BusinessComponent bc, Class<E> typeOfEntity, Class<T> typeOfDTO)CreateResult<T>createEntity(BusinessComponent bc)Creates an entity based on a business componentActionResultDTO<T>deleteEntity(BusinessComponent bc)Deletes an entity based on a business componentprotected AssociateResultDTOdoAssociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc)protected TdoGetOne(BusinessComponent bc)protected org.cxbox.api.data.ResultPage<T>dtoListToResultPage(List<T> dtos, int limit)protected org.cxbox.api.data.ResultPage<T>entitiesToDtos(BusinessComponent bc, org.cxbox.api.data.ResultPage<E> entities)protected org.cxbox.api.data.ResultPage<E>entityListToResultPage(List<E> entities, int limit)Deprecated.protected TentityToDto(BusinessComponent bc, E entity)Actions<T>getActions()Returns actions for entity with conditions of their availability invoked by method getAvailableActionsList<String>getAssociatedSsNames()ActionsDTOgetAvailableActions(RowMetaType metaType, org.cxbox.api.data.dto.DataResponseDTO data, BusinessComponent bc)Returns actions for entity with conditions of their availability invoke method getActionsprotected org.springframework.data.jpa.domain.Specification<E>getBcSpecification(InnerBcDescription bcDescription)protected javax.persistence.EntityGraph<? super E>getFetchGraph(BusinessComponent bc)protected StringgetFetchGraphName(BusinessComponent bc)Class<? extends FieldMetaBuilder<T>>getFieldMetaBuilder()Returns FieldMetaBuilder for classprotected org.springframework.data.jpa.domain.Specification<E>getLinkSpecification(BusinessComponent bc)org.cxbox.api.data.ResultPage<T>getList(BusinessComponent bc)Returns a list of matched objects based on a business componentprotected org.cxbox.api.data.ResultPage<T>getList(BaseDAO dao, BusinessComponent bc)protected org.cxbox.api.data.ResultPage<T>getList(BaseDAO dao, BusinessComponent bc, Class<E> typeOfEntity, Class<T> typeOfDTO)TgetOne(BusinessComponent bc)Returns object based on a business componentEgetOneAsEntity(BusinessComponent bc)Returns an entity based on a business componentprotected org.cxbox.api.data.ResultPage<E>getPageEntities(BusinessComponent bc, QueryParameters queryParameters)protected org.springframework.data.jpa.domain.Specification<E>getParentSpecification(BusinessComponent bc)protected List<PreActionEvent>getPreActionsForSave()protected org.springframework.data.jpa.domain.Specification<E>getSecuritySpecification(InnerBcDescription bcDescription)protected org.springframework.data.jpa.domain.Specification<E>getSpecification(BusinessComponent bc)booleanhasPersister()Determines whether the service interacts with an entity from the databaseActionResultDTO<T>invokeAction(BusinessComponent bc, String actionName, org.cxbox.api.data.dto.DataResponseDTO data)Invokes action with given name, add preactions, loads or updates entity if necessarybooleanisDeferredCreationSupported(BusinessComponent bc)Determines is deferred saving of new objects supportedprotected EisExist(Long id)protected EloadEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)ActionResultDTOonCancel(BusinessComponent bc)Returns actions invoked with cancelActionResultDTO<T>preview(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)Updates an entity based on a business component by DTO Used in forceactive fields<V> voidsetIfChanged(T dto, DtoField<? super T,V> dtoField, Consumer<V> entitySetter)Saving the value of the DTO field (when it changes) in the entity field.<V> voidsetIfChanged(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).<D,V>
voidsetMappedIfChanged(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.<D,V>
voidsetMappedIfChanged(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).<V> Vunwrap(Class<V> cls)ActionResultDTO<T>updateEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)Updates an entity based on a business component by DTOvoidvalidate(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)Validates the entry on save-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cxbox.core.service.ResponseService
getTypeOfDTO, getTypeOfEntity
-
-
-
-
Field Detail
-
typeOfEntity
protected final Class<E extends BaseEntity> typeOfEntity
-
parentSpec
protected final javax.persistence.metamodel.SingularAttribute<? super E extends BaseEntity,? extends BaseEntity> parentSpec
-
securitySpecificationHolder
protected Class<? extends SecuritySpecificationHolder<E extends BaseEntity>> securitySpecificationHolder
-
bcSpecificationHolder
protected Class<? extends BcSpecificationHolder<E extends BaseEntity>> bcSpecificationHolder
-
linkSpecificationHolder
protected Class<? extends LinkSpecificationHolder<E extends BaseEntity>> linkSpecificationHolder
-
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
-
-
Method Detail
-
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 fieldV- type of entity field to the value is to be saved- Parameters:
dto- DTO-object, which value to be saved to the entity fielddtoField- the DTO-object field, which value to be saved to the entity fieldentitySetter- method for saving a value (when it changes) to an entitydtoGetter- method for retrieving a value (when it changes) from the DTOmapper- 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 fielddtoField- the DTO-object field, which value to be saved to the entity fieldentitySetter- method for saving a value (when it changes) to an entitydtoGetter- 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 fieldV- type of entity field to the value is to be saved- Parameters:
dto- DTO-object, which value to be saved to the entity fielddtoField- the DTO-object field, which value to be saved to the entity fieldentitySetter- method for saving a value (when it changes) to an entitymapper- 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 fielddtoField- the DTO-object field, which value to be saved to the entity fieldentitySetter- method for saving a value (when it changes) to an entity
-
unwrap
public <V> V unwrap(Class<V> cls)
- Specified by:
unwrapin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
-
isDeferredCreationSupported
public boolean isDeferredCreationSupported(BusinessComponent bc)
Description copied from interface:ResponseServiceDetermines is deferred saving of new objects supported- Specified by:
isDeferredCreationSupportedin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponent
-
hasPersister
public boolean hasPersister()
Description copied from interface:ResponseServiceDetermines whether the service interacts with an entity from the database- Specified by:
hasPersisterin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Returns:
- true/false
-
getOneAsEntity
public E getOneAsEntity(BusinessComponent bc)
Description copied from interface:ResponseServiceReturns an entity based on a business component- Specified by:
getOneAsEntityin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponent- Returns:
BaseEntityentity
-
getOne
@Cacheable(cacheResolver="cxboxCacheResolver", cacheNames="requestCache", key="{#root.targetClass, #root.methodName, #bc.name, #bc.id}") public T getOne(BusinessComponent bc)Description copied from interface:ResponseServiceReturns object based on a business component- Specified by:
getOnein interfaceResponseService<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:ResponseServiceDeletes an entity based on a business component- Specified by:
deleteEntityin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponent- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
getList
public org.cxbox.api.data.ResultPage<T> getList(BusinessComponent bc)
Description copied from interface:ResponseServiceReturns a list of matched objects based on a business component- Specified by:
getListin interfaceResponseService<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 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:ResponseServiceReturns actions for entity with conditions of their availability invoke method getActions- Specified by:
getAvailableActionsin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
metaType- type of metadata- information about entity, it's changed fields, errorsbc- businessComponent- Returns:
AssociateResultDTOclass with DataResponseDTO and postactions
-
onCancel
public ActionResultDTO onCancel(BusinessComponent bc)
Description copied from interface:ResponseServiceReturns actions invoked with cancel- Specified by:
onCancelin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponent- Returns:
AssociateResultDTOclass with DataResponseDTO and postactions
-
invokeAction
public ActionResultDTO<T> invokeAction(BusinessComponent bc, String actionName, org.cxbox.api.data.dto.DataResponseDTO data)
Description copied from interface:ResponseServiceInvokes action with given name, add preactions, loads or updates entity if necessary- Specified by:
invokeActionin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponentactionName- name of actiondata- information about entity, it's changed fields, errors- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
count
public long count(BusinessComponent bc)
Description copied from interface:ResponseServiceReturns the number of matching entities- Specified by:
countin interfaceResponseService<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:ResponseServiceValidates the entry on save- Specified by:
validatein interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponentdata- information about entity, it's changed fields, errors
-
getActions
public Actions<T> getActions()
Description copied from interface:ResponseServiceReturns actions for entity with conditions of their availability invoked by method getAvailableActions- Specified by:
getActionsin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Returns:
AssociateResultDTOclass 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)
-
loadEntity
protected E loadEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
-
getFieldMetaBuilder
public Class<? extends FieldMetaBuilder<T>> getFieldMetaBuilder()
Description copied from interface:ResponseServiceReturns FieldMetaBuilder for class- Specified by:
getFieldMetaBuilderin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Returns:
FieldMetaBuilderclass for building field meta
-
updateEntity
public ActionResultDTO<T> updateEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
Description copied from interface:ResponseServiceUpdates an entity based on a business component by DTO- Specified by:
updateEntityin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponentdata- information about entity, it's changed fields, errors- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
preview
public ActionResultDTO<T> preview(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data)
Description copied from interface:ResponseServiceUpdates an entity based on a business component by DTO Used in forceactive fields- Specified by:
previewin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponentdata- information about entity, it's changed fields, errors- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
createEntity
public CreateResult<T> createEntity(BusinessComponent bc)
Description copied from interface:ResponseServiceCreates an entity based on a business component- Specified by:
createEntityin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
bc- businessComponent- Returns:
CreateResultclass 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:
associatein interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>- Parameters:
data- information about an entity, whether the entity was associatedbc- businessComponent- Returns:
AssociateResultDTOclass 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)
-
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)
-
-