Package org.zeroexchange.model.resource

Examples of org.zeroexchange.model.resource.Resource


            @Override
            protected Item<Resource> newRowItem(String id, int index,
                    IModel<Resource> model) {
                Item<Resource> rowItem = super.newRowItem(id, index, model);
                Integer currentUserId = authorizedUserService.getCurrentUserId();
                Resource resource = rowItem.getModelObject();
                if(resourceReader.isUserParticipant(resource, currentUserId)) {
                    if(resourceReader.isResourceAccepted(resource)) {
                        rowItem.add(new AttributeModifier("class", "resource-accepted"));
                    } else {
                        rowItem.add(new AttributeModifier("class", "resource-unaccepted"));
View Full Code Here


            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource entity = rowModel.getObject();
                cellItem.add(new Label(
                        componentId, entity.getTitle()));
            }

        });
       
        // Owner column
        columns.add(new AbstractColumn<Resource, String>(new ResourceModel(MKEY_OWNER),
                Resource.FIELD_OWNER + "." + User.FIELD_DISPLAY_NAME) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource resource = rowModel.getObject();
                User owner = resource.getOwner();
                cellItem.add(new Label(componentId, owner == null ? "" : owner.getDisplayName()));
            }
        });

        // Producers column
        columns.add(new AbstractColumn<Resource, String>(new ResourceModel(MKEY_PRODUCERS)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource resource = rowModel.getObject();
                Set<User> consumers = getResourceTenderOwners(
                        resource.getSupplies());
                String representation = representationFactory.getRepresentation(
                        consumers, CLEN_TENDER_OWNERS);
                cellItem.add(new Label(componentId, representation));
            }
        });

        // Consumers column
        columns.add(new AbstractColumn<Resource, String>(new ResourceModel(MKEY_CONSUMERS)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource resource = rowModel.getObject();
                Set<User> consumers = getResourceTenderOwners(resource.getNeeds());
                String representation = representationFactory.getRepresentation(
                        consumers, CLEN_TENDER_OWNERS);
                cellItem.add(new Label(componentId, representation));
            }
        });

        // Needed/Supplied amount column
        columns.add(new AbstractColumn<Resource, String>(new ResourceModel(MKEY_AMOUNT)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource resource = rowModel.getObject();
                cellItem.add(new Label(componentId,
                        resourceInformant.getConsumeAmount(resource).toString() + " / "
                        + resourceInformant.getSupplyAmount(resource).toString() + " "
                        + getString(CommonStringKeys.MKEY_UOM_PREFIX + resourceInformant.getResourceUOM(resource))));
            }
View Full Code Here

            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<Resource>> cellItem,
                    String componentId, IModel<Resource> rowModel) {
                Resource resource = rowModel.getObject();
                Contract contract = resource.getContract();
                cellItem.add(new PageLinkPanel(componentId, EditContract.class,
                        new Model<String>(contract.getTitle()),
                        new PageParameters().add(EditContract.PARAM_CONTRACT_ID, contract.getId())));
            }
        });
