예제 #1
0
  private String validateCredentials(String userid, String password) {
    if (userid == null) {
      return "No userid was specified.";
    }
    if (password == null) {
      return "No password was specified.";
    }

    String loggedOnUserID = sb.getUserid();
    if (loggedOnUserID != null) {
      if (!loggedOnUserID.equals(userid)) {
        return "User '"
            + loggedOnUserID
            + "' is already logged on in this"
            + " browser instance (in another tab or window)."
            + " Only one user logon per browser "
            + " instance is possible. If you wish to view you work"
            + " queued items via your iGoogle Gadget, please "
            + " logout the currently logged on user first.";
      } else sb.setRssAlreadyLoggedOn(true);
    } else {
      if (rm == null) {
        return "Could not connect to work queue, service unavailable.";
      }
      Participant p = rm.getParticipantFromUserID(userid);
      if (p == null) {
        return "Unknown userid: " + userid;
      }
      if (!p.getPassword().equals(password)) {
        return "Incorrect password.";
      }
      if (!rm.hasOrgDataSource()) {
        msgPanel.error(
            "Missing or invalid organisational data source. The resource"
                + " service requires a connection to a valid data source"
                + " that contains organisational data. Please check the"
                + " settings of the 'OrgDataSource' parameter in the service's"
                + " web.xml to ensure a valid data source is set, and/or check"
                + " the configuration properties set for the data source.");
      }
      String handle = rm.login(userid, password, sb.getExternalSessionID());
      if (!rm.successful(handle)) {
        return (msgPanel.format(handle));
      }

      initSession(p, userid, handle);
    }
    return success; // successful login
  }
  /**
   * 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;
  }
예제 #3
0
  /* saves a newly added category to the org database */
  public boolean addCategory(String name) {
    if (!_orgDataSet.isKnownNonHumanCategoryName(name)) {
      NonHumanCategory category = new NonHumanCategory(name);
      storeSimpleFieldValues(category);
      category.addSubCategory("None");
      String newID = _orgDataSet.addNonHumanCategory(category);
      if (_rm.successful(newID)) {
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Category");

    return false;
  }
  public void withdrawOffer(WorkItemRecord wir, HashSet<Participant> offeredSet) {
    if (offeredSet != null) {
      for (Participant p : offeredSet) {
        p.getWorkQueues().removeFromQueue(wir, WorkQueue.OFFERED);
        _rm.announceModifiedQueue(p.getID());
      }
    }

    // a fired instance of a multi-instance workitem on the unoffered queue will
    // never have been offered, so the warning should be suppressed for those
    else if (!wir.getStatus().equals(WorkItemRecord.statusFired)) {
      _log.warn(
          "Workitem '"
              + wir.getID()
              + "' does not have 'Offered' status, "
              + "or is no longer active");
    }
  }
예제 #5
0
  /** updates a workitem after editing on a dynamic form */
  private void postEditWIR() {
    if (_sb.isWirEdit()) {
      WorkItemRecord wir = _sb.getVisualiserEditedWIR();
      if (wir != null) {
        Element data =
            JDOMUtil.stringToElement(((DynFormFactory) getBean("DynFormFactory")).getDataList());
        wir.setUpdatedData(data);
        _rm.getWorkItemCache().update(wir);

        if (_sb.isCompleteAfterEdit()) {
          completeWorkItem(wir, _sb.getParticipant());
        }
      } else {
        msgPanel.error("Could not complete workitem. Check log for details.");
      }
    }
    _sb.setWirEdit(false);
    _sb.setCompleteAfterEdit(false);
    _sb.setVisualiserReferred(false);
    _sb.setVisualiserEditedWIR(null);
    if (msgPanel.hasMessage()) forceRefresh();
  }
예제 #6
0
  /* saves a newly added resource to the org database */
  public boolean addResource(String name) {
    if (!_orgDataSet.isKnownNonHumanResourceName(name)) {
      String catID = (String) cbbCategory.getSelected();
      NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID);
      String subCat = (String) cbbSubCategory.getSelected();

      NonHumanResource resource = _sb.getSelectedNonHumanResource();
      if (resource == null) resource = new NonHumanResource();
      resource.setName(name);
      resource.setCategory(category);
      resource.setSubCategory(subCat);
      resource.setDescription((String) txtDesc.getText());
      resource.setNotes((String) txtNotes.getText());
      String newID = _orgDataSet.addNonHumanResource(resource);
      if (_rm.successful(newID)) {
        updateSelectedResource(resource, false);
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Resource");

    return false;
  }
예제 #7
0
  public void prerender() {
    if (sb.isRssFormDisplay()) {
      String msg = "";
      FormViewer form = sb.getFormViewerInstance();
      if (form != null) {
        msg = form.postDisplay(sb.getRssFormWIR());
        sb.resetPostFormDisplay();
        if (successful(msg)) {
          msg = "Work Item successfully processed.";
        }
      } else {
        msg = "Unsuccessful form completion - could not finalise form.";
      }
      showMessage(msg + " Please click the button below to close this window/tab.");
    } else {
      HttpServletRequest request = getRequest();
      String userid = request.getParameter("userid");
      String password = request.getParameter("password");
      String itemid = request.getParameter("itemid");

      String msg = validateCredentials(userid, password);
      WorkItemRecord wir = null;
      if (successful(msg)) {
        wir = rm.getWorkItemRecord(itemid);
        if (wir == null) {
          msg =
              "Unknown Work Item ID - perhaps it has already been actioned"
                  + " and/or moved to another queue. Please refresh your worklist.";
        }
      }
      if (successful(msg)) {
        startAndShow(userid, wir);
      } else {
        showMessage(msg);
      }
    }
  }
 /**
  * Adds a participant to the initial distribution list
  *
  * @param id - the id of the participant
  */
 public void addParticipant(String id) {
   Participant p = _rm.getOrgDataSet().getParticipant(id);
   if (p != null) _participants.add(p);
   else _log.warn("Unknown Participant ID in Offer spec: " + id);
 }
/**
 * This class describes the requirements of a task at the offer phase of allocating resources.
 *
 * @author Michael Adams v0.1, 02/08/2007
 */
public class OfferInteraction extends AbstractInteraction {

  // initial distribution set
  private HashSet<Participant> _participants = new HashSet<Participant>();
  private HashSet<Role> _roles = new HashSet<Role>();
  private HashSet<DynParam> _dynParams = new HashSet<DynParam>();

  // complete distribution set expanded to a set of participants
  private HashSet<Participant> _distributionSet = new HashSet<Participant>();

  private HashSet<AbstractFilter> _filters = new HashSet<AbstractFilter>();
  private HashSet<AbstractConstraint> _constraints = new HashSet<AbstractConstraint>();

  private String _familiarParticipantTask;

  private ResourceManager _rm = ResourceManager.getInstance();
  private static final Logger _log = Logger.getLogger(OfferInteraction.class);

  // Dynamic Parameter types
  public static final int USER_PARAM = 0;
  public static final int ROLE_PARAM = 1;

  /** ***************************************************************************** */

  // CONSTRUCTORS //

  public OfferInteraction() {
    super();
  } // required for reflection

  public OfferInteraction(String ownerTaskID) {
    super(ownerTaskID);
  }

  /**
   * @param initiator - either AbstractInteraction.SYSTEM_INITIATED or
   *     AbstractInteraction.USER_INITIATED
   */
  public OfferInteraction(int initiator) {
    super(initiator);
  }

  /** ***************************************************************************** */

  // MEMBER MODIFIERS //

  /**
   * Adds a participant to the initial distribution list
   *
   * @param id - the id of the participant
   */
  public void addParticipant(String id) {
    Participant p = _rm.getOrgDataSet().getParticipant(id);
    if (p != null) _participants.add(p);
    else _log.warn("Unknown Participant ID in Offer spec: " + id);
  }

  public void addParticipantUnchecked(String id) {
    Participant p = new Participant(id);
    _participants.add(p);
  }

  /**
   * variation of the above
   *
   * @param p - the Participant object to add to the initial distribution list
   */
  public void addParticipant(Participant p) {
    if (_rm.getOrgDataSet().isKnownParticipant(p)) _participants.add(p);
    else _log.warn("Could not add unknown Participant to Offer: " + p.getID());
  }

  public void addParticipantsByID(String idList) {
    String[] ids = idList.split(",");
    for (String id : ids) addParticipant(id.trim());
  }

  public void addParticipantsByID(Set idSet) {
    for (Object id : idSet) addParticipant((String) id);
  }

  public void addParticipants(Set pSet) {
    for (Object id : pSet) addParticipant((Participant) id);
  }

  public void addRole(String rid) {
    Role r = _rm.getOrgDataSet().getRole(rid);
    if (r != null) _roles.add(r);
    else _log.warn("Unknown Role ID in Offer spec: " + rid);
  }

  public void addRoleUnchecked(String rid) {
    Role r = new Role();
    r.setID(rid);
    _roles.add(r);
  }

  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 addRoles(String roleList) {
    String[] roles = roleList.split(",");
    for (String role : roles) addRole(role.trim());
  }

  public void addRoles(Set rSet) {
    for (Object role : rSet) addRole((Role) role);
  }

  public boolean addInputParam(String name, int type) {
    if ((type == USER_PARAM) || (type == ROLE_PARAM)) {
      DynParam p = new DynParam(name, type);
      _dynParams.add(p);
      return true;
    } else return false;
  }

  public void addInputParams(Map pMap) {
    for (Object name : pMap.keySet()) {
      int type = Integer.parseInt((String) pMap.get(name));
      addInputParam((String) name, type);
    }
  }

  public void addFilters(Set filters) {
    _filters.addAll(filters);
  }

  public void addFilter(AbstractFilter f) {
    _filters.add(f);
  }

  public void addConstraints(Set constraints) {
    _constraints.addAll(constraints);
  }

  public void addConstraint(AbstractConstraint c) {
    _constraints.add(c);
  }

  public void setFamiliarParticipantTask(String taskid) {
    _familiarParticipantTask = taskid;
  }

  public Set<Participant> getParticipants() {
    return _participants;
  }

  public Set<Role> getRoles() {
    return _roles;
  }

  public Set<AbstractFilter> getFilters() {
    return _filters;
  }

  public Set<AbstractConstraint> getConstraints() {
    return _constraints;
  }

  public Set<Participant> getDistributionSet() {
    return _distributionSet;
  }

  public Set<String> getDynParamNames() {
    Set<String> names = new HashSet<String>();
    for (DynParam param : _dynParams) {
      names.add(param.getName() + "[" + param.getRefersString() + "]");
    }
    return names;
  }

  /** ***************************************************************************** */

  /**
   * 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;
  }

  public void withdrawOffer(WorkItemRecord wir, HashSet<Participant> offeredSet) {
    if (offeredSet != null) {
      for (Participant p : offeredSet) {
        p.getWorkQueues().removeFromQueue(wir, WorkQueue.OFFERED);
        _rm.announceModifiedQueue(p.getID());
      }
    }

    // a fired instance of a multi-instance workitem on the unoffered queue will
    // never have been offered, so the warning should be suppressed for those
    else if (!wir.getStatus().equals(WorkItemRecord.statusFired)) {
      _log.warn(
          "Workitem '"
              + wir.getID()
              + "' does not have 'Offered' status, "
              + "or is no longer active");
    }
  }

  private void addParticipantToDistributionSet(
      HashSet<Participant> distributionSet, ArrayList<String> uniqueIDs, Participant p) {
    if (!uniqueIDs.contains(p.getID())) {
      uniqueIDs.add(p.getID());
      distributionSet.add(p);
    }
  }

  /** ***************************************************************************** */

  // Resource Specification Offer Parsing Methods //

  public void parse(Element e, Namespace nsYawl) throws ResourceParseException {

    parseInitiator(e, nsYawl);

    // if offer is not system-initiated, there's no more to do
    if (!isSystemInitiated()) return;

    parseDistributionSet(e, nsYawl);
    parseFamiliarTask(e, nsYawl);
  }

  private void parseDistributionSet(Element e, Namespace nsYawl) throws ResourceParseException {
    Element eDistSet = e.getChild("distributionSet", nsYawl);
    if (eDistSet != null) {
      parseInitialSet(eDistSet, nsYawl);
      parseFilters(eDistSet, nsYawl);
      parseConstraints(eDistSet, nsYawl);
    } else
      throw new ResourceParseException("Missing required element in Offer block: distributionSet");
  }

  private void parseInitialSet(Element e, Namespace nsYawl) throws ResourceParseException {

    Element eInitialSet = e.getChild("initialSet", nsYawl);
    if (eInitialSet != null) {
      parseParticipants(eInitialSet, nsYawl);
      parseRoles(eInitialSet, nsYawl);
      parseDynParams(eInitialSet, nsYawl);
    } else
      throw new ResourceParseException(
          "Missing required distributionSet child element in Offer block: initialSet");
  }

  private void parseParticipants(Element e, Namespace nsYawl) {

    // from the specified initial set, add all participants
    for (Element eParticipant : e.getChildren("participant", nsYawl)) {
      String participant = eParticipant.getText();
      if (participant.indexOf(',') > -1) addParticipantsByID(participant);
      else addParticipant(participant);
    }
  }

  private void parseRoles(Element e, Namespace nsYawl) {

    // ... and roles
    for (Element eRole : e.getChildren("role", nsYawl)) {
      String role = eRole.getText();
      if (role.indexOf(',') > -1) addRoles(role);
      else addRole(role);
    }
  }

  private void parseDynParams(Element e, Namespace nsYawl) {

    // ... and input parameters
    for (Element eParam : e.getChildren("param", nsYawl)) {
      String name = eParam.getChildText("name", nsYawl);
      String refers = eParam.getChildText("refers", nsYawl);
      int pType = refers.equals("role") ? ROLE_PARAM : USER_PARAM;
      addInputParam(name, pType);
    }
  }

  private void parseFilters(Element e, Namespace nsYawl) throws ResourceParseException {

    // get the Filters
    Element eFilters = e.getChild("filters", nsYawl);
    if (eFilters != null) {
      List<Element> filters = eFilters.getChildren("filter", nsYawl);
      if (filters == null)
        throw new ResourceParseException("No filter elements found in filters element");

      for (Element eFilter : filters) {
        String filterClassName = eFilter.getChildText("name", nsYawl);
        if (filterClassName != null) {
          AbstractFilter filter = PluginFactory.newFilterInstance(filterClassName);
          if (filter != null) {
            filter.setParams(parseParams(eFilter, nsYawl));
            _filters.add(filter);
          } else throw new ResourceParseException("Unknown filter name: " + filterClassName);
        } else throw new ResourceParseException("Missing filter element: name");
      }
    }
  }

  private void parseConstraints(Element e, Namespace nsYawl) throws ResourceParseException {
    // get the Constraints
    Element eConstraints = e.getChild("constraints", nsYawl);
    if (eConstraints != null) {
      List<Element> constraints = eConstraints.getChildren("constraint", nsYawl);
      if (constraints == null)
        throw new ResourceParseException("No constraint elements found in constraints element");

      for (Element eConstraint : constraints) {
        String constraintClassName = eConstraint.getChildText("name", nsYawl);
        if (constraintClassName != null) {
          AbstractConstraint constraint = PluginFactory.newConstraintInstance(constraintClassName);
          if (constraint != null) {
            constraint.setParams(parseParams(eConstraint, nsYawl));
            _constraints.add(constraint);
          } else
            throw new ResourceParseException("Unknown constraint name: " + constraintClassName);
        } else throw new ResourceParseException("Missing constraint element: name");
      }
    }
  }

  private void parseFamiliarTask(Element e, Namespace nsYawl) {

    // finally, get the familiar participant task
    Element eFamTask = e.getChild("familiarParticipant", nsYawl);
    if (eFamTask != null) _familiarParticipantTask = eFamTask.getAttributeValue("taskID");
  }

  /** ***************************************************************************** */
  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();
  }

  /** **************************************************************************** */
  /** **************************************************************************** */

  /**
   * A class that encapsulates one dynamic parameter - i.e. a data variable that at runtime will
   * contain a value corresponding to a participant or role that the task is to be offered to.
   */
  private class DynParam {

    private String _name; // the name of the data variable
    private int _refers; // participant or role

    /**
     * the constructor
     *
     * @param name - the name of a data variable of this task that will contain a runtime value
     *     specifying a particular participant or role.
     * @param refers - either USER_PARAM or ROLE_PARAM
     */
    public DynParam(String name, int refers) {
      _name = name;
      _refers = refers;
    }

    /** **************************************************************************** */

    // GETTERS & SETTERS //

    public String getName() {
      return _name;
    }

    public int getRefers() {
      return _refers;
    }

    public void setName(String name) {
      _name = name;
    }

    public void setRefers(int refers) {
      _refers = refers;
    }

    public String getRefersString() {
      if (_refers == USER_PARAM) return "participant";
      else return "role";
    }

    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;
    }

    private String getNetParamValue(WorkItemRecord wir, String name) {
      String result = null;
      try {
        result = _rm.getNetParamValue(wir.getCaseID(), _name);
        if (result == null)
          _log.error(
              "Unable to retrieve value from net parameter '"
                  + name
                  + "' for deferred allocation of workitem '"
                  + wir.getID()
                  + "'.");
      } catch (IOException ioe) {
        _log.error(
            "Caught exception attempting to retrieve value from net parameter '"
                + name
                + "' for deferred allocation of workitem '"
                + wir.getID()
                + "'.");
      }
      return result;
    }

    private List<String> getVarIDList(WorkItemRecord wir) {
      List<String> idList = new ArrayList<String>();
      String varValue = getNetParamValue(wir, _name);
      if (varValue != null) {
        for (String id : varValue.split(",")) {
          idList.add(id.trim());
        }
      }
      return idList;
    }

    /** **************************************************************************** */

    /** this is for the spec file */
    public String toXML() {
      StringBuilder xml = new StringBuilder("<param>");
      xml.append("<name>").append(_name).append("</name>");
      xml.append("<refers>").append(getRefersString()).append("</refers>");
      xml.append("</param>");
      return xml.toString();
    }
  } // end of private class DynParam

  /** **************************************************************************** */
}
 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 addRole(String rid) {
   Role r = _rm.getOrgDataSet().getRole(rid);
   if (r != null) _roles.add(r);
   else _log.warn("Unknown Role ID in Offer spec: " + rid);
 }
 /**
  * variation of the above
  *
  * @param p - the Participant object to add to the initial distribution list
  */
 public void addParticipant(Participant p) {
   if (_rm.getOrgDataSet().isKnownParticipant(p)) _participants.add(p);
   else _log.warn("Could not add unknown Participant to Offer: " + p.getID());
 }
예제 #13
0
public class pfNHResources extends AbstractFragmentBean {
  private int __placeholder;

  private void _init() throws Exception {}

  private Listbox lbxItems = new Listbox();

  public Listbox getLbxItems() {
    return lbxItems;
  }

  public void setLbxItems(Listbox l) {
    this.lbxItems = l;
  }

  private Label lblItems = new Label();

  public Label getLblItems() {
    return lblItems;
  }

  public void setLblItems(Label l) {
    this.lblItems = l;
  }

  private Label lblName = new Label();

  public Label getLblName() {
    return lblName;
  }

  public void setLblName(Label l) {
    this.lblName = l;
  }

  private TextField txtName = new TextField();

  public TextField getTxtName() {
    return txtName;
  }

  public void setTxtName(TextField tf) {
    this.txtName = tf;
  }

  private Label lblCategory = new Label();

  public Label getLblCategory() {
    return lblCategory;
  }

  public void setLblCategory(Label l) {
    this.lblCategory = l;
  }

  private Label lblDesc = new Label();

  public Label getLblDesc() {
    return lblDesc;
  }

  public void setLblDesc(Label l) {
    this.lblDesc = l;
  }

  private Label lblNotes = new Label();

  public Label getLblNotes() {
    return lblNotes;
  }

  public void setLblNotes(Label l) {
    this.lblNotes = l;
  }

  private TextArea txtDesc = new TextArea();

  public TextArea getTxtDesc() {
    return txtDesc;
  }

  public void setTxtDesc(TextArea ta) {
    this.txtDesc = ta;
  }

  private TextArea txtNotes = new TextArea();

  public TextArea getTxtNotes() {
    return txtNotes;
  }

  public void setTxtNotes(TextArea ta) {
    this.txtNotes = ta;
  }

  private DropDown cbbCategory = new DropDown();

  public DropDown getCbbCategory() {
    return cbbCategory;
  }

  public void setCbbCategory(DropDown dd) {
    this.cbbCategory = dd;
  }

  private DropDown cbbSubCategory = new DropDown();

  public DropDown getCbbSubCategory() {
    return cbbSubCategory;
  }

  public void setCbbSubCategory(DropDown dd) {
    this.cbbSubCategory = dd;
  }

  private Label lblSubCategory = new Label();

  public Label getLblSubCategory() {
    return lblSubCategory;
  }

  public void setLblSubCategory(Label l) {
    this.lblSubCategory = l;
  }

  private DropDown cbbMembers = new DropDown();

  public DropDown getCbbMembers() {
    return cbbMembers;
  }

  public void setCbbMembers(DropDown dd) {
    this.cbbMembers = dd;
  }

  private Label lblMembers = new Label();

  public Label getLblMembers() {
    return lblMembers;
  }

  public void setLblMembers(Label l) {
    this.lblMembers = l;
  }

  private Listbox lbxSubCatItems = new Listbox();

  public Listbox getLbxSubCatItems() {
    return lbxSubCatItems;
  }

  public void setLbxSubCatItems(Listbox l) {
    this.lbxSubCatItems = l;
  }

  private TextField txtSubCat = new TextField();

  public TextField getTxtSubCat() {
    return txtSubCat;
  }

  public void setTxtSubCat(TextField tf) {
    this.txtSubCat = tf;
  }

  private Button btnRemoveSubCat = new Button();

  public Button getBtnRemoveSubCat() {
    return btnRemoveSubCat;
  }

  public void setBtnRemoveSubCat(Button b) {
    btnRemoveSubCat = b;
  }

  private Button btnAddSubCat = new Button();

  public Button getBtnAddSubCat() {
    return btnAddSubCat;
  }

  public void setBtnAddSubCat(Button b) {
    btnAddSubCat = b;
  }

  private Button btnConfirmAddSubCat = new Button();

  public Button getBtnConfirmAddSubCat() {
    return btnConfirmAddSubCat;
  }

  public void setBtnConfirmAddSubCat(Button b) {
    btnConfirmAddSubCat = b;
  }

  private Button btnCancelAddSubCat = new Button();

  public Button getBtnCancelAddSubCat() {
    return btnCancelAddSubCat;
  }

  public void setBtnCancelAddSubCat(Button b) {
    btnCancelAddSubCat = b;
  }

  /** ****************************************************** */
  public pfNHResources() {}

  /** Return a reference to the scoped data bean. */
  protected RequestBean getRequestBean() {
    return (RequestBean) getBean("RequestBean");
  }

  /** Return a reference to the scoped data bean. */
  protected SessionBean getSessionBean() {
    return (SessionBean) getBean("SessionBean");
  }

  /** Return a reference to the scoped data bean. */
  protected ApplicationBean getApplicationBean() {
    return (ApplicationBean) getBean("ApplicationBean");
  }

  public void init() {
    // Perform initializations inherited from our superclass
    super.init();

    // *Note* - this logic should NOT be modified
    try {
      _init();
    } catch (Exception e) {
      log("pfNHResources Initialization Failure", e);
      throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
    }
  }

  public void destroy() {}

  private SessionBean _sb = getSessionBean();
  private MessagePanel _msgPanel = _sb.getMessagePanel();
  private ResourceManager _rm = getApplicationBean().getResourceManager();
  private ResourceDataSet _orgDataSet = _rm.getOrgDataSet();

  /* triggered by both tabs */
  public void lbxItems_processValueChange(ValueChangeEvent event) {
    _sb.setSourceTabAfterListboxSelection();
    updateSelectedResource(null); // resets currently selected
  }

  /* triggered by categories tab only */
  public void lbxSubCatItems_processValueChange(ValueChangeEvent event) {
    _sb.setSourceTabAfterListboxSelection();
  }

  /* triggered by resources tab only */
  public void cbbCategory_processValueChange(ValueChangeEvent event) {
    NonHumanResource resource = _sb.getSelectedNonHumanResource();
    if (resource != null) {
      storeSimpleFieldValues(resource);
      NonHumanCategory category = _orgDataSet.getNonHumanCategory((String) event.getNewValue());
      if (category != null) {
        resource.setCategory(category);
        resource.setSubCategory("None");
      }
    }
  }

  /* triggered by resources tab only */
  public void cbbSubCategory_processValueChange(ValueChangeEvent event) {
    NonHumanResource resource = _sb.getSelectedNonHumanResource();
    if (resource != null) {
      storeSimpleFieldValues(resource);
      resource.setSubCategory((String) event.getNewValue());
    }
  }

  /* set mode to add a new subcategory - triggered by categories tab only */
  public String btnAddSubCat_action() {
    _sb.setSubCatAddMode(true);
    setSubCatAddMode(true);
    return null;
  }

  /* removes a subcategory - triggered by categories tab only */
  public String btnRemoveSubCat_action() {
    NonHumanCategory category = getCurrentlySelectedCategory();
    if (category != null) {
      if (category.removeSubCategory(_sb.getNhResourcesSubcategoryChoice())) {
        _orgDataSet.updateNonHumanCategory(category);
        _sb.setNhResourcesSubcategoryChoice("None");
      } else _msgPanel.error("Failed to remove subcategory.");
    }
    return null;
  }

  /* adds a new subcategory - triggered by categories tab only */
  public String btnConfirmAddSubCat_action() {
    String name = (String) txtSubCat.getText();
    if ((name != null) && (name.length() > 0)) {
      NonHumanCategory category = getCurrentlySelectedCategory();
      if (category != null) {
        if (category.addSubCategory(name)) { // won't add if duplicate
          _orgDataSet.updateNonHumanCategory(category);
          _sb.setSubCatAddMode(false);
          txtSubCat.setText(null);
        } else _msgPanel.error("Subcategory already exists: " + name);
      }
    } else _msgPanel.error("Please enter a subcategory to add.");
    return null;
  }

  /* reset mode to browse/edit for subcategories - triggered by categories tab only */
  public String btnCancelAddSubCat_action() {
    _sb.setSubCatAddMode(false);
    return null;
  }

  protected void populateGUI(String id, nonHumanMgt.SelType type) {
    switch (type) {
      case resource:
        populateGUI(_sb.getSelectedNonHumanResource(), id);
        break;
      case category:
        populateGUI(_orgDataSet.getNonHumanCategory(id));
        break;
    }
    lbxItems.setSelected(id);
  }

  /* fills ui with the selected resource's values */
  private void populateGUI(NonHumanResource resource, String id) {

    // selected resource is null after a selection change
    if (resource == null) {
      resource = _orgDataSet.getNonHumanResource(id);
      updateSelectedResource(resource);
    }
    if (resource != null) {
      populateSimpleFields(resource);
      NonHumanCategory category = resource.getCategory();
      String subCatName = resource.getSubCategoryName();
      if (category == null) {
        category = getFirstListedCategory(); // default
      }
      if (subCatName == null) subCatName = "None";
      if (category != null) {
        cbbCategory.setSelected(category.getID());
        _sb.setNhResourcesSubcategoryItems(getSubCategoryList(category));
        cbbSubCategory.setSelected(subCatName);
      } else _sb.setNhResourcesSubcategoryItems(null); // no categories defined
    }
    _sb.setNhResourcesSubcategoryList(null); // empty the category tab list box
  }

  /* fills ui with the selected category's values */
  private void populateGUI(NonHumanCategory category) {
    if (category != null) {
      populateSimpleFields(category);
      _sb.setNhResourcesSubcategoryList(getSubCategoryList(category));
      int membership = _sb.setCategoryMembers(category);
      lblMembers.setText("Members (" + membership + ")");
    }
    _sb.setNhResourcesSubcategoryItems(null); // empty the resource tab combo box
  }

  /* sets or hides fields depending on which tab is shown */
  public void setVisibleComponents(nonHumanMgt.SelType sType) {
    boolean catTab = (sType == nonHumanMgt.SelType.category);

    // these only appear on the resources tab
    cbbCategory.setVisible(!catTab);
    lblSubCategory.setVisible(!catTab);
    cbbSubCategory.setVisible(!catTab);

    // these only appear on the categories tab
    lblMembers.setVisible(catTab);
    cbbMembers.setVisible(catTab);
    lbxSubCatItems.setVisible(catTab);
    btnAddSubCat.setVisible(catTab);
    btnRemoveSubCat.setVisible(catTab);

    // nullify lists
    if (catTab) {
      cbbCategory.setItems(null);
      cbbSubCategory.setItems(null);
    } else lbxSubCatItems.setItems(null);
  }

  /* enable or disable fields depending on whether we are in browse/edit or add mode */
  public void setAddMode(boolean adding, String selectedTab) {
    lbxItems.setDisabled(adding);
    if (selectedTab.equals("tabCategories")) {
      lbxSubCatItems.setDisabled(adding);
      btnAddSubCat.setDisabled(adding);
      btnRemoveSubCat.setDisabled(adding);
      disableInputFields(!adding);
      disableSubCatButtons(adding);
      _sb.setCategoryMembers(null);
    }
    if (adding) clearTextFields();
    txtName.setText("");
    lblMembers.setText("Members (0)");
  }

  /* saves updates to the values of the selected resource or category */
  public boolean saveChanges(String id) {
    String activeTab = _sb.getActiveTab();
    if (activeTab.equals("tabResources")) return saveResourceChanges(id);
    else if (activeTab.equals("tabCategories")) return saveCategoryChanges(id);

    return false;
  }

  /* saves updates to the values of the currently selected resource */
  public boolean saveResourceChanges(String id) {
    NonHumanResource cloned = _sb.getSelectedNonHumanResource();
    if (cloned == null) {
      _msgPanel.error("Could not retrieve changes from session");
      return false;
    }
    NonHumanResource resource = _orgDataSet.getNonHumanResource(id);
    if (resource == null) {
      _msgPanel.error("Invalid resource id: " + id);
      return false;
    }

    // check that any name change is valid
    String name = (String) txtName.getText();
    if ((!name.equals(resource.getName())) && _orgDataSet.isKnownNonHumanResourceName(name)) {
      addDuplicationError("Resource");
      return false;
    }
    storeSimpleFieldValues(cloned);
    resource.merge(cloned); // update resource with clone's values
    cloned.clearCategory(); // remove cloned from its category
    _orgDataSet.updateNonHumanResource(resource);
    updateSelectedResource(resource);
    return true;
  }

  /* saves updates to the values of the currently selected category */
  public boolean saveCategoryChanges(String id) {
    NonHumanCategory category = _orgDataSet.getNonHumanCategory(id);
    if (category == null) {
      _msgPanel.error("Invalid category id: " + id);
      return false;
    }

    // check that any name change is valid
    String name = (String) txtName.getText();
    if ((!name.equals(category.getName())) && _orgDataSet.isKnownNonHumanCategoryName(name)) {
      addDuplicationError("Category");
      return false;
    }

    storeSimpleFieldValues(category);
    _orgDataSet.updateNonHumanCategory(category);
    return true;
  }

  /* saves a newly added resource or category to the org database */
  public boolean addNewItem(nonHumanMgt.SelType sType) {
    String newName = (String) txtName.getText();
    if ((newName == null) || (newName.length() == 0)) {
      _msgPanel.error("Please enter a name for the new Item.");
      return false;
    }
    switch (sType) {
      case resource:
        return addResource(newName);
      case category:
        return addCategory(newName);
    }
    return false;
  }

  /* saves a newly added resource to the org database */
  public boolean addResource(String name) {
    if (!_orgDataSet.isKnownNonHumanResourceName(name)) {
      String catID = (String) cbbCategory.getSelected();
      NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID);
      String subCat = (String) cbbSubCategory.getSelected();

      NonHumanResource resource = _sb.getSelectedNonHumanResource();
      if (resource == null) resource = new NonHumanResource();
      resource.setName(name);
      resource.setCategory(category);
      resource.setSubCategory(subCat);
      resource.setDescription((String) txtDesc.getText());
      resource.setNotes((String) txtNotes.getText());
      String newID = _orgDataSet.addNonHumanResource(resource);
      if (_rm.successful(newID)) {
        updateSelectedResource(resource, false);
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Resource");

    return false;
  }

  /* saves a newly added category to the org database */
  public boolean addCategory(String name) {
    if (!_orgDataSet.isKnownNonHumanCategoryName(name)) {
      NonHumanCategory category = new NonHumanCategory(name);
      storeSimpleFieldValues(category);
      category.addSubCategory("None");
      String newID = _orgDataSet.addNonHumanCategory(category);
      if (_rm.successful(newID)) {
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Category");

    return false;
  }

  private void addDuplicationError(String type) {
    String dupErrMsg = "There is already a %s by that name - please choose another.";
    _msgPanel.error(String.format(dupErrMsg, type));
  }

  public void clearTextFields() {
    txtDesc.setText("");
    txtNotes.setText("");
  }

  public void clearFieldsAfterRemove() {
    clearTextFields();
    lbxItems.setSelected(getFirstListboxItem());
  }

  public void clearAllFieldsAndLists() {
    clearTextFields();
    clearCombos();
    _sb.setNhResourcesCategoryItems(null);
    _sb.setNhResourcesSubcategoryItems(null); // resource tab combo box
    _sb.setNhResourcesSubcategoryList(null); // category tab list box
    lblMembers.setText("Members (0)");
  }

  protected void clearCombos() {
    cbbCategory.setSelected(null);
    cbbSubCategory.setSelected(null);
    cbbCategory.setItems(null);
    cbbSubCategory.setItems(null);
  }

  /* returns the value of the first item in the listbox, if any */
  private String getFirstListboxItem() {
    Option[] items = (Option[]) lbxItems.getItems();
    if ((items != null) && items.length > 0) {
      Option item = items[0];
      if (item != null) return (String) item.getValue();
    }
    return null;
  }

  /* returns the value of the first listed category, sorted */
  private NonHumanCategory getFirstListedCategory() {
    Option[] catItems = _sb.getNhResourcesCategoryList();
    if ((catItems != null) && (catItems.length > 0)) {
      String catID = (String) catItems[0].getValue();
      return _orgDataSet.getNonHumanCategory(catID);
    }
    return null;
  }

  private void storeSimpleFieldValues(NonHumanResource resource) {
    String name = (String) txtName.getText();
    if ((name != null) && (name.length() > 0)) resource.setName(name);
    String desc = (String) txtDesc.getText();
    if (desc != null) resource.setDescription(desc);
    String notes = (String) txtNotes.getText();
    if (notes != null) resource.setNotes(notes);
  }

  private void storeSimpleFieldValues(NonHumanCategory category) {
    String name = (String) txtName.getText();
    if (name.length() > 0) category.setName(name);
    category.setDescription((String) txtDesc.getText());
    category.setNotes((String) txtNotes.getText());
  }

  private void populateSimpleFields(NonHumanResource resource) {
    populateSimpleFields(resource.getName(), resource.getDescription(), resource.getNotes());
  }

  private void populateSimpleFields(NonHumanCategory category) {
    populateSimpleFields(category.getName(), category.getDescription(), category.getNotes());
  }

  private void populateSimpleFields(String name, String desc, String notes) {
    txtName.setText(name);
    txtDesc.setText(desc);
    txtNotes.setText(notes);
  }

  /* gets the full list of subcategories for a given category as listbox items */
  private Option[] getSubCategoryList(NonHumanCategory category) {
    Option[] subCatList = new Option[category.getSubCategoryCount()];
    int i = 0;
    for (NonHumanSubCategory subCat : category.getSubCategories()) {
      subCatList[i++] = new Option(subCat.getName());
    }
    Arrays.sort(subCatList, new OptionComparator());
    return subCatList;
  }

  /* checks if currently selected subcat may be removed. pre: in 'edit' mode */
  private boolean subCatUnremovable() {
    String subCatStr = _sb.getNhResourcesSubcategoryChoice();
    return (subCatStr == null) || subCatStr.equals("None");
  }

  /* enables or disables fields depending on whether a sub category is being added */
  protected void setSubCatAddMode(boolean adding) {
    showSubCatAddFields(adding);
    disableInputFields(adding);
    lbxItems.setDisabled(adding);
    lbxSubCatItems.setDisabled(adding);
    //        btnAddSubCat.setDisabled(adding);
    //        btnRemoveSubCat.setDisabled(adding || subCatUnremovable());
  }

  protected void disableInputFields(boolean disable) {
    txtName.setDisabled(disable);
    txtDesc.setDisabled(disable);
    txtNotes.setDisabled(disable);
    cbbMembers.setDisabled(disable);
    cbbCategory.setDisabled(disable);
    cbbSubCategory.setDisabled(disable);
    btnAddSubCat.setDisabled(disable);
    btnRemoveSubCat.setDisabled(disable || subCatUnremovable());
  }

  protected void disableSubCatButtons(boolean disable) {
    btnAddSubCat.setDisabled(disable);
    btnRemoveSubCat.setDisabled(disable || subCatUnremovable());
  }

  protected void showSubCatAddFields(boolean adding) {
    txtSubCat.setVisible(adding);
    btnConfirmAddSubCat.setVisible(adding);
    btnCancelAddSubCat.setVisible(adding);
  }

  protected void updateSelectedResource(NonHumanResource resource) {
    updateSelectedResource(resource, true);
  }

  protected void updateSelectedResource(NonHumanResource resource, boolean editing) {
    try {
      _sb.setSelectedNonHumanResource(resource, editing);
    } catch (CloneNotSupportedException cnse) {
      _msgPanel.error("Could not update form: cloning Exception");
    }
  }

  protected void createNewResource() {
    NonHumanResource resource = new NonHumanResource();
    resource.setID("_TEMP_");
    NonHumanCategory category = getFirstListedCategory();
    if (category != null) {
      resource.setCategory(category);
    }
    updateSelectedResource(resource);
  }

  private NonHumanCategory getCurrentlySelectedCategory() {
    String catID = _sb.getNhResourcesChoice(); // get selected category id
    return (catID != null) ? _orgDataSet.getNonHumanCategory(catID) : null;
  }
}
예제 #14
0
  private void startAndShow(String userid, WorkItemRecord wir) {
    String errMsg = null;
    WorkItemRecord startedItem = null;
    Participant p = rm.getParticipantFromUserID(userid);
    if (wir.hasStatus(WorkItemRecord.statusEnabled) || wir.hasStatus(WorkItemRecord.statusFired)) {
      if (wir.hasResourceStatus(WorkItemRecord.statusResourceOffered)
          || wir.hasResourceStatus(WorkItemRecord.statusResourceUnoffered)) {
        errMsg = checkParticipantHasQueuedItem(p, wir, WorkQueue.OFFERED);
        if (successful(errMsg)) {
          errMsg = null;
          wir = rm.acceptOffer(p, wir);
          if (wir.hasStatus(WorkItemRecord.statusExecuting)) { // system start
            startedItem = wir;
          }
        }
      }
      if ((errMsg == null) && (startedItem == null)) {
        if (wir.hasResourceStatus(WorkItemRecord.statusResourceAllocated)) {
          errMsg = checkParticipantHasQueuedItem(p, wir, WorkQueue.ALLOCATED);
          if (successful(errMsg)) {
            errMsg = null;
            if (rm.start(p, wir)) {
              startedItem = rm.getExecutingChild(wir);
            } else {
              errMsg =
                  "Could not start workitem '"
                      + wir.getID()
                      + "'. Please see the log files for details.";
            }
          }
        } else {
          errMsg =
              "Could not allocate workitem '"
                  + wir.getID()
                  + "'. Please see the log files for details.";
        }
      }
    } else {
      if (wir.hasResourceStatus(WorkItemRecord.statusResourceSuspended)) {
        errMsg = checkParticipantHasQueuedItem(p, wir, WorkQueue.SUSPENDED);
        if (successful(errMsg)) {
          errMsg = null;
          rm.unsuspendWorkItem(p, wir);
        }
      }
      if (errMsg == null) {
        errMsg = checkParticipantHasQueuedItem(p, wir, WorkQueue.STARTED);
        if (successful(errMsg)) {
          errMsg = null;
          startedItem = wir;
        }
      }
    }
    if ((errMsg == null) && (startedItem == null)) {
      errMsg =
          "Could not start workitem '" + wir.getID() + "'. Please see the log files for details.";
    }

    if (errMsg != null) {
      showMessage(errMsg);
    } else {
      showForm(startedItem);
    }
  }
예제 #15
0
 private Dimension getViewSize() {
   Dimension d = _rm.getVisualiserDimension();
   return (d != null) ? d : DEFAULT_DIMENSION;
 }
예제 #16
0
 private void completeWorkItem(WorkItemRecord wir, Participant p) {
   String result = _rm.checkinItem(p, wir);
   if (_rm.successful(result)) _sb.removeWarnedForNonEdit(wir.getID());
   else msgPanel.error(result);
 }