From 5ebffa666bc39f1e6f29cca7698a7932072ad8f9 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 7 Nov 2012 21:41:12 +0100 Subject: [PATCH] New web service returning the assigned tasks of a user It uses MyTasksAreaModel, as the main UI for bound users. The service is only accessible for bound users. FEA: ItEr77S14BoundUsersWebServices --- .../orders/entities/OrderElement.java | 17 ++++ .../dashboard/MyTasksAreaController.java | 26 +------ .../ws/boundusers/api/IBoundUserService.java | 33 ++++++++ .../libreplan/ws/boundusers/api/TaskDTO.java | 78 +++++++++++++++++++ .../ws/boundusers/api/TaskListDTO.java | 47 +++++++++++ .../ws/boundusers/api/package-info.java | 28 +++++++ .../boundusers/impl/BoundUserServiceREST.java | 52 +++++++++++++ .../ws/boundusers/impl/TaskConverter.java | 74 ++++++++++++++++++ .../libreplan-webapp-spring-config.xml | 1 + ...ibreplan-webapp-spring-security-config.xml | 6 ++ 10 files changed, 339 insertions(+), 23 deletions(-) create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/IBoundUserService.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskDTO.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskListDTO.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/package-info.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/BoundUserServiceREST.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/TaskConverter.java diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java index 87b0b4c2e..c22f4cc62 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java @@ -42,6 +42,7 @@ import org.hibernate.validator.Valid; import org.joda.time.LocalDate; import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes; import org.libreplan.business.advance.entities.AdvanceAssignment; +import org.libreplan.business.advance.entities.AdvanceMeasurement; import org.libreplan.business.advance.entities.AdvanceType; import org.libreplan.business.advance.entities.DirectAdvanceAssignment; import org.libreplan.business.advance.entities.IndirectAdvanceAssignment; @@ -70,6 +71,7 @@ import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.business.templates.entities.OrderElementTemplate; import org.libreplan.business.trees.ITreeNode; import org.libreplan.business.util.deepcopy.DeepCopy; +import org.libreplan.business.workingday.EffortDuration; import org.libreplan.business.workingday.IntraDayDate; import org.libreplan.business.workreports.daos.IWorkReportLineDAO; import org.libreplan.business.workreports.entities.WorkReportLine; @@ -1588,4 +1590,19 @@ public abstract class OrderElement extends IntegrationEntity implements parent = null; } + public AdvanceMeasurement getLastAdvanceMeasurement() { + DirectAdvanceAssignment advanceAssignment = getReportGlobalAdvanceAssignment(); + if (advanceAssignment == null) { + return null; + } + return advanceAssignment.getLastAdvanceMeasurement(); + } + + public String getEffortAsString() { + SumChargedEffort sumChargedEffort = getSumChargedEffort(); + EffortDuration effort = sumChargedEffort != null ? sumChargedEffort + .getTotalChargedEffort() : EffortDuration.zero(); + return effort.toFormattedString(); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MyTasksAreaController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MyTasksAreaController.java index 75b214b94..d72d1402a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MyTasksAreaController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/MyTasksAreaController.java @@ -28,12 +28,9 @@ import javax.annotation.Resource; import org.joda.time.LocalDate; import org.libreplan.business.advance.entities.AdvanceMeasurement; -import org.libreplan.business.advance.entities.DirectAdvanceAssignment; import org.libreplan.business.common.entities.PersonalTimesheetsPeriodicityEnum; import org.libreplan.business.orders.entities.OrderElement; -import org.libreplan.business.orders.entities.SumChargedEffort; import org.libreplan.business.planner.entities.Task; -import org.libreplan.business.workingday.EffortDuration; import org.libreplan.web.common.Util; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; @@ -75,21 +72,15 @@ public class MyTasksAreaController extends GenericForwardComposer { Util.appendLabel(row, getProgress(orderElement)); - Util.appendLabel(row, getEffort(orderElement)); + Util.appendLabel(row, _("{0} h", orderElement.getEffortAsString())); appendTimeTrackingButton(row, task); } - private String getEffort(OrderElement orderElement) { - SumChargedEffort sumChargedEffort = orderElement.getSumChargedEffort(); - EffortDuration effort = sumChargedEffort != null ? sumChargedEffort - .getTotalChargedEffort() : EffortDuration.zero(); - return _("{0} h", effort.toFormattedString()); - } - private String getProgress(OrderElement orderElement) { - AdvanceMeasurement lastAdvanceMeasurement = getLastAdvanceMeasurement(orderElement); + AdvanceMeasurement lastAdvanceMeasurement = orderElement + .getLastAdvanceMeasurement(); if (lastAdvanceMeasurement != null) { return MessageFormat.format("[{0} %] ({1})", lastAdvanceMeasurement.getValue(), @@ -98,17 +89,6 @@ public class MyTasksAreaController extends GenericForwardComposer { return ""; } - private AdvanceMeasurement getLastAdvanceMeasurement( - OrderElement orderElement) { - DirectAdvanceAssignment advanceAssignment = orderElement - .getReportGlobalAdvanceAssignment(); - if (advanceAssignment == null) { - return null; - } - return advanceAssignment - .getLastAdvanceMeasurement(); - } - private void appendTimeTrackingButton(Row row, final Task task) { EventListener trackTimeButtonListener = new EventListener() { @Override diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/IBoundUserService.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/IBoundUserService.java new file mode 100644 index 000000000..666879af2 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/IBoundUserService.java @@ -0,0 +1,33 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * Copyright (C) 2010-2011 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.ws.boundusers.api; + +/** + * Service for managing operations related with bound users. + * + * @author Manuel Rego Casasnovas + */ +public interface IBoundUserService { + + TaskListDTO getTasks(); + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskDTO.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskDTO.java new file mode 100644 index 000000000..fd2790293 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskDTO.java @@ -0,0 +1,78 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.ws.boundusers.api; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.libreplan.business.planner.entities.Task; + +/** + * DTO for a {@link Task} entity. + * + * @author Manuel Rego Casasnovas + */ +@XmlRootElement(name = "task") +public class TaskDTO { + + @XmlAttribute + public String name; + + @XmlAttribute + public String code; + + @XmlAttribute(name = "project-name") + public String projectName; + + @XmlAttribute(name = "start-date") + public XMLGregorianCalendar startDate; + + @XmlAttribute(name = "end-date") + public XMLGregorianCalendar endDate; + + @XmlAttribute(name = "progress-value") + public BigDecimal progressValue; + + @XmlAttribute(name = "progress-date") + public XMLGregorianCalendar progressDate; + + @XmlAttribute + public String effort; + + public TaskDTO() {} + + public TaskDTO(String name, String code, String projectName, + XMLGregorianCalendar startDate, XMLGregorianCalendar endDate, + BigDecimal progressValue, XMLGregorianCalendar progressDate, + String effort) { + this.name = name; + this.code = code; + this.projectName = projectName; + this.startDate = startDate; + this.endDate = endDate; + this.progressValue = progressValue; + this.progressDate = progressDate; + this.effort = effort; + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskListDTO.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskListDTO.java new file mode 100644 index 000000000..cf67a4ce0 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/TaskListDTO.java @@ -0,0 +1,47 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.ws.boundusers.api; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.libreplan.business.planner.entities.Task; + +/** + * DTO for a list of {@link Task} entities. + * + * @author Manuel Rego Casasnovas + */ +@XmlRootElement(name = "task-list") +public class TaskListDTO { + + @XmlElement(name = "task") + public List tasks = new ArrayList(); + + public TaskListDTO() {} + + public TaskListDTO(List tasks) { + this.tasks = tasks; + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/package-info.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/package-info.java new file mode 100644 index 000000000..6f4fc9079 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/api/package-info.java @@ -0,0 +1,28 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/** + * Specification of namespace for REST-based services. + * + * @author Manuel Rego Casasnovas + */ +@javax.xml.bind.annotation.XmlSchema(elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = WSCommonGlobalNames.REST_NAMESPACE) +package org.libreplan.ws.boundusers.api; + +import org.libreplan.ws.common.api.WSCommonGlobalNames; diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/BoundUserServiceREST.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/BoundUserServiceREST.java new file mode 100644 index 000000000..3249460e8 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/BoundUserServiceREST.java @@ -0,0 +1,52 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.ws.boundusers.impl; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.libreplan.web.users.dashboard.IMyTasksAreaModel; +import org.libreplan.ws.boundusers.api.IBoundUserService; +import org.libreplan.ws.boundusers.api.TaskListDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * REST-based implementation of {@link IBoundUserService}; + * + * @author Manuel Rego Casasnovas + */ +@Path("/bounduser/") +@Produces("application/xml") +@Service("boundUserServiceREST") +public class BoundUserServiceREST implements IBoundUserService { + + @Autowired + private IMyTasksAreaModel myTasksAreaModel; + + @Override + @GET + @Path("/mytasks/") + public TaskListDTO getTasks() { + return TaskConverter.toDTO(myTasksAreaModel.getTasks()); + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/TaskConverter.java b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/TaskConverter.java new file mode 100644 index 000000000..6feac7ca4 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/boundusers/impl/TaskConverter.java @@ -0,0 +1,74 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.ws.boundusers.impl; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.joda.time.LocalDate; +import org.libreplan.business.advance.entities.AdvanceMeasurement; +import org.libreplan.business.orders.entities.OrderElement; +import org.libreplan.business.planner.entities.Task; +import org.libreplan.ws.boundusers.api.TaskDTO; +import org.libreplan.ws.boundusers.api.TaskListDTO; +import org.libreplan.ws.common.impl.DateConverter; + +/** + * Converter from/to {@link Task} related entities to/from DTOs. + * + * @author Manuel Rego Casasnovas + */ +public final class TaskConverter { + + private TaskConverter() { + } + + public final static TaskDTO toDTO(Task task) { + OrderElement orderElement = task.getOrderElement(); + + AdvanceMeasurement lastAdvanceMeasurement = orderElement + .getLastAdvanceMeasurement(); + BigDecimal progressValue = null; + LocalDate progressDate = null; + if (lastAdvanceMeasurement != null) { + progressValue = lastAdvanceMeasurement.getValue(); + progressDate = lastAdvanceMeasurement.getDate(); + } + + return new TaskDTO(task.getName(), orderElement.getCode(), orderElement + .getOrder().getName(), + DateConverter.toXMLGregorianCalendar(task.getStartDate()), + DateConverter.toXMLGregorianCalendar(task.getEndDate()), + progressValue, + DateConverter.toXMLGregorianCalendar(progressDate), + orderElement.getEffortAsString()); + } + + public final static TaskListDTO toDTO(Collection tasks) { + List dtos = new ArrayList(); + for (Task each : tasks) { + dtos.add(toDTO(each)); + } + return new TaskListDTO(dtos); + } + +} diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml index f55c52312..da70d704a 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml @@ -73,6 +73,7 @@ + diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml index 457f0deaa..1f17b75b7 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml @@ -13,6 +13,12 @@ entry-point-ref="customAuthenticationEntryPoint"> + +