Esempio n. 1
0
 public Map<String, String> getRoleIdentifiers() {
   Map<String, String> idMap = new Hashtable<String, String>();
   for (Role r : getRoles()) {
     idMap.put(r.getID(), r.getName());
   }
   return idMap;
 }
Esempio n. 2
0
 public Set<Participant> resolveParticipantsFromResourceName(String anyName) {
   Set<Participant> pSet = new HashSet<Participant>();
   Participant p = getParticipantFromUserID(anyName);
   if (p != null) {
     pSet.add(p);
     return pSet;
   }
   Role r = getRoleByName(anyName);
   if (r != null) {
     pSet.addAll(getRoleParticipants(r.getID()));
     return pSet;
   }
   Position pos = getPositionByLabel(anyName);
   if (pos != null) {
     pSet.addAll(getPositionParticipants(pos.getID()));
     return pSet;
   }
   OrgGroup o = getOrgGroupByLabel(anyName);
   if (o != null) {
     pSet.addAll(getOrgGroupParticipants(o.getID()));
     return pSet;
   }
   Capability c = getCapabilityByLabel(anyName);
   if (c != null) {
     pSet.addAll(getCapabilityParticipants(c.getID()));
   }
   return pSet;
 }
Esempio n. 3
0
 // @return a csv listing of the full name of each role
 public String getRoleNames() {
   StringBuilder csvList = new StringBuilder();
   for (Role r : roleMap.values()) {
     if (csvList.length() > 0) csvList.append(",");
     csvList.append(r.getName());
   }
   return csvList.toString();
 }
Esempio n. 4
0
  public String getRolesAsXML() {
    ArrayList<Role> rList = new ArrayList<Role>(roleMap.values());
    Collections.sort(rList);

    StringBuilder xml = new StringBuilder("<roles>");
    for (Role r : rList) xml.append(r.toXML());
    xml.append("</roles>");
    return xml.toString();
  }
Esempio n. 5
0
 public String getParticpantsWithRoleAsXML(String roleName) {
   String result = "<participants/>";
   if (roleName != null) {
     Role r = getRoleByName(roleName);
     if (r != null) {
       result = getRoleParticipantsAsXML(r.getID());
     }
   }
   return result;
 }
Esempio n. 6
0
 public String getParticipantRolesAsXML(String pid) {
   Set<Role> roles = getParticipantRoles(pid);
   if (roles != null) {
     String header = String.format("<roles participantid=\"%s\">", pid);
     StringBuilder xml = new StringBuilder(header);
     for (Role r : roles) xml.append(r.toXML());
     xml.append("</roles>");
     return xml.toString();
   } else return ("<roles/>");
 }
Esempio n. 7
0
 public Set<Participant> getParticipantsInDescendantRoles(Role owner) {
   Set<Participant> result = new HashSet<Participant>();
   Set<Role> roleSet = getRoles();
   for (Role role : roleSet) {
     if (role.ultimatelyBelongsTo(owner)) {
       result.addAll(castToParticipantSet(role.getResources()));
     }
   }
   return result;
 }
Esempio n. 8
0
 public Set<Participant> getParticipantsWithRole(String roleName) {
   Set<Participant> result = null;
   if (roleName != null) {
     Role r = getRoleByName(roleName);
     if (r != null) {
       result = getRoleParticipants(r.getID());
     }
   }
   return result;
 }
  /** ***************************************************************************** */
  public String toXML() {
    StringBuilder xml = new StringBuilder("<offer ");

    xml.append("initiator=\"").append(getInitiatorString()).append("\">");

    // the rest of the xml is only needed if it's system initiated
    if (isSystemInitiated()) {
      xml.append("<distributionSet>");
      xml.append("<initialSet>");

      if (_participants != null) {
        for (Participant p : _participants) {
          xml.append("<participant>").append(p.getID()).append("</participant>");
        }
      }
      if (_roles != null) {
        for (Role r : _roles) {
          xml.append("<role>").append(r.getID()).append("</role>");
        }
      }
      if (_dynParams != null) {
        for (DynParam p : _dynParams) {
          xml.append(p.toXML());
        }
      }

      xml.append("</initialSet>");

      if ((_filters != null) && (!_filters.isEmpty())) {
        xml.append("<filters>");
        for (AbstractFilter filter : _filters) {
          xml.append(filter.toXML());
        }
        xml.append("</filters>");
      }

      if ((_constraints != null) && (!_constraints.isEmpty())) {
        xml.append("<constraints>");
        for (AbstractConstraint constraint : _constraints) {
          xml.append(constraint.toXML());
        }
        xml.append("</constraints>");
      }

      xml.append("</distributionSet>");

      if (_familiarParticipantTask != null) {
        xml.append("<familiarParticipant taskID=\"");
        xml.append(_familiarParticipantTask).append("\"/>");
      }
    }

    xml.append("</offer>");
    return xml.toString();
  }
  /**
   * Takes the initial distribution set of participants, then expands any roles and/or dynamic
   * parameters to their 'set of participants' equivalents, then applies the specified filters
   * and/or constraints, and returns the final distribution set of participants.
   *
   * @param wir the workitem being offered
   * @return the final distribution set of Participant objects
   */
  public Set<Participant> performOffer(WorkItemRecord wir) {
    _distributionSet = new HashSet<Participant>();

    // if familiar task specified, get the participant(s) who completed that task,
    // & offer this item to them - no more to do
    if (_familiarParticipantTask != null) {
      Set<Participant> pSet = _rm.getWhoCompletedTask(_familiarParticipantTask, wir);
      if (pSet != null) _distributionSet.addAll(pSet);
    } else {
      // make sure each participant is added only once
      ArrayList<String> uniqueIDs = new ArrayList<String>();

      // add Participants
      for (Participant p : _participants) {
        uniqueIDs.add(p.getID());
        _distributionSet.add(p);
      }

      // add roles
      for (Role role : _roles) {
        Set<Participant> pSet = _rm.getOrgDataSet().castToParticipantSet(role.getResources());
        pSet.addAll(_rm.getOrgDataSet().getParticipantsInDescendantRoles(role));
        for (Participant p : pSet) {
          addParticipantToDistributionSet(_distributionSet, uniqueIDs, p);
        }
      }

      // add dynamic params
      for (DynParam param : _dynParams) {
        Set<Participant> pSet = param.evaluate(wir);
        for (Participant p : pSet) {
          addParticipantToDistributionSet(_distributionSet, uniqueIDs, p);
        }
      }

      // apply each filter
      for (AbstractFilter filter : _filters)
        _distributionSet = (HashSet<Participant>) filter.performFilter(_distributionSet);

      // apply each constraint
      for (AbstractConstraint constraint : _constraints)
        _distributionSet =
            (HashSet<Participant>) constraint.performConstraint(_distributionSet, wir);
    }

    // ok - got our final set
    return _distributionSet;
  }
