Search in sources :

Example 1 with Script

use of com.cognifide.cq.cqsm.api.scripts.Script in project APM by Cognifide.

the class ReplicationExecutor method runReplicated.

private JobResult runReplicated(ResourceResolver resolver, String searchPath) {
    JobResult result = JobResult.FAILED;
    final Script script = scriptFinder.find(searchPath, resolver);
    if (script == null) {
        LOG.warn("Replicated script cannot be found by script manager: {}", searchPath);
    } else if (ExecutionMode.ON_DEMAND.equals(script.getExecutionMode()) && script.isPublishRun()) {
        try {
            process(script, resolver);
            result = JobResult.OK;
        } catch (PersistenceException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return result;
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 2 with Script

use of com.cognifide.cq.cqsm.api.scripts.Script in project APM by Cognifide.

the class ScheduleExecutor method runScheduled.

private void runScheduled(ResourceResolver resolver) throws PersistenceException {
    final List<Script> scripts = scriptFinder.findAll(filterOnSchedule(new Date()), resolver);
    if (scripts.size() == 0) {
        return;
    }
    LOG.info("Schedule executor is trying to execute script(s): " + scripts.size());
    LOG.info(MessagingUtils.describeScripts(scripts));
    for (Script script : scripts) {
        processScript(script, resolver);
    }
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script) Date(java.util.Date)

Example 3 with Script

use of com.cognifide.cq.cqsm.api.scripts.Script in project APM by Cognifide.

the class StartupExecutor method runOnStartup.

private void runOnStartup(ResourceResolver resolver) throws PersistenceException {
    final List<Script> scripts = scriptFinder.findAll(filterOnStart(resolver), resolver);
    if (scripts.size() > 0) {
        LOG.info("Startup script executor is trying to execute scripts on startup: {}", scripts.size());
        LOG.info(MessagingUtils.describeScripts(scripts));
        for (Script script : scripts) {
            runScript(resolver, script);
        }
    } else {
        LOG.info("Startup script executor has nothing to do");
    }
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script)

Example 4 with Script

use of com.cognifide.cq.cqsm.api.scripts.Script in project APM by Cognifide.

the class RemoteScriptExecutionActionReceiver method handleAction.

@Override
public void handleAction(final ValueMap valueMap) {
    Preconditions.checkState(instanceTypeProvider.isOnAuthor(), "Action Receiver has to be called in author");
    String userId = valueMap.get(ReplicationAction.PROPERTY_USER_ID, String.class);
    SlingHelper.operateTraced(resolverFactory, userId, new OperateCallback() {

        @Override
        public void operate(ResourceResolver resolver) throws Exception {
            // FIXME would be lovely to cast ValueMap -> ModifiableEntryBuilder
            String scriptLocation = valueMap.get(ModifiableEntryBuilder.FILE_PATH_PROPERTY, String.class);
            Resource scriptResource = resolver.getResource(scriptLocation);
            Script script = scriptResource.adaptTo(ScriptImpl.class);
            InstanceDetails instanceDetails = getInstanceDetails(valueMap);
            Progress progress = getProgress(valueMap, resolver.getUserID());
            Calendar executionTime = getCalendar(valueMap);
            Mode mode = getMode(valueMap);
            history.logRemote(script, mode, progress, instanceDetails, executionTime);
        }
    });
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script) Progress(com.cognifide.cq.cqsm.api.logger.Progress) InstanceDetails(com.cognifide.cq.cqsm.api.history.InstanceDetails) ScriptImpl(com.cognifide.cq.cqsm.core.scripts.ScriptImpl) Calendar(java.util.Calendar) Mode(com.cognifide.cq.cqsm.api.executors.Mode) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) OperateCallback(com.cognifide.cq.cqsm.core.utils.sling.OperateCallback)

Example 5 with Script

use of com.cognifide.cq.cqsm.api.scripts.Script in project APM by Cognifide.

the class ScriptManagerImpl method evaluate.

@Override
public Progress evaluate(String scriptContent, Mode mode, Map<String, String> customDefinitions, ResourceResolver resolver) throws RepositoryException, PersistenceException {
    Script script = scriptFinder.find(ScriptManager.FILE_FOR_EVALUATION, false, resolver);
    if (script != null) {
        scriptStorage.remove(script, resolver);
    }
    InputStream stream = new ByteArrayInputStream(scriptContent.getBytes(StandardCharsets.UTF_8));
    script = scriptStorage.save(FILE_FOR_EVALUATION, stream, true, resolver);
    Progress progress = process(script, mode, customDefinitions, resolver);
    scriptStorage.remove(script, resolver);
    return progress;
}
Also used : ModifiableScript(com.cognifide.cq.cqsm.api.scripts.ModifiableScript) Script(com.cognifide.cq.cqsm.api.scripts.Script) Progress(com.cognifide.cq.cqsm.api.logger.Progress) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

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