use of com.developmentontheedge.be5.env.Injector 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);
}
use of com.developmentontheedge.be5.env.Injector 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));
}
use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class OperationHelper method getTagsFromCustomSelectionViewExecute.
//
// public Map<String, String> getTagsMapFromQuery( Map<String, String> parameters, String query, Object... params )
// {
// //return getTagsListFromQuery( Collections.emptyMap(), query, params );
// List<String[]> tags = db.selectList("SELECT " + valueColumnName + ", " + textColumnName + " FROM " + tableName,
// rs -> new String[]{rs.getString(valueColumnName), rs.getString(textColumnName)}
// );
// String[][] stockArr = new String[tags.size()][2];
// return tags.toArray(stockArr);
// }
private String[][] getTagsFromCustomSelectionViewExecute(Query query, Map<String, ?> parameters) {
String entityName = query.getEntity().getName();
// todo refactoring Be5QueryExecutor,
Map<String, String> stringStringMap = new HashMap<>();
// parameters.forEach((key, value) -> stringStringMap.put(key, value.toString()));
for (Map.Entry<String, ?> entry : parameters.entrySet()) {
if (entry.getValue() != null)
stringStringMap.put(entry.getKey(), entry.getValue().toString());
}
TableModel table = TableModel.from(query, stringStringMap, false, injector).limit(Integer.MAX_VALUE).build();
String[][] stockArr = new String[table.getRows().size()][2];
int i = 0;
for (TableModel.RowModel row : table.getRows()) {
String first = row.getCells().size() >= 1 ? row.getCells().get(0).content.toString() : "";
String second = row.getCells().size() >= 2 ? row.getCells().get(1).content.toString() : "";
stockArr[i++] = new String[] { first, userAwareMeta.getColumnTitle(entityName, second) };
}
return stockArr;
}
use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class DownloadComponent method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
String entity = req.getNonEmpty("_t_");
String ID = req.get("ID");
String typeColumn = req.get("_typeColumn_");
String filenameColumn = req.get("_filenameColumn_");
String dataColumn = req.getNonEmpty("_dataColumn_");
String charsetColumn = req.get("_charsetColumn_");
// String encoding = req.get("_enc_");
boolean download = "yes".equals(req.get("_download_"));
RecordModel record = injector.get(DatabaseModel.class).getEntity(entity).get(ID);
String filename = record.getValueAsString(filenameColumn);
String contentType = record.getValueAsString(typeColumn);
String charset = MoreObjects.firstNonNull(record.getValueAsString(charsetColumn), Charsets.UTF_8.name());
Object data = record.getValue(dataColumn);
InputStream in;
if (data instanceof byte[]) {
in = new ByteArrayInputStream((byte[]) data);
} else // else if (data instanceof Blob)
// {
// in = ((Blob) data).getBinaryStream();
// }
// else if (data instanceof String)
// {
// in = new ByteArrayInputStream(((String) data).getBytes(charset));
// }
{
throw Be5Exception.internal("Unknown data type");
}
HttpServletResponse response = res.getRawResponse();
response.setContentType(contentType + "; charset=" + charset);
if (download) {
response.setHeader("Content-disposition", "attachment; filename=" + UrlEscapers.urlFormParameterEscaper().escape(filename));
} else {
response.setHeader("Content-disposition", "filename=" + UrlEscapers.urlFormParameterEscaper().escape(filename));
}
try {
ByteStreams.copy(in, response.getOutputStream());
} catch (IOException e) {
throw Be5Exception.internal(e);
}
}
use of com.developmentontheedge.be5.env.Injector in project be5 by DevelopmentOnTheEdge.
the class Menu method generateMenu.
private MenuResponse generateMenu(Injector injector, boolean withIds, EntityType entityType) {
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
List<String> roles = UserInfoHolder.getCurrentRoles();
String language = UserInfoHolder.getLanguage();
List<RootNode> entities = collectEntities(injector.getMeta(), userAwareMeta, language, roles, withIds, entityType);
return new MenuResponse(entities);
}
Aggregations