Package org.spw.model

Examples of org.spw.model.Fundraising


        EntityManager em = emf.createEntityManager();
        for (int i = 0; i < plan.length; i++) {
            if (plan[i].getMonthFunding() < 1 || plan[i].getMonthFunding() > 12)
                throw new IllegalArgumentException("Month funding in fundraising plan should be from 1 to 12, found " + plan[i]);
        }
        Fundraising fundraising = null;
        em.getTransaction().begin();
        try {
            fundraising = em.find(Fundraising.class, year);
            if (fundraising == null)
                throw new IllegalArgumentException("The fundraising does not exist for this year " + year);
            List<FundraisingPlan> previous = new ArrayList<FundraisingPlan>(fundraising.getFundraisingPlans());
            //remove the previous instances
            for (FundraisingPlan p : previous) {
                if (p.getMonthSelected() == monthSelected) {
                    fundraising.getFundraisingPlans().remove(p);
                    p.setFundraising(null);
                    em.remove(p);
                }
            }
            // add the new ones
            for (int i = 0; i < plan.length; i++) {
                FundraisingPlan p = new FundraisingPlan();
                p.setFundraising(fundraising);
                p.setMonthSelected(monthSelected);
                p.setMonthFunding(plan[i].getMonthFunding());
                p.setAmount(plan[i].getAmount());
                fundraising.getFundraisingPlans().add(p);
                plan[i] = p;
            }
            //update
            fundraising = em.merge(fundraising);
            em.getTransaction().commit();
View Full Code Here


     */
    public FundraisingPlan[] getFundraisingsPlan(int year, int monthSelected) {
        if (monthSelected < 1 || monthSelected > 12)
            throw new IllegalArgumentException("Month selected in fundraising plan should be from 1 to 12, found " + monthSelected);
        EntityManager em = emf.createEntityManager();
        Fundraising fundraising = null;
        FundraisingPlan[] monthPlan = new FundraisingPlan[12];
        try {
            fundraising = em.find(Fundraising.class, year);
            if (fundraising == null)
                throw new IllegalArgumentException("The fundraising does not exist for this year " + year);
           
           
            for (FundraisingPlan p : fundraising.getFundraisingPlans()) {
                if (p.getMonthSelected() == monthSelected) {
                    monthPlan[p.getMonthFunding()-1] = p;
                }
            }
            // add the new ones (begin from the selected month, can't be before
View Full Code Here

    public String buttonDelete_action() {
        RowKey rk = tableRowGroup1.getRowKey();
        if (rk != null) {
            FundraisingController ctrl = new FundraisingController();
            Fundraising fundraising = (Fundraising)list.getObject(rk);
            ctrl.delete(fundraising);
            list.refreshList();
        }
       
        return null;
View Full Code Here

       
        return null;
    }

    public String buttonAdd_action() {
        getSessionBean1().setFundraising(new Fundraising());
        return "new";
    }
View Full Code Here

    }

    public String buttonPlan_action() {
        RowKey rk = tableRowGroup1.getRowKey();
        if (rk != null) {
            Fundraising fundraising = (Fundraising)list.getObject(rk);
            getSessionBean1().setFundraising(fundraising);
        }
       
        return "plan";
    }
View Full Code Here

    }

    public String buttonEdit_action() {
        RowKey rk = tableRowGroup1.getRowKey();
        if (rk != null) {
            Fundraising fundraising = (Fundraising)list.getObject(rk);
            getSessionBean1().setFundraising(fundraising);
        }
       
        return "edit";
    }
View Full Code Here

        super(testName);
    }
   
    protected void setUp() throws Exception {
        FundraisingController ctrl = new FundraisingController();
        Fundraising fr = new Fundraising();
        fr.setYearFunding(TEST_YEAR);
        fr.setTarget(new BigDecimal(3600));
        ctrl.create(fr);
    }
View Full Code Here

        ctrl.create(fr);
    }
   
    protected void tearDown() throws Exception {
        FundraisingController ctrl = new FundraisingController();
        Fundraising fr = ctrl.read(TEST_YEAR);
        if (fr != null) ctrl.delete(fr);
        fr = ctrl.read(TEST_YEAR+1);
        if (fr != null) ctrl.delete(fr);
    }
View Full Code Here

     * Test of create method, of class org.spw.controller.FundraisingController.
     */
    public void testCreate() {
        System.out.println("create");
       
        Fundraising object = new Fundraising();
        object.setYearFunding(TEST_YEAR+1);
        object.setTarget(new BigDecimal(3600));
        FundraisingController instance = new FundraisingController();
       
        instance.create(object);
       
        // test double
        try {
            object = new Fundraising();
            object.setYearFunding(TEST_YEAR+1);
            object.setTarget(new BigDecimal(3600));
            instance.create(object);
            fail("double must throw an exception");
        } catch (EntityExistsException eee) {
            //OK
        }
View Full Code Here

    public void testRead() {
        System.out.println("read");
       
        FundraisingController instance = new FundraisingController();
       
        Fundraising result = instance.read(TEST_YEAR);
        assertEquals((int)TEST_YEAR, (int)result.getYearFunding());
        assertEquals(new BigDecimal(3600), result.getTarget());
       
    }
View Full Code Here

TOP

Related Classes of org.spw.model.Fundraising

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.