Search in sources :

Example 21 with Script

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()));
    }
}
Also used : ModifiableScript(com.cognifide.cq.cqsm.api.scripts.ModifiableScript) Script(com.cognifide.cq.cqsm.api.scripts.Script) ModifiableScript(com.cognifide.cq.cqsm.api.scripts.ModifiableScript) ModifiableScriptWrapper(com.cognifide.cq.cqsm.core.scripts.ModifiableScriptWrapper) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) PersistenceException(org.apache.sling.api.resource.PersistenceException) ReplicationException(com.day.cq.replication.ReplicationException) ExecutionException(com.cognifide.cq.cqsm.api.exceptions.ExecutionException)

Aggregations

Script (com.cognifide.cq.cqsm.api.scripts.Script)21 RepositoryException (javax.jcr.RepositoryException)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 Progress (com.cognifide.cq.cqsm.api.logger.Progress)4 ModifiableScript (com.cognifide.cq.cqsm.api.scripts.ModifiableScript)4 Mode (com.cognifide.cq.cqsm.api.executors.Mode)3 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 PersistenceException (org.apache.sling.api.resource.PersistenceException)3 Resource (org.apache.sling.api.resource.Resource)3 ModifiableScriptWrapper (com.cognifide.cq.cqsm.core.scripts.ModifiableScriptWrapper)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Session (javax.jcr.Session)2 ActionCreationException (com.cognifide.cq.cqsm.api.exceptions.ActionCreationException)1 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)1 InstanceDetails (com.cognifide.cq.cqsm.api.history.InstanceDetails)1 ScriptImpl (com.cognifide.cq.cqsm.core.scripts.ScriptImpl)1 OperateCallback (com.cognifide.cq.cqsm.core.utils.sling.OperateCallback)1