Package org.cxbox.core.crudma.impl
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final Class<? extends AnySourceBaseDAO<E>>When using the no-argument constructor, the fieldanySourceBaseDAOClasswill be null.protected org.springframework.context.ApplicationContextprotected Class<? extends PreActionConditionHolderAssoc>protected Class<? extends PreActionConditionHolderDataResponse<T>> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractAnySourceResponseService(Class<T> typeOfDTO, Class<E> typeOfEntity, Class<? extends AnySourceFieldMetaBuilder<T>> metaBuilder, Class<? extends AnySourceBaseDAO<E>> anySourceBaseDAOClass) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionassociate(List<org.cxbox.api.data.dto.AssociateDTO> data, BusinessComponent bc) Creates links between entitiesstatic <T> TlongReturns the number of matching entitiesCreates 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.entityToDto(BusinessComponent bc, E entity) Returns actions for entity with conditions of their availability invoked by method getAvailableActionsClass<? extends AnySourceBaseDAO<E>>Class<? extends AnySourceFieldMetaBuilder<T>>Returns AnySourceFieldMetaBuilder for classgetAvailableActions(RowMetaType metaType, org.cxbox.api.data.dto.DataResponseDTO data, BusinessComponent bc) Returns actions for entity with conditions of their availability invoke method getActionsgetBc()Class<? extends AnySourceBaseDAO<E>>getDao()org.cxbox.api.data.ResultPage<T>Returns a list of matched objects based on a business componentClass<? extends AnySourceFieldMetaBuilder<T>>getMeta()Class<? extends AnySourceFieldMetaBuilder<T>>Returns object based on a business componentReturns an entity based on a business componentprotected <P extends org.cxbox.api.data.dto.DataResponseDTO,F>
FgetParentField(DtoField<P, F> dtoField, BusinessComponent bc) protected List<PreActionEvent>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.AnySourceResponseService
getTypeOfDTO, getTypeOfEntity
-
Field Details
-
typeOfDTO
-
typeOfEntity
-
anySourceBaseDAOClass
When using the no-argument constructor, the field
anySourceBaseDAOClasswill be null. This field should only be accessed throughgetDao(). -
preActionConditionHolderDataResponse
protected Class<? extends PreActionConditionHolderDataResponse<T extends org.cxbox.api.data.dto.DataResponseDTO>> preActionConditionHolderDataResponse -
preActionConditionHolderAssoc
-
applicationContext
@Autowired protected org.springframework.context.ApplicationContext applicationContext
-
-
Constructor Details
-
AbstractAnySourceResponseService
@Deprecated public AbstractAnySourceResponseService(Class<T> typeOfDTO, Class<E> typeOfEntity, Class<? extends AnySourceFieldMetaBuilder<T>> metaBuilder, Class<? extends AnySourceBaseDAO<E>> anySourceBaseDAOClass) Deprecated.To useRequiredArgsConstructorand/or a constructor without parameters, you need to add fieldsmetaBuilder,anySourceBaseDAOClass:@Getter private final Class<ExampleMeta> fieldMetaBuilder = ExampleMeta.class; @Getter private final Class<ExampleDao> anySourceBaseDAOClass = ExampleDao.class;
Alternatively, you can override methodsgetMetaBuilder()getAnySourceBaseDAOClass()
to your subclass.public final Class<? extends AnySourceFieldMetaBuilder<ExampleDTO>> getMetaBuilder() { return ExampleMeta.class; } public final Class<? extends AnySourceBaseDAO<ExampleDTO>> getAnySourceBaseDAOClass() { return ExampleDao.class; } -
AbstractAnySourceResponseService
public AbstractAnySourceResponseService()
-
-
Method Details
-
getBaseDao
- Specified by:
getBaseDaoin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
-
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 interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
-
isDeferredCreationSupported
Description copied from interface:AnySourceResponseServiceDetermines is deferred saving of new objects supported- Specified by:
isDeferredCreationSupportedin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponent
-
hasPersister
public boolean hasPersister()Description copied from interface:AnySourceResponseServiceDetermines whether the service interacts with an entity from the database- Specified by:
hasPersisterin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Returns:
- true/false
-
getOneAsEntity
Description copied from interface:AnySourceResponseServiceReturns an entity based on a business component- Specified by:
getOneAsEntityin interfaceAnySourceResponseService<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:AnySourceResponseServiceReturns object based on a business component- Specified by:
getOnein interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponent- Returns:
- object
-
doGetOne
-
deleteEntity
Description copied from interface:AnySourceResponseServiceDeletes an entity based on a business component- Specified by:
deleteEntityin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponent- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
getList
Description copied from interface:AnySourceResponseServiceReturns a list of matched objects based on a business component- Specified by:
getListin interfaceAnySourceResponseService<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:AnySourceResponseServiceReturns actions for entity with conditions of their availability invoke method getActions- Specified by:
getAvailableActionsin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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:AnySourceResponseServiceReturns actions invoked with cancel- Specified by:
onCancelin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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:AnySourceResponseServiceInvokes action with given name, add preactions, loads or updates entity if necessary- Specified by:
invokeActionin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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:AnySourceResponseServiceReturns the number of matching entities- Specified by:
countin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponent- Returns:
- count
-
validate
Description copied from interface:AnySourceResponseServiceValidates the entry on save- Specified by:
validatein interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponentdata- information about entity, it's changed fields, errors
-
getActions
Description copied from interface:AnySourceResponseServiceReturns actions for entity with conditions of their availability invoked by method getAvailableActions- Specified by:
getActionsin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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
- Specified by:
entityToDtoin interfaceAnySourceResponseService<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
-
getParentField
protected <P extends org.cxbox.api.data.dto.DataResponseDTO,F> F getParentField(DtoField<P, F> dtoField, BusinessComponent bc) seeAbstractResponseService.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 seeAbstractResponseService.getParentField(org.cxbox.constgen.DtoField, org.cxbox.core.crudma.bc.BusinessComponent)) -
isExist
-
loadEntity
-
getAnySourceFieldMetaBuilder
Description copied from interface:AnySourceResponseServiceReturns AnySourceFieldMetaBuilder for class- Specified by:
getAnySourceFieldMetaBuilderin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Returns:
AnySourceFieldMetaBuilderclass for building field meta
-
getMetaBuilder
-
getAnySourceBaseDAOClass
-
getMeta
-
getDao
-
updateEntity
public ActionResultDTO<T> updateEntity(BusinessComponent bc, org.cxbox.api.data.dto.DataResponseDTO data) Description copied from interface:AnySourceResponseServiceUpdates an entity based on a business component by DTO- Specified by:
updateEntityin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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:AnySourceResponseServiceUpdates an entity based on a business component by DTO Used in forceactive fields- Specified by:
previewin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - Parameters:
bc- businessComponentdata- information about entity, it's changed fields, errors- Returns:
ActionResultDTOclass with DataResponseDTO and postactions
-
createEntity
Description copied from interface:AnySourceResponseServiceCreates an entity based on a business component- Specified by:
createEntityin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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:AnySourceResponseServiceCreates links between entities- Specified by:
associatein interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E> - 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) -
getActionType
- Specified by:
getActionTypein interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
-
getBc
- Specified by:
getBcin interfaceAnySourceResponseService<T extends org.cxbox.api.data.dto.DataResponseDTO,E>
-