r14 - in trunk: . cash-business/src/main/java/org/chorem/cash/business cash-business/src/main/java/org/chorem/cash/impl cash-business/src/test/java/org/chorem/cash/impl cash-ui/src/main/java/org/chorem/cash/ui/components cash-ui/src/main/resources/org/chorem/cash/ui/components cash-ui/src/main/webapp/img/icons/crystal
Author: fdesbois Date: 2009-08-19 10:10:53 +0200 (Wed, 19 Aug 2009) New Revision: 14 Added: trunk/cash-business/src/main/java/org/chorem/cash/business/Periodicity.java trunk/cash-ui/src/main/webapp/img/icons/crystal/clock.png trunk/cash-ui/src/main/webapp/img/icons/crystal/movedown.png trunk/cash-ui/src/main/webapp/img/icons/crystal/movetobottom.png trunk/cash-ui/src/main/webapp/img/icons/crystal/movetotop.png trunk/cash-ui/src/main/webapp/img/icons/crystal/moveup.png Modified: trunk/cash-business/src/main/java/org/chorem/cash/business/EntryHelper.java trunk/cash-business/src/main/java/org/chorem/cash/impl/ServiceEntryImpl.java trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java trunk/cash-ui/src/main/java/org/chorem/cash/ui/components/CategoryComponent.java trunk/cash-ui/src/main/resources/org/chorem/cash/ui/components/CategoryComponent.tml trunk/pom.xml Log: - Begin implementation for periodicity - Change rank icons in UI - Change scope for Oasis CIQ Api and XMLBeans (better for embedded mode) Modified: trunk/cash-business/src/main/java/org/chorem/cash/business/EntryHelper.java =================================================================== --- trunk/cash-business/src/main/java/org/chorem/cash/business/EntryHelper.java 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/cash-business/src/main/java/org/chorem/cash/business/EntryHelper.java 2009-08-19 08:10:53 UTC (rev 14) @@ -20,7 +20,12 @@ package org.chorem.cash.business; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.apache.commons.logging.Log; import org.chorem.cash.CashModelDAOHelper; import org.chorem.cash.ContextUtilCash; import org.chorem.cash.dto.Entry; @@ -28,9 +33,14 @@ import org.chorem.cash.persistence.CategoryEntity; import org.chorem.cash.persistence.EntryEntity; import org.chorem.cash.persistence.EntryEntityDAO; +import org.chorem.cash.persistence.EntryFrequencyEntity; +import org.chorem.cash.persistence.EntryFrequencyEntityDAO; import org.chorem.cash.persistence.ReferenceEntity; import org.chorem.exceptions.ConvertException; +import org.chorem.exceptions.EntityException; import org.chorem.utils.Convert; +import org.chorem.utils.DateUtils; +import org.chorem.utils.ServiceHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -58,7 +68,76 @@ for (ReferenceEntity ref : entity.getReferences()) { references.add(ReferenceHelper.getReference(ref)); } + + EntryFrequencyEntity frequency = entity.getEntryFrequencyEntity(); + if (frequency != null) { + + String frequencyId = ContextUtilCash.convertId(frequency.getTopiaId()); + entry.setFrequencyId(frequencyId); + entry.setInterval(frequency.getInterval()); + entry.setNbTimes(frequency.getNbTimes()); + entry.setUnlimited(frequency.getUnlimited()); + entry.setUntilDate(frequency.getUntilDate()); + entry.setPeriodicity(frequency.getPeriodicity()); + entry.setMonths(frequency.getMonths()); + + } + return entry; } + + public static EntryFrequencyEntity createUpdateFrequency(Entry entry, TopiaContext transaction, Log log) + throws IllegalArgumentException, TopiaException, EntityException { + + Map<String, Object> saveParams = new HashMap<String, Object>(); + + saveParams.put(EntryFrequencyEntity.PERIODICITY, entry.getPeriodicity()); + saveParams.put(EntryFrequencyEntity.INTERVAL, entry.getInterval()); + + if (!entry.getUnlimited() && entry.getNbTimes() > 0) { + saveParams.put(EntryFrequencyEntity.NB_TIMES, entry.getNbTimes()); + } else if (entry.getUnlimited()) { + saveParams.put(EntryFrequencyEntity.UNLIMITED, entry.getUnlimited()); + + int firstMonth = DateUtils.getMonth(entry.getEntryDate()); + Collection<Integer> months = getMonthsIntervals(entry.getInterval(), firstMonth); + + if (log.isDebugEnabled()) { + log.debug(months); + } + + saveParams.put(EntryFrequencyEntity.MONTHS, months); + } else if (entry.getUntilDate() != null) { + saveParams.put(EntryFrequencyEntity.UNTIL_DATE, entry.getUntilDate()); + } + + EntryFrequencyEntityDAO dao = CashModelDAOHelper.getEntryFrequencyEntityDAO(transaction); + + EntryFrequencyEntity entity = ServiceHelper.createUpdateEntity(dao, entry.getFrequencyId(), null, saveParams, log); + + String id = ContextUtilCash.convertId(entity.getTopiaId()); + entry.setFrequencyId(id); + + return entity; + } + + private static Collection<Integer> getMonthsIntervals(int interval, int firstMonth) { + int max = 12 / interval; + //int[] results = new int[max]; + List<Integer> results = new ArrayList<Integer>(); + + //results[0] = firstMonth; + results.add(new Integer(firstMonth)); + //results.set(0, new Integer(firstMonth)); + + for (int i = 1; i < max; i++) { + int curr = results.get(i-1).intValue(); + int res = ( curr + interval ) % 12; + results.add(new Integer(res)); + //results[i] = ( results[i-1] + interval ) % 12; + } + + return results; + } } Added: trunk/cash-business/src/main/java/org/chorem/cash/business/Periodicity.java =================================================================== --- trunk/cash-business/src/main/java/org/chorem/cash/business/Periodicity.java (rev 0) +++ trunk/cash-business/src/main/java/org/chorem/cash/business/Periodicity.java 2009-08-19 08:10:53 UTC (rev 14) @@ -0,0 +1,14 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.chorem.cash.business; + +/** + * + * @author fdesbois + */ +public enum Periodicity { + MONTHLY +} Modified: trunk/cash-business/src/main/java/org/chorem/cash/impl/ServiceEntryImpl.java =================================================================== --- trunk/cash-business/src/main/java/org/chorem/cash/impl/ServiceEntryImpl.java 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/cash-business/src/main/java/org/chorem/cash/impl/ServiceEntryImpl.java 2009-08-19 08:10:53 UTC (rev 14) @@ -32,6 +32,7 @@ import org.chorem.cash.CashModelDAOHelper; import org.chorem.cash.ContextUtilCash; import org.chorem.cash.business.EntryHelper; +import org.chorem.cash.business.Periodicity; import org.chorem.cash.business.ReferenceHelper; import org.chorem.cash.dto.Category; import org.chorem.cash.dto.Entry; @@ -40,6 +41,7 @@ import org.chorem.cash.persistence.CategoryEntityDAO; import org.chorem.cash.persistence.EntryEntity; import org.chorem.cash.persistence.EntryEntityDAO; +import org.chorem.cash.persistence.EntryFrequencyEntity; import org.chorem.cash.services.ServiceEntry; import org.chorem.cash.services.ServiceEntryAbstract; import org.chorem.utils.DateUtils; @@ -106,7 +108,18 @@ saveParams.put(EntryEntity.COMMENT, entry.getComment()); saveParams.put(EntryEntity.ENTRY_DATE, entry.getEntryDate()); + if (entry.getPeriodicity() != null && !entry.getPeriodicity().isEmpty()) { + String periodicity = entry.getPeriodicity(); + if (Periodicity.valueOf(periodicity).equals(Periodicity.MONTHLY)) { + + EntryFrequencyEntity frequency = EntryHelper.createUpdateFrequency(entry, transaction, log); + + saveParams.put(EntryEntity.ENTRY_FREQUENCY_ENTITY, frequency); + } + + } + EntryEntity entity = ServiceHelper.createUpdateEntity(dao, entry.getId(), null, saveParams, log); entry.setId(ContextUtilCash.convertId(entity.getTopiaId())); @@ -194,12 +207,27 @@ List<EntryEntity> entries = transaction.find( "FROM " + EntryEntity.class.getName() + " WHERE " + EntryEntity.ENTRY_DATE + " BETWEEN :dateFrom AND :dateThru" + + " AND " + EntryEntity.ENTRY_FREQUENCY_ENTITY + " IS NULL " + " ORDER BY " + EntryEntity.ENTRY_DATE, "dateFrom", period.getFromDate(), "dateThru", period.getThruDate()); + /*List<EntryEntity> periodicEntries = new ArrayList<EntryEntity>(); + for (Date monthDate : period.getMonths()) { + List<EntryEntity> queryResults = transaction.find( + "FROM " + EntryEntity.class.getName() + + " WHERE " + EntryEntity.ENTRY_FREQUENCY_ENTITY + " IS NOT NULL " + + " AND " + EntryEntity.ENTRY_FREQUENCY_ENTITY + "." + EntryFrequencyEntity.UNLIMITED + " = :ok" + + " AND :month IN " + EntryEntity.ENTRY_FREQUENCY_ENTITY + "." + EntryFrequencyEntity.MONTHS + + " ORDER BY " + EntryEntity.ENTRY_DATE, + "ok", true, + "month", DateUtils.getMonth(monthDate)); + periodicEntries.addAll(queryResults); + }*/ + if (log.isDebugEnabled()) { log.debug("NbEntries find : " + entries.size()); + //log.debug("NbPeriodicEntries find : " + periodicEntries.size()); } for (EntryEntity entity : entries) { @@ -245,4 +273,5 @@ } return total; } + } Modified: trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java =================================================================== --- trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java 2009-08-19 08:10:53 UTC (rev 14) @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.cash.CashException; import org.chorem.cash.ContextUtilCash; +import org.chorem.cash.business.Periodicity; import org.chorem.cash.dto.Category; import org.chorem.cash.dto.Entry; import org.chorem.cash.services.ServiceEntry; @@ -73,77 +74,8 @@ @After public void tearDown() { } - + /** - * Test of createUpdateEntry method, of class ServiceEntryImpl. - */ - /*@Test - public void testCreateUpdateEntry() throws Exception { - System.out.println("createUpdateEntry"); - Entry entry = null; - ServiceEntryImpl instance = new ServiceEntryImpl(); - instance.createUpdateEntry(entry); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getEntry method, of class ServiceEntryImpl. - */ - /*@Test - public void testGetEntry() throws Exception { - System.out.println("getEntry"); - String entryId = ""; - ServiceEntryImpl instance = new ServiceEntryImpl(); - Entry expResult = null; - Entry result = instance.getEntry(entryId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getEntries method, of class ServiceEntryImpl. - */ - /*@Test - public void testGetEntries() throws Exception { - System.out.println("getEntries"); - ServiceEntryImpl instance = new ServiceEntryImpl(); - List expResult = null; - List result = instance.getEntries(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of deleteEntry method, of class ServiceEntryImpl. - */ - /*@Test - public void testDeleteEntry() throws Exception { - System.out.println("deleteEntry"); - String entryId = ""; - ServiceEntryImpl instance = new ServiceEntryImpl(); - instance.deleteEntry(entryId); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getNewEntry method, of class ServiceEntryImpl. - */ - /*@Test - public void testGetNewEntry() { - System.out.println("getNewEntry"); - ServiceEntryImpl instance = new ServiceEntryImpl(); - Entry expResult = null; - Entry result = instance.getNewEntry(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** * Test of getEntriesBetweenDates method, of class ServiceEntryImpl. */ @Test @@ -208,6 +140,57 @@ } + /*@Test + public void testCreateUpdateEntry() throws Exception { + log.info("createUpdateEntry"); + + ServiceEntryImpl instance = new ServiceEntryImpl(); + + ServiceCategoryImpl serviceCateg = new ServiceCategoryImpl(); + Category categ = ServiceCategoryImplTest.addParentCategory(serviceCateg, "CATEG", 1, true); + + Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ); + + log.debug("PERIODIC ENTRY : MONTHLY -> unlimited, interval = " + 3 + ", date = 12/07/2009"); + + Entry entry2 = instance.getNewEntry(); + entry2.setLibelle("SECOND"); + entry2.setAmount(152.14); + entry2.setEntryDate(DateUtils.createDate(12,7,2009)); + entry2.setCategory(categ); + + entry2.setPeriodicity(Periodicity.MONTHLY.toString()); + entry2.setUnlimited(true); + entry2.setInterval(3); + + try { + instance.createUpdateEntry(entry2); + assertNotNull(entry2.getId()); + } catch (CashException eee) { + log.error("Erreur createUpdateEntry : " + eee.getMessage()); + fail("CashException"); + } + + try { + Entry result = instance.getEntry(entry2.getId()); + assertNotNull(result); + assertNotNull(result.getMonths()); + assertEquals(result.getMonths().size(), 4); + } catch (CashException eee) { + log.error("Erreur getEntry : " + eee.getMessage()); + fail("CashException"); + } + + try { + instance.deleteEntry(entry1.getId()); + instance.deleteEntry(entry2.getId()); + } catch (CashException eee) { + log.error("Erreur deleteEntry : " + eee.getMessage()); + fail("CashException"); + } + + }*/ + @Test public void testGetSumBeforeDate() throws Exception { log.info("getSumBeforeDate"); Modified: trunk/cash-ui/src/main/java/org/chorem/cash/ui/components/CategoryComponent.java =================================================================== --- trunk/cash-ui/src/main/java/org/chorem/cash/ui/components/CategoryComponent.java 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/cash-ui/src/main/java/org/chorem/cash/ui/components/CategoryComponent.java 2009-08-19 08:10:53 UTC (rev 14) @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.tapestry5.ComponentResources; -import org.apache.tapestry5.ajax.MultiZoneUpdate; import org.apache.tapestry5.annotations.InjectComponent; import org.apache.tapestry5.annotations.InjectContainer; import org.apache.tapestry5.annotations.Log; @@ -31,7 +30,6 @@ import org.apache.tapestry5.annotations.Property; import org.apache.tapestry5.beaneditor.BeanModel; import org.apache.tapestry5.corelib.components.Grid; -import org.apache.tapestry5.corelib.components.Zone; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.BeanModelSource; import org.chorem.cash.CashException; Modified: trunk/cash-ui/src/main/resources/org/chorem/cash/ui/components/CategoryComponent.tml =================================================================== --- trunk/cash-ui/src/main/resources/org/chorem/cash/ui/components/CategoryComponent.tml 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/cash-ui/src/main/resources/org/chorem/cash/ui/components/CategoryComponent.tml 2009-08-19 08:10:53 UTC (rev 14) @@ -51,16 +51,16 @@ </p:nameCell> <p:actionsCell> <a t:type="actionlink" class="img" t:id="moveUpCategory" t:context="indexCategory" t:zone="${zoneId}" title="${message:moveup-category}"> - <img src="${asset:context:/img/icons/moveup.png}" alt="${message:moveup-category}"/> + <img src="${asset:context:/img/icons/crystal/moveup.png}" alt="${message:moveup-category}"/> </a> <a t:type="actionlink" class="img" t:id="moveDownCategory" t:context="indexCategory" t:zone="${zoneId}" title="${message:movedown-category}"> - <img src="${asset:context:/img/icons/movedown.png}" alt="${message:movedown-category}"/> + <img src="${asset:context:/img/icons/crystal/movedown.png}" alt="${message:movedown-category}"/> </a> <a t:type="actionlink" class="img" t:id="moveToTopCategory" t:context="indexCategory" t:zone="${zoneId}" title="${message:movetotop-category}"> - <img src="${asset:context:/img/icons/movetotop.png}" alt="${message:movetotop-category}"/> + <img src="${asset:context:/img/icons/crystal/movetotop.png}" alt="${message:movetotop-category}"/> </a> <a t:type="actionlink" class="img" t:id="moveToBottomCategory" t:context="indexCategory" t:zone="${zoneId}" title="${message:movetobottom-category}"> - <img src="${asset:context:/img/icons/movetobottom.png}" alt="${message:movetobottom-category}"/> + <img src="${asset:context:/img/icons/crystal/movetobottom.png}" alt="${message:movetobottom-category}"/> </a> <a t:type="actionlink" class="img" t:id="editCategory" t:context="indexCategory" t:zone="${zoneId}" title="${message:edit-category}"> <img src="${asset:context:/img/icons/crystal/edit.png}" alt="${message:edit-category}"/> Added: trunk/cash-ui/src/main/webapp/img/icons/crystal/clock.png =================================================================== (Binary files differ) Property changes on: trunk/cash-ui/src/main/webapp/img/icons/crystal/clock.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/cash-ui/src/main/webapp/img/icons/crystal/movedown.png =================================================================== (Binary files differ) Property changes on: trunk/cash-ui/src/main/webapp/img/icons/crystal/movedown.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/cash-ui/src/main/webapp/img/icons/crystal/movetobottom.png =================================================================== (Binary files differ) Property changes on: trunk/cash-ui/src/main/webapp/img/icons/crystal/movetobottom.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/cash-ui/src/main/webapp/img/icons/crystal/movetotop.png =================================================================== (Binary files differ) Property changes on: trunk/cash-ui/src/main/webapp/img/icons/crystal/movetotop.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/cash-ui/src/main/webapp/img/icons/crystal/moveup.png =================================================================== (Binary files differ) Property changes on: trunk/cash-ui/src/main/webapp/img/icons/crystal/moveup.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-08-17 16:45:27 UTC (rev 13) +++ trunk/pom.xml 2009-08-19 08:10:53 UTC (rev 14) @@ -38,7 +38,6 @@ <groupId>org.chorem</groupId> <artifactId>oasis-ciq-api</artifactId> <version>${choreg.version}</version> - <scope>provided</scope> </dependency> <dependency> <groupId>org.nuiton.topia</groupId> @@ -59,7 +58,6 @@ <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.4.0</version> - <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId>
participants (1)
-
fdesbois@users.chorem.org