use of com.cognifide.cq.cqsm.api.scripts.Script 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