List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:org.openwms.common.comm.err.tcp.ErrorTelegramMapper.java
/** * {@inheritDoc}/* w ww. j av a2 s . c om*/ */ @Override public Message<ErrorMessage> mapTo(String telegram, Map<String, Object> headers) { int startPayload = LENGTH_HEADER + forType().length(); int startCreateDate = startPayload + ERROR_CODE_LENGTH; try { return new GenericMessage<>(new ErrorMessage.Builder() .withErrorCode(telegram.substring(startPayload, startCreateDate)) .withCreateDate(telegram.substring(startCreateDate, startCreateDate + DATE_LENGTH)).build(), CommonMessageFactory.createHeaders(telegram, headers)); } catch (ParseException e) { throw new MessageMismatchException(e.getMessage()); } }
From source file:org.apache.xmlrpc.DefaultTypeFactory.java
public Object createDate(String cdata) { try {/*from w ww . jav a 2 s . com*/ return dateTool.parse(cdata.trim()); } catch (ParseException p) { throw new RuntimeException(p.getMessage()); } }
From source file:org.openwms.common.comm.synq.tcp.TimesyncTelegramMapper.java
/** * {@inheritDoc}//from ww w.j a va 2 s . com */ @Override public Message<TimesyncRequest> mapTo(String telegram, Map<String, Object> headers) { LOGGER.debug("Telegram to transform: [{}]", telegram); int startSendertime = LENGTH_HEADER + forType().length(); TimesyncRequest request = new TimesyncRequest(); try { request.setSenderTimer(asDate(telegram.substring(startSendertime, startSendertime + DATE_LENGTH))); GenericMessage<TimesyncRequest> result = new GenericMessage<>(request, CommonMessageFactory.createHeaders(telegram, headers)); LOGGER.debug("Transformed telegram into TimesyncRequest message:" + result); return result; } catch (ParseException e) { throw new MessageMismatchException(e.getMessage()); } }
From source file:com.company.controller.admin.StudentController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(HttpServletRequest req) { try {/* w w w .ja va2 s. c o m*/ Student s = new Student(); s.setFirstName(req.getParameter("firstName")); s.setLastName(req.getParameter("lastName")); s.setEmail(req.getParameter("email")); s.setGender(req.getParameter("gender")); s.setContactNo(req.getParameter("contactNo")); try { DateFormat dob = new SimpleDateFormat("yyyy-mm-dd"); s.setDob(dob.parse(req.getParameter("dob"))); } catch (ParseException pe) { System.out.println(pe.getMessage()); } s.setStatus(req.getParameter("status") != null); if (req.getParameter("id") != null && req.getParameter("id").equals("0")) { //return s.toString(); studentService.insert(s); } else { s.setId(Integer.parseInt(req.getParameter("id"))); studentService.update(s); } } catch (SQLException se) { return se.getMessage(); } return "redirect:/admin/students"; }
From source file:org.openwms.common.comm.sysu.tcp.SYSUTelegramMapper.java
/** * {@inheritDoc}/*from ww w .j a va 2s. c om*/ */ @Override public Message<SystemUpdateMessage> mapTo(String telegram, Map<String, Object> headers) { LOGGER.debug("Telegram to transform: [{}]", telegram); if (provider == null) { throw new RuntimeException("Telegram handling " + SystemUpdateMessage.IDENTIFIER + " not supported"); } int startLocationGroup = LENGTH_HEADER + forType().length(); int startErrorCode = startLocationGroup + provider.lengthLocationGroupName(); int startCreateDate = startErrorCode + ERROR_CODE_LENGTH; SystemUpdateMessage message; try { message = new SystemUpdateMessage.Builder() .withLocationGroupName(telegram.substring(startLocationGroup, startErrorCode)) .withErrorCode(telegram.substring(startErrorCode, startCreateDate)) .withCreateDate(telegram.substring(startCreateDate, startCreateDate + DATE_LENGTH)).build(); return new GenericMessage<>(message, CommonMessageFactory.createHeaders(telegram, headers)); } catch (ParseException e) { throw new MessageMismatchException(e.getMessage()); } }
From source file:com.tearoffcalendar.activities.FaceUpCardFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { // Notify the parent activity of selected item String string = cardNames.get(position); Log.v(TAG, "onListItemClick Card name: " + string); SimpleDateFormat dateFormat = new SimpleDateFormat(Card.DATE_FORMAT); try {// w w w . j a va 2 s .c o m Date convertedDate = dateFormat.parse(string); mCallback.onCardSelected(convertedDate); } catch (ParseException pe) { Log.e(TAG, pe.getMessage()); } // Set the item as checked to be highlighted when in two-pane layout getListView().setItemChecked(position, true); }
From source file:fm.last.citrine.web.TaskDTOValidator.java
@Override public void validate(Object object, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "task.groupName", "group.empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "task.name", "name.empty"); Task task = ((TaskDTO) object).getTask(); if (!StringUtils.isEmpty(task.getTimerSchedule())) { // if there is a timer schedule, check it is valid for quartz cron trigger try {//from w ww .j a va 2 s .co m new CronExpression(task.getTimerSchedule()); } catch (ParseException e) { errors.rejectValue("task.timerSchedule", "timer.schedule.invalid", e.getMessage()); } } if (task.getGroupName() != null && Constants.GROUP_NAME_ALL.equals(task.getGroupName().trim())) { errors.rejectValue("task.groupName", "group.illegal", Constants.GROUP_NAME_ALL + " not allowed as group name"); } }
From source file:org.openwms.common.comm.req.tcp.RequestTelegramMapper.java
/** * {@inheritDoc}/* ww w .j a v a2 s .c o m*/ */ @Override public Message<RequestMessage> mapTo(String telegram, Map<String, Object> headers) { if (provider == null) { throw new RuntimeException("Telegram handling " + RequestMessage.IDENTIFIER + " not supported"); } int startPayload = LENGTH_HEADER + forType().length(); int startActualLocation = startPayload + provider.barcodeLength(); int startTargetLocation = startActualLocation + provider.locationIdLength(); int startErrorCode = startTargetLocation + provider.locationIdLength(); int startCreateDate = startErrorCode + Payload.ERROR_CODE_LENGTH; RequestMessage message; try { message = new RequestMessage.Builder(provider) .withBarcode(telegram.substring(startPayload, startActualLocation)) .withActualLocation(telegram.substring(startActualLocation, startTargetLocation)) .withTargetLocation(telegram.substring(startTargetLocation, startErrorCode)) .withErrorCode(telegram.substring(startErrorCode, startCreateDate)) .withCreateDate(telegram.substring(startCreateDate, startCreateDate + Payload.DATE_LENGTH)) .build(); return new GenericMessage<>(message, CommonMessageFactory.createHeaders(telegram, headers)); } catch (ParseException e) { throw new MessageMismatchException(e.getMessage()); } }
From source file:org.kuali.student.core.krms.termresolver.PersonId2DeceasedDateTermResolver.java
@Override public Date resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { String personId = (String) resolvedPrereqs.get(RulesExecutionConstants.PERSON_ID_TERM.getName()); Entity entity = getIdentityService().getEntity(personId); Date deceasedDate = null;//from ww w . j a va 2 s . c o m if (entity.getBioDemographics().getDeceasedDate() != null) { try { deceasedDate = DateUtils.parseDate(entity.getBioDemographics().getDeceasedDate(), new String[] { EntityBioDemographicsContract.DECEASED_DATE_FORMAT }); } catch (ParseException e) { throw new TermResolutionException(e.getMessage(), this, parameters, e); } } return deceasedDate; }
From source file:com.basetechnology.s0.agentserver.AgentDefinition.java
static public AgentDefinition fromJson(AgentServer agentServer, User user, JSONObject agentJson, boolean update) throws AgentServerException, SymbolException { // Parse the JSON for the agent definition // If we have the user, ignore user from JSON if (user == null) { String userId = agentJson.optString("user"); if (userId == null || userId.trim().length() == 0) throw new AgentServerException("Agent definition user id ('user') is missing"); user = agentServer.getUser(userId); if (user == User.noUser) throw new AgentServerException("Agent definition user id does not exist: '" + userId + "'"); }//from w w w. j ava 2 s.co m // Parse agent definition name String agentDefinitionName = agentJson.optString("name"); if (agentDefinitionName == null || agentDefinitionName.trim().length() == 0 && !update) throw new AgentServerException("Agent definition name ('name') is missing"); // Parse agent definition description String agentDescription = agentJson.optString("description"); if (agentDescription == null || agentDescription.trim().length() == 0) agentDescription = ""; //log.info("Adding new agent definition named: " + agentDefinitionName + " for user: " + user.id); // TODO: Parse comment AgentDefinitionList agentMap = agentServer.agentDefinitions.get(user.id); if (agentMap == null) { agentMap = new AgentDefinitionList(); agentServer.agentDefinitions.add(user.id, agentMap); } // Check if named agent definition already exists if (agentMap.containsKey(agentDefinitionName)) throw new AgentServerException("Agent definition name already exists: '" + agentDefinitionName + "'"); AgentDefinition agent = null; SymbolManager symbolManager = new SymbolManager(); String invalidParameterNames = ""; // Parse 'parameter' fields FieldList parameters = null; if (agentJson.has("parameters")) { JSONArray parameterJson = agentJson.optJSONArray("parameters"); parameters = new FieldList(); int numparameter = parameterJson.length(); for (int i = 0; i < numparameter; i++) { JSONObject outputJson = parameterJson.optJSONObject(i); Field field = Field.fromJsonx(symbolManager.getSymbolTable("parameter"), outputJson); // TODO: give error for dup names parameters.add(field); } } // Parse inputs - data source references DataSourceReferenceList inputs = null; if (agentJson.has("inputs")) { SymbolTable symbolTable = symbolManager.getSymbolTable("parameter_values"); JSONArray inputsJson = agentJson.optJSONArray("inputs"); inputs = new DataSourceReferenceList(); int numInputs = inputsJson.length(); for (int i = 0; i < numInputs; i++) { Object element = inputsJson.opt(i); String dataSourceName = null; DataSourceReference dataSourceReference = null; if (element instanceof JSONObject) { // Ignore empty data sources JSONObject elementJson = (JSONObject) element; if (elementJson.length() == 0) continue; // Parse the 'name' for data source if (!elementJson.has("name")) throw new AgentServerException("Inputs JSON object is missing 'name' key"); dataSourceName = elementJson.optString("name"); // Parse the 'data_source' if (!elementJson.has("data_source")) throw new AgentServerException("Inputs JSON object is missing 'data_source' key"); String dataSourceDataSource = elementJson.optString("data_source"); // Validate the data source reference AgentDefinition dataSourceDefinition = agentMap.get(dataSourceDataSource); if (dataSourceDefinition == null) throw new AgentServerException( "Inputs JSON for data source name '" + dataSourceName + "' references data source '" + dataSourceDataSource + "' which is not a defined data source"); // Parse the optional 'parameter_values' SymbolValues parameterValues = null; if (elementJson.has("parameter_values")) { Object parametersObject = elementJson.opt("parameter_values"); if (!(parametersObject instanceof JSONObject)) throw new AgentServerException( "Inputs parameters_values value expected JSON object but found " + parametersObject.getClass().getSimpleName()); JSONObject parameterValuesJson = elementJson.optJSONObject("parameter_values"); parameterValues = SymbolValues.fromJson(symbolTable, parameterValuesJson); } else parameterValues = new SymbolValues("parameters"); // Validate that parameter value keys are all valid data source definition parameters Map<String, Value> treeMap = new TreeMap<String, Value>(); for (Symbol symbol : parameterValues) treeMap.put(symbol.name, null); invalidParameterNames = ""; for (String parameterName : treeMap.keySet()) if (!dataSourceDefinition.parameters.containsKey(parameterName)) invalidParameterNames += (invalidParameterNames.length() > 0 ? ", " : "") + parameterName; if (invalidParameterNames.length() > 0) throw new AgentServerException("Invalid parameter field names for inputs name '" + dataSourceName + "' for data source '" + agentDefinitionName + "': " + invalidParameterNames); // Construct the data source reference, including parameter values dataSourceReference = new DataSourceReference(dataSourceName, dataSourceDefinition, parameterValues); } else if (element instanceof String) { String dataSourceDataSource = (String) element; dataSourceName = dataSourceDataSource; // Validate the data source reference AgentDefinition dataSourceDefinition = agentMap.get(dataSourceDataSource); if (dataSourceDefinition == null) throw new AgentServerException("Inputs JSON references data source '" + dataSourceDataSource + "' which is not a defined data source"); // Construct the data source reference dataSourceReference = new DataSourceReference(dataSourceName, dataSourceDefinition); } else throw new AgentServerException( "Expected JSON object or string for input data source, but encountered " + element.getClass().getSimpleName()); // Add this data source reference to the list inputs.add(dataSourceReference); } } // Parse 'timers' list NameValueList<AgentTimer> timers = null; if (agentJson.has("timers")) { timers = new NameValueList<AgentTimer>(); JSONArray timersJson = agentJson.optJSONArray("timers"); if (timersJson != null) { int numScripts = timersJson.length(); for (int i = 0; i < numScripts; i++) { // Get JSON for next timer JSONObject timerJson = timersJson.optJSONObject(i); // Ignore empty timers if (!timerJson.keys().hasNext()) continue; AgentTimer timerDefinition = AgentTimer.fromJson(timerJson); timers.put(timerDefinition.name, timerDefinition); } } } // Parse 'conditions' list NameValueList<AgentCondition> conditions = null; if (agentJson.has("conditions")) { conditions = new NameValueList<AgentCondition>(); JSONArray conditionsJson = agentJson.optJSONArray("conditions"); if (conditionsJson != null) { int numScripts = conditionsJson.length(); for (int i = 0; i < numScripts; i++) { // Get JSON for next condition JSONObject conditionJson = conditionsJson.optJSONObject(i); // Ignore empty conditions if (!conditionJson.keys().hasNext()) continue; AgentCondition conditionDefinition = AgentCondition.fromJson(conditionJson); conditions.put(conditionDefinition.name, conditionDefinition); } } } // Parse 'notifications' list NameValueList<NotificationDefinition> notifications = null; if (agentJson.has("notifications")) { notifications = new NameValueList<NotificationDefinition>(); JSONArray notificationsJson = agentJson.optJSONArray("notifications"); if (notificationsJson != null) { int numScripts = notificationsJson.length(); for (int i = 0; i < numScripts; i++) { // Get JSON for next notification JSONObject notificationJson = notificationsJson.optJSONObject(i); // Ignore empty notifications if (!notificationJson.keys().hasNext()) continue; NotificationDefinition notificationDefinition = NotificationDefinition .fromJson(notificationJson); notifications.put(notificationDefinition.name, notificationDefinition); } } } // Parse 'scripts' list NameValueList<ScriptDefinition> scripts = null; if (agentJson.has("scripts")) { scripts = new NameValueList<ScriptDefinition>(); JSONArray scriptsJson = agentJson.optJSONArray("scripts"); if (scriptsJson != null) { int numScripts = scriptsJson.length(); for (int i = 0; i < numScripts; i++) { // Get JSON for next script JSONObject scriptJson = scriptsJson.optJSONObject(i); // Ignore empty scripts if (!scriptJson.keys().hasNext()) continue; ScriptDefinition scriptDefinition = ScriptDefinition.fromJson(scriptJson); scripts.put(scriptDefinition.name, scriptDefinition); } } } FieldList outputsList = null; if (agentJson.has("outputs")) { JSONArray outputsJson = agentJson.optJSONArray("outputs"); outputsList = new FieldList(); int numOutputs = outputsJson.length(); for (int i = 0; i < numOutputs; i++) { // Get next output field definition JSONObject outputJson = outputsJson.optJSONObject(i); // Ignore empty field definitions if (outputJson.length() == 0) continue; // Parse the output field definition Field field = Field.fromJsonx(symbolManager.getSymbolTable("outputs"), outputJson); // TODO: give error for dup names // Add parsed field to the outputs field list outputsList.add(field); } } // Parse 'scratchpad' fields FieldList scratchpad = null; if (agentJson.has("scratchpad")) { JSONArray scratchpadJson = agentJson.optJSONArray("scratchpad"); scratchpad = new FieldList(); int numMemory = scratchpadJson.length(); for (int i = 0; i < numMemory; i++) { JSONObject fieldJson = scratchpadJson.optJSONObject(i); Field field = Field.fromJsonx(symbolManager.getSymbolTable("scratchpad"), fieldJson); // TODO: give error for dup names scratchpad.add(field); } } // Parse 'memory' fields FieldList memory = null; if (agentJson.has("memory")) { JSONArray memoryJson = agentJson.optJSONArray("memory"); memory = new FieldList(); int numMemory = memoryJson.length(); for (int i = 0; i < numMemory; i++) { JSONObject fieldJson = memoryJson.optJSONObject(i); Field field = Field.fromJsonx(symbolManager.getSymbolTable("memory"), fieldJson); // TODO: give error for dup names memory.add(field); } } // Parse 'goals' List<Goal> goalsList = null; if (agentJson.has("goals")) { JSONArray goalsJson = agentJson.optJSONArray("goals"); goalsList = new ArrayList<Goal>(); int numGoals = goalsJson.length(); for (int i = 0; i < numGoals; i++) { // Get next goal definition JSONObject goalJson = goalsJson.optJSONObject(i); // Ignore empty goal definitions if (goalJson.length() == 0) continue; // Parse the goal definition Goal goal = Goal.fromJson(goalJson); // Add parsed goal to the goals list goalsList.add(goal); } } String reportingIntervalExpression = agentJson.has("reporting_interval") ? agentJson.optString("reporting_interval") : update ? null : agentServer.getDefaultReportingInterval(); String triggerIntervalExpression = agentJson.has("trigger_interval") ? agentJson.optString("trigger_interval") : update ? null : agentServer.getDefaultTriggerInterval(); String created = agentJson.optString("created", null); long timeCreated = -1; try { timeCreated = created != null ? DateUtils.parseRfcString(created) : -1; } catch (ParseException e) { throw new AgentServerException("Unable to parse created date ('" + created + "') - " + e.getMessage()); } String modified = agentJson.optString("modified", null); long timeModified = -1; try { timeModified = modified != null ? DateUtils.parseRfcString(modified) : -1; } catch (ParseException e) { throw new AgentServerException( "Unable to parse modified date ('" + modified + "') - " + e.getMessage()); } Boolean enabled = update ? null : true; if (agentJson.has("enabled")) enabled = agentJson.optBoolean("enabled"); // Validate keys JsonUtils.validateKeys(agentJson, "Agent definition", new ArrayList<String>(Arrays.asList("user", "name", "description", "parameters", "inputs", "timers", "conditions", "notifications", "scripts", "outputs", "scratchpad", "memory", "goals", "created", "modified", "reporting_interval", "trigger_interval", "enabled"))); // TODO: Differentiate create vs. recreate vs. update - handling of SHA agent = new AgentDefinition(agentServer, user, agentDefinitionName, agentDescription, parameters, inputs, timers, conditions, scripts, scratchpad, memory, notifications, outputsList, goalsList, triggerIntervalExpression, reportingIntervalExpression, timeCreated, timeModified, enabled, update); // Return the created agent definition return agent; }