Search in sources :

Example 1 with EasyCrudExceptionStrategy

use of org.summerb.easycrud.api.EasyCrudExceptionStrategy in project summerb by skarpushin.

the class EasyCrudScaffoldImpl method initService.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected <TId, TDto extends HasId<TId>> void initService(EasyCrudServicePluggableImpl<TId, TDto, EasyCrudDao<TId, TDto>> service, Class<TDto> dtoClass, String messageCode, String tableName, EasyCrudDao<TId, TDto> dao, Object... injections) throws Exception {
    service.setDtoClass(dtoClass);
    service.setDao(dao);
    service.setEntityTypeMessageCode(messageCode);
    beanFactory.autowireBean(service);
    if (injections == null || injections.length == 0) {
        service.afterPropertiesSet();
        return;
    }
    // NOTE: Ok. This thing around EasyCrudExceptionStrategy tells me this code is
    // begging to be refactored. Screamign about OCP... I'll do it later.
    List<EasyCrudWireTap<TId, TDto>> wireTaps = Arrays.stream(injections).filter(x -> !(x instanceof EasyCrudExceptionStrategy)).map(injectionToWireTapMapper(dtoClass, messageCode, tableName)).collect(Collectors.toList());
    if (wireTaps.size() > 0) {
        service.setWireTap(new EasyCrudWireTapDelegatingImpl<>(wireTaps));
    }
    EasyCrudExceptionStrategy exceptionStrategy = Arrays.stream(injections).filter(x -> x instanceof EasyCrudExceptionStrategy).map(x -> (EasyCrudExceptionStrategy) x).findFirst().orElse(null);
    if (exceptionStrategy != null) {
        service.setGenericExceptionStrategy(exceptionStrategy);
    }
    // x.
    service.afterPropertiesSet();
}
Also used : Arrays(java.util.Arrays) EasyCrudWireTap(org.summerb.easycrud.api.EasyCrudWireTap) Autowired(org.springframework.beans.factory.annotation.Autowired) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) EasyCrudValidationStrategy(org.summerb.easycrud.api.EasyCrudValidationStrategy) EasyCrudTableAuthStrategy(org.summerb.easycrud.api.EasyCrudTableAuthStrategy) Function(java.util.function.Function) EasyCrudWireTapTableAuthImpl(org.summerb.easycrud.impl.wireTaps.EasyCrudWireTapTableAuthImpl) EasyCrudDao(org.summerb.easycrud.api.EasyCrudDao) DataSource(javax.sql.DataSource) EasyCrudServicePluggableImpl(org.summerb.easycrud.impl.EasyCrudServicePluggableImpl) EasyCrudScaffold(org.summerb.easycrud.scaffold.api.EasyCrudScaffold) EasyCrudWireTapValidationImpl(org.summerb.easycrud.impl.wireTaps.EasyCrudWireTapValidationImpl) EasyCrudServiceProxyFactory(org.summerb.easycrud.scaffold.api.EasyCrudServiceProxyFactory) EasyCrudDaoMySqlImpl(org.summerb.easycrud.impl.mysql.EasyCrudDaoMySqlImpl) HasId(org.summerb.easycrud.api.dto.HasId) Collectors(java.util.stream.Collectors) QueryToNativeSqlCompilerMySqlImpl(org.summerb.easycrud.impl.mysql.QueryToNativeSqlCompilerMySqlImpl) EasyCrudExceptionStrategy(org.summerb.easycrud.api.EasyCrudExceptionStrategy) List(java.util.List) EasyCrudPerRowAuthStrategy(org.summerb.easycrud.api.EasyCrudPerRowAuthStrategy) EasyCrudWireTapDelegatingImpl(org.summerb.easycrud.impl.wireTaps.EasyCrudWireTapDelegatingImpl) EasyCrudWireTapPerRowAuthImpl(org.summerb.easycrud.impl.wireTaps.EasyCrudWireTapPerRowAuthImpl) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) DtoBase(org.summerb.utils.DtoBase) EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Preconditions(com.google.common.base.Preconditions) EasyCrudWireTap(org.summerb.easycrud.api.EasyCrudWireTap) EasyCrudExceptionStrategy(org.summerb.easycrud.api.EasyCrudExceptionStrategy)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 DataSource (javax.sql.DataSource)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)1 EasyCrudDao (org.summerb.easycrud.api.EasyCrudDao)1 EasyCrudExceptionStrategy (org.summerb.easycrud.api.EasyCrudExceptionStrategy)1 EasyCrudPerRowAuthStrategy (org.summerb.easycrud.api.EasyCrudPerRowAuthStrategy)1 EasyCrudService (org.summerb.easycrud.api.EasyCrudService)1 EasyCrudTableAuthStrategy (org.summerb.easycrud.api.EasyCrudTableAuthStrategy)1 EasyCrudValidationStrategy (org.summerb.easycrud.api.EasyCrudValidationStrategy)1 EasyCrudWireTap (org.summerb.easycrud.api.EasyCrudWireTap)1 HasId (org.summerb.easycrud.api.dto.HasId)1 EasyCrudServicePluggableImpl (org.summerb.easycrud.impl.EasyCrudServicePluggableImpl)1 EasyCrudDaoMySqlImpl (org.summerb.easycrud.impl.mysql.EasyCrudDaoMySqlImpl)1