| 1 28 29 package com.opencms.workplace; 30 31 import org.opencms.file.CmsGroup; 32 import org.opencms.file.CmsObject; 33 import org.opencms.file.CmsProject; 34 import org.opencms.file.CmsRequestContext; 35 import org.opencms.file.CmsUser; 36 import org.opencms.main.CmsException; 37 import org.opencms.util.CmsDateUtil; 38 import org.opencms.workflow.CmsTask; 39 import org.opencms.workflow.CmsTaskService; 40 41 import com.opencms.legacy.CmsLegacyException; 42 import com.opencms.template.A_CmsXmlContent; 43 44 import java.lang.reflect.InvocationTargetException ; 45 import java.lang.reflect.Method ; 46 import java.util.ArrayList ; 47 import java.util.Calendar ; 48 import java.util.Date ; 49 import java.util.GregorianCalendar ; 50 import java.util.Hashtable ; 51 import java.util.List ; 52 53 import org.w3c.dom.Element ; 54 55 66 67 public class CmsTaskList extends A_CmsWpElement implements I_CmsWpElement { 68 69 86 87 public Object handleSpecialWorkplaceTag( 88 CmsObject cms, 89 Element n, 90 A_CmsXmlContent doc, 91 Object callingObject, 92 Hashtable parameters, 93 CmsXmlLanguageFile lang) throws CmsException { 94 95 CmsXmlWpTemplateFile listdef = getTaskListDefinitions(cms); 97 CmsRequestContext context = cms.getRequestContext(); 98 String listMethod = n.getAttribute("method"); 99 100 Method callingMethod = null; 102 List list = new ArrayList (); 103 try { 104 callingMethod = callingObject.getClass().getMethod( 105 listMethod, 106 new Class [] {CmsObject.class, CmsXmlLanguageFile.class}); 107 list = (List )callingMethod.invoke(callingObject, new Object [] {cms, lang}); 108 } catch (NoSuchMethodException exc) { 109 110 throwException("Could not find method " 112 + listMethod 113 + " in calling class " 114 + callingObject.getClass().getName() 115 + " for generating lasklist content.", CmsLegacyException.C_NOT_FOUND); 116 } catch (InvocationTargetException targetEx) { 117 118 Throwable e = targetEx.getTargetException(); 121 if (!(e instanceof CmsException)) { 122 123 throwException("User method " 125 + listMethod 126 + " in calling class " 127 + callingObject.getClass().getName() 128 + " throwed an exception. " 129 + e); 130 } else { 131 132 throw (CmsException)e; 135 } 136 } catch (Exception exc2) { 137 throwException("User method " 138 + listMethod 139 + " in calling class " 140 + callingObject.getClass().getName() 141 + " was found but could not be invoked. " 142 + exc2, CmsLegacyException.C_XML_NO_USER_METHOD); 143 } 144 145 146 StringBuffer result = new StringBuffer (); 147 String priority; 148 String projectname; 149 String stateIcon; 150 String style; 151 String contextmenu; 152 long startTime; 153 long timeout; 154 GregorianCalendar cal = new GregorianCalendar (); 155 cal.setTime(new Date (System.currentTimeMillis())); 156 cal.set(Calendar.HOUR, 0); 157 cal.set(Calendar.MINUTE, 0); 158 cal.set(Calendar.SECOND, 0); 159 cal.set(Calendar.MILLISECOND, 0); 160 GregorianCalendar newcal = new GregorianCalendar ( 161 cal.get(Calendar.YEAR), 162 cal.get(Calendar.MONTH), 163 cal.get(Calendar.DAY_OF_MONTH), 164 0, 165 0, 166 0); 167 long now = newcal.getTime().getTime(); 168 CmsTaskService taskService = cms.getTaskService(); 169 for (int i = 0; i < list.size(); i++) { 170 171 CmsTask task = (CmsTask)list.get(i); 173 CmsProject project = null; 174 projectname = "?"; 175 try { 176 project = taskService.readProject(task); 177 } catch (Exception exc) { 178 179 continue; 181 } 182 if ((project == null) || (project.getFlags() == com.opencms.core.I_CmsConstants.C_PROJECT_STATE_ARCHIVE)) { 183 184 continue; 186 } 187 projectname = project.getName(); 188 priority = listdef.getProcessedDataValue("priority" + task.getPriority(), callingObject); 189 startTime = task.getStartTime().getTime(); 190 timeout = task.getTimeOut().getTime(); 191 listdef.setData("taskid", task.getId() + ""); 192 listdef.setData("count", i + ""); 193 194 CmsUser owner = null; 197 String ownerName = ""; 198 try { 199 owner = taskService.readOwner(task); 200 ownerName = owner.getName(); 201 } catch (Exception exc) { 202 203 } 205 CmsUser editor = null; 206 try { 207 editor = taskService.readAgent(task); 208 } catch (Exception exc) { 209 210 } 212 CmsGroup role = null; 213 String roleName = ""; 214 try { 215 role = taskService.readGroup(task); 216 roleName = role.getName(); 217 } catch (Exception exc) { 218 219 } 221 boolean isOwner = context.currentUser().equals(owner); 222 boolean isEditor = context.currentUser().equals(editor); 223 boolean isInRole = false; 224 try { 225 isInRole = cms.userInGroup(context.currentUser().getName(), roleName); 226 } catch (Exception exc) { 227 228 } 230 231 if (task.getState() == CmsTaskService.TASK_STATE_ENDED) { 233 if (isOwner) { 234 contextmenu = "task1"; 235 } else { 236 if (isEditor) { 237 contextmenu = "task2"; 238 } else { 239 if (isInRole) { 240 contextmenu = "task3"; 241 } else { 242 contextmenu = "task3"; 243 } 244 } 245 } 246 listdef.setData("contextmenu", contextmenu); 247 stateIcon = listdef.getProcessedDataValue("ok", callingObject); 248 style = listdef.getProcessedDataValue("style_ok", callingObject); 249 } else { 250 if (task.getPercentage() == 0) { 251 if (isOwner && isEditor) { 252 contextmenu = "task4"; 253 } else { 254 if (isOwner) { 255 contextmenu = "task5"; 256 } else { 257 if (isEditor) { 258 contextmenu = "task6"; 259 } else { 260 if (isInRole) { 261 contextmenu = "task7"; 262 } else { 263 contextmenu = "task8"; 264 } 265 } 266 } 267 } 268 listdef.setData("contextmenu", contextmenu); 269 if (timeout < now) { 270 stateIcon = listdef.getProcessedDataValue("alert", callingObject); 271 style = listdef.getProcessedDataValue("style_alert", callingObject); 272 } else { 273 stateIcon = listdef.getProcessedDataValue("new", callingObject); 274 style = listdef.getProcessedDataValue("style_new", callingObject); 275 } 276 } else { 277 if (isOwner && isEditor) { 278 contextmenu = "task9"; 279 } else { 280 if (isOwner) { 281 contextmenu = "task10"; 282 } else { 283 if (isEditor) { 284 contextmenu = "task11"; 285 } else { 286 if (isInRole) { 287 contextmenu = "task12"; 288 } else { 289 contextmenu = "task13"; 290 } 291 } 292 } 293 } 294 listdef.setData("contextmenu", contextmenu); 295 if (timeout < now) { 296 stateIcon = listdef.getProcessedDataValue("alert", callingObject); 297 style = listdef.getProcessedDataValue("style_alert", callingObject); 298 } else { 299 stateIcon = listdef.getProcessedDataValue("activ", callingObject); 300 style = listdef.getProcessedDataValue("style_activ", callingObject); 301 } 302 } 303 } 304 String agent = ""; 305 String group = ""; 306 String due = ""; 307 String from = ""; 308 try { 309 agent = taskService.readAgent(task).getName(); 310 } catch (Exception exc) { 311 312 } 314 try { 315 group = taskService.readGroup(task).getName(); 316 } catch (Exception exc) { 317 318 } 320 try { 321 due = CmsDateUtil.getDateShort(timeout); 322 } catch (Exception exc) { 323 324 } 326 try { 327 from = CmsDateUtil.getDateShort(startTime); 328 } catch (Exception exc) { 329 330 } 332 333 listdef.setData("stateicon", stateIcon); 335 listdef.setData("style", style); 336 listdef.setData("priority", priority); 337 listdef.setData("taskid", task.getId() + ""); 338 listdef.setData("task", task.getName()); 339 listdef.setData("foruser", agent); 340 listdef.setData("forrole", group); 341 listdef.setData("actuator", ownerName); 342 listdef.setData("due", due); 343 listdef.setData("from", from); 344 listdef.setData("project", projectname); 345 result.append(listdef.getProcessedDataValue("defaulttasklist", callingObject, parameters)); 346 } 347 return result.toString(); 348 } 349 350 360 361 public boolean isCacheable( 362 CmsObject cms, 363 String templateFile, 364 String elementName, 365 Hashtable parameters, 366 String templateSelector) { 367 368 return false; 369 } 370 } 371 | Popular Tags |