use of org.webpieces.router.api.actions.Action in project webpieces by deanhiller.
the class RouteInvoker method invokeImpl.
public CompletableFuture<Void> invokeImpl(MatchResult result, Service<MethodMeta, Action> service, RequestContext requestCtx, ResponseStreamer responseCb) {
RouteMeta meta = result.getMeta();
ResponseProcessor processor = new ResponseProcessor(requestCtx, reverseRoutes, reverseTranslator, meta, responseCb);
if (meta.getRoute().getRouteType() == RouteType.STATIC) {
StaticRoute route = (StaticRoute) meta.getRoute();
boolean isOnClassPath = route.getIsOnClassPath();
RenderStaticResponse resp = new RenderStaticResponse(route.getTargetCacheLocation(), isOnClassPath);
if (route.isFile()) {
resp.setFilePath(route.getFileSystemPath());
} else {
String relativeUrl = result.getPathParams().get("resource");
resp.setRelativeFile(route.getFileSystemPath(), relativeUrl);
}
return processor.renderStaticResponse(resp);
}
Object obj = meta.getControllerInstance();
if (obj == null)
throw new IllegalStateException("Someone screwed up, as controllerInstance should not be null at this point, bug");
Method method = meta.getMethod();
if (service == null)
throw new IllegalStateException("Bug, service should never be null at this point");
Messages messages = new Messages(meta.getI18nBundleName(), "webpieces");
requestCtx.setMessages(messages);
RequestLocalCtx.set(processor);
Current.setContext(requestCtx);
CompletableFuture<Action> response;
try {
response = invokeMethod(service, obj, method, meta);
} finally {
RequestLocalCtx.set(null);
Current.setContext(null);
}
CompletableFuture<Void> future = response.thenCompose(resp -> continueProcessing(processor, resp, responseCb));
return future;
}
use of org.webpieces.router.api.actions.Action in project webpieces by deanhiller.
the class CrudUserController method userAddEdit.
public Action userAddEdit(Integer id) {
if (id == null) {
return Actions.renderThis("entity", new UserDbo(), "levels", EducationEnum.values(), "roles", RoleEnum.values());
}
UserDbo user = UserDbo.findWithJoin(Em.get(), id);
List<UserRole> roles = user.getRoles();
List<RoleEnum> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
return Actions.renderThis("entity", user, "levels", EducationEnum.values(), "roles", RoleEnum.values(), "selectedRoles", selectedRoles);
}
Aggregations