use of com.cognifide.cq.cqsm.api.scripts.ModifiableScript in project APM by Cognifide.
the class ScriptConfigServlet method doPost.
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
final ResourceResolver resolver = request.getResourceResolver();
final String searchPath = request.getParameter("scriptPath");
final Script script = scriptFinder.find(searchPath, resolver);
if (script == null) {
ServletUtils.writeMessage(response, "error", "Script not found: " + searchPath);
return;
}
final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script);
try {
final String executionMode = request.getParameter("executionMode");
if (executionMode != null) {
modifiableScript.setExecutionMode(ExecutionMode.valueOf(executionMode.toUpperCase()));
}
final String executionEnabled = request.getParameter("executionEnabled");
if (executionEnabled != null) {
modifiableScript.setExecutionEnabled(BooleanUtils.toBoolean(executionEnabled));
}
ServletUtils.writeMessage(response, "success", "Script configuration updated");
} catch (PersistenceException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ServletUtils.writeMessage(response, "error", "Cannot update script configuration: " + e.getMessage());
}
}
use of com.cognifide.cq.cqsm.api.scripts.ModifiableScript in project APM by Cognifide.
the class ScriptReplicationServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
ResourceResolver resolver = request.getResourceResolver();
final String searchPath = request.getParameter("fileName");
final String run = request.getParameter("run");
if (StringUtils.isEmpty(searchPath)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
ServletUtils.writeMessage(response, "error", "File name parameter is required");
return;
}
final Script script = scriptFinder.find(searchPath, resolver);
if (script == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
ServletUtils.writeMessage(response, "error", String.format("Script cannot be found: %s", searchPath));
return;
}
final String scriptPath = script.getPath();
try {
final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script);
if (PUBLISH_RUN.equals(run)) {
modifiableScript.setPublishRun(true);
}
scriptReplicator.replicate(script, resolver);
ServletUtils.writeMessage(response, "success", String.format("Script '%s' replicated successfully", scriptPath));
} catch (PersistenceException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ServletUtils.writeMessage(response, "error", String.format("Script '%s' cannot be processed because of" + " repository error: %s", scriptPath, e.getMessage()));
} catch (ExecutionException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ServletUtils.writeMessage(response, "error", String.format("Script '%s' cannot be processed: %s", scriptPath, e.getMessage()));
} catch (ReplicationException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ServletUtils.writeMessage(response, "error", String.format("Script '%s' cannot be replicated: %s", scriptPath, e.getMessage()));
}
}
Aggregations