use of com.cognifide.cq.cqsm.api.actions.ActionResult 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.actions.ActionResult in project APM by Cognifide.
the class AddToGroup method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = new ActionResult();
List<String> errors = new ArrayList<>();
Authorizable authorizable = null;
try {
authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
}
for (String id : groupIds) {
try {
Group group = AuthorizablesUtils.getGroup(context, id);
if (authorizable.isGroup()) {
ActionUtils.checkCyclicRelations(group, (Group) authorizable);
}
LOGGER.info(String.format("Adding Authorizable with id = %s to group with id = %s", authorizable.getID(), group.getID()));
if (execute) {
group.addMember(authorizable);
}
actionResult.logMessage(MessagingUtils.addedToGroup(authorizable.getID(), id));
} catch (RepositoryException | ActionExecutionException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
if (!errors.isEmpty()) {
ActionUtils.logErrors(errors, actionResult);
actionResult.logError("Execution interrupted");
}
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class Allow method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = new ActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
context.getSession().getNode(path);
final PermissionActionHelper permissionActionHelper = new PermissionActionHelper(context.getValueFactory(), path, glob, permissions);
LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob)));
if (simulate) {
permissionActionHelper.checkPermissions(context.getAccessControlManager());
} else {
permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), true);
}
actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path);
if (permissions.contains("MODIFY")) {
String preparedGlob = "";
if (!StringUtils.isBlank(glob)) {
preparedGlob = glob;
if (StringUtils.endsWith(glob, "*")) {
preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
}
}
new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate);
}
} catch (final PathNotFoundException e) {
if (ignoreInexistingPaths) {
actionResult.logWarning("Path " + path + " not found");
} else {
actionResult.logError("Path " + path + " not found");
return actionResult;
}
} catch (RepositoryException | PermissionException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class CheckIncludes method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = new ActionResult();
Group authorizable = tryGetGroup(context, actionResult);
if (authorizable == null) {
return actionResult;
}
List<String> errors = new ArrayList<>();
boolean checkFailed = checkMembers(context, actionResult, authorizable, errors);
if (execute && checkFailed) {
actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
return actionResult;
}
ActionUtils.logErrors(errors, actionResult);
return actionResult;
}
use of com.cognifide.cq.cqsm.api.actions.ActionResult in project APM by Cognifide.
the class CheckNotExists method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = new ActionResult();
List<String> errors = new ArrayList<>();
boolean checkFailed = checkAuthorizables(context, actionResult, errors);
if (execute && checkFailed) {
actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
return actionResult;
}
logErrors(actionResult, errors);
return actionResult;
}
Aggregations