Search in sources :

Example 6 with ResourceData

use of com.developmentontheedge.be5.model.jsonapi.ResourceData 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 7 with ResourceData

use of com.developmentontheedge.be5.model.jsonapi.ResourceData in project be5 by DevelopmentOnTheEdge.

the class DocumentGeneratorImpl method getDocument.

@Override
public JsonApiModel getDocument(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
    Object data = routeAndRun(query, parameters, sortColumn, sortDesc);
    HashUrl url = new HashUrl(TABLE_ACTION, query.getEntity().getName(), query.getName()).named(parameters);
    List<ResourceData> included = new ArrayList<>();
    String topForm = (String) ParseRequestUtils.getValuesFromJson(query.getLayout()).get(TOP_FORM);
    if (topForm != null) {
        com.developmentontheedge.be5.operation.Operation operation = operationExecutor.create(query.getEntity().getName(), query.getName(), topForm, new String[] {}, parameters);
        Either<FormPresentation, OperationResult> dataTopForm = generateForm(operation, Collections.emptyMap());
        included.add(new ResourceData(TOP_FORM, dataTopForm.isFirst() ? FORM_ACTION : OPERATION_RESULT, dataTopForm.get(), Collections.singletonMap(SELF_LINK, operation.getUrl().toString())));
    }
    return JsonApiModel.data(new ResourceData(TABLE_ACTION, data, Collections.singletonMap(SELF_LINK, url.toString())), included.toArray(new ResourceData[0]), null);
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) FormPresentation(com.developmentontheedge.be5.model.FormPresentation) ArrayList(java.util.ArrayList) HashUrl(com.developmentontheedge.be5.util.HashUrl) OperationResult(com.developmentontheedge.be5.operation.OperationResult)

Example 8 with ResourceData

use of com.developmentontheedge.be5.model.jsonapi.ResourceData in project be5 by DevelopmentOnTheEdge.

the class ResponseTest method testJsonObject.

@Test
public void testJsonObject() {
    JsonApiModel jsonApiModel = JsonApiModel.data(new ResourceData("testType", "test", Collections.singletonMap(SELF_LINK, "url")), Collections.singletonMap(TIMESTAMP_PARAM, 1503291145939L));
    response.sendAsJson(jsonApiModel);
    verify(writer).append(doubleQuotes("{" + "'data':{'attributes':'test','links':{'self':'url'},'type':'testType'}," + "'meta':{'_ts_':1503291145939}" + "}"));
}
Also used : ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 9 with ResourceData

use of com.developmentontheedge.be5.model.jsonapi.ResourceData 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)9 StaticPagePresentation (com.developmentontheedge.be5.model.StaticPagePresentation)4 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)4 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2 FormPresentation (com.developmentontheedge.be5.model.FormPresentation)2 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)2 OperationResult (com.developmentontheedge.be5.operation.OperationResult)2 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)2 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2 Test (org.junit.Test)2 Request (com.developmentontheedge.be5.api.Request)1 Response (com.developmentontheedge.be5.api.Response)1 OperationExecutor (com.developmentontheedge.be5.api.services.OperationExecutor)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 Operation (com.developmentontheedge.be5.operation.Operation)1 Be5QueryExecutor (com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor)1 SqlQuery (com.developmentontheedge.sql.model.SqlQuery)1 ImmutableMap (com.google.common.collect.ImmutableMap)1