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);
}
}
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);
}
}
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);
}
});
}
Aggregations