Package org.spw.model

Examples of org.spw.model.Fundraising


     */
    public void testUpdate() {
        System.out.println("update");
       
        FundraisingController instance = new FundraisingController();
        Fundraising fr = instance.read(TEST_YEAR);
        BigDecimal newTarget = new BigDecimal(new BigInteger("360002"), 2);
        fr.setTarget(newTarget);
       
        Fundraising result = instance.update(fr);
        assertEquals(newTarget, result.getTarget());
       
        fr = instance.read(TEST_YEAR);
        assertEquals(newTarget, fr.getTarget());
    }
View Full Code Here


     */
    public void testDelete() {
        System.out.println("delete");
       
        FundraisingController instance = new FundraisingController();
        Fundraising object = instance.read(TEST_YEAR);
       
        instance.delete(object);
        object = instance.read(TEST_YEAR);
        assertNull(object);
       
View Full Code Here

       
        FundraisingController instance = new FundraisingController();
       
        instance.addFundraisingsPlan(year, month, plan);
       
        Fundraising result = instance.read(year);
        assertEquals(2, result.getFundraisingPlans().size());
        for (FundraisingPlan item: result.getFundraisingPlans()) {
            assertEquals(month, item.getMonthSelected());
            assertTrue(item.getMonthFunding() > 0);
            assertTrue(item.getAmount().compareTo(new BigDecimal(99.99)) > 0);
        }
       
        plan = new FundraisingPlan[3];
        plan[0] = result.getFundraisingPlans().get(0);
        p2 = new FundraisingPlan();
        p2.setMonthSelected(month);
        p2.setMonthFunding(2);
        p2.setAmount(new BigDecimal(2500));
        plan[1] = p2;
        FundraisingPlan p3 = new FundraisingPlan();
        p3.setMonthSelected(month);
        p3.setMonthFunding(2);
        p3.setAmount(new BigDecimal(1500));
        plan[2] = p3;
        instance.addFundraisingsPlan(year, month, plan);
        result = instance.read(year);
        assertEquals(3, result.getFundraisingPlans().size());
        for (FundraisingPlan item: result.getFundraisingPlans()) {
            assertEquals(month, item.getMonthSelected());
            assertTrue(item.getMonthFunding() > 0);
            assertTrue(item.getAmount().compareTo(new BigDecimal(99.99)) > 0);
        }
       
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);
        int year = 1900;
        int month = 1;
        FundraisingPlan[] plan = new FundraisingPlan[2];
        FundraisingPlan p1 = new FundraisingPlan();
View Full Code Here

        ctrl.addFundraisingsPlan(year, month, plan);       
    }
   
    protected void tearDown() throws Exception {
        FundraisingController ctrl = new FundraisingController();
        Fundraising fr = ctrl.read(TEST_YEAR);
        if (fr != null) ctrl.delete(fr);
    }
View Full Code Here

     * Creates a new instance of VolunteerDetailsFundraisingXmlReport
     */
    public VolunteerSummaryFundraisingXmlReport(int year) {
        this.year = year;
        //check the fundraising of this year
        Fundraising fundraising = new FundraisingController().read(year);
        target = (fundraising != null)? fundraising.getTarget() : new BigDecimal(0);
       
        programs = new ProgramController().getProgramsYear(year);
        volunteersByMonth = new ArrayList[13];
        Calendar cal = Calendar.getInstance();
        for (Program program: programs) {
View Full Code Here

        }
    }
   
    public Fundraising read(Integer key) {
        EntityManager em = emf.createEntityManager();
        Fundraising retValue = null;
        try {
            retValue = em.find(Fundraising.class, key);
        } catch (Exception e) {
            Logger.getLogger(FundraisingController.class.getName()).log(Level.SEVERE, "Error reading " + key, e);
            if (em.getTransaction().isActive())
View Full Code Here

        }
        return retValue;
    }
   
    public Fundraising update(Fundraising object) {
        Fundraising result = null;
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            result = em.merge(object);
            em.getTransaction().commit();
View Full Code Here

   
    public void delete(Fundraising object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            Fundraising entity = em.find(Fundraising.class, object.getYearFunding());
            em.remove(entity);
            em.getTransaction().commit();
        } catch (Exception e) {
            Logger.getLogger(FundraisingController.class.getName()).log(Level.SEVERE, "Error deleting " + object, e);
            if (em.getTransaction().isActive())
View Full Code Here

        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

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.