Search in sources :

Example 1 with StaticPagePresentation

use of com.developmentontheedge.be5.model.StaticPagePresentation in project be5 by DevelopmentOnTheEdge.

the class QueryBuilder method insert.

private void insert(String sql, Injector injector) {
    Object id = injector.getSqlService().insert(sql);
    resourceDataList.add(new ResourceData("result", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Insert was successful", "New primaryKey: " + id), null));
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation)

Example 2 with StaticPagePresentation

use of com.developmentontheedge.be5.model.StaticPagePresentation in project be5 by DevelopmentOnTheEdge.

the class QueryBuilder method select.

private void select(String sql, Request req, Injector injector) {
    DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
    String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
    Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
    Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query query = new Query(userQBuilderQueryName, entity);
    query.setType(QueryType.D1_UNKNOWN);
    if (sql != null) {
        query.setQuery(sql);
    }
    DataElementUtils.save(query);
    try {
        resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    try {
        JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
        // todo refactor documentGenerator
        document.getData().setId("result");
        resourceDataList.add(document.getData());
        resourceDataList.addAll(Arrays.asList(document.getIncluded()));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    entity.getOrigin().remove(entityName);
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) Entity(com.developmentontheedge.be5.metadata.model.Entity) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation) Query(com.developmentontheedge.be5.metadata.model.Query) SqlQuery(com.developmentontheedge.sql.model.SqlQuery) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel) Be5QueryExecutor(com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel)

Example 3 with StaticPagePresentation

use of com.developmentontheedge.be5.model.StaticPagePresentation in project be5 by DevelopmentOnTheEdge.

the class QueryBuilder method update.

private void update(String sql, Injector injector) {
    Object id = injector.getSqlService().update(sql);
    resourceDataList.add(new ResourceData("result", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Update was successful", id + " row(s) affected"), null));
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation)

Example 4 with StaticPagePresentation

use of com.developmentontheedge.be5.model.StaticPagePresentation in project be5 by DevelopmentOnTheEdge.

the class StaticPageComponent method generate.

@Override
public void generate(Request req, Response res, Injector injector) {
    String language = UserInfoHolder.getLanguage();
    String page = req.getRequestUri();
    String staticPageContent = injector.getProject().getStaticPageContent(language, page);
    if (staticPageContent == null) {
        // todo localize
        res.sendErrorAsJson(new ErrorModel("500", ErrorTitles.formatTitle(Be5ErrorCode.NOT_FOUND, page), Collections.singletonMap(SELF_LINK, "static/" + page)), req.getDefaultMeta());
    } else {
        res.sendAsJson(new ResourceData(STATIC_ACTION, new StaticPagePresentation("", staticPageContent), Collections.singletonMap(SELF_LINK, "static/" + page)), req.getDefaultMeta());
    }
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel)

Example 5 with StaticPagePresentation

use of com.developmentontheedge.be5.model.StaticPagePresentation in project be5 by DevelopmentOnTheEdge.

the class StaticPageComponentTest method generate.

@Test
public void generate() throws Exception {
    Response response = mock(Response.class);
    String page = "info.be";
    Request req = getSpyMockRequest(page, ImmutableMap.of(TIMESTAMP_PARAM, "123456789"));
    component.generate(req, response, injector);
    // todo         verify(response).sendAsJson(eq(new ResourceData(STATIC_ACTION,
    // new StaticPagePresentation("", "<h1>Info</h1><p>Test text.</p>"))),
    // eq(ImmutableMap.of(TIMESTAMP_PARAM, "123456789")),
    // eq(Collections.singletonMap(SELF_LINK, "static/" + page)));
    verify(response).sendAsJson(any(ResourceData.class), any(Map.class));
}
Also used : Response(com.developmentontheedge.be5.api.Response) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) Request(com.developmentontheedge.be5.api.Request) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Aggregations

ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)5 StaticPagePresentation (com.developmentontheedge.be5.model.StaticPagePresentation)4 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)2 Request (com.developmentontheedge.be5.api.Request)1 Response (com.developmentontheedge.be5.api.Response)1 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)1 Be5QueryExecutor (com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor)1 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)1 SqlQuery (com.developmentontheedge.sql.model.SqlQuery)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Test (org.junit.Test)1