Author: meynier Date: 2013-07-16 17:13:01 +0200 (Tue, 16 Jul 2013) New Revision: 363 Url: http://chorem.org/projects/chorem/repository/revisions/363 Log: Add useful methods for project module in ChoremClient and ChoremUtil (temporary methods for dailyReturn and dailyHoursWorked) Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java trunk/chorem-entities/src/main/java/org/chorem/ChoremUtil.java Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2013-07-10 12:09:21 UTC (rev 362) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2013-07-16 15:13:01 UTC (rev 363) @@ -41,6 +41,7 @@ import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.WikittyServiceFactory; import org.nuiton.wikitty.WikittyUtil; +import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyExtension; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; @@ -384,4 +385,42 @@ WikittyQueryResult<Task> taskResult = findAllByQuery(Task.class, taskQuery); return taskResult.getAll(); } + + /** + * Returns the daily return of the given empoyee + * @param e + * @return + */ + public double getDailyReturn(Employee e) { + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //Code commented before confirmation or modification of the contract implementation + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + //Wikitty w = this.restore(e.getWikittyId()); + //if(w.hasExtension("Contract") && w.getFieldAsDouble("Contract", "dailyReturn") != 0) { + // return w.getFieldAsDouble("Contract", "dailyHoursWorked"); + //} + //else { + return this.getConfiguration().getDailyHoursWorked(); + //} + } + /** + * Returns the daily hours worked of the given empoyee + * @param e + * @return + */ + public double getDailyHoursWorked(Employee e) { + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //Code commented before confirmation or modification of the contract implementation + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + //Wikitty w = this.restore(e.getWikittyId()); + //Divide the hours by the daily hours worked (default if it's not specified) + //if(w.hasExtension("Contract") && w.getFieldAsDouble("Contract", "dailyHoursWorked") != 0) { + // return w.getFieldAsDouble("Contract", "dailyHoursWorked"); + //} + //else { + return this.getConfiguration().getDailyHoursWorked(); + //} + } } Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremUtil.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremUtil.java 2013-07-10 12:09:21 UTC (rev 362) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremUtil.java 2013-07-16 15:13:01 UTC (rev 363) @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -45,4 +46,25 @@ } return result; } + + /** + * Returns the number of seconds between the two given dates + * @param start Start date + * @param end End date + * @return period in seconds + */ + public static double getPeriodInSeconds(Date start, Date end) { + return (end.getTime()-start.getTime())/1000; + } + + /** + * Returns the number of hours between the two given dates + * @param start Start date + * @param end End date + * @return period in hours + */ + public static double getPeriodInHours(Date start, Date end) { + return getPeriodInSeconds(start, end)/3600; + } + }