private String constructCyclicAttributeErrorMessage( List<String> chain, String type, String refName) { String templateMsg = "Cyclic Reference Error: The selected %s cannot %s to %s " + "'%s' because it references itself in the hierarchy '%s'."; String refType = (type.equals("position")) ? "report" : "belong"; StringBuilder chainStr = new StringBuilder(chain.get(0)); for (int i = 1; i < chain.size(); i++) { chainStr.append(" --> ").append(chain.get(i)); } return String.format(templateMsg, type, refType, type, refName, chainStr.toString()); }
private synchronized void disconnectResources(AbstractResourceAttribute attrib) { Set<AbstractResource> resources = attrib.getResources(); // get ids to avoid ConcurrentModificationException List<String> ids = new ArrayList<String>(); for (AbstractResource resource : resources) ids.add(resource.getID()); for (String id : ids) { Participant p = getParticipant(id); if (attrib instanceof Role) p.removeRole((Role) attrib); else if (attrib instanceof Capability) p.removeCapability((Capability) attrib); else if (attrib instanceof Position) p.removePosition((Position) attrib); updateParticipant(p); } }
public String checkCyclicOrgGroupReference(OrgGroup orgGroup, String refID) { String result = null; List<String> hierarchy = new ArrayList<String>(); hierarchy.add(orgGroup.getGroupName()); OrgGroup owner = getOrgGroup(refID); String refName = owner.getGroupName(); // name of group attempting to add to while (owner != null) { hierarchy.add(owner.getGroupName()); if (owner.equals(orgGroup)) { result = constructCyclicAttributeErrorMessage(hierarchy, "org group", refName); break; } owner = owner.getBelongsTo(); } return result; }
public String checkCyclicPositionReference(Position position, String refID) { String result = null; List<String> hierarchy = new ArrayList<String>(); hierarchy.add(position.getTitle()); Position owner = getPosition(refID); String refName = owner.getTitle(); // title of posn attempting to add to while (owner != null) { hierarchy.add(owner.getTitle()); if (owner.equals(position)) { result = constructCyclicAttributeErrorMessage(hierarchy, "position", refName); break; } owner = owner.getReportsTo(); } return result; }
public String checkCyclicRoleReference(Role role, String refID) { String result = null; List<String> hierarchy = new ArrayList<String>(); hierarchy.add(role.getName()); Role owner = getRole(refID); String refName = owner.getName(); // name of role attempting to add to while (owner != null) { hierarchy.add(owner.getName()); if (owner.equals(role)) { result = constructCyclicAttributeErrorMessage(hierarchy, "role", refName); break; } owner = owner.getOwnerRole(); } return result; }