Skip to content

Instantly share code, notes, and snippets.

@mtheoryx
Created December 12, 2012 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtheoryx/4268703 to your computer and use it in GitHub Desktop.
Save mtheoryx/4268703 to your computer and use it in GitHub Desktop.
AssignmentEntity.java
// set the item to be accessible only to the specific groups.
// null to make it accessible to the whole site
public void setGroups(Collection<String> groups) {
if (assignment == null)
assignment = getAssignment(id);
if (assignment == null)
return;
String siteId = ToolManager.getCurrentPlacement().getContext();
Site site = null;
String ref = "/assignment/a/" + siteId + "/" + id;
try {
site = SiteService.getSite(siteId);
} catch (Exception e) {
log.warn("Unable to find site " + siteId, e);
return;
}
AssignmentEdit edit = null;
try {
edit = AssignmentService.editAssignment(ref);
} catch (IdUnusedException e) {
log.warn("ID unused ", e);
return;
} catch (PermissionException e) {
log.warn(e);
return;
} catch (InUseException e) {
log.warn(e);
return;
}
boolean doCancel = true;
try {
// need this to make sure we always unlock
if (groups != null && groups.size() > 0) {
List<Group> groupObjs = new ArrayList<Group>();
for (String groupId : groups) {
Group group = site.getGroup(groupId);
if (group != null)
groupObjs.add(group);
}
edit.setGroupAccess(groupObjs);
} else {
edit.setAccess(Assignment.AssignmentAccess.SITE);
edit.clearGroupAccess();
}
AssignmentService.commitEdit(edit);
doCancel = false;
return;
} catch (Exception e) {
log.warn(e);
return;
} finally {
if (doCancel) {
AssignmentService.commitEdit(edit);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment