use of com.cognifide.cq.cqsm.api.exceptions.ExecutionException in project APM by Cognifide.
the class ScriptManagerImpl method execute.
private Progress execute(Script script, final Mode mode, Map<String, String> customDefinitions, ResourceResolver resolver) throws ExecutionException, RepositoryException {
if (script == null) {
throw new ExecutionException("Script is not specified");
}
if (mode == null) {
throw new ExecutionException("Execution mode is not specified");
}
final String path = script.getPath();
actionFactory.update();
LOG.info(String.format("Script execution started: %s [%s]", path, mode));
Progress progress = new ProgressImpl(resolver.getUserID());
final List<ActionDescriptor> descriptors = parseAllDescriptors(script, customDefinitions, resolver);
final ActionExecutor actionExecutor = createExecutor(mode, resolver);
final Context context = actionExecutor.getContext();
final SessionSavingPolicy savingPolicy = context.getSavingPolicy();
eventManager.trigger(Event.BEFORE_EXECUTE, script, mode, progress);
for (ActionDescriptor descriptor : descriptors) {
ActionResult result = actionExecutor.execute(descriptor);
progress.addEntry(descriptor, result);
if ((Status.ERROR == result.getStatus()) && (Mode.DRY_RUN != mode)) {
eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
return progress;
}
savingPolicy.save(context.getSession(), SessionSavingMode.EVERY_ACTION);
}
savingPolicy.save(context.getSession(), SessionSavingMode.SINGLE);
eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
return progress;
}
use of com.cognifide.cq.cqsm.api.exceptions.ExecutionException in project APM by Cognifide.
the class ScriptManagerImpl method process.
@Override
public Progress process(Script script, final Mode mode, final Map<String, String> customDefinitions, ResourceResolver resolver) throws RepositoryException, PersistenceException {
Progress progress;
try {
progress = execute(script, mode, customDefinitions, resolver);
} catch (ExecutionException e) {
progress = new ProgressImpl(resolver.getUserID());
progress.addEntry(Message.getErrorMessage(e.getMessage()), Status.ERROR);
}
process(script, mode, progress.isSuccess(), resolver);
return progress;
}
use of com.cognifide.cq.cqsm.api.exceptions.ExecutionException 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