Package org.zeroexchange.model.resource.participant

Examples of org.zeroexchange.model.resource.participant.Supply


    contract.getResources().add(resource);
    nextStatus = uncompletedStep.nextStep(contract);
    Assert.assertEquals(nextStatus, ContractStatus.UNCOMPLETED);

    //+Supply
    Supply offer = new Supply();
    offer.setAcceptDate(new Date());
    offer.setAmount(BigDecimal.ONE);
    User offerOwner = new User();
    offerOwner.setId(2);
    offer.setUser(offerOwner);
    resource.getSupplies().add(offer);
    nextStatus = uncompletedStep.nextStep(contract);
    Assert.assertEquals(nextStatus, ContractStatus.READY);
  }
View Full Code Here


    public void reconcile(Resource resource, User consumer) {
        //Write-off cycle
        int consumersCount = 0;
        User supplier = null;
        Need consumerTender = null;
        Supply supplierTender = null;
        BigDecimal totalSuppliersPrice = BigDecimal.ZERO;
        BigDecimal totalConsumerAmount = BigDecimal.ZERO;
        for(Supply supply: resource.getSupplies()) {
            if(supply.getAcceptDate() != null) {
                //TODO: Consider coefficients depending on business regulators(
                //    reputation, demand/supply, etc...
                totalSuppliersPrice = totalSuppliersPrice.add(supplierTender.getTotalPrice());
                break;
            }
        }
        for(Need need: resource.getNeeds()) {
            if(need.getCompletionDate() == null) {
                totalConsumerAmount = totalConsumerAmount.add(need.getAmount());
                consumersCount++;
                if(consumer.equals(need.getUser())) {
                    consumerTender = need;
                }
            }
        }

        if(consumerTender == null) {
            throw new BusinessLogicException("The specified user #" + consumer.getId() + " is not consumer of the specified resource #" + resource.getId());
        }
       
        //Complete the tender
        needManager.completeTender(consumerTender);
       
        //Write-on cycle
        BigDecimal writeOnAmount = totalSuppliersPrice.
                divide(BigDecimal.valueOf(consumersCount), RoundingMode.HALF_UP);
        moneyManager.performAutoMovement(Collections.singleton(
                new PayerData(supplier, writeOnAmount, supplierTender.getCurrency())),
                Collections.singleton(consumer));
    }
View Full Code Here

            data.setInfo(userTender.getAdditionalInfo());
            data.setTenderType(userTender instanceof Supply ? TenderType.SUPPLY
                    : TenderType.NEED);
            data.setLocation(userTender.getLocation());
            if (userTender instanceof Supply) {
                Supply supply = (Supply) userTender;
                BigDecimal workingHours = supply.getHours();
                data.setWorkingHours(workingHours);
                BigDecimal totalPrice = supply.getTotalPrice();
                PriceType priceType = supply.getPriceType();
                data.setTotalPrice(totalPrice);
                data.setPriceType(priceType);
                data.setSupplyTime(supply.getSupplyTime());
            }
        } else {
            data.setLocation(currentUser.getLocation());
        }
View Full Code Here

        ResourceTender tender = null;
        boolean isSupply = tenderData.getTenderType() == TenderType.SUPPLY;
        IModel<Resource> resourceModel = getResourceModel();
        Resource resource = resourceModel.getObject();
        if (isSupply) {
            Supply supply = new Supply();
            tender = supply;

            BigDecimal workingHours = tenderData.getWorkingHours();
            supply.setHours(workingHours);
            PriceType priceType = tenderData.getPriceType();
            supply.setPriceType(priceType);
            ZECurrency currencyCode = moneyManager.getDefaultCurrency();
            supply.setCurrency(currencyCode);
            BigDecimal totalPrice = tenderData.getTotalPrice();
            supply.setTotalPrice(totalPrice);
            supply.setSupplyTime(tenderData.getSupplyTime());
        } else {
            tender = new Need();
        }       
        User currentUser = authorizedUserService.getCurrentUser();
        tender.setResource(resource);
View Full Code Here

TOP

Related Classes of org.zeroexchange.model.resource.participant.Supply

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.