Created
December 12, 2012 15:31
-
-
Save mtheoryx/4268703 to your computer and use it in GitHub Desktop.
AssignmentEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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