use of com.developmentontheedge.be5.api.Response in project be5 by DevelopmentOnTheEdge.
the class UserInfoComponentTest method generateSelectRolesAndSendEmpty.
@Test
public void generateSelectRolesAndSendEmpty() throws Exception {
Response response = mock(Response.class);
component.generate(getSpyMockRequest("", ImmutableMap.of("roles", "")), response, injector);
verify(response).sendAsRawJson(new UserInfoComponent.State(true, TEST_USER, Collections.singletonList(RoleType.ROLE_ADMINISTRATOR), Collections.singletonList(RoleType.ROLE_ADMINISTRATOR), any(Date.class)));
}
use of com.developmentontheedge.be5.api.Response in project be5 by DevelopmentOnTheEdge.
the class Document method sendError.
private void sendError(Request req, Response res, HashUrl url, Be5Exception e) {
String message = "";
// message += GroovyRegister.getErrorCodeLine(e, query.getQuery());
res.sendErrorAsJson(new ErrorModel(e, message, Collections.singletonMap(SELF_LINK, url.toString())), req.getDefaultMeta());
}
use of com.developmentontheedge.be5.api.Response in project be5 by DevelopmentOnTheEdge.
the class Document method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
String queryName = req.getNonEmpty(RestApiConstants.QUERY);
int sortColumn = req.getInt("order[0][column]", -1);
boolean sortDesc = "desc".equals(req.get("order[0][dir]"));
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
HashUrl url = new HashUrl(TABLE_ACTION, entityName, queryName).named(parametersMap);
Query query;
try {
query = userAwareMeta.getQuery(entityName, queryName);
} catch (Be5Exception e) {
sendError(req, res, url, e);
return;
}
try {
switch(req.getRequestUri()) {
case "":
JsonApiModel document = documentGenerator.getDocument(query, parametersMap, sortColumn, sortDesc);
document.setMeta(req.getDefaultMeta());
res.sendAsJson(document);
return;
case "moreRows":
res.sendAsRawJson(new MoreRowsGenerator(injector).generate(req));
return;
default:
res.sendUnknownActionError();
}
} catch (Be5Exception e) {
sendError(req, res, url, e);
} catch (Throwable e) {
sendError(req, res, url, Be5Exception.internalInQuery(e, query));
}
}
use of com.developmentontheedge.be5.api.Response in project be5 by DevelopmentOnTheEdge.
the class Form method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
OperationExecutor operationExecutor = injector.get(OperationExecutor.class);
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
String queryName = req.getNonEmpty(RestApiConstants.QUERY);
String operationName = req.getNonEmpty(RestApiConstants.OPERATION);
String[] selectedRows = ParseRequestUtils.selectedRows(nullToEmpty(req.get(RestApiConstants.SELECTED_ROWS)));
Map<String, String> operationParams = req.getValuesFromJsonAsStrings(RestApiConstants.OPERATION_PARAMS);
Map<String, Object> values = req.getValuesFromJson(RestApiConstants.VALUES);
Operation operation;
try {
operation = operationExecutor.create(entityName, queryName, operationName, selectedRows, operationParams);
} catch (Be5Exception e) {
HashUrl url = new HashUrl(FORM_ACTION, entityName, queryName, operationName).named(operationParams);
res.sendErrorAsJson(new ErrorModel(e, "", Collections.singletonMap(SELF_LINK, url.toString())), req.getDefaultMeta());
return;
}
Either<FormPresentation, OperationResult> data;
try {
switch(req.getRequestUri()) {
case "":
data = documentGenerator.generateForm(operation, values);
break;
case "apply":
data = documentGenerator.executeForm(operation, values);
break;
default:
res.sendUnknownActionError();
return;
}
} catch (Be5Exception e) {
res.sendErrorAsJson(documentGenerator.getErrorModel(e, operation.getUrl()), req.getDefaultMeta());
return;
}
res.sendAsJson(new ResourceData(data.isFirst() ? FORM_ACTION : OPERATION_RESULT, data.get(), Collections.singletonMap(SELF_LINK, operation.getUrl().toString())), req.getDefaultMeta());
}
use of com.developmentontheedge.be5.api.Response in project be5 by DevelopmentOnTheEdge.
the class TemplateProcessor method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String title = userAwareMeta.getColumnTitle("index", "page", "title");
String description = userAwareMeta.getColumnTitle("index", "page", "description");
Context context = new Context();
context.setVariable("lang", UserInfoHolder.getLanguage());
context.setVariable("title", title);
context.setVariable("description", description);
String reqWithoutContext = req.getRequestUri().replaceFirst(req.getContextPath(), "");
if (!reqWithoutContext.endsWith("/"))
reqWithoutContext += "/";
context.setVariable("baseUrl", req.getContextPath() + reqWithoutContext);
context.setVariable("baseUrlWithoutContext", reqWithoutContext);
res.sendHtml(templateEngine.process(reqWithoutContext + "index", context));
}
Aggregations