001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 */
018package org.nuxeo.ecm.platform.task.dashboard;
019
020import java.util.Date;
021import java.util.List;
022import java.util.Locale;
023
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.DocumentRef;
026import org.nuxeo.ecm.platform.task.Task;
027import org.nuxeo.ecm.platform.task.TaskComment;
028
029/**
030 * Dashboard item implementation.
031 *
032 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a>
033 * @since 5.5
034 */
035public class DashBoardItemImpl extends AbstractDashBoardItemImpl implements DashBoardItem {
036
037    private static final long serialVersionUID = 919752175741886376L;
038
039    protected final String id;
040
041    protected final String name;
042
043    protected final String description;
044
045    protected final Date startDate;
046
047    protected final Date dueDate;
048
049    protected final boolean expired;
050
051    protected final String directive;
052
053    protected final DocumentModel document;
054
055    protected final Task task;
056
057    protected String comment;
058
059    public DashBoardItemImpl(Task task, Locale locale) {
060        this(task, task.getDocument(), locale);
061    }
062
063    public DashBoardItemImpl(Task task, DocumentModel document, Locale locale) {
064        this.task = task;
065        this.document = document;
066        this.locale = locale;
067        id = task.getId();
068        name = task.getName();
069        description = task.getDescription();
070        dueDate = task.getDueDate();
071        startDate = task.getCreated();
072        directive = task.getDirective();
073        List<TaskComment> comments = task.getComments();
074        if (comments != null && !comments.isEmpty()) {
075            comment = comments.get(comments.size() - 1).getText();
076        } else {
077            comment = null;
078        }
079        if (dueDate != null) {
080            Date today = new Date();
081            expired = dueDate.before(today);
082        } else {
083            expired = false;
084        }
085    }
086
087    @Override
088    public String getComment() {
089        return comment;
090    }
091
092    @Override
093    public String getDescription() {
094        return description;
095    }
096
097    @Override
098    public DocumentRef getDocRef() {
099        return document.getRef();
100    }
101
102    @Override
103    public Date getDueDate() {
104        return dueDate;
105    }
106
107    @Override
108    public String getId() {
109        return id;
110    }
111
112    @Override
113    public Date getStartDate() {
114        return startDate;
115    }
116
117    @Override
118    public String getName() {
119        return name;
120    }
121
122    @Override
123    public String getDirective() {
124        return directive;
125    }
126
127    @Override
128    public DocumentModel getDocument() {
129        return document;
130    }
131
132    @Override
133    public boolean isExpired() {
134        return expired;
135    }
136
137    @Override
138    public Task getTask() {
139        return task;
140    }
141
142}