r86 - in trunk/chorem-web/src/main: java/org/chorem/gepeto/action resources webapp/WEB-INF/jsp/gepeto
Author: vbriand Date: 2011-04-14 17:51:02 +0200 (Thu, 14 Apr 2011) New Revision: 86 Url: http://chorem.org/repositories/revision/chorem/86 Log: The projects can now be displayed by year Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java trunk/chorem-web/src/main/resources/struts.xml trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/home.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-04-14 13:38:04 UTC (rev 85) +++ trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-04-14 15:51:02 UTC (rev 86) @@ -1,7 +1,11 @@ package org.chorem.gepeto.action; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.UUID; @@ -95,6 +99,31 @@ return result; } + /** + * Tests whether the year is valid or not + * + * @return true if the year is valid, false otherwise + */ + public String projectsByYear() { + String result = SUCCESS; + Calendar cal = Calendar.getInstance(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy"); + + if (year != null) { + try { + Date date = formatter.parse(year); + cal.setTime(date); + yearInt = cal.get(Calendar.YEAR); + } catch (ParseException e) { + result = ERROR; + } + } else { + result = ERROR; + } + return result; + } + + protected int yearInt; protected String year; protected String name; protected String description; @@ -133,8 +162,7 @@ public List<Project> getAllProjects() { ChoremProxy proxy = getChoremProxy(); Search search = Search.query(); - Criteria criteria = search.isNotNull(Project.FQ_FIELD_PROJECT_NAME). - criteria(); + Criteria criteria = search.exteq(Project.EXT_PROJECT).criteria(); PagedResult<Project> result = proxy.findAllByCriteria(Project.class, criteria); List<Project> projects = result.getAll(); @@ -142,6 +170,39 @@ } /** + * Gets the projects by year + * + * @return the list of projects + */ + public List<Project> getProjectsByYear() { + ChoremProxy proxy = getChoremProxy(); + Calendar cal = Calendar.getInstance(); + Search search = Search.query(); + Criteria criteria = search.exteq(ProjectOrder.EXT_PROJECTORDER).criteria(); + PagedResult<ProjectOrder> result = proxy. + findAllByCriteria(ProjectOrder.class, criteria); + List<ProjectOrder> projectOrders = result.getAll(); + List<Project> projects = new ArrayList<Project>(); + Quotation quotation; + Project project; + int beginYear, endYear; + + for (ProjectOrder projectOrder : projectOrders) { + cal.setTime(projectOrder.getBeginDate()); + beginYear = cal.get(Calendar.YEAR); + cal.setTime(projectOrder.getEndDate()); + endYear = cal.get(Calendar.YEAR); + if (beginYear <= yearInt && yearInt <= endYear) { + quotation = proxy.restore(Quotation.class, + projectOrder.getQuotation()); + project = proxy.restore(Project.class, quotation.getProject()); + projects.add(project); + } + } + return projects; + } + + /** * Gets the quotations attached with this project * * @return the quotations linked with this project Modified: trunk/chorem-web/src/main/resources/struts.xml =================================================================== --- trunk/chorem-web/src/main/resources/struts.xml 2011-04-14 13:38:04 UTC (rev 85) +++ trunk/chorem-web/src/main/resources/struts.xml 2011-04-14 15:51:02 UTC (rev 86) @@ -106,7 +106,8 @@ <result name="error" type="redirectAction">home</result> <result>/WEB-INF/jsp/gepeto/projectOrderDetails.jsp</result> </action> - <action name="getProjectsByYear" class="org.chorem.gepeto.action.ProjectAction"> + <action name="getProjectsByYear" class="org.chorem.gepeto.action.ProjectAction" method="projectsByYear"> + <result name="error" type="redirectAction">home</result> <result>/WEB-INF/jsp/gepeto/projectsByYear.jsp</result> </action> <action name="projectDetails" class="org.chorem.gepeto.action.ProjectAction" method="projectDetails"> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/home.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/home.jsp 2011-04-14 13:38:04 UTC (rev 85) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/home.jsp 2011-04-14 15:51:02 UTC (rev 86) @@ -10,7 +10,10 @@ <body> <p> <s:a action="addProjectInput"><s:text name="chorem.gepeto.project.add" /></s:a><br /> - <s:a action="getProjectsByYear"><s:text name="chorem.gepeto.projects" /></s:a><br /> + <s:url action="getProjectsByYear" var="getProjectsByYear"> + <s:param name="year">2011</s:param> + </s:url> + <a href="${getProjectsByYear}"><s:text name="chorem.gepeto.projects" /></a><br /> </p> </body> </html> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp 2011-04-14 13:38:04 UTC (rev 85) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp 2011-04-14 15:51:02 UTC (rev 86) @@ -32,7 +32,7 @@ </thead> <tbody> <% - List<Project> projects = ProjectAction.getAction().getAllProjects(); + List<Project> projects = ProjectAction.getAction().getProjectsByYear(); for (Project project : projects) { %>
participants (1)
-
vbriand@users.chorem.org