use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class QueryBuilder method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
if (UserInfoHolder.isSystemDeveloper()) {
String sql = req.get("sql");
boolean execute = sql != null;
List<String> history;
if (req.getAttribute(QUERY_BUILDER_HISTORY) != null) {
history = (List<String>) req.getAttribute(QUERY_BUILDER_HISTORY);
} else {
history = new ArrayList<>();
}
if (sql == null) {
if (!history.isEmpty()) {
sql = history.get(history.size() - 1);
} else {
sql = "select * from users";
}
} else {
if (history.isEmpty() || !history.get(history.size() - 1).equals(sql)) {
history.add(sql);
req.setAttribute(QUERY_BUILDER_HISTORY, history);
}
}
ResourceData resourceData = new ResourceData("queryBuilder", new Data(sql, history), Collections.singletonMap(SELF_LINK, "queryBuilder"));
try {
SqlType type = getSqlType(sql);
if (type == SqlType.SELECT) {
select(sql, req, injector);
} else {
if (execute) {
switch(type) {
case INSERT:
insert(sql, injector);
break;
case UPDATE:
update(sql, injector);
break;
case DELETE:
update(sql, injector);
break;
default:
res.sendUnknownActionError();
return;
}
}
}
} catch (Throwable e) {
errorModelList.add(new ErrorModel(Be5Exception.internal(e)));
}
res.sendAsJson(JsonApiModel.data(resourceData, errorModelList.toArray(new ErrorModel[0]), resourceDataList.toArray(new ResourceData[0]), req.getDefaultMeta(), null));
} else {
res.sendErrorAsJson(new ErrorModel(Be5Exception.accessDenied(), "Role " + RoleType.ROLE_SYSTEM_DEVELOPER + " required.", Collections.singletonMap(SELF_LINK, "queryBuilder")), req.getDefaultMeta());
}
}
use of com.developmentontheedge.be5.env.Injector 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.env.Injector in project be5 by DevelopmentOnTheEdge.
the class MainServlet method runTemplateProcessor.
private void runTemplateProcessor(String componentId, Request req, Response res) {
if (UserInfoHolder.getUserInfo() == null) {
injector.get(UserHelper.class).initGuest(req);
}
try {
runRequestPreprocessors(componentId, req, res);
new TemplateProcessor(servletContext).generate(req, res, injector);
} catch (Be5Exception ex) {
if (ex.getCode().isInternal() || ex.getCode().isAccessDenied()) {
log.log(Level.SEVERE, ex.getMessage(), ex);
}
res.sendError(ex);
} catch (Throwable e) {
log.log(Level.SEVERE, e.getMessage(), e);
res.sendError(Be5Exception.internal(e));
}
}
use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method getTable.
public TablePresentation getTable(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
List<TableOperationPresentation> operations = collectOperations(query);
final boolean selectable = !operations.isEmpty() && query.getType() == QueryType.D1;
int limit = userAwareMeta.getQuerySettings(query).getMaxRecordsPerPage();
if (limit == 0) {
// todo delete defaultPageLimit, use getQuerySettings(query).getMaxRecordsPerPage()
limit = Integer.parseInt(getLayoutObject(query).getOrDefault("defaultPageLimit", coreUtils.getSystemSetting("be5_defaultPageLimit", "10")).toString());
}
TableModel table = TableModel.from(query, parameters, selectable, injector).sortOrder(sortColumn, sortDesc).limit(limit).build();
return getTable(query, parameters, table);
}
use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class LanguageSelectorTest method generateSelect.
@Test
public void generateSelect() throws Exception {
Response response = mock(Response.class);
Request request = getSpyMockRequest("select", ImmutableMap.of("language", "RU"));
component.generate(request, response, injector);
verify(response).sendAsRawJson(eq(languageSelectorResponse));
}
Aggregations