001/* 002 * (C) Copyright 2006-2012 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 * Nicolas Ulrich, Antoine Taillefer 016 * 017 */ 018 019package org.nuxeo.ecm.platform.task; 020 021import java.io.Serializable; 022import java.util.Date; 023import java.util.List; 024import java.util.Map; 025import java.util.Optional; 026 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.api.DocumentModel; 029import org.nuxeo.ecm.core.api.InstanceRef; 030import org.nuxeo.ecm.core.event.EventContext; 031 032/** 033 * @since 5.5 034 */ 035public interface Task extends Serializable { 036 037 /** 038 * @since 5.6 039 */ 040 String TASK_PROVIDER_KEY = "taskProviderId"; 041 042 DocumentModel getDocument(); 043 044 String getId(); 045 046 /** 047 * @deprecated 048 * @since 5.8, getTargetDocumentsIds() should be used instead 049 */ 050 @Deprecated 051 String getTargetDocumentId(); 052 053 List<String> getActors(); 054 055 String getInitiator(); 056 057 String getName(); 058 059 /** 060 * @since 5.6 061 */ 062 String getType(); 063 064 /** 065 * @since 5.6 066 */ 067 String getProcessId(); 068 069 /** 070 * @since 7.4 071 */ 072 String getProcessName(); 073 074 String getDescription(); 075 076 String getDirective(); 077 078 List<TaskComment> getComments(); 079 080 String getVariable(String key); 081 082 Date getDueDate(); 083 084 Date getCreated(); 085 086 Boolean isCancelled(); 087 088 Boolean isOpened(); 089 090 Boolean hasEnded(); 091 092 Boolean isAccepted(); 093 094 Map<String, String> getVariables(); 095 096 void setActors(List<String> actors); 097 098 void setInitiator(String initiator); 099 100 /** 101 * @deprecated 102 * @since 5.8, setTargetDocumentsIds(List<String> ids) should be used instead 103 */ 104 @Deprecated 105 void setTargetDocumentId(String targetDocumentId); 106 107 void setName(String name); 108 109 /** 110 * @since 5.6 111 */ 112 void setType(String type); 113 114 /** 115 * @since 5.6 116 */ 117 void setProcessId(String processId); 118 119 /** 120 * @since 7.4 121 */ 122 void setProcessName(String processName); 123 124 void setDescription(String description); 125 126 void setDirective(String directive); 127 128 void setVariable(String key, String value); 129 130 void setDueDate(Date dueDate); 131 132 void setCreated(Date created); 133 134 void setAccepted(Boolean accepted); 135 136 void setVariables(Map<String, String> variables); 137 138 void addComment(String author, String text); 139 140 void cancel(CoreSession coreSession); 141 142 void end(CoreSession coreSession); 143 144 enum TaskVariableName { 145 needi18n, taskType 146 }; 147 148 /** 149 * @since 5.8 150 */ 151 List<String> getDelegatedActors(); 152 153 /** 154 * @since 5.8 155 */ 156 void setDelegatedActors(List<String> delegatedActors); 157 158 /** 159 * @since 5.8 160 */ 161 List<String> getTargetDocumentsIds(); 162 163 /** 164 * The first id on the list is also set as 'targetDocumentId' 165 * 166 * @since 5.8 167 */ 168 void setTargetDocumentsIds(List<String> ids); 169 170 /** 171 * Tasks instance is transmitted as an instance reference which prevent to serialize 172 * the document content as part of the listener work. 173 * 174 * @since 7.10 175 */ 176 public static Optional<Task> optionalTask(EventContext context) { 177 InstanceRef ref = (InstanceRef) context.getProperty(TaskService.TASK_INSTANCE_EVENT_PROPERTIES_KEY); 178 if (ref == null) { 179 return Optional.empty(); 180 } 181 Task task = ((DocumentModel) ref.reference()).getAdapter(Task.class); 182 return Optional.of(task); 183 } 184}