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 *     ldoguin
016 */
017package org.nuxeo.ecm.platform.routing.dm.adapter;
018
019import java.util.Calendar;
020import java.util.Date;
021import java.util.List;
022
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.platform.routing.dm.api.RoutingTaskConstants;
025
026/**
027 * @deprecated since 5.9.2 - Use only routes of type 'graph'
028 */
029@Deprecated
030public class TaskStepImpl implements TaskStep {
031
032    protected DocumentModel doc;
033
034    public TaskStepImpl(DocumentModel doc) {
035        this.doc = doc;
036    }
037
038    @Override
039    public DocumentModel getDocument() {
040        return doc;
041    }
042
043    @Override
044    public String getId() {
045        return doc.getId();
046    }
047
048    @Override
049    public List<String> getActors() {
050        return getPropertyValue(RoutingTaskConstants.TASK_STEP_ACTORS_PROPERTY_NAME);
051    }
052
053    @Override
054    public String getName() {
055        return doc.getTitle();
056    }
057
058    @Override
059    public String getDirective() {
060        return getPropertyValue(RoutingTaskConstants.TASK_STEP_DIRECTIVE_PROPERTY_NAME);
061    }
062
063    @SuppressWarnings("unchecked")
064    @Override
065    public List<String> getComments() {
066        return (List<String>) getPropertyValue(RoutingTaskConstants.TASK_STEP_COMMENTS_PROPERTY_NAME);
067    }
068
069    @Override
070    public Date getDueDate() {
071        return getDatePropertyValue(RoutingTaskConstants.TASK_STEP_DUE_DATE_PROPERTY_NAME);
072    }
073
074    @Override
075    public Boolean hasAutomaticValidation() {
076        return getPropertyValue(RoutingTaskConstants.TASK_STEP_AUTOMATIC_VALIDATION_PROPERTY_NAME);
077    }
078
079    @SuppressWarnings("unchecked")
080    protected <T> T getPropertyValue(String propertyName) {
081        return (T) doc.getPropertyValue(propertyName);
082    }
083
084    protected Date getDatePropertyValue(String propertyName) {
085        Calendar cal = (Calendar) doc.getPropertyValue(propertyName);
086        if (cal != null) {
087            return cal.getTime();
088        }
089        return null;
090    }
091
092}