Search in sources :

Example 6 with Be5Exception

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;
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) Formatter(com.developmentontheedge.sql.format.Formatter) AstBeSqlSubQuery(com.developmentontheedge.sql.model.AstBeSqlSubQuery) DynamicPropertySetSupport(com.developmentontheedge.beans.DynamicPropertySetSupport)

Example 7 with Be5Exception

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));
    }
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) UserHelper(com.developmentontheedge.be5.api.helpers.UserHelper) TemplateProcessor(com.developmentontheedge.be5.components.TemplateProcessor)

Example 8 with Be5Exception

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));
    }
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) UserHelper(com.developmentontheedge.be5.api.helpers.UserHelper) Component(com.developmentontheedge.be5.api.Component)

Example 9 with Be5Exception

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);
}
Also used : HashMap(java.util.HashMap) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonNull(com.google.gson.JsonNull) JsonArray(com.google.gson.JsonArray) Base64File(com.developmentontheedge.be5.api.impl.model.Base64File) JsonObject(com.google.gson.JsonObject) HashMap(java.util.HashMap) Map(java.util.Map) JsonParser(com.google.gson.JsonParser)

Aggregations

Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)6 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)4 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)3 UserHelper (com.developmentontheedge.be5.api.helpers.UserHelper)2 Query (com.developmentontheedge.be5.metadata.model.Query)2 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)2 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2 Component (com.developmentontheedge.be5.api.Component)1 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)1 Base64File (com.developmentontheedge.be5.api.impl.model.Base64File)1 OperationExecutor (com.developmentontheedge.be5.api.services.OperationExecutor)1 TemplateProcessor (com.developmentontheedge.be5.components.TemplateProcessor)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 FormPresentation (com.developmentontheedge.be5.model.FormPresentation)1 StaticPagePresentation (com.developmentontheedge.be5.model.StaticPagePresentation)1 Operation (com.developmentontheedge.be5.operation.Operation)1 OperationResult (com.developmentontheedge.be5.operation.OperationResult)1 MoreRowsGenerator (com.developmentontheedge.be5.query.impl.MoreRowsGenerator)1 Be5QueryExecutor (com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor)1