Search in sources :

Example 1 with TemplateNotAvailableException

use of io.lumeer.core.exception.TemplateNotAvailableException in project engine by Lumeer.

the class ResourceVariableCreator method createComments.

private void createComments() {
    final JSONArray variables = (JSONArray) templateParser.template.get("variables");
    List<ResourceVariable> currentVariables = resourceVariableFacade.getInProject(projectId);
    Set<String> currentKeys = currentVariables.stream().map(ResourceVariable::getKey).collect(Collectors.toSet());
    ;
    if (variables != null) {
        final List<ResourceVariable> result = new ArrayList<>();
        variables.forEach(variableObj -> {
            try {
                var variableJson = (JSONObject) variableObj;
                var resourceVariable = mapper.readValue(variableJson.toJSONString(), ResourceVariable.class);
                resourceVariable.setId(null);
                if (currentKeys.contains(resourceVariable.getKey()) || resourceVariable.getResourceType() == ResourceType.ORGANIZATION) {
                    return;
                }
                if (resourceVariable.getResourceType() == ResourceType.PROJECT) {
                    resourceVariable.setOrganizationId(organizationId);
                    resourceVariable.setProjectId(null);
                    resourceVariable.setResourceId(projectId);
                } else {
                    resourceVariable.setOrganizationId(organizationId);
                    resourceVariable.setProjectId(projectId);
                    var translatedResourceId = templateParser.translateString(resourceVariable.getResourceId(), constraintManager);
                    resourceVariable.setResourceId(translatedResourceId != null ? translatedResourceId.toString() : null);
                }
                currentKeys.add(resourceVariable.getKey());
                result.add(resourceVariable);
            } catch (IOException e) {
                throw new TemplateNotAvailableException(e);
            }
        });
        resourceVariableFacade.storeResourceVariables(result, organizationId, projectId);
    }
}
Also used : TemplateNotAvailableException(io.lumeer.core.exception.TemplateNotAvailableException) ResourceVariable(io.lumeer.api.model.ResourceVariable) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with TemplateNotAvailableException

use of io.lumeer.core.exception.TemplateNotAvailableException in project engine by Lumeer.

the class ResourceCommentCreator method createComments.

private void createComments() {
    final JSONArray comments = (JSONArray) templateParser.template.get("comments");
    if (comments != null) {
        final List<ResourceComment> result = new ArrayList<>();
        comments.forEach(commentObj -> {
            try {
                var commentJson = (JSONObject) commentObj;
                var resourceComment = mapper.readValue(commentJson.toJSONString(), ResourceCommentWrapper.class);
                var translatedParentId = templateParser.translateString(resourceComment.getParentId(), constraintManager);
                resourceComment.setParentId(translatedParentId != null ? translatedParentId.toString() : null);
                var translatedResourceId = templateParser.translateString(resourceComment.getResourceId(), constraintManager);
                resourceComment.setResourceId(translatedResourceId != null ? translatedResourceId.toString() : null);
                resourceComment.setId(null);
                result.add(resourceComment.getResourceComment());
            } catch (IOException e) {
                throw new TemplateNotAvailableException(e);
            }
        });
        resourceCommentFacade.storeResourceComments(result);
    }
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment) TemplateNotAvailableException(io.lumeer.core.exception.TemplateNotAvailableException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 3 with TemplateNotAvailableException

use of io.lumeer.core.exception.TemplateNotAvailableException in project engine by Lumeer.

the class ViewCreator method createViews.

private void createViews() {
    ((JSONArray) templateParser.getTemplate().get("views")).forEach(viewObj -> {
        try {
            var viewJson = (JSONObject) viewObj;
            var templateId = TemplateParserUtils.getId(viewJson);
            viewJson.remove("_id");
            var view = mapper.readValue(viewJson.toJSONString(), View.class);
            viewJson.put("_id", templateId);
            view.setCode(null);
            view.setQuery(translateQuery(view.getQuery()));
            view.setConfig(templateParser.translateConfig(view.getConfig(), constraintManager));
            view.setSettings(templateParser.translateConfig(view.getSettings(), constraintManager));
            view = viewFacade.createView(view);
            templateParser.getDict().addView(templateId, view);
        } catch (IOException e) {
            throw new TemplateNotAvailableException(e);
        }
    });
}
Also used : TemplateNotAvailableException(io.lumeer.core.exception.TemplateNotAvailableException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) IOException(java.io.IOException)

Aggregations

TemplateNotAvailableException (io.lumeer.core.exception.TemplateNotAvailableException)3 IOException (java.io.IOException)3 JSONArray (org.json.simple.JSONArray)3 JSONObject (org.json.simple.JSONObject)3 ArrayList (java.util.ArrayList)2 ResourceComment (io.lumeer.api.model.ResourceComment)1 ResourceVariable (io.lumeer.api.model.ResourceVariable)1