List of usage examples for java.text ParseException getCause
public synchronized Throwable getCause()
From source file:uk.ac.ebi.intact.editor.controller.curate.publication.PublicationController.java
public void publicationYearChanged(ValueChangeEvent evt) { setUnsavedChanges(true);/*from ww w . j ava 2 s . c o m*/ Short newValue = (Short) evt.getNewValue(); if (newValue != null && newValue > 0) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy"); try { this.publication.setPublicationDate(formatter.parse(Short.toString(newValue))); this.year = newValue; setExperimentAnnotation(Annotation.PUBLICATION_YEAR, Annotation.PUBLICATION_YEAR_MI, Short.toString(newValue)); } catch (ParseException e) { this.year = null; addErrorMessage("The publication year is not a valid year " + newValue, e.getCause() + ": " + e.getMessage()); } } else { this.publication.setPublicationDate(null); this.year = null; } }
From source file:churashima.action.manage.ExpensesAction.java
@Execute(input = "expenses.jsp") public String entryExecute() { ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class); SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class); Expenses expenses = new Expenses(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); try {//from w ww .j a v a 2 s.co m expenses.date = sdf.parse(expensesForm.strDate); } catch (ParseException e) { e.printStackTrace(); } if (expensesForm.subjectId == null) { ActionMessages errors = new ActionMessages(); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", //?????? new Object[] { "" })); ActionMessagesUtil.addErrors(RequestUtil.getRequest(), errors); expensesForm.subjectList = subjectDao.selectForSearch(null, null); return "expenses.jsp"; } expenses.subjectId = expensesForm.subjectId; expenses.place = expensesForm.place; expenses.name = expensesForm.name; expenses.comment = expensesForm.comment; expenses.category = expensesForm.category; expenses.categoryDetail = expensesForm.detail; expenses.openFlg = expensesForm.openFlg; expenses.isExcludeTax = expensesForm.isExcludeTax; TaxDao taxDao = SingletonS2Container.getComponent(TaxDao.class); BigDecimal tax = taxDao.selectByDate(expenses.date); if (Const.TAX_EXCLUDE.equals(expensesForm.isExcludeTax)) { // ????? expenses.priceTax = expensesForm.price.multiply(tax); expenses.priceExcludeTax = expensesForm.price; expenses.price = expenses.priceExcludeTax.add(expenses.priceTax); } else { // ???? expenses.price = expensesForm.price; expenses.priceExcludeTax = expensesForm.price.divide(BigDecimal.valueOf(1).add(tax), 3, BigDecimal.ROUND_HALF_UP); // ? expenses.priceTax = expenses.price.subtract(expenses.priceExcludeTax); } // Timestamp now = new Timestamp(System.currentTimeMillis()); expenses.deleted = false; expenses.updDate = now; expenses.updId = null; expenses.insDate = now; expenses.insId = null; try { expensesDao.insert(expenses); } catch (SQLRuntimeException e) { SQLException e2 = (SQLException) e.getCause(); if (e2.getErrorCode() == 0) { //??? ActionMessages errors = new ActionMessages(); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.already.entried", //?????? new Object[] { "????" })); ActionMessagesUtil.addErrors(RequestUtil.getRequest(), errors); return "/manage/expenses"; } } return "/manage/expenses"; }
From source file:com.virtusa.akura.staff.controller.ClassTeacherController.java
/** * Saves or updates the relevant instance of ClassTeacher. * * @param request - an object of HttpServletRequest * @param result - containing list of errors and ClassTeacher instance to which data was bound * @param model - a HashMap that contains information of the ClassTeacher * @param classTeacher - an instance of ClassTeacher * @return - name of the view which is redirected to * @throws AkuraAppException - The exception details that occurred when saving or updating ClassTeacher * instances./*from w w w . ja v a 2 s. c om*/ */ @RequestMapping(REQ_MAP_SAVE_UPDATE_CLASS_TEACHER) public String saveOrUpdateClassTeacher(@ModelAttribute(MODEL_ATT_CLASS_TEACHER) ClassTeacher classTeacher, BindingResult result, HttpServletRequest request, ModelMap model) throws AkuraAppException { String message; String year = (request.getParameter(GET_PARA_CLASS_TEACHER_YEAR) != null) ? request.getParameter(GET_PARA_CLASS_TEACHER_YEAR) : AkuraWebConstant.STRING_ZERO; model.addAttribute(MODEL_ATT_THIS_YEAR, request.getParameter(GET_PARA_YEAR)); String reqClassGrade = request.getParameter(GET_PARA_CLASS_GRADE); ClassTeacher classTeacherObj = staffService.findClassTeacher(classTeacher.getClassTeacherId()); if (year.equals(YEAR_ZERO) || classTeacher.getStaff().getStaffId() == 0 || classTeacher.getClassGrade().getClassGradeId() == 0) { model.addAttribute(MODEL_ATT_CLASS_GRADE, reqClassGrade); message = new ErrorMsgLoader().getErrorMessage(ERROR_MESSAGE_REQUIRED_FIELD); model.addAttribute(MODEL_ATT_THIS_YEAR, request.getParameter(GET_PARA_YEAR)); model.addAttribute(MODEL_ATT_SELECTED_YEAR_VAL, year); model.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_VAL, classTeacher.getClassGrade().getClassGradeId()); model.addAttribute(MODEL_ATT_SELECTED_STAFF_ID_VAL, classTeacher.getStaff().getStaffId()); request.setAttribute(REQUEST_STATE, Boolean.TRUE); model.addAttribute(MODEL_ATT_MESSAGE, message); model.addAttribute(MODEL_ATT_SEARCH_CLASS_TEACHER, SortUtil.sortClassTeacherList(getClassTeacherList(request))); if (Boolean.parseBoolean(request.getParameter(REQUEST_PARA_SELECT_VAL))) { model.addAttribute(MODEL_ATT_SHOW_EDIT, Boolean.TRUE); model.addAttribute(SELECTED_OBJ, classTeacherObj); } return VIEW_GET_CLASS_TEACHER_ALLOCATION; } else { try { year = year + YEAR_01_01; SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); Date date = null; try { date = (Date) formatter.parse(year); } catch (ParseException e) { LOG.debug(PARSE_EXCEPTION); } classTeacher.setYear(date); int classGradeId = classTeacher.getClassGrade().getClassGradeId(); int staffId = classTeacher.getStaff().getStaffId(); ClassGrade classGrade = commonService.findClassGrade(classGradeId); Staff staff = staffService.findStaff(staffId); classTeacher.setClassGrade(classGrade); classTeacher.setStaff(staff); List<ClassTeacher> classTeachers = staffService.getClassTeacherListByYear(date); if (classTeacher.getClassTeacherId() > 0) { return updateClassTeacher(classTeacher, model, date, classGrade, classTeachers); } else { // This if,else statement was written in order to validate the departure date // of the current Teacher and to assign a new class teacher for that // Particular class as a new teacher ClassTeacher currentClassTeacher = staffService.getClassTeacher(classGrade, Integer.parseInt(request.getParameter(GET_PARA_CLASS_TEACHER_YEAR).toString())); if (currentClassTeacher == null) { return createNewClassTeacher(classTeacher, model, date, classTeachers); } else { int staffIdForGetCurrentStaffMember = currentClassTeacher.getStaff().getStaffId(); Staff currentStaffObject = staffService.findStaff(staffIdForGetCurrentStaffMember); if (currentStaffObject.getDateOfDeparture() != null) { return createNewClassTeacher(classTeacher, model, date, classTeachers); } else { int currentYear = DateUtil.currentYearOnly(); if (Integer.parseInt(request.getParameter(GET_PARA_YEAR)) == currentYear) { model.addAttribute(MODEL_ATT_SHOW_EDIT, Boolean.TRUE); request.setAttribute(REQUEST_STATE, Boolean.TRUE); } model.addAttribute(MODEL_ATT_CLASS_GRADE, reqClassGrade); model.addAttribute(MODEL_ATT_THIS_YEAR, request.getParameter(GET_PARA_YEAR)); model.addAttribute(MODEL_ATT_SELECTED_YEAR_VAL, request.getParameter(GET_PARA_CLASS_TEACHER_YEAR)); model.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_VAL, classTeacher.getClassGrade().getClassGradeId()); model.addAttribute(MODEL_ATT_SELECTED_STAFF_ID_VAL, classTeacher.getStaff().getStaffId()); model.addAttribute(MODEL_ATT_SEARCH_CLASS_TEACHER, SortUtil.sortClassTeacherList(getClassTeacherList(request))); return updateClassTeacher(classTeacher, model, date, classGrade, classTeachers); } } } } catch (AkuraAppException e) { if (e.getCause() instanceof DataIntegrityViolationException) { message = new ErrorMsgLoader().getErrorMessage(REF_UI_CLASSTEACHER_EXIST); ClassTeacher newClassTeacher = new ClassTeacher(); model.addAttribute(MODEL_ATT_CLASS_TEACHER, newClassTeacher); model.addAttribute(MODEL_ATT_MESSAGE, message); return VIEW_GET_CLASS_TEACHER_ALLOCATION; } else { throw e; } } } }
From source file:org.kuali.kpme.tklm.time.missedpunch.web.MissedPunchLookupableImpl.java
@Override protected Collection<?> executeSearch(Map<String, String> searchCriteria, List<String> wildcardAsLiteralSearchCriteria, boolean bounded, Integer searchResultsLimit) { List<MissedPunchBo> results = new ArrayList<MissedPunchBo>(); LocalDate fromDate = null;/*from w w w .ja va 2 s. c o m*/ LocalDate toDate = null; String toDateString = TKUtils.getToDateString(searchCriteria.get("actionDate")); String fromDateString = TKUtils.getFromDateString(searchCriteria.get("actionDate")); String actionTimeString = searchCriteria.get("actionTime"); searchCriteria.remove("actionTime"); if (StringUtils.isNotBlank(searchCriteria.get("actionDate"))) { Range range = SearchExpressionUtils.parseRange(searchCriteria.get("actionDate")); boolean invalid = false; if (range.getLowerBoundValue() != null && range.getUpperBoundValue() != null) { fromDate = TKUtils.formatDateString(fromDateString); if (fromDate == null) { GlobalVariables.getMessageMap().putError("lookupCriteria[rangeLowerBoundKeyPrefix_actionDate]", "error.invalidLookupDate", range.getLowerBoundValue()); invalid = true; } toDate = TKUtils.formatDateString(toDateString); if (toDate == null) { GlobalVariables.getMessageMap().putError("lookupCriteria[actionDate]", "error.invalidLookupDate", range.getUpperBoundValue()); invalid = true; } } else if (range.getLowerBoundValue() != null) { fromDate = TKUtils.formatDateString(fromDateString); if (fromDate == null) { GlobalVariables.getMessageMap().putError("lookupCriteria[rangeLowerBoundKeyPrefix_actionDate]", "error.invalidLookupDate", range.getLowerBoundValue()); invalid = true; } } else if (range.getUpperBoundValue() != null) { toDate = TKUtils.formatDateString(toDateString); if (toDate == null) { GlobalVariables.getMessageMap().putError("lookupCriteria[actionDate]", "error.invalidLookupDate", range.getUpperBoundValue()); invalid = true; } } if (invalid) { return new ArrayList<TimeBlockBo>(); } } searchCriteria.remove("actionDate"); Collection<?> searchResults = super.executeSearch(searchCriteria, wildcardAsLiteralSearchCriteria, bounded, searchResultsLimit); //clear result messages, these will be re-added with the correct number of retrieved objects once filtering has been completed. if (ObjectUtils .isNotNull(GlobalVariables.getMessageMap().getInfoMessagesForProperty("LookupResultMessages"))) { GlobalVariables.getMessageMap().getInfoMessagesForProperty("LookupResultMessages").clear(); } for (Object searchResult : searchResults) { MissedPunchBo missedPunch = (MissedPunchBo) searchResult; results.add(missedPunch); } results = filterByPrincipalId(results, GlobalVariables.getUserSession().getPrincipalId()); results = filterByActionDateRange(results, fromDate, toDate); if (!StringUtils.isBlank(actionTimeString)) { try { results = filterByActionTime(results, actionTimeString); } catch (ParseException e) { LOG.warn("caught ParseException while filtering results by Missed Action Time. Cause: " + e.getCause()); } } //LookupableImpl sets an info message with the number of results it found. //locate the position of this specific message and replace it with the number of filtered results. /* AutoPopulatingList<ErrorMessage> infos = GlobalVariables.getMessageMap().getInfoMessagesForProperty("LookupResultMessages"); AutoPopulatingList<ErrorMessage> correctedInfos = new AutoPopulatingList(ErrorMessage.class);*/ //copy alll but the /* for(ErrorMessage info : infos) { if(!info.getErrorKey().equalsIgnoreCase(RiceKeyConstants.INFO_LOOKUP_RESULTS_DISPLAY_ALL)) { correctedInfos.add(info); } }*/ /* for(ErrorMessage info : correctedInfos) { GlobalVariables.getMessageMap().putError("LookupResultMessages", info); }*/ super.generateLookupResultsMessages(searchCriteria, results, bounded, searchResultsLimit); return results; }
From source file:org.wso2.carbon.analytics.dataservice.core.indexing.AnalyticsDataIndexer.java
private DrillDownQuery createDrillDownQuery(AnalyticsDrillDownRequest drillDownRequest, Map<String, ColumnDefinition> indices, FacetsConfig config, String rangeField, AnalyticsDrillDownRange range) throws AnalyticsIndexException { Query languageQuery = new MatchAllDocsQuery(); try {// w w w . j a v a 2 s .co m if (drillDownRequest.getQuery() != null && !drillDownRequest.getQuery().isEmpty()) { Analyzer analyzer = getPerFieldAnalyzerWrapper(indices); languageQuery = new AnalyticsQueryParser(analyzer, indices).parse(drillDownRequest.getQuery()); } DrillDownQuery drillDownQuery = new DrillDownQuery(config, languageQuery); if (range != null && rangeField != null) { drillDownQuery.add(rangeField, NumericRangeQuery.newDoubleRange(rangeField, range.getFrom(), range.getTo(), true, false)); } if (drillDownRequest.getCategoryPaths() != null && !drillDownRequest.getCategoryPaths().isEmpty()) { for (Map.Entry<String, List<String>> entry : drillDownRequest.getCategoryPaths().entrySet()) { List<String> path = entry.getValue(); String[] pathAsArray; if (path == null || path.isEmpty()) { pathAsArray = new String[] {}; } else { pathAsArray = path.toArray(new String[path.size()]); } drillDownQuery.add(entry.getKey(), pathAsArray); } } return drillDownQuery; } catch (org.apache.lucene.queryparser.classic.ParseException e) { throw new AnalyticsIndexException( "Error while parsing lucene query '" + languageQuery + "': " + e.getMessage(), e.getCause()); } }