001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 */
016package org.nuxeo.ecm.platform.task.dashboard;
017
018import java.util.Date;
019import java.util.List;
020import java.util.Locale;
021
022import org.nuxeo.ecm.core.api.DocumentModel;
023import org.nuxeo.ecm.core.api.DocumentRef;
024import org.nuxeo.ecm.platform.task.Task;
025import org.nuxeo.ecm.platform.task.TaskComment;
026
027/**
028 * Dashboard item implementation.
029 *
030 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a>
031 * @since 5.5
032 */
033public class DashBoardItemImpl extends AbstractDashBoardItemImpl implements DashBoardItem {
034
035    private static final long serialVersionUID = 919752175741886376L;
036
037    protected final String id;
038
039    protected final String name;
040
041    protected final String description;
042
043    protected final Date startDate;
044
045    protected final Date dueDate;
046
047    protected final boolean expired;
048
049    protected final String directive;
050
051    protected final DocumentModel document;
052
053    protected final Task task;
054
055    protected String comment;
056
057    public DashBoardItemImpl(Task task, Locale locale) {
058        this(task, task.getDocument(), locale);
059    }
060
061    public DashBoardItemImpl(Task task, DocumentModel document, Locale locale) {
062        this.task = task;
063        this.document = document;
064        this.locale = locale;
065        id = task.getId();
066        name = task.getName();
067        description = task.getDescription();
068        dueDate = task.getDueDate();
069        startDate = task.getCreated();
070        directive = task.getDirective();
071        List<TaskComment> comments = task.getComments();
072        if (comments != null && !comments.isEmpty()) {
073            comment = comments.get(comments.size() - 1).getText();
074        } else {
075            comment = null;
076        }
077        if (dueDate != null) {
078            Date today = new Date();
079            expired = dueDate.before(today);
080        } else {
081            expired = false;
082        }
083    }
084
085    @Override
086    public String getComment() {
087        return comment;
088    }
089
090    @Override
091    public String getDescription() {
092        return description;
093    }
094
095    @Override
096    public DocumentRef getDocRef() {
097        return document.getRef();
098    }
099
100    @Override
101    public Date getDueDate() {
102        return dueDate;
103    }
104
105    @Override
106    public String getId() {
107        return id;
108    }
109
110    @Override
111    public Date getStartDate() {
112        return startDate;
113    }
114
115    @Override
116    public String getName() {
117        return name;
118    }
119
120    @Override
121    public String getDirective() {
122        return directive;
123    }
124
125    @Override
126    public DocumentModel getDocument() {
127        return document;
128    }
129
130    @Override
131    public boolean isExpired() {
132        return expired;
133    }
134
135    @Override
136    public Task getTask() {
137        return task;
138    }
139
140}