List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarWSAction.java
public ActionForward getValidAssignments(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeDetailWSActionForm tdaf = (TimeDetailWSActionForm) form; //need an asOfDate here LocalDate asOfDate = tdaf.getTimesheetDocument().getAsOfDate(); if (tdaf.getStartDate() != null) { try {/*from ww w .ja v a 2 s . co m*/ DateTime utilDate = HrConstants.DateTimeFormats.BASIC_DATE_FORMAT .parseDateTime(tdaf.getStartDate()); asOfDate = utilDate.toLocalDate(); } catch (Exception ex) { //ignore and use the timesheet as of date. } } String earnCode = tdaf.getSelectedEarnCode(); List<Map<String, Object>> assignments = new ArrayList<Map<String, Object>>(); if (tdaf.getTimesheetDocument() != null && StringUtils.isNotEmpty(earnCode)) { assignments = getAssignmentsForRegEarnCode(tdaf.getTimesheetDocument().getAssignmentMap().get(asOfDate), earnCode, asOfDate); } tdaf.setOutputString(JSONValue.toJSONString(assignments)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarWSAction.java
public ActionForward getAssignmentJson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LeaveCalendarWSForm lcf = (LeaveCalendarWSForm) form; String earnCode = lcf.getSelectedEarnCode(); LocalDate asOfDate = null;// w ww . ja v a 2 s . co m if (lcf.getStartDate() != null) { try { DateTime utilDate = HrConstants.DateTimeFormats.BASIC_DATE_FORMAT.parseDateTime(lcf.getStartDate()); asOfDate = utilDate.toLocalDate(); } catch (Exception ex) { //ignore and use the leaveCalendar as of date. } } List<Map<String, Object>> assignments = new ArrayList<Map<String, Object>>(); if (asOfDate == null) { Map<String, Object> assignmentMap = new HashMap<String, Object>(2); assignmentMap.put("assignment", ""); assignmentMap.put("desc", "-- enter valid date range --"); assignments.add(assignmentMap); } lcf.setLeaveCalendarDocument( LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(lcf.getDocumentId())); if (lcf.getLeaveCalendarDocument() != null && asOfDate != null) { //check date to see if assignment is active String principalId = lcf.getLeaveCalendarDocument().getPrincipalId(); CalendarEntry ce = lcf.getLeaveCalendarDocument().getCalendarEntry(); Map<LocalDate, List<Assignment>> history = lcf.getLeaveCalendarDocument().getAssignmentMap(); List<Assignment> dayAssignments = history.get(asOfDate); dayAssignments = HrServiceLocator.getAssignmentService() .filterAssignmentListForUser(HrContext.getPrincipalId(), dayAssignments); if (CollectionUtils.isNotEmpty(dayAssignments)) { if (dayAssignments.size() > 1) { Map<String, Object> assignmentMap = new HashMap<String, Object>(2); assignmentMap.put("assignment", ""); assignmentMap.put("desc", "-- select an assignment --"); assignments.add(assignmentMap); } for (Assignment a : dayAssignments) { Map<String, Object> assignmentMap = new HashMap<String, Object>(2); assignmentMap.put("assignment", a.getAssignmentKey()); assignmentMap.put("desc", HrServiceLocator.getAssignmentService() .getAssignmentDescriptionForAssignment(a, asOfDate)); assignments.add(assignmentMap); } } } lcf.setOutputString(JSONValue.toJSONString(assignments)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.leave.request.approval.web.LeaveRequestApprovalAction.java
public ActionForward validateNewActions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LeaveRequestApprovalActionForm lraaForm = (LeaveRequestApprovalActionForm) form; JSONArray errorMsgList = new JSONArray(); List<String> errors = new ArrayList<String>(); if (StringUtils.isEmpty(lraaForm.getActionList())) { errors.add("No Actions selected. Please try again."); } else {//from w w w. j av a 2s .co m if (StringUtils.isNotEmpty(lraaForm.getActionList())) { String[] actionList = lraaForm.getActionList().split(DOC_SEPARATOR); for (String docId : actionList) { if (StringUtils.isNotEmpty(docId) && !StringUtils.equals(docId, DOC_SEPARATOR)) { LeaveRequestDocument lrd = LmServiceLocator.getLeaveRequestDocumentService() .getLeaveRequestDocument(docId); if (lrd == null) { errors.add(DOC_NOT_FOUND + docId); break; } else { LeaveBlock lb = LmServiceLocator.getLeaveBlockService() .getLeaveBlock(lrd.getLmLeaveBlockId()); if (lb == null) { errors.add(LEAVE_BLOCK_NOT_FOUND + docId); break; } } } } } } errorMsgList.addAll(errors); lraaForm.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.leave.summary.LeaveSummary.java
public String toJsonString() { List<Map<String, Object>> acSections = new ArrayList<Map<String, Object>>(); for (LeaveSummaryRow lsr : this.leaveSummaryRows) { Map<String, Object> acs = new HashMap<String, Object>(); acs.put("accrualCategory", lsr.getAccrualCategory()); acs.put("periodUsage", lsr.getPendingLeaveRequests()); acs.put("available", lsr.getLeaveBalance()); acSections.add(acs);/*from w w w . j a v a 2s . co m*/ } return JSONValue.toJSONString(acSections); }
From source file:org.kuali.kpme.tklm.time.approval.service.TimeApproveServiceImpl.java
@Override public List<ApprovalTimeSummaryRow> getApprovalSummaryRows(String calGroup, List<String> principalIds, List<String> payCalendarLabels, CalendarEntry payCalendarEntry, String docIdSearchTerm) { DateTime payBeginDate = payCalendarEntry.getBeginPeriodFullDateTime(); DateTime payEndDate = payCalendarEntry.getEndPeriodFullDateTime(); List<Map<String, Object>> timeBlockJsonMap = new ArrayList<Map<String, Object>>(); List<ApprovalTimeSummaryRow> rows = new LinkedList<ApprovalTimeSummaryRow>(); Map<String, TimesheetDocumentHeader> principalDocumentHeader = getPrincipalDocumentHeader(principalIds, payBeginDate, payEndDate, docIdSearchTerm); Calendar payCalendar = HrServiceLocator.getCalendarService() .getCalendar(payCalendarEntry.getHrCalendarId()); DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); List<Interval> dayIntervals = TKUtils.getDaySpanForCalendarEntry(payCalendarEntry); String color = null;/* w ww .j av a 2 s . co m*/ Map<String, String> userColorMap = new HashMap<String, String>(); Set<String> randomColors = new HashSet<String>(); String approverId = HrContext.getPrincipalId(); String timeZoneString = HrServiceLocator.getTimezoneService().getApproverTimezone(approverId); DateTimeZone approverTimeZone = StringUtils.isNotBlank(timeZoneString) ? DateTimeZone.forID(timeZoneString) : null; for (String principalId : principalIds) { TimesheetDocumentHeader tdh = new TimesheetDocumentHeader(); String documentId = ""; if (principalDocumentHeader.containsKey(principalId)) { tdh = principalDocumentHeader.get(principalId); documentId = principalDocumentHeader.get(principalId).getDocumentId(); } else if (StringUtils.isNotBlank(docIdSearchTerm)) { continue; // if there's a search term for document id, only build the rows for principalIds from principalDocumentHeader } List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>(); List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>(); List<Note> notes = new ArrayList<Note>(); List<String> warnings = new ArrayList<String>(); List<String> clockLogWarnings = new ArrayList<String>(); ApprovalTimeSummaryRow approvalSummaryRow = new ApprovalTimeSummaryRow(); if (principalDocumentHeader.containsKey(principalId)) { approvalSummaryRow.setApprovalStatus(HrConstants.DOC_ROUTE_STATUS.get(tdh.getDocumentStatus())); } TimesheetDocument td = null; if (StringUtils.isNotBlank(documentId)) { td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId); timeBlocks = td.getTimeBlocks(); clockLogWarnings = TkServiceLocator.getClockLogService().getUnapprovedIPWarning(timeBlocks); //timeBlocks = TkServiceLocator.getTimeBlockService() // .getTimeBlocks(documentId); List<String> assignKeys = new ArrayList<String>(); for (Assignment a : td.getAllAssignments()) { assignKeys.add(a.getAssignmentKey()); } leaveBlocks.addAll(LmServiceLocator.getLeaveBlockService().getLeaveBlocksForTimeCalendar( principalId, payBeginDate.toLocalDate(), payEndDate.toLocalDate(), assignKeys)); notes = getNotesForDocument(documentId); Map<String, List<LocalDate>> earnCodeMap = new HashMap<String, List<LocalDate>>(); for (TimeBlock tb : td.getTimeBlocks()) { if (!earnCodeMap.containsKey(tb.getEarnCode())) { List<LocalDate> lst = new ArrayList<LocalDate>(); lst.add(tb.getBeginDateTime().toLocalDate()); earnCodeMap.put(tb.getEarnCode(), lst); } else earnCodeMap.get(tb.getEarnCode()).add(tb.getBeginDateTime().toLocalDate()); } warnings = HrServiceLocator.getEarnCodeGroupService().getWarningTextFromEarnCodeGroups(earnCodeMap); // Get Timesheet blocks List<Interval> intervals = TKUtils.getFullWeekDaySpanForCalendarEntry(payCalendarEntry); TkTimeBlockAggregate tbAggregate = buildAndMergeAggregates(timeBlocks, leaveBlocks, payCalendarEntry, payCalendar, dayIntervals); // TkTimeBlockAggregate tbAggregate = new TkTimeBlockAggregate(timeBlocks, payCalendarEntry, payCalendar, true,intervals); // use both time aggregate to populate the calendar TkCalendar cal = TkCalendar.getCalendar(tbAggregate); for (CalendarWeek week : cal.getWeeks()) { for (CalendarDay day : week.getDays()) { TkCalendarDay tkDay = (TkCalendarDay) day; for (TimeBlockRenderer renderer : tkDay.getBlockRenderers()) { Map<String, Object> timeBlockMap = new HashMap<String, Object>(); // set title.. StringBuffer title = new StringBuffer(); if (!renderer.getEarnCodeType().equalsIgnoreCase(HrConstants.EARN_CODE_AMOUNT)) { if (renderer.getDetailRenderers() != null && !renderer.getDetailRenderers().isEmpty()) { for (TimeHourDetailRenderer thdr : renderer.getDetailRenderers()) { title.append("\n"); title = new StringBuffer(thdr.getTitle()); title.append(" - " + thdr.getHours()); } } } timeBlockMap.put("start", tkDay.getDateString()); StringBuffer titleString = new StringBuffer(); titleString.append(renderer.getTitle()); if (renderer.getTimeRange() != null && !renderer.getTimeRange().isEmpty()) { titleString.append("\n" + renderer.getTimeRange()); } titleString.append("\n" + title.toString()); timeBlockMap.put("title", titleString.toString()); timeBlockMap.put("id", tkDay.getDayNumberString()); if (!userColorMap.containsKey(principalId)) { color = TKUtils.getRandomColor(randomColors); randomColors.add(color); userColorMap.put(principalId, color); } color = userColorMap.get(principalId); timeBlockMap.put("color", userColorMap.get(principalId)); timeBlockMap.put("className", "event-approval"); timeBlockJsonMap.add(timeBlockMap); } } } warnings = HrServiceLocator.getEarnCodeGroupService() .getWarningTextFromEarnCodeGroups(td.getEarnCodeMap()); } Map<String, Set<String>> transactionalWarnings = LeaveCalendarValidationUtil .validatePendingTransactions(principalId, payCalendarEntry.getBeginPeriodFullDateTime().toLocalDate(), payCalendarEntry.getEndPeriodFullDateTime().toLocalDate()); warnings.addAll(transactionalWarnings.get("infoMessages")); warnings.addAll(transactionalWarnings.get("warningMessages")); warnings.addAll(transactionalWarnings.get("actionMessages")); Map<String, Set<String>> eligibleTransfers = findWarnings(principalId, payCalendarEntry); warnings.addAll(eligibleTransfers.get("warningMessages")); warnings.addAll(clockLogWarnings); Map<String, BigDecimal> hoursToPayLabelMap = getHoursToPayDayMap(principalId, payEndDate, payCalendarLabels, timeBlocks, leaveBlocks, null, payCalendarEntry, payCalendar, dateTimeZone, dayIntervals); Map<String, BigDecimal> hoursToFlsaPayLabelMap = getHoursToFlsaWeekMap(principalId, payEndDate, payCalendarLabels, timeBlocks, leaveBlocks, null, payCalendarEntry, payCalendar, dateTimeZone, dayIntervals); EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); approvalSummaryRow.setName(name != null && name.getDefaultName() != null && name.getDefaultName().getCompositeName() != null ? name.getDefaultName().getCompositeName() : principalId); approvalSummaryRow.setPrincipalId(principalId); approvalSummaryRow.setColor(userColorMap.get(principalId)); approvalSummaryRow.setPayCalendarGroup(calGroup); approvalSummaryRow.setDocumentId(documentId); approvalSummaryRow.setHoursToPayLabelMap(hoursToPayLabelMap); approvalSummaryRow.setHoursToFlsaPayLabelMap(hoursToFlsaPayLabelMap); approvalSummaryRow.setPeriodTotal(hoursToPayLabelMap.get("Period Total")); approvalSummaryRow.setLstTimeBlocks(timeBlocks); approvalSummaryRow.setNotes(notes); approvalSummaryRow.setWarnings(warnings); // Compare last clock log versus now and if > threshold // highlight entry ClockLog lastClockLog = TkServiceLocator.getClockLogService().getLastClockLog(principalId); if (isSynchronousUser(principalId)) { approvalSummaryRow .setClockStatusMessage(createLabelForLastClockLog(lastClockLog, approverTimeZone)); } if (lastClockLog != null && (StringUtils.equals(lastClockLog.getClockAction(), TkConstants.CLOCK_IN) || StringUtils.equals(lastClockLog.getClockAction(), TkConstants.LUNCH_IN))) { DateTime startTime = lastClockLog.getClockDateTime(); DateTime endTime = new DateTime(); Hours hour = Hours.hoursBetween(startTime, endTime); if (hour != null) { int elapsedHours = hour.getHours(); if (elapsedHours >= TkConstants.NUMBER_OF_HOURS_CLOCKED_IN_APPROVE_TAB_HIGHLIGHT && isSynchronousUser(principalId)) { approvalSummaryRow.setClockedInOverThreshold(true); } } } //KPME-2563 try { if (td != null) { TimeSummaryContract ts = TkServiceLocator.getTimeSummaryService().getTimeSummary( td.getPrincipalId(), td.getTimeBlocks(), td.getCalendarEntry(), td.getAssignmentMap()); approvalSummaryRow.setTimeSummary(ts); } } catch (Exception ex) { ex.printStackTrace(); } rows.add(approvalSummaryRow); } String outputString = JSONValue.toJSONString(timeBlockJsonMap); if (rows != null && !rows.isEmpty()) { rows.get(0).setOutputString(outputString); } return rows; }
From source file:org.kuali.kpme.tklm.time.approval.web.TimeApprovalWSAction.java
/** * Action called via AJAX. (ajaj really...) * <p/>//from w w w .ja v a 2 s .c om * This search returns quick-results to the search box for the user to further * refine upon. The end value can then be form submitted. */ public ActionForward searchApprovalRows(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeApprovalActionForm taaf = (TimeApprovalActionForm) form; List<Map<String, String>> results = new LinkedList<Map<String, String>>(); List<String> workAreaList = new ArrayList<String>(); if (StringUtils.isEmpty(taaf.getSelectedWorkArea())) { String principalId = HrContext.getTargetPrincipalId(); Set<Long> workAreas = new HashSet<Long>(); RoleService roleService = KimApiServiceLocator.getRoleService(); List<String> roleIds = new ArrayList<String>(); roleIds.add(roleService.getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.REVIEWER.getRoleName())); roleIds.add(roleService.getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName())); roleIds.add(roleService.getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName())); roleIds.add(roleService.getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR.getRoleName())); roleIds.add(roleService.getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR_DELEGATE.getRoleName())); workAreas.addAll(HrServiceLocator.getKPMERoleService().getWorkAreasForPrincipalInRoles(principalId, roleIds, LocalDate.now().toDateTimeAtStartOfDay(), true)); for (Long workArea : workAreas) { workAreaList.add(workArea.toString()); } } else { workAreaList.add(taaf.getSelectedWorkArea()); } if (StringUtils.isNotBlank(taaf.getSelectedPayPeriod())) { CalendarEntry currentCE = HrServiceLocator.getCalendarEntryService() .getCalendarEntry(taaf.getSelectedPayPeriod()); if (currentCE != null) { LocalDate endDate = currentCE.getEndPeriodFullDateTime().toLocalDate(); LocalDate beginDate = currentCE.getBeginPeriodFullDateTime().toLocalDate(); List<String> principalIds = TkServiceLocator.getTimeApproveService() .getTimePrincipalIdsWithSearchCriteria(workAreaList, taaf.getSelectedPayCalendarGroup(), endDate, beginDate, endDate); Collections.sort(principalIds); if (StringUtils.equals(taaf.getSearchField(), CalendarApprovalForm.ORDER_BY_PRINCIPAL)) { for (String id : principalIds) { if (StringUtils.contains(id, taaf.getSearchTerm())) { Map<String, String> labelValue = new HashMap<String, String>(); labelValue.put("id", id); labelValue.put("result", id); results.add(labelValue); } } } else if (StringUtils.equals(taaf.getSearchField(), CalendarApprovalForm.ORDER_BY_DOCID)) { Map<String, TimesheetDocumentHeader> principalDocumentHeaders = TkServiceLocator .getTimeApproveService().getPrincipalDocumentHeader(principalIds, beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), ""); List<String> docIdList = new ArrayList<String>(); for (Map.Entry<String, TimesheetDocumentHeader> entry : principalDocumentHeaders.entrySet()) { if (StringUtils.contains(entry.getValue().getDocumentId(), taaf.getSearchTerm())) { docIdList.add(entry.getValue().getDocumentId()); } } Collections.sort(docIdList); for (String aString : docIdList) { Map<String, String> labelValue = new HashMap<String, String>(); labelValue.put("id", aString); labelValue.put("result", aString); results.add(labelValue); } } } } taaf.setOutputString(JSONValue.toJSONString(results)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.clock.web.ClockAction.java
public ActionForward validateNewTimeBlock(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from w w w .ja v a 2 s.c om*/ ClockActionForm caf = (ClockActionForm) form; String tbId = caf.getTbId(); String[] assignments = caf.getNewAssignDesCol().split(SEPERATOR); String[] beginDates = caf.getNewBDCol().split(SEPERATOR); String[] beginTimes = caf.getNewBTCol().split(SEPERATOR); String[] endDates = caf.getNewEDCol().split(SEPERATOR); String[] endTimes = caf.getNewETCol().split(SEPERATOR); String[] hrs = caf.getNewHrsCol().split(SEPERATOR); List<Interval> newIntervals = new ArrayList<Interval>(); JSONArray errorMsgList = new JSONArray(); // validates that all fields are available if (assignments.length != beginDates.length || assignments.length != beginTimes.length || assignments.length != endDates.length || assignments.length != endTimes.length || assignments.length != hrs.length) { errorMsgList.add("All fields are required"); caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); } for (int i = 0; i < hrs.length; i++) { String index = String.valueOf(i + 1); // validate the hours field BigDecimal dc = new BigDecimal(hrs[i]); if (dc.compareTo(new BigDecimal("0")) == 0) { errorMsgList.add("The entered hours for entry " + index + " is not valid."); caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); } // check if the begin / end time are valid // should not include time zone in consideration when conparing time intervals DateTime beginDateTime = TKUtils.convertDateStringToDateTimeWithoutZone(beginDates[i], beginTimes[i]); DateTime endDateTime = TKUtils.convertDateStringToDateTimeWithoutZone(endDates[i], endTimes[i]); if ((beginDateTime.compareTo(endDateTime) > 0 || endDateTime.compareTo(beginDateTime) < 0)) { errorMsgList.add("The time or date for entry " + index + " is not valid."); caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); } // check if new time blocks overlap with existing time blocks Interval addedTimeblockInterval = new Interval(beginDateTime, endDateTime); newIntervals.add(addedTimeblockInterval); for (TimeBlock timeBlock : caf.getTimesheetDocument().getTimeBlocks()) { if (timeBlock.getTkTimeBlockId().equals(tbId)) { // ignore the original time block continue; } if (timeBlock.getHours().compareTo(BigDecimal.ZERO) == 0) { // ignore time blocks with zero hours continue; } DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime timeBlockBeginTimestamp = new DateTime(timeBlock.getBeginDateTime(), dateTimeZone) .withZone(TKUtils.getSystemDateTimeZone()); DateTime timeBlockEndTimestamp = new DateTime(timeBlock.getEndDateTime(), dateTimeZone) .withZone(TKUtils.getSystemDateTimeZone()); Interval timeBlockInterval = new Interval(timeBlockBeginTimestamp, timeBlockEndTimestamp); if (timeBlockInterval.overlaps(addedTimeblockInterval)) { errorMsgList.add("The time block you are trying to add for entry " + index + " overlaps with an existing time block."); caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); } } } // check if new time blocks overlap with each other if (newIntervals.size() > 1) { for (Interval intv1 : newIntervals) { for (Interval intv2 : newIntervals) { if (intv1.equals(intv2)) { continue; } if (intv1.overlaps(intv2)) { errorMsgList.add("There is time overlap between the entries."); caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); } } } } caf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.detail.web.ActionFormUtils.java
/** * This method will build the JSON data structure needed for calendar * manipulation and processing on the client side. Start and End times here * are based on the pre-timezone adjusted times startDisplayTime, and * endDisplayTime./*w w w .j a v a 2s. c om*/ * * @param timeBlocks * @return */ public static String getTimeBlocksJson(List<? extends TimeBlockContract> timeBlocks) { if (timeBlocks == null || timeBlocks.size() == 0) { return ""; } List<Map<String, Object>> timeBlockList = new LinkedList<Map<String, Object>>(); String timezone = HrServiceLocator.getTimezoneService().getUserTimezone(); String principalId = GlobalVariables.getUserSession().getPrincipalId(); boolean isAnyApprover = HrServiceLocator.getKPMERoleService().principalHasRole(principalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay()) || HrServiceLocator.getKPMERoleService().principalHasRole(principalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay()); for (TimeBlockContract timeBlock : timeBlocks) { Map<String, Object> timeBlockMap = new LinkedHashMap<String, Object>(); WorkArea workArea = HrServiceLocator.getWorkAreaService().getWorkArea(timeBlock.getWorkArea(), timeBlock.getEndDateTime().toLocalDate()); String workAreaDesc = workArea.getDescription(); timeBlockMap.put("isApprover", isAnyApprover); timeBlockMap.put("isSynchronousUser", timeBlock.isClockLogCreated()); timeBlockMap.put("canEditTb", TkServiceLocator.getTKPermissionService().canEditTimeBlock(principalId, timeBlock)); timeBlockMap.put("canEditTBOvt", TkServiceLocator.getTKPermissionService().canEditOvertimeEarnCode(principalId, timeBlock)); if (TkServiceLocator.getTKPermissionService().canEditTimeBlockAllFields(principalId, timeBlock)) { timeBlockMap.put("canEditTBAll", true); timeBlockMap.put("canEditTBAssgOnly", false); } else { timeBlockMap.put("canEditTBAll", false); timeBlockMap.put("canEditTBAssgOnly", true); } // tracking any kind of 'mutating' state with this object, it's just a one off modification under a specific circumstance. DateTime start = timeBlock.getBeginTimeDisplay(); DateTime end = timeBlock.getEndTimeDisplay(); /** * This is the timeblock backward pushing logic. * the purpose of this is to accommodate the virtual day mode where the start/end period time is not from 12a to 12a. * A timeblock will be pushed back if the timeblock is still within the previous interval */ if (timeBlock.isPushBackward()) { start = start.minusDays(1); end = end.minusDays(1); } timeBlockMap.put("documentId", timeBlock.getDocumentId()); timeBlockMap.put("title", workAreaDesc); EarnCodeContract ec = HrServiceLocator.getEarnCodeService().getEarnCode(timeBlock.getEarnCode(), timeBlock.getBeginDateTime().toLocalDate()); timeBlockMap.put("earnCode", timeBlock.getEarnCode()); timeBlockMap.put("earnCodeDesc", ec != null ? ec.getDescription() : StringUtils.EMPTY); //TODO: need to cache this or pre-load it when the app boots up // EarnCode earnCode = HrServiceLocator.getEarnCodeService().getEarnCode(timeBlock.getEarnCode(), timeBlock.getBeginDateTime().toLocalDate()); timeBlockMap.put("earnCodeType", timeBlock.getEarnCodeType()); // TODO: Cleanup the start / end time related properties. We certainly don't need all of them. // The ones which are used by the javascript are startDate, endDate, startTime, endTime, startTimeHourMinute, and endTimeHourMinute timeBlockMap.put("start", start.toString(ISODateTimeFormat.dateTimeNoMillis())); timeBlockMap.put("end", end.toString(ISODateTimeFormat.dateTimeNoMillis())); timeBlockMap.put("startDate", start.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); timeBlockMap.put("endDate", end.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); timeBlockMap.put("startNoTz", start.toString(ISODateTimeFormat.dateHourMinuteSecond())); timeBlockMap.put("endNoTz", end.toString(ISODateTimeFormat.dateHourMinuteSecond())); // start / endTimeHourMinute fields are for only for the display purpose timeBlockMap.put("startTimeHourMinute", start.toString(TkConstants.DT_BASIC_TIME_FORMAT)); timeBlockMap.put("endTimeHourMinute", end.toString(TkConstants.DT_BASIC_TIME_FORMAT)); // start / endTime are the actual fields used by the adding / editing timeblocks timeBlockMap.put("startTime", start.toString(TkConstants.DT_MILITARY_TIME_FORMAT)); timeBlockMap.put("endTime", end.toString(TkConstants.DT_MILITARY_TIME_FORMAT)); timeBlockMap.put("id", timeBlock.getTkTimeBlockId() == null ? null : timeBlock.getTkTimeBlockId()); timeBlockMap.put("hours", timeBlock.getHours()); timeBlockMap.put("amount", timeBlock.getAmount()); timeBlockMap.put("timezone", timezone); timeBlockMap.put("assignment", new AssignmentDescriptionKey(timeBlock.getGroupKeyCode(), timeBlock.getJobNumber(), timeBlock.getWorkArea(), timeBlock.getTask()).toAssignmentKeyString()); timeBlockMap.put("tkTimeBlockId", timeBlock.getTkTimeBlockId() != null ? timeBlock.getTkTimeBlockId() : ""); timeBlockMap.put("lunchDeleted", timeBlock.isLunchDeleted()); List<Map<String, Object>> timeHourDetailList = new LinkedList<Map<String, Object>>(); for (TimeHourDetailContract timeHourDetail : timeBlock.getTimeHourDetails()) { Map<String, Object> timeHourDetailMap = new LinkedHashMap<String, Object>(); timeHourDetailMap.put("earnCode", timeHourDetail.getEarnCode()); timeHourDetailMap.put("hours", timeHourDetail.getHours()); timeHourDetailMap.put("amount", timeHourDetail.getAmount()); // if there is a lunch hour deduction, add a flag to the timeBlockMap if (StringUtils.equals(timeHourDetail.getEarnCode(), "LUN")) { timeBlockMap.put("lunchDeduction", true); } timeHourDetailList.add(timeHourDetailMap); } timeBlockMap.put("timeHourDetails", JSONValue.toJSONString(timeHourDetailList)); timeBlockList.add(timeBlockMap); //System.out.println("\n\n\n\n"); //System.out.println(sw.prettyPrint()); //System.out.println("\n\n\n\n"); } // Map<String, Map<String, Object>> jsonMappedList = new HashMap<String, Map<String, Object>>(); // for (Map<String, Object> tbm : timeBlockList) { // String id = (String) tbm.get("id"); // jsonMappedList.put(id, tbm); // } String value = JSONValue.toJSONString(timeBlockList); return value; }
From source file:org.kuali.kpme.tklm.time.detail.web.ActionFormUtils.java
/** * This method will build the leave blocks JSON data structure needed for calendar * manipulation and processing on the client side. * * @param leaveBlocks/*from ww w . j a va 2 s. c o m*/ * @return */ public static String getLeaveBlocksJson(List<LeaveBlock> leaveBlocks) { if (CollectionUtils.isEmpty(leaveBlocks)) { return ""; } List<Map<String, Object>> leaveBlockList = new LinkedList<Map<String, Object>>(); for (LeaveBlockContract leaveBlock : leaveBlocks) { Map<String, Object> leaveBlockMap = new LinkedHashMap<String, Object>(); leaveBlockMap.put("title", leaveBlock.getAssignmentTitle()); leaveBlockMap.put("assignment", leaveBlock.getAssignmentKey()); leaveBlockMap.put("earnCode", leaveBlock.getEarnCode()); leaveBlockMap.put("lmLeaveBlockId", leaveBlock.getLmLeaveBlockId()); leaveBlockMap.put("leaveAmount", leaveBlock.getLeaveAmount().toString()); DateTime leaveDate = leaveBlock.getLeaveLocalDate().toDateTimeAtStartOfDay(); leaveBlockMap.put("leaveDate", leaveDate.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); leaveBlockMap.put("id", leaveBlock.getLmLeaveBlockId()); leaveBlockMap.put("canTransfer", LmServiceLocator.getLMPermissionService().canTransferSSTOUsage(leaveBlock)); leaveBlockMap.put("startDate", leaveDate.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); leaveBlockMap.put("endDate", leaveDate.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); if (leaveBlock.getBeginDateTime() != null && leaveBlock.getEndDateTime() != null) { DateTime start = leaveBlock.getBeginDateTime(); DateTime end = leaveBlock.getEndDateTime(); leaveBlockMap.put("startTimeHourMinute", start.toString(TkConstants.DT_BASIC_TIME_FORMAT)); leaveBlockMap.put("endTimeHourMinute", end.toString(TkConstants.DT_BASIC_TIME_FORMAT)); leaveBlockMap.put("startTime", start.toString(TkConstants.DT_MILITARY_TIME_FORMAT)); leaveBlockMap.put("endTime", end.toString(TkConstants.DT_MILITARY_TIME_FORMAT)); leaveBlockMap.put("startDate", start.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); leaveBlockMap.put("endDate", end.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); } leaveBlockList.add(leaveBlockMap); } return JSONValue.toJSONString(leaveBlockList); }
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailWSAction.java
/** * This is an ajax call triggered after a user submits the time entry form. * If there is any error, it will return error messages as a json object. * * @param mapping/* w ww . j a v a2 s .co m*/ * @param form * @param request * @param response * @return jsonObj * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward validateTimeEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeDetailActionFormBase tdaf = (TimeDetailActionFormBase) form; JSONArray errorMsgList = new JSONArray(); List<String> errors; // validates the selected earn code exists on every day within the date range errors = TimeDetailValidationUtil.validateEarnCode(tdaf.getSelectedEarnCode(), tdaf.getStartDate(), tdaf.getEndDate()); if (errors.isEmpty()) { EarnCode ec = HrServiceLocator.getEarnCodeService().getEarnCode(tdaf.getSelectedEarnCode(), TKUtils.formatDateTimeStringNoTimezone(tdaf.getEndDate()).toLocalDate()); if (ec != null && StringUtils.isNotEmpty(ec.getLeavePlan())) { // leave blocks changes errors = TimeDetailValidationUtil.validateLeaveEntry(tdaf); } else { // time blocks changes errors = TimeDetailValidationUtil.validateTimeEntryDetails(tdaf); } } errorMsgList.addAll(errors); tdaf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }