| | 157 | public String getTimeValueForJS(String dateToStart) |
|---|
| | 158 | { |
|---|
| | 159 | PnCalendar cal = new PnCalendar(); |
|---|
| | 160 | if (dateToStart != null) { |
|---|
| | 161 | startDate = new Date(Long.parseLong(dateToStart)); |
|---|
| | 162 | } else { |
|---|
| | 163 | cal.setTime(new Date()); |
|---|
| | 164 | startDate = cal.startOfWeek(); |
|---|
| | 165 | } |
|---|
| | 166 | cal.setTime(startDate); |
|---|
| | 167 | cal.add(PnCalendar.DATE, -7); |
|---|
| | 168 | scrollBackStartDate=cal.getTime(); |
|---|
| | 169 | |
|---|
| | 170 | cal.setTime(startDate); |
|---|
| | 171 | cal.add(PnCalendar.DATE, 7); |
|---|
| | 172 | scrollForwardStartDate=cal.getTime(); |
|---|
| | 173 | |
|---|
| | 174 | endDate = cal.endOfDay(); |
|---|
| | 175 | |
|---|
| | 176 | getDateHeaders(); |
|---|
| | 177 | setDateValues(); |
|---|
| | 178 | String timesValueString=""; |
|---|
| | 179 | for (Iterator it = dateLongNames.iterator(); it.hasNext();) { |
|---|
| | 180 | String timeValue = (String)it.next(); |
|---|
| | 181 | timesValueString+=timeValue+"" + (it.hasNext() ? "," : ""); |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | return timesValueString; |
|---|
| | 185 | } |
|---|
| | 186 | public void setDateValues(){ |
|---|
| | 187 | dateValues = new HashMap(); |
|---|
| | 188 | summaryDateValues = new HashMap(); |
|---|
| | 189 | |
|---|
| | 190 | PnCalendar cal = new PnCalendar(); |
|---|
| | 191 | DBBean db = new DBBean(); |
|---|
| | 192 | try { |
|---|
| | 193 | db.prepareStatement( |
|---|
| | 194 | "select" + |
|---|
| | 195 | " aw.object_id, aw.work_start, aw.work_end, aw.work, aw.work_units "+ |
|---|
| | 196 | "from " + |
|---|
| | 197 | " pn_assignment_work aw," + |
|---|
| | 198 | " pn_object o "+ |
|---|
| | 199 | "where " + |
|---|
| | 200 | " aw.person_id = ? " + |
|---|
| | 201 | " and aw.work_start <= ? " + |
|---|
| | 202 | " and aw.work_end >= ? " + |
|---|
| | 203 | " and o.object_id = aw.object_id " + |
|---|
| | 204 | " and o.record_status = 'A' " |
|---|
| | 205 | ); |
|---|
| | 206 | |
|---|
| | 207 | db.pstmt.setString(1, SessionManager.getUser().getID()); |
|---|
| | 208 | DatabaseUtils.setTimestamp(db.pstmt, 2, endDate); |
|---|
| | 209 | DatabaseUtils.setTimestamp(db.pstmt, 3, startDate); |
|---|
| | 210 | |
|---|
| | 211 | db.executePrepared(); |
|---|
| | 212 | |
|---|
| | 213 | //Iterate through all the assignment work and assign it to the |
|---|
| | 214 | //correct day in our map. |
|---|
| | 215 | while (db.result.next()) { |
|---|
| | 216 | String objectID = db.result.getString(1); |
|---|
| | 217 | Date workStart = DatabaseUtils.getTimestamp(db.result, 2); |
|---|
| | 218 | Date workEnd = DatabaseUtils.getTimestamp(db.result, 3); |
|---|
| | 219 | TimeQuantity work = DatabaseUtils.getTimeQuantity(db.result, 4, 5); |
|---|
| | 220 | |
|---|
| | 221 | Date endOfDay = cal.endOfDay(workStart); |
|---|
| | 222 | if (workEnd.after(endOfDay)) { |
|---|
| | 223 | //This work occurs on two days according to our current time |
|---|
| | 224 | //zone. Separate it accordingly. |
|---|
| | 225 | |
|---|
| | 226 | //We'll keep track of all the work we are recording to make |
|---|
| | 227 | //sure it is the same as what is in the database |
|---|
| | 228 | TimeQuantity totalWork = new TimeQuantity(0, TimeQuantityUnit.HOUR); |
|---|
| | 229 | |
|---|
| | 230 | //Figure out how much work is now done on the first day |
|---|
| | 231 | AssignmentDate dateID = new AssignmentDate(cal.startOfDay(workStart), objectID); |
|---|
| | 232 | TimeQuantity dayWork = new DateRange(workStart, endOfDay).getTimeQuantity(TimeQuantityUnit.HOUR, 2); |
|---|
| | 233 | totalWork = totalWork.add(dayWork); |
|---|
| | 234 | |
|---|
| | 235 | addWorkToDay(dateValues, summaryDateValues, dateID, dayWork); |
|---|
| | 236 | |
|---|
| | 237 | //Now figure out how much work was done on the second day |
|---|
| | 238 | Date startOfSecondDay = cal.startOfDay(workEnd); |
|---|
| | 239 | dateID = new AssignmentDate(startOfSecondDay, objectID); |
|---|
| | 240 | dayWork = new DateRange(startOfSecondDay, workEnd).getTimeQuantity(TimeQuantityUnit.HOUR, 2); |
|---|
| | 241 | totalWork = totalWork.add(dayWork); |
|---|
| | 242 | |
|---|
| | 243 | addWorkToDay(dateValues, summaryDateValues, dateID, dayWork); |
|---|
| | 244 | |
|---|
| | 245 | //Make sure that the amount of work we assigned matches what's in the database |
|---|
| | 246 | assert totalWork.equals(work) : "Unexpected error: Work " + |
|---|
| | 247 | "spanned multiple days. When we attempted to split that " + |
|---|
| | 248 | "work, our splitting algorithm didn't yield the same " + |
|---|
| | 249 | "work as the database indicated that we should have."; |
|---|
| | 250 | } else { |
|---|
| | 251 | //All work is on the same day |
|---|
| | 252 | AssignmentDate dateID = new AssignmentDate(cal.startOfDay(workStart), objectID); |
|---|
| | 253 | addWorkToDay(dateValues, summaryDateValues, dateID, work); |
|---|
| | 254 | } |
|---|
| | 255 | } |
|---|
| | 256 | }catch(SQLException e){ |
|---|
| | 257 | e.printStackTrace(); |
|---|
| | 258 | } finally { |
|---|
| | 259 | db.release(); |
|---|
| | 260 | } |
|---|
| | 261 | } |
|---|
| | 262 | public void addWorkToDay(Map dateValues, Map summaryDateValues, AssignmentDate dateID, TimeQuantity work) { |
|---|
| | 263 | //First, add the work to the summary we are collecting for that day. |
|---|
| | 264 | TimeQuantity existingSummaryWork = (TimeQuantity)summaryDateValues.get(dateID.date); |
|---|
| | 265 | if (existingSummaryWork == null) { |
|---|
| | 266 | summaryDateValues.put(dateID.date, work); |
|---|
| | 267 | } else { |
|---|
| | 268 | summaryDateValues.put(dateID.date, existingSummaryWork.add(work)); |
|---|
| | 269 | } |
|---|
| | 270 | |
|---|
| | 271 | //Second, add the work for this object/day |
|---|
| | 272 | TimeQuantity existingDayWork = (TimeQuantity)dateValues.get(dateID); |
|---|
| | 273 | if (existingDayWork != null) { |
|---|
| | 274 | work = work.add(existingDayWork); |
|---|
| | 275 | } |
|---|
| | 276 | |
|---|
| | 277 | dateValues.put(dateID, work); |
|---|
| | 278 | } |
|---|
| | 279 | /** |
|---|
| | 280 | * To get the dataHeaders list. by Nilesh |
|---|
| | 281 | * |
|---|
| | 282 | */ |
|---|
| | 283 | |
|---|
| | 284 | public void getDateHeaders() { |
|---|
| | 285 | PnCalendar cal = new PnCalendar(); |
|---|
| | 286 | dateHeaders =new LinkedList(); |
|---|
| | 287 | dateLongNames = new ArrayList(); |
|---|
| | 288 | |
|---|
| | 289 | //Iterate through 7 days, storing a header for each |
|---|
| | 290 | DateFormat dateFormat = SessionManager.getUser().getDateFormatter(); |
|---|
| | 291 | SimpleDateFormat dayOfWeekFormatter = new SimpleDateFormat("EEE"); |
|---|
| | 292 | //sjmittal: please set the timezone for fix of bfd 2897 |
|---|
| | 293 | dayOfWeekFormatter.setTimeZone(cal.getTimeZone()); |
|---|
| | 294 | cal.setTime(startDate); |
|---|
| | 295 | for (int i = 0; i < 7; i++) { |
|---|
| | 296 | DateHeader dh = new DateHeader(); |
|---|
| | 297 | dh.date = dateFormat.formatDate(cal.getTime(), java.text.DateFormat.SHORT); |
|---|
| | 298 | dh.dayOfWeek = dayOfWeekFormatter.format(cal.getTime()); |
|---|
| | 299 | dateHeaders.add(dh); |
|---|
| | 300 | dateLongNames.add(String.valueOf(cal.getTime().getTime())); |
|---|
| | 301 | cal.add(Calendar.DATE, 1); |
|---|
| | 302 | } |
|---|
| | 303 | } |
|---|
| | 304 | public void getAssignments(String objectID1) throws PersistenceException { |
|---|
| | 305 | String objectID = objectID1; |
|---|
| | 306 | String[] objectIDList = {objectID1}; |
|---|
| | 307 | assignments = null; |
|---|
| | 308 | |
|---|
| | 309 | String personId = SessionManager.getUser().getID(); |
|---|
| | 310 | if (!Validator.isBlankOrNull(objectID)) { |
|---|
| | 311 | //sjmittal: |
|---|
| | 312 | //this has been click for capture work so we are loading |
|---|
| | 313 | //assignments from pn_assignment table. |
|---|
| | 314 | //if no assignment is present is creates a dummy assignment object in memory |
|---|
| | 315 | //and the work against that is logged only in the pn_assignment_work table |
|---|
| | 316 | |
|---|
| | 317 | //objectIDList = request.getParameterValues("objectID"); |
|---|
| | 318 | FinderFilterList filters = new FinderFilterList(); |
|---|
| | 319 | filters.setSelected(true); |
|---|
| | 320 | AssignmentManager mgr = new AssignmentManager(); |
|---|
| | 321 | |
|---|
| | 322 | if (objectIDList.length == 1) { |
|---|
| | 323 | TextFilter objectIDFilter = new TextFilter("objectID", AssignmentFinder.OBJECT_ID_COLUMN, false); |
|---|
| | 324 | objectIDFilter.setSelected(true); |
|---|
| | 325 | objectIDFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 326 | objectIDFilter.setValue(objectID); |
|---|
| | 327 | filters.add(objectIDFilter); |
|---|
| | 328 | } else { |
|---|
| | 329 | StringDomainFilter filter = new StringDomainFilter("objectID", "", AssignmentFinder.OBJECT_ID_COLUMN, (TextComparator)TextComparator.EQUALS); |
|---|
| | 330 | filter.setSelected(true); |
|---|
| | 331 | filter.setSelectedValues(objectIDList); |
|---|
| | 332 | |
|---|
| | 333 | filters.add(filter); |
|---|
| | 334 | } |
|---|
| | 335 | |
|---|
| | 336 | mgr.setPersonID(personId); |
|---|
| | 337 | |
|---|
| | 338 | mgr.addFilters(filters); |
|---|
| | 339 | mgr.loadAssignments(); |
|---|
| | 340 | assignments = mgr.getAssignments(); |
|---|
| | 341 | showFilterPane= new Boolean(false); |
|---|
| | 342 | } else { |
|---|
| | 343 | //sjmittal: |
|---|
| | 344 | // this has been clicked from the timesheet module |
|---|
| | 345 | // we need to get all the assignments and activities for this person |
|---|
| | 346 | // best is to fetch it from pn_assignment_work as all the work |
|---|
| | 347 | //is stored in this table |
|---|
| | 348 | Iterator iter = dateValues.keySet().iterator(); |
|---|
| | 349 | //get all the object ids against which work has been logged |
|---|
| | 350 | //in the timesheet period |
|---|
| | 351 | Set<String> objectIdSet = new HashSet<String>(); |
|---|
| | 352 | while(iter.hasNext()) { |
|---|
| | 353 | AssignmentDate aDate = (AssignmentDate) iter.next(); |
|---|
| | 354 | TimeQuantity work = (TimeQuantity) dateValues.get(aDate); |
|---|
| | 355 | objectIdSet.add(aDate.id); |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | Object[] srcArray = objectIdSet.toArray(); |
|---|
| | 359 | //populate the objectIDList |
|---|
| | 360 | objectIDList = new String[srcArray.length]; |
|---|
| | 361 | System.arraycopy(srcArray, 0, objectIDList, 0, srcArray.length); |
|---|
| | 362 | //here assignments is blank |
|---|
| | 363 | assignments = new ArrayList(); |
|---|
| | 364 | showFilterPane= new Boolean(true); |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | //passThru(model, "objectID"); |
|---|
| | 368 | |
|---|
| | 369 | assignmentMap = CollectionUtils.listToMap(assignments, new CollectionUtils.MapKeyLocator() { |
|---|
| | 370 | public Object getKey(Object listObject) { |
|---|
| | 371 | return ((Assignment)listObject).getObjectID(); |
|---|
| | 372 | } |
|---|
| | 373 | }); |
|---|
| | 374 | |
|---|
| | 375 | Map spaceIDMap = new HashMap(); |
|---|
| | 376 | Map nameMap = new HashMap(); |
|---|
| | 377 | Map typeMap = new HashMap(); |
|---|
| | 378 | //Load the name and space id for each object |
|---|
| | 379 | if (objectIDList.length > 0) { |
|---|
| | 380 | DBBean db = new DBBean(); |
|---|
| | 381 | try { |
|---|
| | 382 | //Construct where clause to match object ids |
|---|
| | 383 | String whereClause = " and ("; |
|---|
| | 384 | for (int i = 0; i < objectIDList.length; i++) { |
|---|
| | 385 | if (i > 0) { |
|---|
| | 386 | whereClause += " or "; |
|---|
| | 387 | } |
|---|
| | 388 | whereClause += " oname.object_id = " + objectIDList[i]; |
|---|
| | 389 | } |
|---|
| | 390 | whereClause += ")"; |
|---|
| | 391 | |
|---|
| | 392 | //needed for decoupling tasks from assignmment's work |
|---|
| | 393 | db.prepareStatement( |
|---|
| | 394 | "select /*+ USE_NL(o oname) USE_NL(oname spc) */ "+ |
|---|
| | 395 | " oname.object_id, "+ |
|---|
| | 396 | " oname.name, "+ |
|---|
| | 397 | " spc.space_id, "+ |
|---|
| | 398 | " o.object_type "+ |
|---|
| | 399 | // " coalesce(shp.space_id, spc.space_id) as space_id "+ |
|---|
| | 400 | "from "+ |
|---|
| | 401 | " pn_object o,"+ |
|---|
| | 402 | " pn_object_name oname, "+ |
|---|
| | 403 | // " pn_space_has_plan shp, "+ |
|---|
| | 404 | // " pn_plan_has_task pht, "+ |
|---|
| | 405 | " pn_object_space spc "+ |
|---|
| | 406 | "where "+ |
|---|
| | 407 | // " oname.object_id = pht.task_id(+) "+ |
|---|
| | 408 | // " and pht.plan_id = shp.plan_id(+) "+ |
|---|
| | 409 | " o.object_id = oname.object_id(+) "+ |
|---|
| | 410 | " and oname.object_id = spc.object_id(+) "+ |
|---|
| | 411 | whereClause |
|---|
| | 412 | ); |
|---|
| | 413 | db.executePrepared(); |
|---|
| | 414 | |
|---|
| | 415 | while (db.result.next()) { |
|---|
| | 416 | String currentObjectID = db.result.getString(1); |
|---|
| | 417 | nameMap.put(currentObjectID, db.result.getString(2)); |
|---|
| | 418 | spaceIDMap.put(currentObjectID, db.result.getString(3)); |
|---|
| | 419 | typeMap.put(currentObjectID, db.result.getString(4)); |
|---|
| | 420 | } |
|---|
| | 421 | } catch (SQLException sqle) { |
|---|
| | 422 | throw new PersistenceException("Unable to load names and space id's for objects", sqle); |
|---|
| | 423 | } finally { |
|---|
| | 424 | db.release(); |
|---|
| | 425 | } |
|---|
| | 426 | } |
|---|
| | 427 | |
|---|
| | 428 | //Now we will look through the id's to see if we have already loaded them, |
|---|
| | 429 | //if not, we can assume they aren't in the database. We'll create unsaved |
|---|
| | 430 | //assignments. |
|---|
| | 431 | boolean assignmentsNotLookedUp = ((Boolean ) showFilterPane).booleanValue(); |
|---|
| | 432 | for (int i = 0; i < objectIDList.length; i++) { |
|---|
| | 433 | String id = objectIDList[i]; |
|---|
| | 434 | Assignment assn = (Assignment)assignmentMap.get(id); |
|---|
| | 435 | |
|---|
| | 436 | //sjmittal: note currently assignments can be non tasks |
|---|
| | 437 | //also. In future more Assignment objects would be added |
|---|
| | 438 | //like forms. Each assignment type might have to be handled differently |
|---|
| | 439 | if (assn == null) { |
|---|
| | 440 | //try to get the assignment from the pn_assignment if not fetched before |
|---|
| | 441 | if (assignmentsNotLookedUp) { |
|---|
| | 442 | AssignmentFinder finder = new AssignmentFinder(); |
|---|
| | 443 | //add the object id |
|---|
| | 444 | TextFilter objectIDFilter = new TextFilter("objectID", AssignmentFinder.OBJECT_ID_COLUMN, false); |
|---|
| | 445 | objectIDFilter.setSelected(true); |
|---|
| | 446 | objectIDFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 447 | objectIDFilter.setValue(id); |
|---|
| | 448 | |
|---|
| | 449 | //add the space id |
|---|
| | 450 | TextFilter spaceIDFilter = new TextFilter("spaceID", AssignmentFinder.SPACE_ID_COLUMN, false); |
|---|
| | 451 | spaceIDFilter.setSelected(true); |
|---|
| | 452 | spaceIDFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 453 | spaceIDFilter.setValue((String)spaceIDMap.get(id)); |
|---|
| | 454 | |
|---|
| | 455 | //add the person id |
|---|
| | 456 | TextFilter personIDFilter = new TextFilter("personID", AssignmentFinder.PERSON_ID_COLUMN, false); |
|---|
| | 457 | personIDFilter.setSelected(true); |
|---|
| | 458 | personIDFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 459 | personIDFilter.setValue(personId); |
|---|
| | 460 | |
|---|
| | 461 | finder.addFinderFilter(objectIDFilter); |
|---|
| | 462 | finder.addFinderFilter(spaceIDFilter); |
|---|
| | 463 | finder.addFinderFilter(personIDFilter); |
|---|
| | 464 | //sjmittal: note this would at max return 1 row because objectid, spaceid, personid |
|---|
| | 465 | //consitute the primary key for this table |
|---|
| | 466 | Collection collection = finder.findAll(); |
|---|
| | 467 | if(collection.size() > 0) { |
|---|
| | 468 | assn = (Assignment) collection.iterator().next(); |
|---|
| | 469 | |
|---|
| | 470 | assignments.add(assn); |
|---|
| | 471 | assignmentMap.put(id, assn); |
|---|
| | 472 | } |
|---|
| | 473 | } |
|---|
| | 474 | } |
|---|
| | 475 | |
|---|
| | 476 | if(assn == null) { |
|---|
| | 477 | String type = (String) typeMap.get(id); |
|---|
| | 478 | |
|---|
| | 479 | if(ObjectType.TASK.equals(type)) { |
|---|
| | 480 | //create a new task type assignment |
|---|
| | 481 | //sjmittal: |
|---|
| | 482 | //this case would occur if the resource wants to enter time against |
|---|
| | 483 | //task that is not yet assigned to him. thus there is no assignment entry |
|---|
| | 484 | ScheduleEntryAssignment seAssn = new ScheduleEntryAssignment(); |
|---|
| | 485 | List assignmentLogs = new AssignmentWorkLogFinder().findByObjectIDPersonID(id, personId); |
|---|
| | 486 | TimeQuantity totalWork = AssignmentWorkLogUtils.getWorkLoggedForAssignee(assignmentLogs, personId); |
|---|
| | 487 | |
|---|
| | 488 | seAssn.setWork(totalWork); |
|---|
| | 489 | seAssn.setWorkComplete(totalWork); |
|---|
| | 490 | seAssn.setPercentComplete(new BigDecimal(1)); |
|---|
| | 491 | seAssn.setComplete(false); |
|---|
| | 492 | seAssn.setPercentAssigned(100); |
|---|
| | 493 | seAssn.setPersonID(personId); |
|---|
| | 494 | seAssn.setSpaceID((String)spaceIDMap.get(id)); |
|---|
| | 495 | seAssn.setObjectID(id); |
|---|
| | 496 | seAssn.setObjectName((String)nameMap.get(id)); |
|---|
| | 497 | |
|---|
| | 498 | assignments.add(seAssn); |
|---|
| | 499 | assignmentMap.put(id, seAssn); |
|---|
| | 500 | } else { |
|---|
| | 501 | //sjmittal: as of now no other assignment type needs to be created |
|---|
| | 502 | continue; |
|---|
| | 503 | } |
|---|
| | 504 | } |
|---|
| | 505 | else if(assn instanceof ScheduleEntryAssignment) { |
|---|
| | 506 | ScheduleEntryAssignment seAssn = (ScheduleEntryAssignment) assn; |
|---|
| | 507 | //load the underlying object ie the task |
|---|
| | 508 | TaskFinder finder = new TaskFinder(); |
|---|
| | 509 | ScheduleEntry task = finder.findObjectByID(id); |
|---|
| | 510 | |
|---|
| | 511 | //Don't create assignments for summary tasks. Their work is |
|---|
| | 512 | //created based on the work of their children. |
|---|
| | 513 | //sjmittal: I think the work for summary task gets added to to |
|---|
| | 514 | //the work performed by its children |
|---|
| | 515 | // if (task.getTaskType().equals(TaskType.SUMMARY)) { |
|---|
| | 516 | // errorReporter.addError( |
|---|
| | 517 | // PropertyProvider.get("prm.personal.assignments.summaryTaskWarning", |
|---|
| | 518 | // task.getNameMaxLength40()) |
|---|
| | 519 | // ); |
|---|
| | 520 | // continue; |
|---|
| | 521 | // } |
|---|
| | 522 | |
|---|
| | 523 | //bfd-set the plan finnished date |
|---|
| | 524 | seAssn.setEndTime(task.getEndTime()); |
|---|
| | 525 | } else if(assn instanceof ActivityAssignment) { |
|---|
| | 526 | //sjmittal: unlike task assignment as of now nothing special needs to be done here as of now |
|---|
| | 527 | continue; |
|---|
| | 528 | } else if(assn instanceof FormAssignment) { |
|---|
| | 529 | //sjmittal: unlike task assignment as of now nothing special needs to be done here as of now |
|---|
| | 530 | continue; |
|---|
| | 531 | } else { |
|---|
| | 532 | //remove the entries which cannot have work log againts them as of now |
|---|
| | 533 | assignments.remove(assignmentMap.remove(id)); |
|---|
| | 534 | } |
|---|
| | 535 | } |
|---|
| | 536 | |
|---|
| | 537 | |
|---|
| | 538 | } |
|---|
| | 539 | public String findUpdatedPercentComplete(HttpServletRequest request, String id) throws ParseException { |
|---|
| | 540 | errorReporter = new ErrorReporter(); |
|---|
| | 541 | Date earliestStartDate = null; |
|---|
| | 542 | Date latestStartDate = null; |
|---|
| | 543 | calendarProvider = (ResourceWorkingTimeCalendarProvider)request.getSession().getAttribute("updateAssignmentsCalendarProvider"); |
|---|
| | 544 | planIDMap = (Map)request.getSession().getAttribute("updateAssignmentsPlanIDMap"); |
|---|
| | 545 | //String otherparams=request.getParameter("otherparams"); |
|---|
| | 546 | |
|---|
| | 547 | //Find all of the work complete. |
|---|
| | 548 | //sjmittal added the validations for fix of bfd 3076 |
|---|
| | 549 | List workCompleteStrings = new ArrayList(); |
|---|
| | 550 | //Total work check. It should not be below zero. |
|---|
| | 551 | double totalRowWork = 0; |
|---|
| | 552 | for (int i = 0; i < 7; i++) { |
|---|
| | 553 | String workString = request.getParameter("wc"+i); |
|---|
| | 554 | Date startDate = new Date(Long.parseLong(request.getParameter("tv"+i))); |
|---|
| | 555 | |
|---|
| | 556 | if (Validator.isBlankOrNull(workString)) { |
|---|
| | 557 | continue; |
|---|
| | 558 | } else if (!Validator.isNumeric(workString)) { |
|---|
| | 559 | errorReporter.addError(new ErrorDescription(PropertyProvider.get("prm.resource.updatework.error.invalid.message", workString, DateFormat.getInstance().formatDate(startDate)))); |
|---|
| | 560 | continue; |
|---|
| | 561 | } else { |
|---|
| | 562 | workCompleteStrings.add(workString); |
|---|
| | 563 | if (earliestStartDate == null || earliestStartDate.after(startDate)) { |
|---|
| | 564 | earliestStartDate = startDate; |
|---|
| | 565 | } |
|---|
| | 566 | if (latestStartDate == null || latestStartDate.before(startDate)) { |
|---|
| | 567 | latestStartDate = startDate; |
|---|
| | 568 | } |
|---|
| | 569 | } |
|---|
| | 570 | totalRowWork += Double.parseDouble(workString); |
|---|
| | 571 | } |
|---|
| | 572 | //this is for all the rows ie tasks for that particular datecolumn |
|---|
| | 573 | double totalColumnWork = 0; |
|---|
| | 574 | String dateLongName = request.getParameter("dateLongName"); |
|---|
| | 575 | int totalAssignments = Integer.parseInt(request.getParameter("totalAssignments")); |
|---|
| | 576 | Date workDate = new Date(Long.parseLong(dateLongName)); |
|---|
| | 577 | for (int i = 0; i < totalAssignments; i++) { |
|---|
| | 578 | String workString = request.getParameter("dln"+i);; |
|---|
| | 579 | if (Validator.isBlankOrNull(workString)) { |
|---|
| | 580 | continue; |
|---|
| | 581 | } else if (!Validator.isNumeric(workString)) { |
|---|
| | 582 | //sjmittal: this is verified above |
|---|
| | 583 | // errorReporter.addError(new ErrorDescription(PropertyProvider.get("prm.resource.updatework.error.invalid.message", workString, DateFormat.getInstance().formatDate(workDate)))); |
|---|
| | 584 | continue; |
|---|
| | 585 | } |
|---|
| | 586 | totalColumnWork += Double.parseDouble(workString); |
|---|
| | 587 | } |
|---|
| | 588 | // if(Validator.isNegative(""+totalColumnWork)) { |
|---|
| | 589 | // errorReporter.addError(new ErrorDescription(PropertyProvider.get("prm.resource.updatework.total.negative.error.message"))); |
|---|
| | 590 | // } |
|---|
| | 591 | |
|---|
| | 592 | // String percentComplete = null; |
|---|
| | 593 | // TimeQuantity assnWork = TimeQuantity.O_HOURS; |
|---|
| | 594 | // TimeQuantity currentWork = assnWork; |
|---|
| | 595 | NumberFormat nf = NumberFormat.getInstance(); |
|---|
| | 596 | assignmentMap = (Map)request.getSession().getAttribute("updateAssignmentsMap"); |
|---|
| | 597 | assignments = (List)request.getSession().getAttribute("updateAssignmentsList"); |
|---|
| | 598 | summaryDateValues = (Map)request.getSession().getAttribute("summaryDateValues"); |
|---|
| | 599 | Assignment baseAssn = (Assignment)assignmentMap.get(id); |
|---|
| | 600 | |
|---|
| | 601 | //one final check |
|---|
| | 602 | TimeQuantity newWorkForDay = new TimeQuantity(nf.parseNumber(""+totalColumnWork), TimeQuantityUnit.HOUR); |
|---|
| | 603 | TimeQuantity oldWorkForDay = (TimeQuantity) summaryDateValues.get(workDate); |
|---|
| | 604 | //no old work added till now for this week |
|---|
| | 605 | if(oldWorkForDay == null) |
|---|
| | 606 | oldWorkForDay = TimeQuantity.O_HOURS; |
|---|
| | 607 | if (newWorkForDay.add(oldWorkForDay).abs().compareTo(MAXIMUM_WORK_HOURS) > 0) { |
|---|
| | 608 | errorReporter.addError(new ErrorDescription(PropertyProvider.get( |
|---|
| | 609 | "prm.resource.assignments.update.error.invalidwork.message", |
|---|
| | 610 | newWorkForDay.add(oldWorkForDay).formatAmount(), |
|---|
| | 611 | MAXIMUM_WORK_HOURS.formatAmount()))); |
|---|
| | 612 | } |
|---|
| | 613 | |
|---|
| | 614 | //We decide to wait until we have a list of work complete strings so we |
|---|
| | 615 | //only have to load the assignment if there are really updates to do. |
|---|
| | 616 | if (workCompleteStrings.size() > 0 && !errorReporter.errorsFound()) { |
|---|
| | 617 | |
|---|
| | 618 | if (baseAssn != null && baseAssn instanceof ScheduleEntryAssignment) { |
|---|
| | 619 | //case of schedule entry assignment created |
|---|
| | 620 | ScheduleEntryAssignment assn = (ScheduleEntryAssignment) baseAssn; |
|---|
| | 621 | currentWork = ScheduleTimeQuantity.convertToHour(assn.getWorkComplete()); |
|---|
| | 622 | assnWork = ScheduleTimeQuantity.convertToHour(assn.getWork()); |
|---|
| | 623 | |
|---|
| | 624 | currentWork = getCurrentWork(workCompleteStrings, nf, currentWork); |
|---|
| | 625 | //Make sure we know the total amount of work in the task which might |
|---|
| | 626 | //be changed if the user has reported more work than is assigned |
|---|
| | 627 | if (assnWork.compareTo(currentWork) < 0) { |
|---|
| | 628 | assnWork = currentWork; |
|---|
| | 629 | } |
|---|
| | 630 | //Calculate the percent complete. We do a clone first so we don't mess |
|---|
| | 631 | //up the preloaded assignments. |
|---|
| | 632 | percentComplete = getPercentComplete(currentWork, assnWork.isZero() ? new TimeQuantity(1, TimeQuantityUnit.HOUR) : assnWork, nf); |
|---|
| | 633 | //finally calculate the esimated finnish date |
|---|
| | 634 | if (assn.getActualStart() == null || assn.getActualStart().after(earliestStartDate)) { |
|---|
| | 635 | assn.setActualStart(earliestStartDate); |
|---|
| | 636 | |
|---|
| | 637 | DefinitionBasedWorkingTimeCalendar cal = calendarProvider.getCalendarForPlan((String)planIDMap.get(id)); |
|---|
| | 638 | assn.calculateEstimatedFinish(cal); |
|---|
| | 639 | |
|---|
| | 640 | } else if (assn.getEstimatedFinish() == null) { |
|---|
| | 641 | DefinitionBasedWorkingTimeCalendar cal = calendarProvider.getCalendarForPlan((String)planIDMap.get(id)); |
|---|
| | 642 | assn.calculateEstimatedFinish(cal); |
|---|
| | 643 | |
|---|
| | 644 | } |
|---|
| | 645 | |
|---|
| | 646 | |
|---|
| | 647 | //updateWorkModel(model, percentComplete, assnWork, currentWork); |
|---|
| | 648 | } else if (baseAssn != null && baseAssn instanceof FormAssignment) { |
|---|
| | 649 | //case of form assignment created |
|---|
| | 650 | FormAssignment assn = (FormAssignment) baseAssn; |
|---|
| | 651 | currentWork = assn.getWorkComplete(); |
|---|
| | 652 | assnWork = assn.getWork(); |
|---|
| | 653 | |
|---|
| | 654 | currentWork = getCurrentWork(workCompleteStrings, nf, currentWork); |
|---|
| | 655 | //Make sure we know the total amount of work in the form assignment which might |
|---|
| | 656 | //be changed if the user has reported more work than is assigned |
|---|
| | 657 | if (assnWork.compareTo(currentWork) < 0) { |
|---|
| | 658 | assnWork = currentWork; |
|---|
| | 659 | } |
|---|
| | 660 | //Calculate the percent complete. |
|---|
| | 661 | percentComplete = getPercentComplete(currentWork, assnWork, nf); |
|---|
| | 662 | assn.setStartTime(earliestStartDate); |
|---|
| | 663 | assn.setEndTime(latestStartDate); |
|---|
| | 664 | |
|---|
| | 665 | //updateWorkModel(model, percentComplete, assnWork, currentWork); |
|---|
| | 666 | } else if (baseAssn != null && baseAssn instanceof ActivityAssignment) { |
|---|
| | 667 | //case of activity assignment created or already present in the Map |
|---|
| | 668 | ActivityAssignment assn = (ActivityAssignment) baseAssn; |
|---|
| | 669 | assnWork = assn.getWork(); |
|---|
| | 670 | |
|---|
| | 671 | assnWork = getCurrentWork(workCompleteStrings, nf, assnWork == null ? TimeQuantity.O_HOURS: assnWork); |
|---|
| | 672 | currentWork = assnWork; |
|---|
| | 673 | percentComplete = nf.formatPercent(1.0, 2); |
|---|
| | 674 | assn.setStartTime(earliestStartDate); |
|---|
| | 675 | assn.setEndTime(latestStartDate); |
|---|
| | 676 | |
|---|
| | 677 | //updateWorkModel(model, percentComplete, assnWork, currentWork); |
|---|
| | 678 | } else { |
|---|
| | 679 | //case of new activity or task added just now in the Map |
|---|
| | 680 | //sjmittal (note*): form assignment cannot be added on fly in the Map |
|---|
| | 681 | //as these are added from a seperate module so personal assignments or timesheet page |
|---|
| | 682 | //would always show form assignments the are already there. so this case in not considered |
|---|
| | 683 | //for form assignments |
|---|
| | 684 | ScheduleEntryAssignment seAssn = null; |
|---|
| | 685 | try { |
|---|
| | 686 | AssignmentFinder finder = new AssignmentFinder(); |
|---|
| | 687 | FinderFilterList filters = new FinderFilterList(); |
|---|
| | 688 | filters.setSelected(true); |
|---|
| | 689 | |
|---|
| | 690 | TextFilter personFilter = new TextFilter("person_id", AssignmentFinder.PERSON_ID_COLUMN, false); |
|---|
| | 691 | personFilter.setSelected(true); |
|---|
| | 692 | personFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 693 | personFilter.setValue(SessionManager.getUser().getID()); |
|---|
| | 694 | filters.add(personFilter); |
|---|
| | 695 | |
|---|
| | 696 | TextFilter objectIDFilter = new TextFilter("object_id", AssignmentFinder.OBJECT_ID_COLUMN, false); |
|---|
| | 697 | objectIDFilter.setSelected(true); |
|---|
| | 698 | objectIDFilter.setComparator((TextComparator)TextComparator.EQUALS); |
|---|
| | 699 | objectIDFilter.setValue(id); |
|---|
| | 700 | filters.add(objectIDFilter); |
|---|
| | 701 | |
|---|
| | 702 | finder.addFinderFilterList(filters); |
|---|
| | 703 | Collection asignments = finder.findAll(); |
|---|
| | 704 | if(asignments.size() == 1) { |
|---|
| | 705 | Assignment assn = (Assignment) asignments.iterator().next(); |
|---|
| | 706 | if(assn instanceof ScheduleEntryAssignment) { |
|---|
| | 707 | seAssn = (ScheduleEntryAssignment) assn; |
|---|
| | 708 | } |
|---|
| | 709 | } |
|---|
| | 710 | } catch (PersistenceException e) { |
|---|
| | 711 | } |
|---|
| | 712 | if(seAssn != null) { |
|---|
| | 713 | assignmentMap.put(id, seAssn); |
|---|
| | 714 | assignments.add(seAssn); |
|---|
| | 715 | |
|---|
| | 716 | currentWork = ScheduleTimeQuantity.convertToHour(seAssn.getWorkComplete()); |
|---|
| | 717 | assnWork = ScheduleTimeQuantity.convertToHour(seAssn.getWork()); |
|---|
| | 718 | |
|---|
| | 719 | currentWork = getCurrentWork(workCompleteStrings, nf, currentWork); |
|---|
| | 720 | //Make sure we know the total amount of work in the task which might |
|---|
| | 721 | //be changed if the user has reported more work than is assigned |
|---|
| | 722 | if (assnWork.compareTo(currentWork) < 0) { |
|---|
| | 723 | assnWork = currentWork; |
|---|
| | 724 | } |
|---|
| | 725 | //Calculate the percent complete. We do a clone first so we don't mess |
|---|
| | 726 | //up the preloaded assignments. |
|---|
| | 727 | percentComplete = getPercentComplete(currentWork, assnWork.isZero() ? new TimeQuantity(1, TimeQuantityUnit.HOUR) : assnWork, nf); |
|---|
| | 728 | //finally calculate the esimated finnish date |
|---|
| | 729 | if (seAssn.getActualStart() == null || seAssn.getActualStart().after(earliestStartDate)) { |
|---|
| | 730 | seAssn.setActualStart(earliestStartDate); |
|---|
| | 731 | |
|---|
| | 732 | DefinitionBasedWorkingTimeCalendar cal = calendarProvider.getCalendarForPlan((String)planIDMap.get(id)); |
|---|
| | 733 | seAssn.calculateEstimatedFinish(cal); |
|---|
| | 734 | |
|---|
| | 735 | } else if (seAssn.getEstimatedFinish() == null) { |
|---|
| | 736 | DefinitionBasedWorkingTimeCalendar cal = calendarProvider.getCalendarForPlan((String)planIDMap.get(id)); |
|---|
| | 737 | seAssn.calculateEstimatedFinish(cal); |
|---|
| | 738 | |
|---|
| | 739 | } |
|---|
| | 740 | } |
|---|
| | 741 | else { |
|---|
| | 742 | ActivityAssignment assn = new ActivityAssignment(); |
|---|
| | 743 | assignmentMap.put(id, assn); |
|---|
| | 744 | assignments.add(assn); |
|---|
| | 745 | |
|---|
| | 746 | |
|---|
| | 747 | assnWork = getCurrentWork(workCompleteStrings, nf, assnWork); |
|---|
| | 748 | currentWork = assnWork; |
|---|
| | 749 | percentComplete = nf.formatPercent(1.0, 2); |
|---|
| | 750 | assn.setStartTime(earliestStartDate); |
|---|
| | 751 | assn.setEndTime(latestStartDate); |
|---|
| | 752 | } |
|---|
| | 753 | |
|---|
| | 754 | //updateWorkModel(model, percentComplete, assnWork, currentWork); |
|---|
| | 755 | } |
|---|
| | 756 | |
|---|
| | 757 | |
|---|
| | 758 | } else { |
|---|
| | 759 | //sjmittal: this is the case if some error occured in work change handler |
|---|
| | 760 | if (baseAssn != null && baseAssn instanceof ScheduleEntryAssignment) { |
|---|
| | 761 | //case of schedule entry assignment created |
|---|
| | 762 | ScheduleEntryAssignment assn = (ScheduleEntryAssignment) baseAssn; |
|---|
| | 763 | percentComplete = getPercentComplete(ScheduleTimeQuantity.convertToHour(assn.getWorkComplete()), ScheduleTimeQuantity.convertToHour(assn.getWork()), nf); |
|---|
| | 764 | } else if (baseAssn != null && baseAssn instanceof FormAssignment) { |
|---|
| | 765 | //case of schedule entry assignment created |
|---|
| | 766 | FormAssignment assn = (FormAssignment) baseAssn; |
|---|
| | 767 | percentComplete = getPercentComplete(assn.getWorkComplete(), assn.getWork(), nf); |
|---|
| | 768 | |
|---|
| | 769 | } else if(baseAssn != null && baseAssn instanceof ActivityAssignment) { |
|---|
| | 770 | //case of activity assignment created or already present in the Map |
|---|
| | 771 | ActivityAssignment assn = (ActivityAssignment) baseAssn; |
|---|
| | 772 | percentComplete = nf.formatPercent(1.0, 2); |
|---|
| | 773 | } else { |
|---|
| | 774 | percentComplete = nf.formatPercent(0.0, 2); |
|---|
| | 775 | } |
|---|
| | 776 | |
|---|
| | 777 | } |
|---|
| | 778 | |
|---|
| | 779 | try{ |
|---|
| | 780 | putObjectsInSession(request, request.getSes |
|---|