Cash-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
August 2009
- 1 participants
- 15 discussions
Author: fdesbois
Date: 2009-08-20 18:33:26 +0200 (Thu, 20 Aug 2009)
New Revision: 18
Modified:
trunk/cash-business/src/test/resources/TopiaContextCash.properties
Log:
Change h2data destination to target folder
Modified: trunk/cash-business/src/test/resources/TopiaContextCash.properties
===================================================================
--- trunk/cash-business/src/test/resources/TopiaContextCash.properties 2009-08-20 16:14:29 UTC (rev 17)
+++ trunk/cash-business/src/test/resources/TopiaContextCash.properties 2009-08-20 16:33:26 UTC (rev 18)
@@ -6,6 +6,6 @@
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.driver_class=org.h2.Driver
-hibernate.connection.url=jdbc:h2:file:~/h2data/test/cash
+hibernate.connection.url=jdbc:h2:file:target/h2data/cash
1
0
r17 - in trunk/cash-business/src: main/java/org/chorem/cash/business main/java/org/chorem/cash/impl main/java/org/chorem/cash/persistence main/xmi test/java/org/chorem/cash/impl
by fdesbois@users.chorem.org 20 Aug '09
by fdesbois@users.chorem.org 20 Aug '09
20 Aug '09
Author: fdesbois
Date: 2009-08-20 18:14:29 +0200 (Thu, 20 Aug 2009)
New Revision: 17
Added:
trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelper.java
trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelperByMonth.java
trunk/cash-business/src/main/java/org/chorem/cash/persistence/EntryEntityDAOImpl.java
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/main/xmi/cash.zargo
trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java
Log:
- Implementation for frequency
- get for tree frequency types (unlimited, untilDate, nbTimes)
- createUpdate for particular case modify only current occurence (unlimited)
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-19 10:12:28 UTC (rev 16)
+++ trunk/cash-business/src/main/java/org/chorem/cash/business/EntryHelper.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -20,17 +20,18 @@
package org.chorem.cash.business;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
+import java.util.Date;
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.Category;
import org.chorem.cash.dto.Entry;
import org.chorem.cash.dto.Reference;
import org.chorem.cash.persistence.CategoryEntity;
+import org.chorem.cash.persistence.CategoryEntityDAO;
import org.chorem.cash.persistence.EntryEntity;
import org.chorem.cash.persistence.EntryEntityDAO;
import org.chorem.cash.persistence.EntryFrequencyEntity;
@@ -57,7 +58,7 @@
*/
public class EntryHelper {
- public static Entry getEntry(EntryEntity entity) throws ConvertException {
+ public static Entry getEntry(EntryEntity entity, Date current) throws ConvertException {
Entry entry = Convert.toDTO(entity, EntryEntity.class, Entry.class);
entry.setId(ContextUtilCash.convertId(entity.getTopiaId()));
CategoryEntity category = entity.getCategoryEntity();
@@ -79,13 +80,62 @@
entry.setUnlimited(frequency.getUnlimited());
entry.setUntilDate(frequency.getUntilDate());
entry.setPeriodicity(frequency.getPeriodicity());
- entry.setMonths(frequency.getMonths());
+ entry.setCurrentDate(current);
+
+ //entry.setMonths(frequency.getMonths());
}
return entry;
}
+
+ public static EntryEntity createUpdateEntry(Entry entry, TopiaContext transaction, Log log)
+ throws TopiaException, IllegalArgumentException, EntityException {
+ for (Reference reference : entry.getReferences()) {
+ ReferenceHelper.createUpdateReference(reference, transaction, log);
+ }
+
+ EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
+
+ Map<String, Object> saveParams = new HashMap<String, Object>();
+
+ saveParams.put(EntryEntity.LIBELLE, entry.getLibelle());
+
+ Category entryCategory = entry.getCategory();
+ if (entryCategory != null) {
+ CategoryEntityDAO categDAO = CashModelDAOHelper.getCategoryEntityDAO(transaction);
+ CategoryEntity category = ServiceHelper.getEntity(categDAO, entryCategory.getId(), log);
+ saveParams.put(EntryEntity.CATEGORY_ENTITY, category);
+ } else {
+ throw new IllegalArgumentException("Null parameter Category");
+ }
+
+ // Modify amount sign if credit is false
+ if (!entry.getCategory().getCredit()) {
+ double amount = entry.getAmount();
+ if (amount > 0) { // no modification if already negatif
+ entry.setAmount(-amount);
+ }
+ }
+
+ saveParams.put(EntryEntity.AMOUNT, entry.getAmount());
+ saveParams.put(EntryEntity.COMMENT, entry.getComment());
+ saveParams.put(EntryEntity.ENTRY_DATE, entry.getEntryDate());
+
+ if (entry.getPeriodicity() != null && !entry.getPeriodicity().isEmpty()) {
+ 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()));
+
+ return entity;
+ }
+
public static EntryFrequencyEntity createUpdateFrequency(Entry entry, TopiaContext transaction, Log log)
throws IllegalArgumentException, TopiaException, EntityException {
@@ -98,15 +148,6 @@
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());
}
@@ -121,23 +162,37 @@
return entity;
}
- private static Collection<Integer> getMonthsIntervals(int interval, int firstMonth) {
+ public static int[] getMonthsIntervals(int interval, int firstMonth) {
int max = 12 / interval;
- //int[] results = new int[max];
- List<Integer> results = new ArrayList<Integer>();
+ int[] results = new int[max];
+ //List<Integer> results = new ArrayList<Integer>();
- //results[0] = firstMonth;
- results.add(new Integer(firstMonth));
+ 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;
+ //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;
}
+
+ public static void addEntryForMonth(EntryEntity entity, Date currentDate, Map<String, List<Entry>> results, String pattern) throws ConvertException {
+ /*if (log.isDebugEnabled() && entity.getEntryFrequencyEntity() != null) {
+ log.debug("PERIODIC ENTRY : beginDate = " + entity.getEntryDate() + " _ current = " + currentDate);
+ }*/
+ Entry result = EntryHelper.getEntry(entity, currentDate);
+ String month = DateUtils.formatDate(currentDate, pattern);
+ List<Entry> current = results.get(month);
+ if (current == null) {
+ current = new ArrayList<Entry>();
+ results.put(month, current);
+ }
+ current.add(result);
+ }
}
Added: trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelper.java
===================================================================
--- trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelper.java (rev 0)
+++ trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelper.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -0,0 +1,112 @@
+/**
+ * *##% Ca$h Business
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
+ */
+
+package org.chorem.cash.business;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.cash.persistence.EntryEntity;
+import org.chorem.cash.persistence.EntryFrequencyEntity;
+import org.chorem.utils.PeriodDates;
+
+/**
+ * PeriodicHelper.java
+ *
+ * Created on 2009-08-20
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public abstract class PeriodicHelper<T> {
+
+ protected static final Log log = LogFactory.getLog(PeriodicHelper.class);
+
+ protected PeriodDates period;
+
+ private Calendar calendarEnd;
+
+ protected Calendar calendar;
+
+ protected EntryEntity entity;
+
+ private int interval;
+
+ private int calendarField;
+
+ protected T results;
+
+ public PeriodicHelper(EntryEntity entity, PeriodDates period) {
+ init(entity);
+ this.period = period;
+ }
+
+ public PeriodicHelper(EntryEntity entity, Date endDate) {
+ init(entity);
+ this.calendarEnd = new GregorianCalendar();
+ this.calendarEnd.setTime(endDate);
+ }
+
+ private void init(EntryEntity entity) {
+ this.entity = entity;
+ this.calendar = new GregorianCalendar();
+ this.calendar.setTime(entity.getEntryDate());
+ EntryFrequencyEntity frequency = entity.getEntryFrequencyEntity();
+ Periodicity periodicity = Periodicity.valueOf(frequency.getPeriodicity());
+ this.interval = frequency.getInterval();
+ this.calendarField = getField(periodicity);
+ }
+
+ private int getField(Periodicity rule) {
+ switch (rule) {
+ case MONTHLY: return Calendar.MONTH;
+ }
+ return Calendar.MONTH;
+ }
+
+ public T execute(T start) throws Exception {
+
+ calendar.add(calendarField, interval);
+ boolean beforeEnd = period != null ? period.beforeEnd(calendar) : calendar.before(calendarEnd);
+
+ while (beforeEnd && predicat()) {
+ if (log.isDebugEnabled()) {
+ log.debug("PREDICAT : beforeEnd = " + beforeEnd + " _ predicat = " + predicat());
+ log.debug("PERIODIC ENTRY : current = " + calendar.getTime());
+ }
+ boolean afterBegin = period != null ? period.afterBegin(calendar) : true;
+ if (afterBegin) {
+ start = action(start); //addEntryForMonth(periodicEntry, calendar.getTime(), results, period.getPattern());
+ }
+ calendar.add(calendarField, interval);
+ beforeEnd = period != null ? period.beforeEnd(calendar) : calendar.before(calendarEnd);
+ }
+ return start;
+ }
+
+ public abstract boolean predicat();
+
+ public abstract T action(T start) throws Exception;
+
+}
Property changes on: trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Added: trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelperByMonth.java
===================================================================
--- trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelperByMonth.java (rev 0)
+++ trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelperByMonth.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -0,0 +1,51 @@
+/**
+ * *##% Ca$h Business
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
+ */
+
+package org.chorem.cash.business;
+
+import java.util.List;
+import java.util.Map;
+import org.chorem.cash.dto.Entry;
+import org.chorem.cash.persistence.EntryEntity;
+import org.chorem.utils.PeriodDates;
+
+/**
+ * PeriodicHelperByMonth.java
+ *
+ * Created on 2009-08-20
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public abstract class PeriodicHelperByMonth extends PeriodicHelper<Map<String, List<Entry>>> {
+
+ public PeriodicHelperByMonth(EntryEntity entity, PeriodDates period) {
+ super(entity, period);
+ }
+
+ @Override
+ public Map<String, List<Entry>> action(Map<String, List<Entry>> start) throws Exception {
+ EntryHelper.addEntryForMonth(entity, calendar.getTime(), start, period.getPattern());
+ return start;
+ }
+
+}
Property changes on: trunk/cash-business/src/main/java/org/chorem/cash/business/PeriodicHelperByMonth.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
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-19 10:12:28 UTC (rev 16)
+++ trunk/cash-business/src/main/java/org/chorem/cash/impl/ServiceEntryImpl.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -26,12 +26,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.cash.CashException;
import org.chorem.cash.CashModelDAOHelper;
import org.chorem.cash.ContextUtilCash;
import org.chorem.cash.business.EntryHelper;
+import org.chorem.cash.business.PeriodicHelper;
+import org.chorem.cash.business.PeriodicHelperByMonth;
import org.chorem.cash.business.Periodicity;
import org.chorem.cash.business.ReferenceHelper;
import org.chorem.cash.dto.Category;
@@ -44,6 +48,7 @@
import org.chorem.cash.persistence.EntryFrequencyEntity;
import org.chorem.cash.services.ServiceEntry;
import org.chorem.cash.services.ServiceEntryAbstract;
+import org.chorem.exceptions.ConvertException;
import org.chorem.utils.DateUtils;
import org.chorem.utils.PeriodDates;
import org.chorem.utils.ServiceHelper;
@@ -76,54 +81,51 @@
try {
transaction = context.beginTransaction();
- for (Reference reference : entry.getReferences()) {
- ReferenceHelper.createUpdateReference(reference, transaction, log);
- }
-
EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
- Map<String, Object> saveParams = new HashMap<String, Object>();
-
- saveParams.put(EntryEntity.LIBELLE, entry.getLibelle());
+ if (entry.getId() != null && !entry.getId().isEmpty()) { // L'entree existe
- Category entryCategory = entry.getCategory();
- if (entryCategory != null) {
- CategoryEntityDAO categDAO = CashModelDAOHelper.getCategoryEntityDAO(transaction);
- CategoryEntity category = ServiceHelper.getEntity(categDAO, entryCategory.getId(), log);
- saveParams.put(EntryEntity.CATEGORY_ENTITY, category);
- } else {
- ContextUtilCash.serviceException(transaction, "Category must be specified to create or update an entry",
- new IllegalArgumentException("Null parameter Category"));
- }
+ EntryEntity oldEntry = ServiceHelper.getEntity(dao, entry.getId(), log);
- // Modify amount sign if credit is false
- if (!entry.getCategory().getCredit()) {
- double amount = entry.getAmount();
- if (amount > 0) { // no modification if already negatif
- entry.setAmount(-amount);
- }
- }
+ EntryFrequencyEntity frequency = oldEntry.getEntryFrequencyEntity();
- saveParams.put(EntryEntity.AMOUNT, entry.getAmount());
- saveParams.put(EntryEntity.COMMENT, entry.getComment());
- saveParams.put(EntryEntity.ENTRY_DATE, entry.getEntryDate());
+ if (frequency != null && (entry.getPeriodicity() == null || "".equals(entry.getPeriodicity()))) { // Entite anciennement periodique mais l'entree courante devient indépendante
- if (entry.getPeriodicity() != null && !entry.getPeriodicity().isEmpty()) {
+ if (frequency.getUnlimited()) { // Cas illimite : une seule entite en base
- String periodicity = entry.getPeriodicity();
- if (Periodicity.valueOf(periodicity).equals(Periodicity.MONTHLY)) {
+ // On recupere l'ancienne version de l'entite (avec sa frequence)
+ Calendar calendar = new GregorianCalendar();
- EntryFrequencyEntity frequency = EntryHelper.createUpdateFrequency(entry, transaction, log);
+ // On cree une nouvelle entree pour la periodicite avant l'occurence courante
+ Entry newBeforeEntry = EntryHelper.getEntry(oldEntry, null);
+ newBeforeEntry.setId("");
+ // On va modifier la frequence en changeant le unlimited par une date de fin (untilDate)
+ // La date de fin est calcule en fonction de la date de l'occurence passe en parametre du service
+ calendar.setTime(entry.getCurrentDate());
+ calendar.add(Calendar.MONTH, -entry.getInterval()); // PERIODICITY = MONTHLY
+ newBeforeEntry.setUntilDate(calendar.getTime());
+ newBeforeEntry.setUnlimited(false);
- saveParams.put(EntryEntity.ENTRY_FREQUENCY_ENTITY, frequency);
+ EntryHelper.createUpdateEntry(newBeforeEntry, transaction, log);
+
+ // On cree une nouvelle entree pour la periodicite apres l'occurence courante
+ Entry newAfterEntry = EntryHelper.getEntry(oldEntry, null);
+ newAfterEntry.setId("");
+ // On va modifier la nouvelle entree en changeant la date de debut (entryDate)
+ calendar.setTime(entry.getCurrentDate());
+ calendar.add(Calendar.MONTH, entry.getInterval()); // PERIODICITY = MONTHLY
+ newAfterEntry.setEntryDate(calendar.getTime());
+
+ EntryHelper.createUpdateEntry(newAfterEntry, transaction, log);
+ } else if (frequency.getNbTimes() > 0) {
+
+ }
}
}
- EntryEntity entity = ServiceHelper.createUpdateEntity(dao, entry.getId(), null, saveParams, log);
+ EntryHelper.createUpdateEntry(entry, transaction, log);
- entry.setId(ContextUtilCash.convertId(entity.getTopiaId()));
-
transaction.commitTransaction();
transaction.closeContext();
} catch (Exception eee) {
@@ -141,7 +143,7 @@
EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
EntryEntity entity = ServiceHelper.getEntity(dao, entryId, log);
- result = EntryHelper.getEntry(entity);
+ result = EntryHelper.getEntry(entity, null);
transaction.closeContext();
} catch (Exception eee) {
@@ -160,7 +162,7 @@
EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
for (EntryEntity entity : dao.findAllWithOrder(EntryEntity.ENTRY_DATE)) {
- Entry result = EntryHelper.getEntry(entity);
+ Entry result = EntryHelper.getEntry(entity, null);
results.add(result);
}
@@ -204,44 +206,87 @@
EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
- 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> entries = dao.findAllBetweenDates(period.getFromDate(), 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);
- }*/
+ for (EntryEntity entity : entries) {
+ EntryHelper.addEntryForMonth(entity, entity.getEntryDate(), results, period.getPattern());
+ }
+ List<EntryEntity> periodicEntries = dao.findUnlimitedPeriodicEntries();
+
+ for (EntryEntity periodicEntry : periodicEntries) {
+ EntryFrequencyEntity frequency = periodicEntry.getEntryFrequencyEntity();
+
+ /*if (frequency.getUnlimited()) {
+ PeriodicHelperByMonth helper = new PeriodicHelperByMonth(periodicEntry, period) {
+ @Override
+ public boolean predicat() {
+ return true;
+ }
+ };
+ results = helper.execute(results);
+ } else if (frequency.getNbTimes() > 0) {
+ PeriodicHelperByMonth helper = new PeriodicHelperByMonth(periodicEntry, period) {
+ private int count = 0;
+
+ @Override
+ public boolean predicat() {
+ return count < entity.getEntryFrequencyEntity().getNbTimes();
+ }
+ };
+ results = helper.execute(results);
+ } else if (frequency.getUntilDate() != null) {
+ PeriodicHelperByMonth helper = new PeriodicHelperByMonth(periodicEntry, period) {
+ @Override
+ public boolean predicat() {
+ Date untilDate = entity.getEntryFrequencyEntity().getUntilDate();
+ return calendar.getTime().before(untilDate) || untilDate.equals(calendar.getTime());
+ }
+ };
+ results = helper.execute(results);
+ }*/
+
+
+ Calendar calendar = new GregorianCalendar();
+ calendar.setTime(periodicEntry.getEntryDate());
+ // Si entryDate est contenu dans la periode, l'entree sera deja dans la liste des entries
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+
+ Periodicity periodicity = Periodicity.valueOf(frequency.getPeriodicity());
+
+ if (frequency.getUnlimited()) {
+ while (period.beforeEnd(calendar)) {
+ if (period.afterBegin(calendar)) {
+ EntryHelper.addEntryForMonth(periodicEntry, calendar.getTime(), results, period.getPattern());
+ }
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+ }
+ } else if (frequency.getNbTimes() > 0) {
+ int count = 0;
+ while (period.beforeEnd(calendar) && count < frequency.getNbTimes()) {
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+ if (period.afterBegin(calendar)) {
+ EntryHelper.addEntryForMonth(periodicEntry, calendar.getTime(), results, period.getPattern());
+ }
+ count++;
+ }
+ } else if (frequency.getUntilDate() != null) {
+ Date untilDate = frequency.getUntilDate();
+ while (period.beforeEnd(calendar) && (calendar.getTime().before(untilDate) || untilDate.equals(calendar.getTime()))) {
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+ if (period.afterBegin(calendar)) {
+ EntryHelper.addEntryForMonth(periodicEntry, calendar.getTime(), results, period.getPattern());
+ }
+ }
+ }
+ }
+
if (log.isDebugEnabled()) {
log.debug("NbEntries find : " + entries.size());
- //log.debug("NbPeriodicEntries find : " + periodicEntries.size());
+ log.debug("NbPeriodicEntries find : " + periodicEntries.size());
+ log.debug("Results added : " + results.size() + " _ keys = " + results.keySet());
}
- for (EntryEntity entity : entries) {
- Entry result = EntryHelper.getEntry(entity);
-
- String entityDate = DateUtils.formatDate(entity.getEntryDate(), period.getPattern());
- List<Entry> current = results.get(entityDate);
- if (current == null) {
- current = new ArrayList<Entry>();
- results.put(entityDate, current);
- }
- current.add(result);
- }
-
transaction.closeContext();
} catch (Exception eee) {
ContextUtilCash.serviceException(transaction, "Unable to get entries between dates " + period.getFromDate() + " and " +
@@ -250,6 +295,8 @@
return results;
}
+
+
@Override
public double getSumBeforeDate(Date date) throws CashException {
TopiaContext transaction = null;
@@ -257,16 +304,50 @@
try {
transaction = context.beginTransaction();
- List results = transaction.find(
- "SELECT SUM(amount) FROM " + EntryEntity.class.getName() +
- " WHERE " + EntryEntity.ENTRY_DATE + " < :date",
- "date", date);
-
- // le find renvoie une liste obligatoirement non null mais non vide (1 seul element potentiellement = null)
- if (results.get(0) != null) {
- total = (Double)results.get(0);
+ EntryEntityDAO dao = CashModelDAOHelper.getEntryEntityDAO(transaction);
+
+ total = dao.sumAmountsBeforeDate(date);
+
+ if (log.isDebugEnabled()) {
+ log.debug("TOTAL before UnlimitedPeriodicEntries : " + total);
}
+ // Recherche sur les entites periodiques sans limite
+ for (EntryEntity periodicEntry : dao.findUnlimitedPeriodicEntries()) {
+
+ /*PeriodicHelper<Double> helper = new PeriodicHelper<Double>(periodicEntry, date) {
+ @Override
+ public boolean predicat() {
+ return true;
+ }
+
+ @Override
+ public Double action(Double start) throws Exception {
+ Double dd = new Double(entity.getAmount());
+ start += dd;
+ return start;
+ }
+ };
+
+ total = helper.execute(total);*/
+
+ EntryFrequencyEntity frequency = periodicEntry.getEntryFrequencyEntity();
+ Calendar calendar = new GregorianCalendar();
+ calendar.setTime(periodicEntry.getEntryDate());
+ // Si entryDate est avant la date, la somme sera deja compte dans le total
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+ int count = 0;
+ while (calendar.getTime().before(date)) {
+ count++;
+ total += periodicEntry.getAmount();
+ calendar.add(Calendar.MONTH, frequency.getInterval());
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("TOTAL after UnlimitedPeriodicEntries : " + total);
+ }
+
transaction.closeContext();
} catch (Exception eee) {
ContextUtilCash.serviceException(transaction, "Unable to get sum before " + date, eee);
Added: trunk/cash-business/src/main/java/org/chorem/cash/persistence/EntryEntityDAOImpl.java
===================================================================
--- trunk/cash-business/src/main/java/org/chorem/cash/persistence/EntryEntityDAOImpl.java (rev 0)
+++ trunk/cash-business/src/main/java/org/chorem/cash/persistence/EntryEntityDAOImpl.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -0,0 +1,81 @@
+/**
+ * *##% Ca$h Business
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
+ */
+
+package org.chorem.cash.persistence;
+
+import java.util.Date;
+import java.util.List;
+import org.nuiton.topia.TopiaException;
+
+/**
+ * ServiceCategoryImpl.java
+ *
+ * Created on 2009-08-20
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class EntryEntityDAOImpl<E extends EntryEntity> extends EntryEntityDAOAbstract<E> {
+
+ @Override
+ public List<EntryEntity> findUnlimitedPeriodicEntries() throws TopiaException {
+ List<EntryEntity> periodicEntries = getContext().find(
+ "FROM " + EntryEntity.class.getName() +
+ " WHERE " + EntryEntity.ENTRY_FREQUENCY_ENTITY + " IS NOT NULL " +
+ " AND " + EntryEntity.ENTRY_FREQUENCY_ENTITY + "." + EntryFrequencyEntity.UNLIMITED + " = :bool" +
+ " ORDER BY " + EntryEntity.ENTRY_DATE,
+ "bool", true);
+ return periodicEntries;
+ }
+
+ @Override
+ public List<EntryEntity> findAllBetweenDates(Date dateFrom, Date dateThru) throws TopiaException {
+ List<EntryEntity> entries = getContext().find(
+ "FROM " + EntryEntity.class.getName() +
+ " WHERE " + EntryEntity.ENTRY_DATE + " BETWEEN :dateFrom AND :dateThru" +
+ /*" AND (" +
+ "(" + EntryEntity.ENTRY_FREQUENCY_ENTITY + " IS NULL) " +
+ " OR ( " + EntryEntity.ENTRY_FREQUENCY_ENTITY + "." + EntryFrequencyEntity.UNLIMITED + " = :bool " +
+ ")" +
+ ")" +*/
+ " ORDER BY " + EntryEntity.ENTRY_DATE,
+ "dateFrom", dateFrom,
+ "dateThru", dateThru);
+ return entries;
+ }
+
+ @Override
+ public double sumAmountsBeforeDate(Date date) throws TopiaException {
+ double total = 0;
+ List results = getContext().find(
+ "SELECT SUM(amount) FROM " + EntryEntity.class.getName() +
+ " WHERE " + EntryEntity.ENTRY_DATE + " < :date",
+ "date", date);
+
+ // le find renvoie une liste obligatoirement non null mais non vide (1 seul element potentiellement = null)
+ if (results.get(0) != null) {
+ total = (Double)results.get(0);
+ }
+ return total;
+ }
+
+}
Property changes on: trunk/cash-business/src/main/java/org/chorem/cash/persistence/EntryEntityDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Modified: trunk/cash-business/src/main/xmi/cash.zargo
===================================================================
(Binary files differ)
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-19 10:12:28 UTC (rev 16)
+++ trunk/cash-business/src/test/java/org/chorem/cash/impl/ServiceEntryImplTest.java 2009-08-20 16:14:29 UTC (rev 17)
@@ -88,11 +88,11 @@
Category categ = ServiceCategoryImplTest.addParentCategory(serviceCateg, "CATEG", 1, true);
- Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ);
+ Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ, 0);
- Entry entry2 = createEntry(instance, "SECOND", DateUtils.createDate(5, 12, 2009), 78.24, categ);
+ Entry entry2 = createEntry(instance, "SECOND", DateUtils.createDate(5, 12, 2009), 78.24, categ, 0);
- Entry entry3 = createEntry(instance, "THIRD", DateUtils.createDate(15, 12, 2009), 258.44, categ);
+ Entry entry3 = createEntry(instance, "THIRD", DateUtils.createDate(15, 12, 2009), 258.44, categ, 0);
try {
List<Entry> list = instance.getEntries();
@@ -105,11 +105,12 @@
fail("CashException");
}
- Date today = new Date();
- Date afterSixMonth = DateUtils.createDateAfterToday(0, 6, 0);
- log.debug("DATES : " + today + " _ " + afterSixMonth);
+ Date date1 = DateUtils.createDate(20, 8, 2009);
+ //Date afterSixMonth = DateUtils.createDateAfterToday(0, 6, 0);
+ Date date2 = DateUtils.createDate(20, 2, 2010);
+ log.debug("DATES : " + date1 + " _ " + date2);
- PeriodDates period = new PeriodDates(today, afterSixMonth);
+ PeriodDates period = new PeriodDates(date1, date2);
period.setPattern(DateUtils.MONTH_PATTERN);
log.info("RANGETIME : " + period + " _ pattern [" + period.getPattern() + "]");
@@ -140,7 +141,7 @@
}
- /*@Test
+ @Test
public void testCreateUpdateEntry() throws Exception {
log.info("createUpdateEntry");
@@ -149,35 +150,43 @@
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);
+ Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ, 0);
- log.debug("PERIODIC ENTRY : MONTHLY -> unlimited, interval = " + 3 + ", date = 12/07/2009");
+ Entry entry2 = createEntry(instance, "SECOND", DateUtils.createDate(12,9,2008), 152.14, categ, 5); // PERIODIC interval = 5
+ /*Date date2 = DateUtils.createDate(12,9,2008);
+ int interval = 5;
+ log.debug("PERIODIC ENTRY : MONTHLY -> unlimited, interval = " + interval + ", date = " + date2);
Entry entry2 = instance.getNewEntry();
entry2.setLibelle("SECOND");
entry2.setAmount(152.14);
- entry2.setEntryDate(DateUtils.createDate(12,7,2009));
+ entry2.setEntryDate(date2);
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");
- }
+ }*/
+ Date from = DateUtils.createDate(12, 8, 2008);
+ Date thru = DateUtils.createDate(15, 10, 2009);
+ PeriodDates period = new PeriodDates(from, thru);
+ period.setPattern(DateUtils.MONTH_PATTERN);
+
+ log.debug("GET ENTRIES BETWEEN : " + period);
+
try {
- Entry result = instance.getEntry(entry2.getId());
- assertNotNull(result);
- assertNotNull(result.getMonths());
- assertEquals(result.getMonths().size(), 4);
+ Map<String, List<Entry>> results = instance.getEntriesBetweenDates(period);
+ assertNotNull(results);
+ assertEquals(results.size(), 4);
+ List<Entry> list = results.get("02/2009");
+ assertNotNull(list);
+ assertEquals(list.size(), 1);
} catch (CashException eee) {
- log.error("Erreur getEntry : " + eee.getMessage());
+ log.error("Erreur getEntriesBetweenDates : " + eee.getMessage());
fail("CashException");
}
@@ -189,7 +198,7 @@
fail("CashException");
}
- }*/
+ }
@Test
public void testGetSumBeforeDate() throws Exception {
@@ -200,31 +209,33 @@
Category categ = ServiceCategoryImplTest.addParentCategory(serviceCateg, "CATEG", 1, true);
Category categ2 = ServiceCategoryImplTest.addParentCategory(serviceCateg, "CATEG2", 2, false);
- Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ);
+ Entry entry1 = createEntry(instance, "FIRST", DateUtils.createDate(5, 9, 2009), 15.00, categ, 1);
- Entry entry2 = createEntry(instance, "SECOND", DateUtils.createDate(5, 12, 2009), 78.24, categ);
+ Entry entry2 = createEntry(instance, "SECOND", DateUtils.createDate(5, 12, 2009), -78.24, categ2, 0);
- Entry entry3 = createEntry(instance, "THIRD", DateUtils.createDate(15, 12, 2009), 258.44, categ);
+ Entry entry3 = createEntry(instance, "THIRD", DateUtils.createDate(15, 12, 2009), 258.44, categ, 0);
- Entry entry4 = createEntry(instance, "FOURTH", DateUtils.createDate(2, 1, 2010), -68.12, categ2);
+ Entry entry4 = createEntry(instance, "FOURTH", DateUtils.createDate(2, 1, 2010), 68.12, categ, 0);
Date date1 = DateUtils.createDate(31,12,2009);
try {
double total1 = instance.getSumBeforeDate(date1);
+ log.debug("CALCUL : 15 * 4 - 78.24 + 258.44");
log.debug("TOTAL1 : " + total1);
- assertEquals(total1, 351.68, 0.01);
+ assertEquals(total1, 240.2, 0.01);
} catch (CashException eee) {
log.error("Erreur getSumBeforeDate : " + eee.getMessage());
fail("CashException");
}
- Date date2 = DateUtils.createDate(8,12,2009);
+ Date date2 = DateUtils.createDate(8,11,2009);
try {
double total2 = instance.getSumBeforeDate(date2);
+ log.debug("CALCUL : 15 * 3");
log.debug("TOTAL2 : " + total2);
- assertEquals(total2, 93.24, 0.01);
+ assertEquals(total2, 45, 0.01);
} catch (CashException eee) {
log.error("Erreur getSumBeforeDate : " + eee.getMessage());
fail("CashException");
@@ -234,8 +245,9 @@
try {
double total3 = instance.getSumBeforeDate(date3);
+ log.debug("CALCUL : 15 * 5 - 78.24 + 258.44 + 68.12");
log.debug("TOTAL3 : " + total3);
- assertEquals(total3, 283.56, 0.01);
+ assertEquals(total3, 323.32, 0.01);
} catch (CashException eee) {
log.error("Erreur getSumBeforeDate : " + eee.getMessage());
fail("CashException");
@@ -264,14 +276,30 @@
}
- private Entry createEntry(ServiceEntry service, String libelle, Date entryDate, double amount, Category categ) {
- log.debug("CREATE ENTRY : " + libelle + " _ " + entryDate + " _ " + amount);
+ /**
+ * Helper to create Entry for test. If interval > 0, entry is MONTHLY periodic unlimited.
+ * @param service ServiceEntry instance to use to create the entry
+ * @param libelle For the entry name
+ * @param entryDate begin date
+ * @param amount amount
+ * @param categ category (must be created before)
+ * @param interval for periodicity (MONTHLY _ UNLIMITED)
+ * @return the new Entry created
+ */
+ private Entry createEntry(ServiceEntry service, String libelle, Date entryDate, double amount, Category categ, int interval) {
+ log.debug("CREATE ENTRY : " + libelle + " _ " + entryDate + " _ " + amount + " _ periodic : " + (interval > 0) + "(" + interval +")");
Entry entry = service.getNewEntry();
entry.setLibelle(libelle);
entry.setAmount(amount);
entry.setEntryDate(entryDate);
entry.setCategory(categ);
+ if (interval > 0) {
+ entry.setPeriodicity(Periodicity.MONTHLY.toString());
+ entry.setUnlimited(true);
+ entry.setInterval(interval);
+ }
+
try {
service.createUpdateEntry(entry);
assertNotNull(entry.getId());
1
0
Author: fdesbois
Date: 2009-08-19 12:12:28 +0200 (Wed, 19 Aug 2009)
New Revision: 16
Modified:
trunk/pom.xml
Log:
Change url for mailing lists
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-08-19 09:44:44 UTC (rev 15)
+++ trunk/pom.xml 2009-08-19 10:12:28 UTC (rev 16)
@@ -178,24 +178,24 @@
<mailingLists>
<mailingList>
<name>cash-commits</name>
- <subscribe>http://list.chorem.org/mailman/listinfo/cash-commits</subscribe>
- <unsubscribe>http://list.chorem.org/mailman/listinfo/cash-commits</unsubscribe>
+ <subscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-commits</subscribe>
+ <unsubscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-commits</unsubscribe>
<post>cash-commits(a)$list.chorem.org</post>
<archive>http://list.chorem.org/pipermail/cash-commits/</archive>
</mailingList>
<mailingList>
<name>cash-devel</name>
- <subscribe>http://list.chorem.org/mailman/listinfo/cash-devel</subscribe>
- <unsubscribe>http://list.chorem.org/mailman/listinfo/cash-devel</unsubscribe>
+ <subscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-devel</subscribe>
+ <unsubscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-devel</unsubscribe>
<post>cash-devel(a)list.chorem.org</post>
<archive>http://list.chorem.org/pipermail/cash-devel/</archive>
</mailingList>
<mailingList>
<name>cash-users</name>
- <subscribe>http://list.chorem.org/mailman/listinfo/cash-users</subscribe>
- <unsubscribe>http://list.chorem.org/mailman/listinfo/cash-users</unsubscribe>
+ <subscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-users</subscribe>
+ <unsubscribe>http://list.chorem.org/cgi-bin/mailman/listinfo/cash-users</unsubscribe>
<post>cash-users(a)list.chorem.org</post>
<archive>http://list.chorem.org/pipermail/cash-users/</archive>
</mailingList>
1
0
Author: fdesbois
Date: 2009-08-19 11:44:44 +0200 (Wed, 19 Aug 2009)
New Revision: 15
Modified:
trunk/cash-business/src/main/xmi/cash.zargo
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/xmi/cash.zargo
===================================================================
(Binary files differ)
1
0
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
by fdesbois@users.chorem.org 19 Aug '09
by fdesbois@users.chorem.org 19 Aug '09
19 Aug '09
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>
1
0