use of com.cognifide.apm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AuthorizableManagerImpl method getAuthorizableIfExists.
private <T extends Authorizable> T getAuthorizableIfExists(Class<T> authorizableClass, String id) throws ActionExecutionException, RepositoryException {
if (checkIfRemoved(id)) {
return null;
}
Authorizable authorizable = existingAuthorizables.get(id);
if (authorizable == null) {
authorizable = userManager.getAuthorizable(id);
}
if (authorizable == null) {
return null;
}
if (!authorizableClass.isInstance(authorizable)) {
throw new ActionExecutionException(format("Authorizable with id %s exists but is a ", authorizableClass.getSimpleName()));
}
existingAuthorizables.put(id, authorizable);
return authorizableClass.cast(authorizable);
}
use of com.cognifide.apm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AddChildren method process.
private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
Group group = null;
try {
group = context.getCurrentGroup();
actionResult.setAuthorizable(group.getID());
LOGGER.info(String.format("Adding authorizables %s to 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().getAuthorizable(authorizableId);
if (authorizable.isGroup()) {
ActionUtils.checkCyclicRelations(group, (Group) authorizable);
}
if (execute) {
group.addMember(authorizable);
}
actionResult.logMessage(MessagingUtils.addedToGroup(authorizableId, group.getID()));
} 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.exceptions.ActionExecutionException 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.exceptions.ActionExecutionException 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.exceptions.ActionExecutionException 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;
}
Aggregations