View Full Code Here

    //Empty contract
    ContractStatus nextStatus = uncompletedStep.nextStep(contract);
    Assert.assertEquals(nextStatus, ContractStatus.UNCOMPLETED);

    //Need only
    Resource resource = new Resource();
    resource.setOwner(contractOwner);
    Need need = new Need();
    need.setAmount(BigDecimal.ONE);
    need.setAcceptDate(new Date());
    User needOwner = new User();
    needOwner.setId(2);
    need.setUser(needOwner);
    resource.getNeeds().add(need);
    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 acceptTender(T foreignTender) {
        T tender = getDAO().getById(foreignTender.getId());
       
        //Reserve resource
        if(tender instanceof Supply && tender.getAcceptDate() == null) {
            Resource resource = tender.getResource();
            stockManager.reserveAmount(tender, resource);
        }
       
        //Accept tender
        tender.setAcceptDate(new Date());
View Full Code Here

    @Override
    public void declineTender(T foreignTender) {
       
        //Free resource
        T tender = getDAO().getById(foreignTender.getId());
        Resource resource = tender.getResource();
        if(tender instanceof Supply && tender.getAcceptDate() != null) {
            stockManager.freeAmount(tender, resource);
        }
       
        //Decline tender
        if(tender instanceof Supply) {
            resource.getSupplies().remove(tender);
        } else if(tender instanceof Need) {
            resource.getNeeds().remove(tender);
        }
        resourceDAO.save(resource);
    }
View Full Code Here

    private EventsDispatcher eventDispatcher;
   
    @Override
    public void remove(Integer resourceId) {
       
        Resource resource = resourceDAO.getById(resourceId);
       
        //Cancel stock reservation
        if(stockManager.isAutoMovementEnabled(resource)) {
            Collection<Supply> supplies = resource.getSupplies();
            for(ResourceTender supply: supplies) {
                if(supply.getAcceptDate() != null) {
                    stockManager.freeAmount(supply, resource);
                }
            }
        }
        Contract contract = resource.getContract();
        if(contract != null) {
            contract.getResources().remove(resource);
            contractDAO.save(contract);
            eventDispatcher.publishEvent(new ResourceDeleted(resource.getContract(), resource));
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isTenderDeclineEnabled(ResourceTender resourceTender) {
        Resource resource = resourceTender.getResource();
        Integer currentUserId = authorizedUserService.getCurrentUserId();
        User resourceOwner = resource.getOwner();
        Contract contract = resourceTender.getResource().getContract();
        ContractStatus contractStatus = contract.getStatus();
        if(contractStatus != ContractStatus.UNCOMPLETED && contractStatus != ContractStatus.READY) {
            return false;
        }
View Full Code Here

    /**
     * Initializes the UI.
     */
    private void initUI() {
        setOutputMarkupId(true);
        Resource resource = getResourceModel().getObject();
        BigDecimal supplyAmount = stockManager.getSupplyAmount(resource);//resourceInformant.getSupplyAmount(resource);
        BigDecimal consumeAmount = stockManager.getConsumeAmount(resource);//resourceInformant.getConsumeAmount(resource);
        BigDecimal availableAmount = supplyAmount.subtract(consumeAmount);
       
        boolean amountManagementEnabled = stockManager.isAmountManagementEnabled(resource, TenderType.SUPPLY) ||
                stockManager.isAmountManagementEnabled(resource, TenderType.NEED);
        User resourceOwner = resource.getOwner();
       
        add(new Label(CKEY_RESOURCE_OWNER, resourceOwner == null ? "-" : resourceOwner.getDisplayName()));
       
        DictionaryItem uomItem = resourceReader.getUnitOfMeasure(resource);
        String uomTitle = uomItem == null ? "" : localizationReader.getString(uomItem);
       
        Label availableAmountLabel = new Label(CKEY_AVAILABLE_AMOUNT, new StringResourceModel(MKEY_AMOUNT_VALUE, null, availableAmount, uomTitle));
        if(availableAmount.compareTo(BigDecimal.ZERO) < 0) {
            availableAmountLabel.add(new AttributeAppender("class", CLASS_WARNING));
        }
        availableAmountLabel.setVisible(amountManagementEnabled);
        add(availableAmountLabel);
   
        add(new Label(CKEY_SUPPLY, new StringResourceModel(MKEY_AMOUNT_VALUE, null, supplyAmount, uomTitle)).
                setVisible(amountManagementEnabled));
        add(new Label(CKEY_CONSUMPTION, new StringResourceModel(MKEY_AMOUNT_VALUE, null, consumeAmount, uomTitle)).
                setVisible(amountManagementEnabled));
       
        add(new Label(CKEY_SUPPLY_PRICE, new StringResourceModel(MKEY_MONEY_VALUE, null,
                resourceInformant.getValue(resource),
                moneyManager.getDefaultCurrency())).setVisible(!(resource instanceof MoneyResource)));

        MultiLineLabel descriptionLabel = new MultiLineLabel(CKEY_RESOURCE_DESCRIPTION, new Model<String>() {

            @Override
            public String getObject() {
                Resource resource = resourceReader.getResource(getResourceModel().getObject().getId());
                return resource .getDescription();
            }
           
        });
        add(descriptionLabel);
    }
View Full Code Here

     * Creates list of the control descriptors.
     * @param form TODO
     */
    protected void createInputControls(Form<? extends ResourceFormData> form) {
       
        Resource resource = getResourceModel().getObject();
           
            form.add(new Label(CKEY_SUBCLASS, new ResourceModel(
                    MKEY_RSUBTYPE_PREFIX + ResourceUtils.getShortSubtype(resource.getClass()))));
   
           
            //Multiplicity
            List<TendersMultiplicity> multiplicityValues = new ArrayList<TendersMultiplicity>();
            CollectionUtils.addAll(multiplicityValues, TendersMultiplicity.values());
View Full Code Here

TOP

Related Classes of org.zeroexchange.model.resource.Resource

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.