Skip to content

Instantly share code, notes, and snippets.

@wgthom
Created February 19, 2016 03:15
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 wgthom/f34fb9edfe3029febf5b to your computer and use it in GitHub Desktop.
Save wgthom/f34fb9edfe3029febf5b to your computer and use it in GitHub Desktop.
/**
* If syncAttribute was applied to the group or one of the parent folders return true
* Method keeps an internal cache of results per run in markedFoldersAndGroups
* Will also check the PIT for recently deleted groups
*/
private boolean isGroupMarkedForSync(String groupName) {
// have we seen this group already in this run
if (markedFoldersAndGroups.containsKey(groupName)) {
return markedFoldersAndGroups.get(groupName).equals(MARKED);
}
boolean markedForSync;
// looking for the group
final Group group = GroupFinder.findByName(GrouperSession.staticGrouperSession(false), groupName, false);
if (group != null) {
// is it marked with the syncAttribute?
markedForSync = group.getAttributeDelegate().hasAttributeOrAncestorHasAttribute(syncAttribute.getName(), false);
} else {
// looking for the deleted group in the PIT
PITGroup pitGroup = PITGroupFinder.findMostRecentByName(groupName, true);
if (pitGroup != null) {
// looking for syncAttribute assignment in the PIT
Set<PITAttributeDefName> pitSyncAttributes = PITAttributeDefNameFinder.findByName(syncAttribute.getName(), false, true);
PITAttributeDefName pitSyncAttribute = pitSyncAttributes.iterator().next();
Set<PITAttributeAssign> pitAttributeAssigns = PITAttributeAssignFinder.findByOwnerPITGroupAndPITAttributeDefName(pitGroup, pitSyncAttribute, pitGroup.getStartTime(), pitGroup.getEndTime());
markedForSync = pitAttributeAssigns.isEmpty();
} else {
// couldn't find group anywhere including the PIT
LOG.info("{} checking for {} marker, but could not find group {} anywhere, including the PIT.", new Object[]{consumerName, syncAttributeName, groupName});
markedForSync = false;
}
}
// remember this for next time
if(markedForSync) {
markedFoldersAndGroups.put(groupName, MARKED);
return true;
} else {
markedFoldersAndGroups.put(groupName, NOT_MARKED);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment