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
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContextprotected BaseDAOprotected final jakarta.persistence.metamodel.SingularAttribute<? super E,? extends BaseEntity> protected Class<? extends PreActionConditionHolderAssoc>protected Class<? extends PreActionConditionHolderDataResponse<T>> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractResponseService(Class<T> typeOfDTO, Class<E> typeOfEntity, jakarta.persistence.metamodel.SingularAttribute<? super E, ? extends BaseEntity> parentSpec, Class<? extends FieldMetaBuilder<T>> metaBuilder) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionassociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc) Сreates links between entitiesstatic <T> TlongReturns the number of matching entitiesprotected longcount(BaseDAO dao, BusinessComponent bc) protected final longCreates an entity based on a business componentDeletes an entity based on a business componentprotected AssociateResultDTOdoAssociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc) protected Tprotected 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) Returns actions for entity with conditions of their availability invoked by method getAvailableActionsgetAvailableActions(RowMetaType metaType, org.cxbox.api.data.dto.DataResponseDTO data, BusinessComponent bc) Returns actions for entity with conditions of their availability invoke method getActionsgetBc()protected jakarta.persistence.EntityGraph<? super E>protected StringClass<? extends FieldMetaBuilder<T>>Returns FieldMetaBuilder for classorg.cxbox.api.data.ResultPage<T>Returns a list of matched objects based on a business componentprotected org.cxbox.api.data.ResultPage<T>getList(BaseDAO dao, BusinessComponent bc) protected final org.cxbox.api.data.ResultPage<T>Class<? extends FieldMetaBuilder<T>>getMeta()Returns object based on a business componentReturns an entity based on a business componentprotected final org.cxbox.api.data.ResultPage<E>getPageEntities(BusinessComponent bc, QueryParameters queryParameters) protected <P extends org.cxbox.api.data.dto.DataResponseDTO,F>
FgetParentField(DtoField<P, F> dtoField, BusinessComponent bc) protected org.springframework.data.jpa.domain.Specification<E>protected List<PreActionEvent>protected org.springframework.data.jpa.domain.Specification<E>booleanDetermines whether the service interacts with an entity from the databaseinvokeAction(BusinessComponent bc, String actionName, org.cxbox.api.data.dto.DataResponseDTO data) Invokes action with given name, add preactions, loads or updates entity if necessarybooleanDetermines is deferred saving of new objects supportedprotected final Eprotected EloadEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data) Returns actions invoked with cancelpreview(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data) Updates an entity based on a business component by DTO Used in forceactive fieldsfinal <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.final <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).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.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).<V> VupdateEntity(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 saveMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cxbox.core.service.ResponseService
getTypeOfDTO, getTypeOfEntity
-
Field Details
-
typeOfDTO
-
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
-
baseDAO
-
applicationContext
@Autowired protected org.springframework.context.ApplicationContext applicationContext
-
-
Constructor Details
-
AbstractResponseService
@Deprecated public AbstractResponseService(Class<T> typeOfDTO, Class<E> typeOfEntity, jakarta.persistence.metamodel.SingularAttribute<? super E, ? extends BaseEntity> parentSpec, Class<? extends FieldMetaBuilder<T>> metaBuilder) Deprecated.To useRequiredArgsConstructorand/or a constructor without parameters, you need to add the fieldmetaBuilder:@Getter private final Class<ExampleMeta> fieldMetaBuilder = ExampleMeta.class;
Alternatively, you can override the methodgetFieldMetaBuilder()
to your subclass.public final Class<? extends FieldMetaBuilder<ExampleDTO>> getFieldMetaBuilder() { return ExampleMeta.class; } -
AbstractResponseService
public AbstractResponseService()
-
-
Method Details
-
cast
-
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
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
- Specified by:
unwrapin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
-
isDeferredCreationSupported
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
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
-
deleteEntity
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
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
-
getList
-
getPageEntities
protected final org.cxbox.api.data.ResultPage<E> getPageEntities(BusinessComponent bc, QueryParameters queryParameters) -
getFetchGraphName
-
getFetchGraph
-
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
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
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
-
count
-
validate
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
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
-
entitiesToDtos
protected org.cxbox.api.data.ResultPage<T> entitiesToDtos(BusinessComponent bc, org.cxbox.api.data.ResultPage<E> entities) -
entityToDto
-
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
-
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 typeF- parent DTO field type- Parameters:
dtoField- parent bc DTO fieldbc- 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
-
loadEntity
-
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
-
getMeta
-
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
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) -
getActionType
- Specified by:
getActionTypein interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
-
getBc
- Specified by:
getBcin interfaceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E extends BaseEntity>
-