Search in sources :

Example 6 with Action

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;
}
Also used : Action(org.webpieces.router.api.actions.Action) Messages(org.webpieces.ctx.api.Messages) ResponseProcessor(org.webpieces.router.impl.ctx.ResponseProcessor) Method(java.lang.reflect.Method) RenderStaticResponse(org.webpieces.router.api.dto.RenderStaticResponse)

Example 7 with Action

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);
}
Also used : Logger(org.webpieces.util.logging.Logger) FlashAndRedirect(org.webpieces.router.api.actions.FlashAndRedirect) Redirect(org.webpieces.router.api.actions.Redirect) Render(org.webpieces.router.api.actions.Render) EntityManager(javax.persistence.EntityManager) Singleton(javax.inject.Singleton) RoleEnum(WEBPIECESxPACKAGE.base.libs.RoleEnum) GET_EDIT_USER_FORM(WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_EDIT_USER_FORM) Collectors(java.util.stream.Collectors) Action(org.webpieces.router.api.actions.Action) List(java.util.List) Query(javax.persistence.Query) Em(org.webpieces.plugins.hibernate.Em) GET_ADD_USER_FORM(WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_ADD_USER_FORM) UseQuery(org.webpieces.plugins.hibernate.UseQuery) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.actions.Actions) EducationEnum(WEBPIECESxPACKAGE.base.libs.EducationEnum) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole) UserDbo(WEBPIECESxPACKAGE.base.libs.UserDbo) UserRole(WEBPIECESxPACKAGE.base.libs.UserRole) RoleEnum(WEBPIECESxPACKAGE.base.libs.RoleEnum)

Aggregations

Action (org.webpieces.router.api.actions.Action)7 Method (java.lang.reflect.Method)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Redirect (org.webpieces.router.api.actions.Redirect)2 MethodMeta (org.webpieces.router.api.dto.MethodMeta)2 GET_ADD_USER_FORM (WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_ADD_USER_FORM)1 GET_EDIT_USER_FORM (WEBPIECESxPACKAGE.base.crud.CrudUserRouteId.GET_EDIT_USER_FORM)1 EducationEnum (WEBPIECESxPACKAGE.base.libs.EducationEnum)1 RoleEnum (WEBPIECESxPACKAGE.base.libs.RoleEnum)1 UserDbo (WEBPIECESxPACKAGE.base.libs.UserDbo)1 UserRole (WEBPIECESxPACKAGE.base.libs.UserRole)1 Injector (com.google.inject.Injector)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 Current (org.webpieces.ctx.api.Current)1