Search in sources :

Example 1 with Component

use of com.developmentontheedge.be5.api.Component in project be5 by DevelopmentOnTheEdge.

the class MenuTest method testGenerateSimpleMenu.

@Test
public void testGenerateSimpleMenu() {
    initUserWithRoles("User");
    Menu menu = (Menu) component;
    Menu.MenuResponse menuResponse = menu.generateSimpleMenu(injector, EntityType.TABLE);
    assertEquals("testtable", menuResponse.root.get(1).getTitle());
    assertEquals(new Action("call", "table/testtable/All records"), menuResponse.root.get(1).getAction());
    assertNull(menuResponse.root.get(1).getChildren());
}
Also used : Action(com.developmentontheedge.be5.model.Action) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 2 with Component

use of com.developmentontheedge.be5.api.Component in project be5 by DevelopmentOnTheEdge.

the class MenuTest method testGenerateSimpleMenuAdmin.

@Test
public void testGenerateSimpleMenuAdmin() {
    initUserWithRoles(RoleType.ROLE_ADMINISTRATOR, RoleType.ROLE_SYSTEM_DEVELOPER);
    Menu menu = (Menu) component;
    Menu.MenuResponse menuResponse = menu.generateSimpleMenu(injector, EntityType.TABLE);
    assertEquals("Добавить", menuResponse.root.get(1).getOperations().get(0).title);
    assertEquals(new Action("call", "form/dateTime/All records/Insert"), menuResponse.root.get(1).getOperations().get(0).action);
    initUserWithRoles(RoleType.ROLE_GUEST);
}
Also used : Action(com.developmentontheedge.be5.model.Action) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 3 with Component

use of com.developmentontheedge.be5.api.Component in project be5 by DevelopmentOnTheEdge.

the class InjectorTests method componentWithInjectAnnotation.

@Test
public void componentWithInjectAnnotation() throws Exception {
    Component component = getComponent("testComponentWithInjectAnnotation");
    component.generate(getMockRequest(""), mock(Response.class), null);
    verify(SqlServiceMock.mock).update("select 1");
}
Also used : Response(com.developmentontheedge.be5.api.Response) Component(com.developmentontheedge.be5.api.Component) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 4 with Component

use of com.developmentontheedge.be5.api.Component in project be5 by DevelopmentOnTheEdge.

the class MainServlet method respond.

/**
 * The general routing method. Tries to determine and find a component using a given request URI.
 * Generation of response is delegated to a found component.
 */
private boolean respond(HttpServletRequest request, HttpServletResponse response, String method, String requestUri, Map<String, String[]> parameters) {
    String origin = request.getHeader("Origin");
    // TODO test origin
    response.addHeader("Access-Control-Allow-Credentials", "true");
    response.addHeader("Access-Control-Allow-Origin", origin);
    response.addHeader("Access-Control-Allow-Methods", "POST, GET");
    response.addHeader("Access-Control-Max-Age", "1728000");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    Response res = new ResponseImpl(response);
    Matcher matcher = uriPattern.matcher(requestUri);
    if (!matcher.matches()) {
        // This prevents triggering engine executions for resource URLs
        // todo remove
        log.log(Level.INFO, requestUri + " ContextPath=" + request.getContextPath());
        String contextPath = request.getContextPath();
        if (requestUri.startsWith(contextPath + (contextPath.endsWith("/") ? "" : "/") + "static/") || // || requestUri.startsWith("/static/")
        requestUri.contains("favicon.ico")) {
            return false;
        }
        String templateComponentID = "templateProcessor";
        if (!injector.hasComponent(templateComponentID)) {
            templateComponentID = "defaultTemplateProcessor";
        }
        RequestImpl req = new RequestImpl(request, requestUri, simplify(parameters));
        UserInfoHolder.setRequest(req);
        runTemplateProcessor(templateComponentID, req, res);
        return true;
    }
    String[] uriParts = requestUri.split("/");
    int ind = 1;
    while (!"api".equals(uriParts[ind]) && ind + 1 < uriParts.length) {
        ind++;
    }
    String subRequestUri = Joiner.on('/').join(Iterables.skip(Arrays.asList(uriParts), ind + 2));
    String componentId = uriParts[ind + 1];
    Request req = new RequestImpl(request, subRequestUri, simplify(parameters));
    UserInfoHolder.setRequest(req);
    runComponent(componentId, req, res);
    return true;
}
Also used : Response(com.developmentontheedge.be5.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Matcher(java.util.regex.Matcher) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.developmentontheedge.be5.api.Request) ServletRequest(javax.servlet.ServletRequest) ResponseImpl(com.developmentontheedge.be5.api.impl.ResponseImpl) RequestImpl(com.developmentontheedge.be5.api.impl.RequestImpl)

Example 5 with Component

use of com.developmentontheedge.be5.api.Component in project be5 by DevelopmentOnTheEdge.

the class MainServlet method runComponent.

void runComponent(String componentId, Request req, Response res) {
    if (UserInfoHolder.getUserInfo() == null) {
        injector.get(UserHelper.class).initGuest(req);
    }
    try {
        runRequestPreprocessors(componentId, req, res);
        Component component = getInjector().getComponent(componentId);
        component.generate(req, res, getInjector());
    } catch (Be5Exception e) {
        if (e.getCode().isInternal() || e.getCode().isAccessDenied()) {
            log.log(Level.SEVERE, e.getMessage(), e);
        }
        res.sendError(e);
    } catch (Throwable e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        res.sendError(Be5Exception.internal(e));
    }
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) UserHelper(com.developmentontheedge.be5.api.helpers.UserHelper) Component(com.developmentontheedge.be5.api.Component)

Aggregations

Component (com.developmentontheedge.be5.api.Component)3 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)3 Test (org.junit.Test)3 Response (com.developmentontheedge.be5.api.Response)2 Action (com.developmentontheedge.be5.model.Action)2 Request (com.developmentontheedge.be5.api.Request)1 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)1 UserHelper (com.developmentontheedge.be5.api.helpers.UserHelper)1 RequestImpl (com.developmentontheedge.be5.api.impl.RequestImpl)1 ResponseImpl (com.developmentontheedge.be5.api.impl.ResponseImpl)1 Matcher (java.util.regex.Matcher)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1