List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:com.qcadoo.mes.operationTimeCalculations.OrderRealizationTimeServiceImpl.java
@Override public BigDecimal getBigDecimalFromField(final Object value, final Locale locale) { try {//from w ww . j a v a 2s . c om DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale); format.setParseBigDecimal(true); return new BigDecimal(format.parse(value.toString()).doubleValue()); } catch (ParseException e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:com.neusoft.mid.clwapi.service.tacks.TacksServiceImpl.java
/** * ???./*from w w w.j av a 2 s. c o m*/ * * @param token * ?. * * @param vin * vin?. * * @param date * ,?yyyymmdd. * @return ??. */ @Override public Response getVinTacksList(String token, String vin, String date) { vin = StringUtils.strip(vin); date = StringUtils.strip(date); logger.info("-vin?:" + vin + ",:" + date); try { TimeUtil.parseStringToDate(date, HttpConstant.DAY_FORMAT); } catch (ParseException e) { logger.error( "-" + date + "?yyyyMMdd?" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } List<TackListInfo> resultList = tcMapper.getCarRunRecs(date, vin); if (CheckRequestParam.isEmpty(resultList)) { logger.info("-VIN:" + vin + "" + date + ""); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } TackListResp resp = new TackListResp(); resp.setResultList(resultList); return Response.ok(JacksonUtils.toJsonRuntimeException(resp)).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJUInt16Editor.java
public Integer getUInt16Value() { final String S_ProcName = "getUInt16Value"; Integer retval;/*from w w w. j av a2 s . c o m*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Short) { Short s = (Short) obj; short v = s.shortValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Integer((int) v); } else if (obj instanceof Integer) { Integer i = (Integer) obj; int v = i.intValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = i; } else if (obj instanceof Long) { Long l = (Long) obj; long v = l.longValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Integer(l.intValue()); } else if (obj instanceof Number) { Number n = (Number) obj; long v = n.longValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Integer(n.intValue()); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, or Number"); } } return (retval); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJUInt32Editor.java
public Long getUInt32Value() { final String S_ProcName = "getUInt32Value"; Long retval;/*from w w w .ja v a2 s . com*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Short) { Short s = (Short) obj; short v = s.shortValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Long((long) v); } else if (obj instanceof Integer) { Integer i = (Integer) obj; int v = i.intValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Long((long) v); } else if (obj instanceof Long) { Long l = (Long) obj; long v = l.longValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = l; } else if (obj instanceof Number) { Number n = (Number) obj; long v = n.longValue(); if ((v < getMinValue()) || (v > getMaxValue())) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, getMinValue(), getMaxValue()); } retval = new Long(n.longValue()); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, or Number"); } } return (retval); }
From source file:edu.hawaii.soest.pacioos.text.FileTextSource.java
protected boolean execute() { log.debug("FileTextSource.execute() called."); boolean failed = false; // indicates overall success of execute() // do not execute the stream if there is no connection if (!isConnected()) return false; try {/*from w ww . j a va 2s.c om*/ // open the data file for monitoring FileReader reader = new FileReader(new File(getDataFilePath())); this.fileReader = new BufferedReader(reader); // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. int channelIndex = 0; long lastSampleTimeAsSecondsSinceEpoch = getLastSampleTime(); // poll the data file for new lines of data and insert them into the RBNB while (true) { String line = fileReader.readLine(); if (line == null) { Thread.currentThread().sleep(this.pollInterval); } else { // test the line for the expected data pattern boolean valid = this.validateSample(line); // if the line matches the data pattern, insert it into the DataTurbine if (valid) { log.debug("This line matches the data line pattern: " + line); Date sampleDate = getSampleDate(line); if (this.dateFormats == null || this.dateFields == null) { log.warn("Using the default datetime format and field for sample data. " + "Use the -f and -d options to explicitly set date time fields."); } log.debug("Sample date is: " + sampleDate.toString()); // convert the sample date to seconds since the epoch long sampleTimeAsSecondsSinceEpoch = (sampleDate.getTime() / 1000L); // only insert samples newer than the last sample seen at startup // and that are not in the future (> 1 hour since the CTD clock // may have drifted) Calendar currentCal = Calendar.getInstance(); this.tz = TimeZone.getTimeZone(this.timezone); currentCal.setTimeZone(this.tz); currentCal.add(Calendar.HOUR, 1); Date currentDate = currentCal.getTime(); if (lastSampleTimeAsSecondsSinceEpoch < sampleTimeAsSecondsSinceEpoch && sampleTimeAsSecondsSinceEpoch < currentDate.getTime() / 1000L) { int numberOfChannelsFlushed = 0; try { //insert into the DataTurbine numberOfChannelsFlushed = this.sendSample(line); } catch (SAPIException sapie) { // reconnect if an exception is thrown on Flush() log.error("Error while flushing the source: " + sapie.getMessage()); failed = true; } // reset the last sample time to the sample just inserted lastSampleTimeAsSecondsSinceEpoch = sampleTimeAsSecondsSinceEpoch; log.debug("Last sample time is now: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L).toString())); log.info(getRBNBClientName() + " Sample sent to the DataTurbine: " + line.trim()); } else { log.info("The current line is earlier than the last entry " + "in the Data Turbine or is a date in the future. " + "Skipping it. The line was: " + line); } } else { log.info("The current line doesn't match an expected " + "data line pattern. Skipping it. The line was: " + line); } } // end if() } // end while } catch (ParseException pe) { log.info("There was a problem parsing the sample date string. The message was: " + pe.getMessage()); failed = true; return !failed; } catch (SAPIException sapie) { log.info("There was a problem communicating with the DataTurbine. The message was: " + sapie.getMessage()); failed = true; return !failed; } catch (InterruptedException ie) { log.info("There was a problem while polling the data file. The message was: " + ie.getMessage()); failed = true; return !failed; } catch (IOException ioe) { log.info("There was a problem opening the data file. The message was: " + ioe.getMessage()); failed = true; return !failed; } finally { try { this.fileReader.close(); } catch (IOException ioe2) { log.error("There was a problem closing the data file. The message was: " + ioe2.getMessage()); } } }
From source file:org.kemri.wellcome.controller.ReportController.java
@RequestMapping(value = Views.SETUP_REPORT, method = RequestMethod.POST) public @ResponseBody Map<String, ? extends Object> setupReport(@RequestBody ReportExecute reportExecute) { Period period;/*from w w w . j a v a 2 s . c om*/ Date reportDate = null; try { reportDate = new SimpleDateFormat("yyyy-MM-dd").parse(reportExecute.getDate()); } catch (ParseException e) { log.error(e.getMessage()); return Collections.singletonMap("u", e.getMessage()); } if (reportExecute.getFrequency().equalsIgnoreCase("Monthly")) { period = new MonthlyPeriod(reportDate); } else { period = new WeeklyPeriod(reportDate); } //prepare import summary ImportSummary importSummary = new ImportSummary(); importSummary.setStatus(ImportStatus.ERROR); importSummary.setUid(UUID.randomUUID().toString()); importSummary.setName(reportExecute.getReportDefinitionName()); importSummary.setDescription("Error posting to DHISv2. No matching parameters on the server"); importSummary.setReportDate(DateUtils.stringToDate(DateUtils.getToday())); importSummary.setDataSetComplete("false"); // Get Location by OrgUnit Code ReportDefinition report = service.getReportDefinition(reportExecute.getReportDefinationId()); Location location = service.getLocationByOU_Code(reportExecute.getLocation()); DataValueSet dvs = service.evaluateReportDefinition(report, period, location); if (dvs.getError() != null && dvs.getError().equalsIgnoreCase("ERROR")) { StringBuilder builder = new StringBuilder(""); for (DataValue dv : dvs.getDataValues()) { builder.append(dv.getError()); builder.append(";"); } importSummary.setReportName(reportExecute.getReportDefinitionName()); importSummary.setStatus(ImportStatus.ERROR); importSummary.setDescription(builder.toString()); createImportCount(importSummary); log.info("User:" + service.getUsername() + " executed report template :" + importSummary.getReportName() + " on " + Calendar.getInstance().getTime()); return Collections.singletonMap("importSummary", importSummary); } else { dvs.setOrgUnit(reportExecute.getLocation()); try { importSummary = service.postDataValueSet(dvs); } catch (DHIS2ReportingException e) { log.error(e.getMessage()); importSummary.setReportName(reportExecute.getReportDefinitionName()); importSummary.setStatus(ImportStatus.ERROR); importSummary.setDescription(e.getMessage()); createImportCount(importSummary); log.info("User:" + service.getUsername() + " executed report template :" + importSummary.getReportName() + " on " + Calendar.getInstance().getTime()); return Collections.singletonMap("importSummary", importSummary); } importSummary.setReportName(reportExecute.getReportDefinitionName()); List<ImportConflict> conflicts = new ArrayList<ImportConflict>(); if (importSummary.getConflicts() != null) { for (ImportConflict conflict : importSummary.getConflicts()) { conflict.setImportSummary(importSummary); conflict.setUid(UUID.randomUUID().toString()); conflict.setName(UUID.randomUUID().toString()); conflicts.add(conflict); } importSummary.setConflicts(conflicts); } importSummary.setReportDate(DateUtils.stringToDate(DateUtils.getToday())); importSummary = service.saveImportSummary(importSummary); log.info("User:" + service.getUsername() + " executed report template :" + importSummary.getReportName() + " on " + Calendar.getInstance().getTime()); return Collections.singletonMap("importSummary", importSummary); } }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTextField.java
@Override public <V> V getValue() { String value = super.getValue(); if (isTrimming()) { value = StringUtils.trim(value); }/*from w w w . ja va 2s . c o m*/ value = Strings.emptyToNull(value); Datatype datatype = getActualDatatype(); if (value != null && datatype != null) { try { return (V) datatype.parse(value, locale); } catch (ParseException e) { Logger log = LoggerFactory.getLogger(WebAbstractTextField.class); log.debug("Unable to parse value of component {}\n{}", getId(), e.getMessage()); return null; } } else { return (V) value; } }
From source file:edu.csudh.goTorosBank.WithdrawServlet.java
/** * TODO: Finish filling this out..../*from w w w . j ava 2 s .c o m*/ * @param request * @param response * @throws ServletException * @throws IOException */ @Override @SuppressWarnings("unchecked") //need this to suppress warnings for our json.put protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { getServletContext().log("goGet () called"); JSONObject returnJSON = new JSONObject(); response.setContentType("application/json"); HttpSession userSession = request.getSession(); String username = (String) userSession.getAttribute("username"); try { DatabaseInterface database = new DatabaseInterface(); User myUser = database.getUser(username); if (request.getParameter("accountID") == null || request.getParameter("amount") == null) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "Not valid arguments!"); //response.getWriter().write(returnJSON.toJSONString()); return; } int accountID = Integer.parseInt(request.getParameter("accountID")); float amount = Float.parseFloat(request.getParameter("amount")); Account accountFrom = myUser.getUserAccount(accountID); String personGettingPaid = request.getParameter("personGettingPaid"); String billType = request.getParameter("billType"); String memo = request.getParameter("memo"); //Checks if user has selected an account if (myUser.getUserAccounts().size() == 0) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "No account to withdraw from"); } //checks if user has sufficient funds else if (0 > (accountFrom.getAccountBalance() - amount)) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "Insufficient funds in account" + accountFrom.getAccountNumber()); } //checks that user withdraws in amounts of 20 else if (amount % 20 != 0) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "Must withdraw in amounts of 20"); } //checks that uer doesn't withdraw more than $500.00 else if (amount > 500) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "Withdraw amount cannot exceed $500.00"); } else if (personGettingPaid == null) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "There is no person getting payed"); } else if (billType == null) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "There is no bill description"); } //creates check for user and makes changes to the database... else { //response.setContentType("image/jpeg"); File blueCheck = new File("blank-blue-check"); String pathToWeb = getServletContext().getRealPath("/" + blueCheck); //File blueCheck = new File(pathToWeb + "blank-blue-check.jpg"); returnJSON.put("pathToWeb", pathToWeb); String fullpath = writeIntoCheck(pathToWeb, username, Float.toString(amount), "AMOUNT IN WORDS", "DATE", personGettingPaid, "BULLSHIT"); String[] fullpathSplit = fullpath.split("/"); String filename = fullpathSplit[fullpathSplit.length - 1]; database.withdraw(accountID, amount, username); returnJSON.put("filename", filename); returnJSON.put("successfulWithdraw", true); returnJSON.put("message", "Successfully withdrew $" + amount + " from account " + accountID); } } catch (SQLException s) { returnJSON.put("errorMessage", "Sorry we have a SQLException"); returnJSON.put("errorMessage2", s); } catch (ClassNotFoundException cl) { returnJSON.put("errorMessage", "Sorry we have a ClassNotFoundException"); returnJSON.put("errorMessage2", cl); } catch (ParseException p) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "ParseException: " + p.getMessage()); } /*added new case, where parseInt finds nothing*/ catch (NumberFormatException e) { returnJSON.put("successfulWithdraw", false); returnJSON.put("message", "NumberFormatException " + e.getMessage()); } response.getWriter().write(returnJSON.toJSONString()); }
From source file:com.flexive.shared.FxFormatUtils.java
/** * Convert a String to DateTime// www . ja v a2s.c om * * @param value value to convert * @return Date */ public static Date toDateTime(String value) { try { try { return FxValueRendererFactory.getDateTimeFormat().parse(unquote(value)); } catch (ParseException e) { try { //fallback to universal format if "short" format is no match return new SimpleDateFormat(UNIVERSAL_TIMEFORMAT).parse(unquote(value)); } catch (ParseException e2) { return getDateFormat().parse(unquote(value)); } } } catch (Exception e) { throw new FxConversionException(e, "ex.conversion.value.error", FxDate.class.getCanonicalName(), value, e.getMessage()).asRuntimeException(); } }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
public static Calendar convertFromStringToCalendar(String sDate, String dateFormat, TimeZone tz) { Calendar calDate = null;/* w ww. j a va2 s . c o m*/ SimpleDateFormat formatter; Date date; if (CRPortalUtil.isValidDate(sDate, dateFormat)) { formatter = new SimpleDateFormat(dateFormat); //formatter.setTimeZone(tz); try { date = (Date) formatter.parse(sDate); calDate = Calendar.getInstance(tz); calDate.setTime(date); } catch (java.text.ParseException e) { LOG.warn(e.getMessage()); LOG.warn("Setting date to null"); } } return calDate; }