use of org.summerb.easycrud.impl.EasyCrudServicePluggableImpl in project summerb by skarpushin.
the class EasyCrudScaffoldImpl method fromService.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <TId, TDto extends HasId<TId>, TService extends EasyCrudService<TId, TDto>> TService fromService(Class<TService> serviceInterface, String messageCode, String tableName, Object... injections) {
try {
Class<TDto> dtoClass = discoverDtoClassFromServiceInterface(serviceInterface);
EasyCrudDao<TId, TDto> dao = buildDao(dtoClass, tableName);
TService proxy = easyCrudServiceProxyFactory.createImpl(serviceInterface);
EasyCrudServicePluggableImpl service = (EasyCrudServicePluggableImpl) java.lang.reflect.Proxy.getInvocationHandler(proxy);
initService(service, dtoClass, messageCode, tableName, dao, injections);
return proxy;
} catch (Throwable t) {
throw new RuntimeException("Failed to scaffold EasyCrudService for " + serviceInterface, t);
}
}
use of org.summerb.easycrud.impl.EasyCrudServicePluggableImpl 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();
}
Aggregations