Search in sources :

Example 1 with ModifiableScriptWrapper

use of com.cognifide.cq.cqsm.core.scripts.ModifiableScriptWrapper 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());
    }
}
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)

Example 2 with ModifiableScriptWrapper

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

ModifiableScript (com.cognifide.cq.cqsm.api.scripts.ModifiableScript)2 Script (com.cognifide.cq.cqsm.api.scripts.Script)2 ModifiableScriptWrapper (com.cognifide.cq.cqsm.core.scripts.ModifiableScriptWrapper)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)1 ReplicationException (com.day.cq.replication.ReplicationException)1