use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class CreateAuthorizable method process.
public ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getAuthorizableManager().getAuthorizableIfExists(id);
LOGGER.info("Creating authorizable with id = " + id);
if (authorizable != null) {
logMessage(actionResult, authorizable);
} else {
authorizable = createStrategy.create(id, password, path, context, actionResult, simulate);
}
context.setCurrentAuthorizable(authorizable);
} catch (RepositoryException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class DestroyUser method execute.
@Override
public ActionResult execute(Context context) throws ActionExecutionException {
ActionResult actionResult;
try {
User user = context.getAuthorizableManager().getUser(userId);
// local context is used here to not override current authorizable in given context
Context localContext = context.newContext();
localContext.setCurrentAuthorizable(user);
Action removeFromGroups = new RemoveParents(getGroups(user));
ActionResult purgeResult = purge.execute(localContext);
ActionResult removeFromGroupsResult = removeFromGroups.execute(localContext);
ActionResult removeResult = remove.execute(localContext);
actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
actionResult.setAuthorizable(context.getCurrentAuthorizable().getID() + " (ignored)");
} catch (RepositoryException | ActionExecutionException e) {
actionResult = context.createActionResult();
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class DestroyUser method simulate.
@Override
public ActionResult simulate(Context context) throws ActionExecutionException {
ActionResult actionResult;
try {
User user = context.getAuthorizableManager().getUser(userId);
context.setCurrentAuthorizable(user);
Action removeFromGroups = new RemoveParents(getGroups(user));
ActionResult purgeResult = purge.simulate(context);
ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
ActionResult removeResult = remove.simulate(context);
actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
} catch (RepositoryException | ActionExecutionException e) {
actionResult = context.createActionResult();
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class RemoveParents method process.
public ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
List<String> errors = new ArrayList<>();
Authorizable authorizable = null;
try {
authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(), groupIds));
} catch (ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
} catch (RepositoryException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
}
for (String id : groupIds) {
try {
Group group = context.getAuthorizableManager().getGroup(id);
if (execute) {
group.removeMember(authorizable);
}
actionResult.logMessage(MessagingUtils.removedFromGroup(authorizable.getID(), id));
} catch (RepositoryException | ActionExecutionException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
if (!errors.isEmpty()) {
for (String error : errors) {
actionResult.logError(error);
}
actionResult.logError("Execution interrupted");
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class RemoveProperty method process.
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Removing property %s from authorizable with id = %s", nameProperty, authorizable.getID()));
if (!simulate) {
authorizable.removeProperty(nameProperty);
}
actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " removed");
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations