public List<Proposal> getTopProposals(String name, Collection<String> proposals) {
    Set<Proposal> set = new LinkedHashSet<Proposal>();

    if (delimiters == null || delimiters.isEmpty())
      return new ArrayList<Proposal>(set); // empty result

    String cleanedName = AutoCompleteHelper.trimWildcards(name);
    Pattern namePattern = AutoCompleteHelper.convertToPattern(cleanedName);
    Proposal topProposal = null;
    for (String proposal : proposals) {
      Matcher m = namePattern.matcher(proposal);
      if (m.find()) {
        int start = m.end();
        if (start == proposal.length()) {
          topProposal = new Proposal(proposal, false);
        } else {
          topProposal = findToken(proposal, start);
        }
        if (topProposal != null) {
          topProposal.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
          set.add(topProposal);
        }
      }
    }
    return new ArrayList<Proposal>(set);
  }
 public Response receive(final Proposal proposal, final int distance) throws Exception {
   TypedProperties props = new TypedProperties();
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
   props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
   props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
   props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
   Notification notification = new Notification(null, NotificationType.PROPOSAL, props);
   managementService.sendNotification(notification);
   return null;
 }
示例#3
0
 public void build() throws Exception {
   ProposalBuilder builder = new ProposalBuilder();
   Proposal result =
       builder
           .with()
           .modification(modification)
           .logAcceptanceProbability(logAcceptanceProbability)
           .build();
   assertThat(result.getLogAcceptanceProbability()).isEqualTo(logAcceptanceProbability);
   assertThat(result.getModification()).isEqualTo(modification);
 }
示例#4
0
 public Object clone() {
   Topic t;
   Set<Proposal> proposals = new HashSet<Proposal>();
   t = new Topic(getTitle(), getDescription(), getCreationDate());
   t.setId(getId());
   t.setProject((Project) getProject().clone());
   t.setUser((User) getUser().clone());
   for (Proposal p : getProposals()) proposals.add((Proposal) p.clone());
   t.setProposals(proposals);
   return t;
 }
  private void checkProposalMinReached(Proposal proposal) {

    int tot = 0;
    for (PurchaseRequest pr : proposal.getPurchaseRequests()) {
      tot += pr.getQuantity();
    }

    if (tot >= proposal.getProduct().getMinToBuyOrder()) proposal.setMinReached(true);
    else proposal.setMinReached(false);

    proposal.merge();
  }
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("Proposal(")
       .append(this.getOriginator())
       .append(",")
       .append(proposal.getProposalID())
       .append(") by ")
       .append(proposal.getRequest().getRequestor())
       .append(", state: ")
       .append(proposal.getProposalState());
   return sb.toString();
 }
  void populateEditForm(Model uiModel, PurchaseRequest purchaseRequest) {
    uiModel.addAttribute("purchaseRequest", purchaseRequest);

    uiModel.addAttribute("proposals", Proposal.findAllProposals());

    uiModel.addAttribute("purchaserequestparts", PurchaseRequestPart.findAllPurchaseRequestParts());
    uiModel.addAttribute("users", User.findAllUsers());
  }
示例#8
0
 public void reset() throws Exception {
   ProposalBuilder builder = new ProposalBuilder();
   Modification otherModification = mock(Modification.class);
   double otherProbability = -987654;
   builder
       .with()
       .modification(otherModification)
       .logAcceptanceProbability(otherProbability)
       .build();
   Proposal result =
       builder
           .with()
           .modification(modification)
           .logAcceptanceProbability(logAcceptanceProbability)
           .build();
   assertThat(result.getLogAcceptanceProbability()).isEqualTo(logAcceptanceProbability);
   assertThat(result.getModification()).isEqualTo(modification);
 }
  @RequestMapping(value = "/purchase/{id}", produces = "text/html")
  public String purchase(@PathVariable("id") Integer id, Model uiModel) {
    uiModel.asMap().clear();

    uiModel.addAttribute("proposal", Proposal.findProposal(id));
    uiModel.addAttribute("proposal_id", id);

    uiModel.addAttribute("purchaseRequest", new PurchaseRequest());
    return "user/purchaserequest/purchase";
  }
  public Response propose(final Proposal proposal) throws Exception {
    // sanity check in case it is already selected
    Response response = responses.get(proposal.getGroupId());
    if (response != null) {
      return response;
    }

    try {
      lock.lock();

      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());

      props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, 0);

      Notification notification = new Notification(null, NotificationType.PROPOSAL, props);

      managementService.sendNotification(notification);

      if (!sendCondition.await(timeout, TimeUnit.MILLISECONDS))
        HornetQLogger.LOGGER.groupHandlerSendTimeout();
      response = responses.get(proposal.getGroupId());

    } finally {
      lock.unlock();
    }
    if (response == null) {
      throw new IllegalStateException(
          "no response received from group handler for " + proposal.getGroupId());
    }
    return response;
  }