use of com.developmentontheedge.be5.api.exceptions.Be5Exception in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method executeSubQuery.
@Override
public List<DynamicPropertySet> executeSubQuery(String subqueryName, CellFormatter.VarResolver varResolver) {
AstBeSqlSubQuery subQuery = contextApplier.applyVars(subqueryName, varResolver::resolve);
if (subQuery.getQuery() == null) {
return Collections.emptyList();
}
String finalSql = new Formatter().format(subQuery.getQuery(), context, parserContext);
List<DynamicPropertySet> dynamicPropertySets;
try {
dynamicPropertySets = listDps(finalSql);
} catch (Throwable e) {
// TODO only for Document presentation, for operations must be error throw
Be5Exception be5Exception = Be5Exception.internalInQuery(e, query);
log.log(Level.SEVERE, be5Exception.toString() + " Final SQL: " + finalSql, be5Exception);
DynamicPropertySetSupport dynamicProperties = new DynamicPropertySetSupport();
dynamicProperties.add(new DynamicProperty("___ID", String.class, "-1"));
dynamicProperties.add(new DynamicProperty("error", String.class, UserInfoHolder.isSystemDeveloper() ? Be5Exception.getMessage(e) : "error"));
dynamicPropertySets = Collections.singletonList(dynamicProperties);
}
// return Collections.singletonList(dynamicProperties);
return dynamicPropertySets;
}
use of com.developmentontheedge.be5.api.exceptions.Be5Exception 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.api.exceptions.Be5Exception in project be5 by DevelopmentOnTheEdge.
the class MainServlet method runComponent.
void runComponent(String componentId, Request req, Response res) {
if (UserInfoHolder.getUserInfo() == null) {
injector.get(UserHelper.class).initGuest(req);
}
try {
runRequestPreprocessors(componentId, req, res);
Component component = getInjector().getComponent(componentId);
component.generate(req, res, getInjector());
} catch (Be5Exception e) {
if (e.getCode().isInternal() || e.getCode().isAccessDenied()) {
log.log(Level.SEVERE, e.getMessage(), e);
}
res.sendError(e);
} catch (Throwable e) {
log.log(Level.SEVERE, e.getMessage(), e);
res.sendError(Be5Exception.internal(e));
}
}
use of com.developmentontheedge.be5.api.exceptions.Be5Exception in project be5 by DevelopmentOnTheEdge.
the class ParseRequestUtils method getValuesFromJson.
public static Map<String, Object> getValuesFromJson(String valuesString) throws Be5Exception {
if (Strings.isNullOrEmpty(valuesString)) {
return Collections.emptyMap();
}
Map<String, Object> fieldValues = new HashMap<>();
// todo gson -> json-b
// InputStream stream = new ByteArrayInputStream(valuesString.getBytes(StandardCharsets.UTF_8.name()));
// javax.json.stream.JsonParser parser = Json.createParser(stream);
//
// javax.json.JsonObject object = parser.getObject();
// Set<Map.Entry<String, JsonValue>> entries = object.entrySet();
JsonObject values = (JsonObject) new JsonParser().parse(valuesString);
for (Map.Entry entry : values.entrySet()) {
String name = entry.getKey().toString();
if (entry.getValue() instanceof JsonNull) {
fieldValues.put(name, null);
} else if (entry.getValue() instanceof JsonArray) {
JsonArray value = (JsonArray) entry.getValue();
String[] arrValues = new String[value.size()];
for (int i = 0; i < value.size(); i++) {
arrValues[i] = value.get(i).getAsString();
}
fieldValues.put(name, arrValues);
} else if (entry.getValue() instanceof JsonObject) {
JsonObject jsonObject = ((JsonObject) entry.getValue());
String type = jsonObject.get("type").getAsString();
if ("Base64File".equals(type)) {
try {
String data = jsonObject.get("data").getAsString();
String base64 = ";base64,";
int base64Pos = data.indexOf(base64);
String mimeTypes = data.substring("data:".length(), base64Pos);
byte[] bytes = data.substring(base64Pos + base64.length(), data.length()).getBytes("UTF-8");
byte[] decoded = Base64.getDecoder().decode(bytes);
fieldValues.put(name, new Base64File(jsonObject.get("name").getAsString(), decoded, mimeTypes));
} catch (UnsupportedEncodingException e) {
throw Be5Exception.internal(e);
}
} else {
fieldValues.put(name, jsonObject.toString());
}
} else if (entry.getValue() instanceof JsonPrimitive) {
fieldValues.put(name, ((JsonPrimitive) entry.getValue()).getAsString());
}
}
return replaceEmptyStringToNull(fieldValues);
}
Aggregations