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());
}
}
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);
}
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}" + "}"));
}
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));
}
Aggregations