Package org.zeroexchange.model.collaboration

Examples of org.zeroexchange.model.collaboration.Contract


        setOutputMarkupId(true);
        add(toolbar = getToolbar(CKEY_TOOLBAR));
       
        Integer currentUserId = authorizedUserService.getCurrentUserId();
        final Contract contract = getContract();
        boolean isUserEffective = contractInformant.isUserEffective(contract, currentUserId);
        add(new Label(CKEY_USER_STATUS_SIGN,
                new ResourceModel(isUserEffective ? MKEY_USER_EFFECTIVE : MKEY_USER_INEFFECTIVE)));

        userBalanceLabel = new Label(CKEY_USER_CONTRIBUTION_SIGN,
                contractInformant.getUserContributionPrice(contract, authorizedUserService.getCurrentUser(),
                        moneyManager.getDefaultCurrency()).toString());
        userBalanceLabel.setOutputMarkupId(true);
        userBalanceLabel.add(new AttributeAppender("class", " error") {
            private static final long serialVersionUID = 1L;

            @Override
            public boolean isEnabled(Component component) {
                return isUserDebtExceeded();
            }
           
        });
        add(userBalanceLabel);
       
        userRestLabel = new Label(CKEY_USER_REST_SIGN, new Model<String>() {
            private static final long serialVersionUID = 1L;

            @Override
            public String getObject() {
                BigDecimal currentUserAmount = moneyManager.getAvailableAmount(
                        moneyManager.getDefaultCurrency(), authorizedUserService.getCurrentUser());
                Contract persistedContract = contractReader.getContract(contract.getId());
                BigDecimal userContribution = contractInformant.getUserContributionPrice(
                        persistedContract, authorizedUserService.getCurrentUser(),
                        moneyManager.getDefaultCurrency());
                BigDecimal rest = currentUserAmount.add(userContribution);
                return rest.toString();
View Full Code Here


     * @return
     */
    protected List<ToolbarItem> getToolbarItems() {
        List<ToolbarItem> toolbarActions = new ArrayList<ToolbarItem>();
       
        final Contract contract = getContract();
        Integer currentUserId = authorizedUserService.getCurrentUserId();


        //'Remove Contract' item
        if(contract.getStatus() == ContractStatus.UNCOMPLETED &&
                currentUserId != null && contract.getOwner() != null && contract.getOwner().getId().equals(currentUserId)) {
            toolbarActions.add(new ToolbarItem() {
                private static final long serialVersionUID = 1L;

                @Override
                public Component getComponent(String componentId) {
                    return new LinkPanel(componentId, new ResourceModel(MKEY_CONTRACT_REMOVE)) {
                        private static final long serialVersionUID = 1L;
                        @Override
                        protected void onClick() {
                            //delete the current contract
                            Contract contract = getContract();
                            contractRemover.remove(contract.getId());
                           
                            //Go to contracts list.
                            setResponsePage(Collaboration.class);
                        }
                    };
                }
            });
        }

        //'Accept Contract' item
        if(contract.getStatus() == ContractStatus.READY &&
                contractStatusInformant.getContractStatus(contract, currentUserId) != ContractStatus.ACCEPTED &&
                !isUserDebtExceeded() &&
                contractInformant.isUserEffective(contract, currentUserId)) {
            toolbarActions.add(new ToolbarItem() {
                private static final long serialVersionUID = 1L;

                @Override
                public Component getComponent(String componentId) {
                    return new AjaxLinkPanel<Void>(componentId, new ResourceModel(MKEY_CONTRACT_ACCEPT)) {
                        private static final long serialVersionUID = 1L;
                        @Override
                        protected void onClick(AjaxRequestTarget target) {
                            //Mark the current contract as accepted
                           
                            Contract contract = getContract();
                            contract = contractWriter.accept(
                                    authorizedUserService.getCurrentUser(),
                                    contract);

                            eventsDispatcher.publishEvent(new ContractAccepted(contract,
                                    authorizedUserService.getCurrentUser()));

                            if(target != null) {
                                target.add(toolbar.getParent());
                                target.add(statusSign);
                            }
                        }
                   };
                }
            });
        }
       
        //'Cancel Acceptance' item
        if(contractPermissionsInformant.isContractCancelAcceptanceAllowed(
                contract)) {
            toolbarActions.add(new ToolbarItem() {
                private static final long serialVersionUID = 1L;

                @Override
                public Component getComponent(String componentId) {
                    return new AjaxLinkPanel<Void>(componentId, new ResourceModel(MKEY_CONTRACT_CANCEL_ACCEPT)) {
                        private static final long serialVersionUID = 1L;
                        @Override
                        protected void onClick(AjaxRequestTarget target) {
                            //Mark the current contract as accepted
                            Contract contract = getContract();
                            contract.getAcceptors().remove(authorizedUserService.getCurrentUser());
                            contract = contractWriter.save(contract);

                            eventsDispatcher.publishEvent(new ContractDeclined(contract,
                                    authorizedUserService.getCurrentUser()));

View Full Code Here

    /**
     * Creates form with simple contract's properties.
     */
    protected Form<ContractData> getContractForm() {
        Contract contract = getContract();
       
        ContractData contractData = new ContractData();
        contractData.setTitle(contract.getTitle());
        contractData.setVisibility(contract.getViewPolicy());
       
        Form<ContractData> form = new Form<ContractData>(CKEY_CONTRACT_FORM, new CompoundPropertyModel<ContractData>(contractData)) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit() {
                ContractData postedData = getModelObject();
                updateContract(postedData);
            }
        };

        User currentUser = authorizedUserService.getCurrentUser();
        boolean isEditEditable = contract.getStatus() != ContractStatus.EXECUTED && currentUser != null && currentUser.equals(contract.getOwner());

        //Title field
        TextField<String> titleInput = new TextField<String>(CKEY_CONTRACT_TITLE);
        titleInput.setEnabled(isEditEditable);
        titleInput.setRequired(true);
View Full Code Here

    /**
     * Updates the contract with the form data
     */
    private void updateContract(ContractData postedData) {
        //Update contact title
        Contract contract = getContract();
        contract.setTitle(postedData.getTitle());
        contract.setViewPolicy(postedData.getVisibility());
        contractWriter.save(contract);

        eventsDispatcher.publishEvent(new ContractSpecificationChanged(contract));
    }
View Full Code Here

    @Override
    public Contract save(Contract contract) {
       
        Date currentDate = new Date();
        if(contract.getId() != null) {
            Contract existentContract = contractDAO.getById(contract.getId());
            if(ContractStatus.COMPLETED == existentContract.getStatus()) {
                throw new BusinessLogicException("Contract #" + contract.getId() + " is already completed!");
            }
        } else {
            contract.setCreationDate(currentDate);
        }
       
        contract.setModificationDate(currentDate);

        //Save the contract
        Contract savedContract = contractDAO.save(contract);
       
        return savedContract;
    }
View Full Code Here

    @Override
    public void markUserEffective(Integer contractId, User tenderOwner) {
        if(tenderOwner == null) {
            return;
        }
        Contract contract = contractDAO.getById(contractId);
        contract.getEffectiveUsers().add(tenderOwner);
        contractDAO.save(contract);
    }
View Full Code Here

    @Override
    public void markUserIneffective(Integer contractId, User tenderOwner) {
        if(tenderOwner == null) {
            return;
        }
        Contract contract = contractDAO.getById(contractId);
        contract.getEffectiveUsers().remove(tenderOwner);
        contractDAO.save(contract);
    }
View Full Code Here

    @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;
        }
        User tenderOwner = resourceTender.getUser();
        if(tenderOwner != null && tenderOwner.getId().equals(currentUserId)){
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public BigDecimal getConsumeAmount(Resource resource) {
        BigDecimal consumeAmount = BigDecimal.ZERO;
        Contract contract = resource.getContract();
       
        /*Collection<User> moneyConsumers = new ArrayList<User>();
        for(Need need: resource.getNeeds()) {
            if(need.getAcceptDate() != null ) {
                moneyConsumers.add(need.getUser());
            }
        }
        for(Resource nextResource: contract.getResources()) {
            for(Supply supply: nextResource.getSupplies()) {
                User tenderOwner = supply.getUser();
                if(supply.getAcceptDate() != null && moneyConsumers.contains(tenderOwner)) {
                    consumeAmount = consumeAmount.add(supply.getTotalPrice());
                }
            }
        }*/
       
        for(Resource nextResource: contract.getResources()) {
            for(Need need: nextResource.getNeeds()) {
                if(need.getAcceptDate() != null) {
                    consumeAmount = consumeAmount.add(need.getAmount());
                }
            }
View Full Code Here

        return dataSet;
    }

    @Override
    public Contract getContract(Integer contractId) throws BusinessLogicException {
        Contract contract = contractDAO.getById(contractId);

        //Initialize contract associations
        Hibernate.initialize(contract.getAcceptors());
        Set<Resource> resources = contract.getResources();
        Hibernate.initialize(resources);
        for(Resource resource: resources) {
            Hibernate.initialize(resource.getSpecification());
            /*
            Category category = resource.getCategory();
View Full Code Here

TOP

Related Classes of org.zeroexchange.model.collaboration.Contract

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.