Esempio n. 11
0
 public String addRole(Role r) {
   if (isDataEditable(ResUnit.Role)) {
     String newID = getDataSource(ResUnit.Role).insert(r); // persist it
     if (!hasDefaultDataSource(ResUnit.Role)) r.setID(newID);
     putRole(r); // ...and add it to the data set
     return newID;
   } else return fail("External Role dataset is read-only");
 }
Esempio n. 12
0
  public Set<AbstractResource> getRoleParticipantsWithCapability(String rid, String cid) {
    Set<AbstractResource> resourceSet = new HashSet<AbstractResource>();
    Role role = getRole(rid);
    if (role != null) {

      // filter role members by capability
      if (cid != null) {
        Capability cap = getCapability(cid);
        if (cap != null) {
          for (AbstractResource member : role.getResources()) {
            if (((Participant) member).getCapabilities().contains(cap)) {
              resourceSet.add(member);
            }
          }
        }
      } else resourceSet = role.getResources(); // no cid means don't filter
    }
    return resourceSet;
  }
 public Set<Participant> evaluate(WorkItemRecord wir) {
   HashSet<Participant> result = new HashSet<Participant>();
   if (_refers == USER_PARAM) {
     for (String varID : getVarIDList(wir)) {
       Participant p = _rm.getParticipantFromUserID(varID);
       if (p != null) result.add(p);
       else
         _log.error("Unknown participant userID '" + varID + "' in dynamic parameter: " + _name);
     }
   } else {
     for (String varID : getVarIDList(wir)) {
       Role r = _rm.getOrgDataSet().getRoleByName(varID);
       if (r != null) {
         Set<Participant> rpSet = _rm.getOrgDataSet().getRoleParticipants(r.getID());
         if (rpSet != null) result.addAll(rpSet);
       } else _log.error("Unknown role '" + varID + "' in dynamic parameter: " + _name);
     }
   }
   return result;
 }
Esempio n. 14
0
 public synchronized void removeRole(Role r) {
   if (isDataEditable(ResUnit.Role)) {
     disconnectResources(r);
     for (Role role : getRoles()) {
       Role owner = role.getOwnerRole();
       if ((owner != null) && owner.getID().equals(r.getID())) {
         role.setOwnerRole((Role) null);
         getDataSource(ResUnit.Role).update(role);
       }
     }
     delRole(r);
     getDataSource(ResUnit.Role).delete(r);
   }
 }
Esempio n. 15
0
 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;
 }
Esempio n. 16
0
 public void delRole(Role r) {
   roleMap.remove(r.getID());
   setChangeStamp(ResUnit.Role);
 }
Esempio n. 17
0
 public void putRole(Role r) {
   roleMap.put(r.getID(), r);
   setChangeStamp(ResUnit.Role);
 }
 public void addRole(Role r) {
   if (_rm.getOrgDataSet().isKnownRole(r)) _roles.add(r);
   else _log.warn("Could not add unknown Role to Offer: " + r.getID());
 }
 public void addRoleUnchecked(String rid) {
   Role r = new Role();
   r.setID(rid);
   _roles.add(r);
 }
Esempio n. 20
0
 public boolean isKnownRole(Role r) {
   return isKnownRole(r.getID());
 }
Esempio n. 21
0
 public Role getRoleByName(String roleName) {
   for (Role r : roleMap.values()) {
     if (r.getName().equalsIgnoreCase(roleName)) return r;
   }
   return null; // no match
 }
Esempio n. 22
0
 public Set<Participant> getRoleParticipants(String rid) {
   Role r = roleMap.get(rid);
   return (r != null) ? castToParticipantSet(r.getResources()) : null;
 }