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;
}
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);
}
}
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");
}
}
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);
}
});
}
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;
}
Aggregations