use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class DeleteGroup method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
List<String> errors = new ArrayList<>();
LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", ")));
for (String id : ids) {
try {
Group group = context.getAuthorizableManager().getGroupIfExists(id);
if (group != null) {
context.getAuthorizableManager().markAuthorizableAsRemoved(group);
if (execute) {
context.getAuthorizableManager().removeGroup(group);
}
actionResult.logMessage("Group with id: " + id + " removed");
}
} 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 RemoveUser method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
List<String> errors = new ArrayList<>();
LOGGER.info(String.format("Removing users with ids = %s", StringUtils.join(ids, ", ")));
for (String id : ids) {
try {
User user = context.getAuthorizableManager().getUserIfExists(id);
if (user != null) {
context.getAuthorizableManager().markAuthorizableAsRemoved(user);
if (execute) {
context.getAuthorizableManager().removeUser(user);
}
actionResult.logMessage("User with id: " + id + " removed");
}
} 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 RemoveChildren method process.
private ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
Group group = null;
try {
group = context.getCurrentGroup();
actionResult.setAuthorizable(group.getID());
LOGGER.info(String.format("Removing authorizables %s from group with id = %s", StringUtils.join(authorizableIds, ", "), group.getID()));
} catch (ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
} catch (RepositoryException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return actionResult;
}
List<String> errors = new ArrayList<>();
for (String authorizableId : authorizableIds) {
try {
Authorizable authorizable = context.getAuthorizableManager().getAuthorizableIfExists(authorizableId);
if (authorizable == null) {
actionResult.logWarning(MessagingUtils.authorizableNotExists(authorizableId));
continue;
}
if (execute) {
group.removeMember(authorizable);
}
actionResult.logMessage(MessagingUtils.removedFromGroup(authorizableId, group.getID()));
} catch (RepositoryException 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 ClearFromGroupDetacher method detachAuthorizableFromParents.
public ActionResult detachAuthorizableFromParents() {
ActionResult actionResult = context.createActionResult();
try {
Authorizable currentAuthorizable = context.getCurrentAuthorizable();
Iterator<Group> groups = getGroupParents(actionResult, currentAuthorizable);
LOGGER.info(String.format("Removing all memberships of authorizable with id = %s", currentAuthorizable.getID()));
detachFromParents(actionResult, currentAuthorizable, groups);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.
the class ClearFromGroupDetacher method detachMembersFromGroup.
public ActionResult detachMembersFromGroup() {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
if (authorizable.isGroup()) {
final Group group = context.getCurrentGroup();
LOGGER.info(String.format("Removing all members of group with id = %s", group.getID()));
Iterator<Authorizable> groupMembers = getGroupMembers(actionResult, group);
detachAllMembers(actionResult, group, groupMembers);
} else {
actionResult.logError("Child members can only be removed from groups");
}
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
Aggregations