List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailWSAction.java
public ActionForward getEarnCodeJson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeDetailWSActionForm tdaf = (TimeDetailWSActionForm) form; boolean containsRegEarnCode = false; List<Map<String, Object>> earnCodeList = new LinkedList<Map<String, Object>>(); if (StringUtils.isNotBlank(tdaf.getSelectedAssignment())) { LocalDate asOfDate = tdaf.getTimesheetDocument().getAsOfDate(); if (tdaf.getStartDate() != null) { try { DateTime utilDate = HrConstants.DateTimeFormats.BASIC_DATE_FORMAT .parseDateTime(tdaf.getStartDate()); asOfDate = utilDate.toLocalDate(); } catch (Exception ex) { //ignore and use the timesheet as of date. }/*from www . j av a 2 s .co m*/ } List<Assignment> assignments = tdaf.getTimesheetDocument().getAssignmentMap().get(asOfDate); AssignmentDescriptionKey key = AssignmentDescriptionKey.get(tdaf.getSelectedAssignment()); Map<String, EarnCode> regEarnCodes = getRegularEarnCodes(assignments); for (Assignment assignment : assignments) { if (assignment.getJobNumber().equals(key.getJobNumber()) && assignment.getGroupKeyCode().equals(key.getGroupKeyCode()) && assignment.getWorkArea().equals(key.getWorkArea()) && assignment.getTask().equals(key.getTask())) { List<EarnCode> earnCodes = new ArrayList<EarnCode>(); if (tdaf.getTimeBlockReadOnly()) { if (regEarnCodes.containsKey(assignment.getAssignmentKey())) { earnCodes.add(regEarnCodes.get(assignment.getAssignmentKey())); } } else { // use endDate to grab earn codes List<EarnCode> aList = TkServiceLocator.getTimesheetService() .getEarnCodesForTime(assignment, asOfDate, tdaf.getTimeBlockReadOnly()); for (EarnCode anEarnCode : aList) { // kpme-2570, overtime earn codes should not show in adding/editing time block widget's earn code option list if (anEarnCode != null && !anEarnCode.isOvtEarnCode()) { earnCodes.add(anEarnCode); } } } for (EarnCode earnCode : earnCodes) { Map<String, Object> earnCodeMap = new HashMap<String, Object>(); earnCodeMap.put("assignment", assignment.getAssignmentKey()); earnCodeMap.put("earnCode", earnCode.getEarnCode()); earnCodeMap.put("desc", earnCode.getDescription()); earnCodeMap.put("type", earnCode.getEarnCodeType()); // for leave blocks earnCodeMap.put("leavePlan", earnCode.getLeavePlan()); if (StringUtils.isNotEmpty(earnCode.getLeavePlan())) { earnCodeMap.put("fractionalTimeAllowed", earnCode.getFractionalTimeAllowed()); earnCodeMap.put("unitOfTime", ActionFormUtils.getUnitOfTimeForEarnCode(earnCode)); } earnCodeMap.put("eligibleForAccrual", earnCode.getEligibleForAccrual()); earnCodeMap.put("accrualBalanceAction", earnCode.getAccrualBalanceAction()); EarnCode regEarnCode = regEarnCodes.get(assignment.getAssignmentKey()); if (regEarnCode != null && StringUtils.equals(regEarnCode.getEarnCode(), earnCode.getEarnCode())) { containsRegEarnCode = true; } earnCodeList.add(earnCodeMap); } } } } if (!containsRegEarnCode) { Map<String, Object> earnCodeMap = new HashMap<String, Object>(); earnCodeMap.put("assignment", ""); earnCodeMap.put("earnCode", ""); earnCodeMap.put("desc", "-- select an earn code --"); earnCodeMap.put("type", ""); // for leave blocks earnCodeMap.put("leavePlan", ""); earnCodeMap.put("eligibleForAccrual", ""); earnCodeList.add(0, earnCodeMap); } LOG.info(tdaf.toString()); tdaf.setOutputString(JSONValue.toJSONString(earnCodeList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailWSAction.java
public ActionForward getOvertimeEarnCodes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeDetailWSActionForm tdaf = (TimeDetailWSActionForm) form; List<EarnCode> overtimeEarnCodes = HrServiceLocator.getEarnCodeService() .getOvertimeEarnCodes(LocalDate.now()); List<Map<String, Object>> overtimeEarnCodeList = new LinkedList<Map<String, Object>>(); if (StringUtils.isNotEmpty(tdaf.getTkTimeBlockId())) { TimeBlock tb = TkServiceLocator.getTimeBlockService().getTimeBlock(tdaf.getTkTimeBlockId()); if (tb != null) { JobContract job = HrServiceLocator.getJobService().getJob(HrContext.getTargetPrincipalId(), tb.getJobNumber(), tb.getEndDateTime().toLocalDate()); if (job != null) { for (EarnCode earnCode : overtimeEarnCodes) { String employee = HrContext.isActiveEmployee() ? "Y" : null; String approver = HrContext.isApprover() ? "Y" : null; String payrollProcessor = HrContext.isPayrollProcessor() ? "Y" : null; // KPME-2532 List<EarnCodeSecurity> securityList = HrServiceLocator.getEarnCodeSecurityService() .getEarnCodeSecurityList(job.getDept(), job.getHrSalGroup(), earnCode.getEarnCode(), employee, approver, payrollProcessor, "Y", tb.getEndDateTime().toLocalDate(), job.getGroupKeyCode()); if (CollectionUtils.isNotEmpty(securityList)) { Map<String, Object> earnCodeMap = new HashMap<String, Object>(); earnCodeMap.put("earnCode", earnCode.getEarnCode()); earnCodeMap.put("desc", earnCode.getDescription()); overtimeEarnCodeList.add(earnCodeMap); }/*from w w w . j av a2 s . c om*/ } } } } LOG.info(tdaf.toString()); tdaf.setOutputString(JSONValue.toJSONString(overtimeEarnCodeList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailWSAction.java
public ActionForward getAssignmentJson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /*/*from w w w.jav a 2 s . co m*/ http://ci.kpme.kuali.org/kpme-trunk/TimeDetailWS.do?methodToCall=getAssignmentJson&documentId=3194&startDate=7%2F7%2F2014&_=1405538575193 */ TimeDetailWSActionForm tdaf = (TimeDetailWSActionForm) form; String chosenStartDate = tdaf.getStartDate(); String chosenEndDate = tdaf.getEndDate(); DateTime calendarBeginDate = tdaf.getTimesheetDocument().getCalendarEntry().getBeginPeriodFullDateTime(); DateTime calendarEndDate = tdaf.getTimesheetDocument().getCalendarEntry().getEndPeriodFullDateTime(); //tdaf.getEndDate(); String earnCode = tdaf.getSelectedEarnCode(); LocalDate asOfDate = null; LocalDate asOfEndDate = null; DateTime utilDate = null; DateTime utilEndDate = null; if (tdaf.getStartDate() != null) { try { utilDate = HrConstants.DateTimeFormats.BASIC_DATE_FORMAT.parseDateTime(tdaf.getStartDate()); asOfDate = utilDate.toLocalDate(); utilEndDate = HrConstants.DateTimeFormats.BASIC_DATE_FORMAT.parseDateTime(tdaf.getEndDate()); asOfEndDate = utilDate.toLocalDate(); } catch (Exception ex) { //ignore and use the timesheet 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); } boolean invalidStartOrEndDates = false; if ((utilDate.isBefore(calendarBeginDate)) || (utilDate.isAfter(calendarEndDate))) { invalidStartOrEndDates = true; } if ((utilEndDate != null) && ((utilEndDate.isAfter(calendarEndDate)) || (utilEndDate.isBefore(calendarBeginDate)))) { invalidStartOrEndDates = true; } if ((utilDate.isEqual(calendarEndDate)) || (utilEndDate.isEqual(calendarEndDate))) { invalidStartOrEndDates = true; } if (invalidStartOrEndDates) { Map<String, Object> assignmentMap = new HashMap<String, Object>(2); assignmentMap.put("assignment", ""); assignmentMap.put("error", "invalid"); assignmentMap.put("desc", ""); tdaf.setOutputString(JSONValue.toJSONString(assignmentMap)); return mapping.findForward("ws"); } if (tdaf.getTimesheetDocument() != null && asOfDate != null) { //check date to see if assignment is active String principalId = tdaf.getTimesheetDocument().getPrincipalId(); CalendarEntry ce = tdaf.getTimesheetDocument().getCalendarEntry(); Map<LocalDate, List<Assignment>> history = tdaf.getTimesheetDocument().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); } } else { Map<String, Object> assignmentMap = new HashMap<String, Object>(2); assignmentMap.put("assignment", ""); assignmentMap.put("desc", "-- no assignments found --"); assignments.add(assignmentMap); } } tdaf.setOutputString(JSONValue.toJSONString(assignments)); return mapping.findForward("ws"); }
From source file:org.lobid.lodmill.hadoop.UnitTestGndNTriplesToJsonLd.java
@Test public void testReducer() throws IOException { // NOPMD (MRUnit) reduceDriver.withInput(new Text(TRIPLE_URI), Arrays.asList(new Text(GND_TRIPLE_1), new Text(GND_TRIPLE_2), new Text(GND_TRIPLE_3))); reduceDriver.withOutput(new Text(""), new Text(JSONValue.toJSONString(correctJson()))); reduceDriver.runTest();//from www. j a v a 2 s . c o m }
From source file:org.lobid.lodmill.hadoop.UnitTestLobidNTriplesToJsonLd.java
@Test public void testReducer() throws IOException { // NOPMD (MRUnit, no explicit // assertion) reduceDriver.withInput(new Text(TRIPLE_URI), Arrays.asList(new Text(TRIPLE_1), new Text(TRIPLE_2), new Text(TRIPLE_3), new Text(TRIPLE_4))); reduceDriver.withOutput(new Text(""), new Text(JSONValue.toJSONString(correctJson()))); reduceDriver.runTest();// w w w. j a v a 2s .com }
From source file:org.mfcrawler.model.export.config.LoadApplicationConfig.java
/** * Save the application configuration/*from w w w . j av a 2 s . co m*/ * @param applicationConfig the application configuration */ public static void saveApplicationConfig(ApplicationConfig applicationConfig) { try { Map<String, Object> jsonMap = new HashMap<String, Object>(); jsonMap.put(AC_LAST_PROJECT, applicationConfig.getLastOpenedProject()); jsonMap.put(AC_USER_AGENT, applicationConfig.getUserAgent()); jsonMap.put(AC_PAGE_TIMEOUT, applicationConfig.getPageRequestTimeout()); jsonMap.put(AC_ROBOTS_TIMEOUT, applicationConfig.getRobotsRequestTimeout()); jsonMap.put(AC_FORBIDDEN_EXTENSIONS, applicationConfig.getForbiddenFileExtensions()); jsonMap.put(AC_PROXY_USE, applicationConfig.getProxyUse()); jsonMap.put(AC_PROXY_HOST, applicationConfig.getProxyHost()); jsonMap.put(AC_PROXY_PORT, applicationConfig.getProxyPort()); File applicationConfigFile = new File(APPLICATION_CONFIG_FILENAME); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(applicationConfigFile)); bufferedWriter.write(JSONValue.toJSONString(jsonMap)); bufferedWriter.close(); } catch (Exception e) { Logger.getLogger(LoadApplicationConfig.class.getName()).log(Level.SEVERE, "Error to write config", e); } }
From source file:org.mfcrawler.model.export.config.LoadCrawlProjectConfig.java
/** * Save the crawl configuration//from w w w . jav a 2s . c om * @param projectName the name of the project * @param crawlConfig the crawl configuration */ public static void saveCrawlConfig(String projectName, CrawlConfig crawlConfig) { try { Map<String, Object> jsonMap = new HashMap<String, Object>(); jsonMap.put(CC_THREAD_NUMBER, crawlConfig.getThreadNumber()); jsonMap.put(CC_INNER_DEEP, crawlConfig.getInnerDeep()); jsonMap.put(CC_OUTER_DEEP, crawlConfig.getOuterDeep()); jsonMap.put(CC_REMAINING_CRAWL_NUMBER, crawlConfig.getRemainingCrawlNumber()); jsonMap.put(CC_MINIMUM_SCORE, crawlConfig.getMinimumScore()); jsonMap.put(CC_CRAWL_DELAY, crawlConfig.getCrawlDelay()); jsonMap.put(CC_FORCE_CRAWL, crawlConfig.getForceCrawl()); jsonMap.put(CC_FORCE_CRAWL_DELAY, crawlConfig.getForceCrawlDelay()); File crawlConfigFile = new File(getCompleteFilename(projectName, CRAWL_CONFIG_FILENAME)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(crawlConfigFile)); bufferedWriter.write(JSONValue.toJSONString(jsonMap)); bufferedWriter.close(); } catch (Exception e) { Logger.getLogger(LoadCrawlProjectConfig.class.getName()).log(Level.SEVERE, "Error to save crawl project", e); } }
From source file:org.nuxeo.ecm.mobile.resource.JsonResource.java
/** * Gets info (as JSON) on an object given its OID. *//* ww w . j ava2s .c o m*/ @GET @Path("info/{oid:.*}") public Object info(@PathParam("oid") String oid) throws ClientException { DocumentRef ref; if (oid == null || oid.isEmpty()) { ref = new PathRef("/"); } else { ref = new IdRef(oid); } DocumentModel doc = session.getDocument(ref); Map<String, Object> model = makeModel(doc); System.out.println(JSONValue.toJSONString(model)); if (doc.isFolder()) { model.put("children", makeDocListModel(session.getChildren(doc.getRef()))); } // Special case if (oid == null || oid.isEmpty()) { model.put("title", "Root"); } System.out.println(JSONValue.toJSONString(model)); return JSONValue.toJSONString(model); }
From source file:org.nuxeo.ecm.mobile.resource.JsonResource.java
/** * Gets info about the recently updated documents. *//* w w w . j a v a 2 s .c o m*/ @GET @Path("updates") public Object updates() throws Exception { DocumentModelList result = session.query("SELECT * FROM Document " + "WHERE ecm:currentLifeCycleState <> 'deleted' " + "AND ecm:primaryType <> 'Folder' " + "AND ecm:primaryType <> 'Workspace' " + "ORDER BY dc:modified DESC", 100); Collection<Map<String, Object>> model = makeDocListModel(result); return JSONValue.toJSONString(model); }
From source file:org.nuxeo.ecm.mobile.resource.JsonResource.java
/** * Performs a full-text search./*ww w .j av a2 s . c o m*/ */ @GET @Path("search") public Object search(@QueryParam("q") String query) throws Exception { query = query.replace("'", " "); String select = "SELECT * FROM Document WHERE ecm:fulltext LIKE '%" + query + "%' LIMIT 10"; DocumentModelList result = session.query(select); Collection<Map<String, Object>> model = makeDocListModel(result); return JSONValue.toJSONString(model); }