List of usage examples for org.joda.time DateTime parse
@FromString public static DateTime parse(String str)
From source file:org.sonatype.nexus.scheduling.schedule.Schedule.java
License:Open Source License
/** * Helper method to get {@link Date} types, handles conversion from string automatically. *///from ww w .ja va 2 s .co m public static Date stringToDate(final String string) { return DateTime.parse(string).toDate(); }
From source file:org.springframework.cloud.dataflow.rest.client.support.JobParameterJacksonDeserializer.java
License:Apache License
@Override public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final String value = node.get("value").asText(); final boolean identifying = node.get("identifying").asBoolean(); final String type = node.get("type").asText(); final JobParameter jobParameter; if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) { if ("DATE".equalsIgnoreCase(type)) { // TODO: when upgraded to Java8 use java DateTime jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying); } else if ("DOUBLE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Double.valueOf(value), identifying); } else if ("LONG".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Long.valueOf(value), identifying); } else {/*w w w. j a v a2s .c om*/ throw new IllegalStateException("Unsupported JobParameter type: " + type); } } else { jobParameter = new JobParameter(value, identifying); } if (logger.isDebugEnabled()) { logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)", jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying())); } return jobParameter; }
From source file:org.springframework.xd.rest.client.impl.support.JobParameterJacksonDeserializer.java
License:Apache License
@Override public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final String value = node.get("value").asText(); final boolean identifying = node.get("identifying").asBoolean(); final String type = node.get("type").asText(); final JobParameter jobParameter; if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) { if ("DATE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying); } else if ("DOUBLE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Double.valueOf(value), identifying); } else if ("LONG".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Long.valueOf(value), identifying); } else {/*from ww w . j a va 2s . com*/ throw new IllegalStateException("Unsupported JobParameter type: " + type); } } else { jobParameter = new JobParameter(value, identifying); } if (logger.isDebugEnabled()) { logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)", jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying())); } return jobParameter; }
From source file:org.supercsv.cellprocessor.joda.ParseDateTime.java
License:Apache License
/** * {@inheritDoc} */ @Override protected DateTime parse(final String string) { return DateTime.parse(string); }
From source file:org.sweble.wom3.swcadapter.utils.WtWom3Toolbox.java
License:Open Source License
public Wom3Document astToWom(PageId pageId, EngProcessedPage ast) { Wom3Document womDoc = AstToWomConverter.convert(getWikiConfig().getParserConfig(), null, null, pageId.getTitle().getTitle(), "Mr. Tester", DateTime.parse("2012-12-07T12:15:30.000+01:00"), ast.getPage());/* ww w.j av a 2 s. com*/ return womDoc; }
From source file:org.tanrabad.survey.entity.Entity.java
License:Apache License
public void setUpdateTimestamp(String updateTimestamp) { this.updateTimestamp = DateTime.parse(updateTimestamp); }
From source file:org.tomighty.plugin.statistics.core.csv.CSVUtil.java
License:Apache License
public static List<Pomodoro> convertCSVListToPomodoros(final List<String[]> csvList) { List<Pomodoro> pomodoroList = newArrayList(); Date start = null;/*ww w. java2 s. c om*/ Date end = null; for (String[] csvRow : csvList) { if (Phase.valueOf(csvRow[1]) == Phase.POMODORO) { final String statusString = csvRow[2]; final Status status = Status.valueOf(statusString); final String time = csvRow[0]; if (status == Status.STARTED) { start = DateTime.parse(time).toDate(); } else if (status == Status.FINISHED) { end = DateTime.parse(time).toDate(); if (start != null) { final Pomodoro pomodoro = new Pomodoro(start, end, Pomodoro.PomodoroStatus.FINISHED); pomodoroList.add(pomodoro); start = null; } } else if (status == Status.INTERRUPTED) { end = DateTime.parse(time).toDate(); if (start != null) { final Pomodoro pomodoro = new Pomodoro(start, end, Pomodoro.PomodoroStatus.UNFINISHED); pomodoroList.add(pomodoro); start = null; } } } } return pomodoroList; }
From source file:org.venice.beachfront.bfapi.services.SceneService.java
License:Apache License
/** * Gets Scene information from the IA-broker. * <p>/*from ww w. j a v a 2s . c om*/ * As part of this process, the Scene metadata will be written to the local Beachfront database. * * @param sceneId * The scene ID * @param planetApiKey * The users planet key * @param withTides * Include tides information or not * @return The Scene object */ public Scene getScene(String sceneId, String planetApiKey, boolean withTides) throws UserException { piazzaLogger.log(String.format("Requesting Scene %s information.", sceneId), Severity.INFORMATIONAL); String provider = this.getProviderUrlFragment(sceneId); String platform = Scene.parsePlatform(sceneId); String externalId = Scene.parseExternalId(sceneId); String scenePath = String.format("%s/%s/%s", provider, platform, externalId); ResponseEntity<JsonNode> response; try { response = this.restTemplate.getForEntity(UriComponentsBuilder.newInstance() .scheme(this.iaBrokerProtocol).host(this.iaBrokerServer).port(this.iaBrokerPort).path(scenePath) .queryParam("PL_API_KEY", planetApiKey).queryParam("tides", withTides).build().toUri(), JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log(String.format("Error Requesting Information for Scene %s with Code %s and Message %s", sceneId, exception.getRawStatusCode(), exception.getResponseBodyAsString()), Severity.ERROR); HttpStatus recommendedErrorStatus = exception.getStatusCode(); if (recommendedErrorStatus.equals(HttpStatus.UNAUTHORIZED)) { recommendedErrorStatus = HttpStatus.BAD_REQUEST; // 401 Unauthorized logs out the client, and we don't // want that } String message = String.format("Upstream error getting Planet scene. (%d) platform=%s id=%s", exception.getStatusCode().value(), platform, externalId); throw new UserException(message, exception.getMessage(), recommendedErrorStatus); } JsonNode responseJson = response.getBody(); Scene scene = new Scene(); try { piazzaLogger.log(String.format("Beginning parsing of successful response of Scene %s data.", sceneId), Severity.INFORMATIONAL); scene.setRawJson(responseJson); scene.setSceneId(platform + ":" + responseJson.get("id").asText()); scene.setCloudCover(responseJson.get("properties").get("cloudCover").asDouble()); scene.setHorizontalAccuracy(responseJson.get("properties").get("srcHorizontalAccuracy").asText()); scene.setResolution(responseJson.get("properties").get("resolution").asInt()); scene.setCaptureTime(DateTime.parse(responseJson.get("properties").get("acquiredDate").asText())); scene.setSensorName(responseJson.get("properties").get("sensorName").asText()); scene.setUri(UriComponentsBuilder.newInstance().scheme(this.iaBrokerProtocol).host(this.iaBrokerServer) .port(this.iaBrokerPort).path(scenePath).toUriString()); try { // The response from IA-Broker is a GeoJSON feature. Convert to Geometry. FeatureJSON featureReader = new FeatureJSON(); String geoJsonString = new ObjectMapper().writeValueAsString(responseJson); SimpleFeature feature = featureReader.readFeature(geoJsonString); Geometry geometry = (Geometry) feature.getDefaultGeometry(); scene.setGeometry(geometry); } catch (IOException exception) { String error = String.format( "Could not convert Scene %s response to GeoJSON object. This scene will not store properly in the database.", scene.getSceneId()); piazzaLogger.log(error, Severity.ERROR); throw new UserException(error, exception, HttpStatus.INTERNAL_SERVER_ERROR); } String status = "active"; if (platform.equals(Scene.PLATFORM_PLANET_RAPIDEYE) || platform.equals(Scene.PLATFORM_PLANET_PLANETSCOPE)) { status = responseJson.get("properties").get("status").asText(); } else { // Status active } scene.setStatus(status); if (withTides) { scene.setTide(responseJson.get("properties").get("currentTide").asDouble()); scene.setTideMin24H(responseJson.get("properties").get("minimumTide24Hours").asDouble()); scene.setTideMax24H(responseJson.get("properties").get("maximumTide24Hours").asDouble()); } } catch (NullPointerException ex) { piazzaLogger.log(String.format( "Error parsing of successful response from IA-Broker for Scene %s data with Error %s. Raw Response content: %s", sceneId, ex.getMessage(), responseJson.toString()), Severity.ERROR); throw new UserException("Error parsing JSON Scene Response from Upstream Broker Service.", ex, HttpStatus.INTERNAL_SERVER_ERROR); } piazzaLogger.log(String.format("Successfully parsed Scene metadata for Scene %s with Status %s", sceneId, scene.getStatus()), Severity.INFORMATIONAL); sceneDao.save(scene); return scene; }
From source file:org.waarp.gateway.kernel.rest.RestArgument.java
License:Open Source License
/** * Check Time only (no signature)//from ww w . j a v a 2 s .c om * * @param maxInterval * @throws HttpInvalidAuthenticationException */ public void checkTime(long maxInterval) throws HttpInvalidAuthenticationException { DateTime dateTime = new DateTime(); String date = getXAuthTimestamp(); if (date != null && !date.isEmpty()) { DateTime received = DateTime.parse(date); if (maxInterval > 0) { Duration duration = new Duration(received, dateTime); if (Math.abs(duration.getMillis()) >= maxInterval) { throw new HttpInvalidAuthenticationException( "timestamp is not compatible with the maximum delay allowed"); } } } else if (maxInterval > 0) { throw new HttpInvalidAuthenticationException("timestamp absent while required"); } }
From source file:org.waarp.gateway.kernel.rest.RestArgument.java
License:Open Source License
/** * This implementation of authentication is as follow: if X_AUTH is included in the URI or Header<br> * 0) Check that timestamp is correct (|curtime - timestamp| < maxinterval) from ARG_X_AUTH_TIMESTAMP, if maxInterval is 0, * not mandatory<br>/*from w ww . j av a2 s .c o m*/ * 1) Get all URI args (except ARG_X_AUTH_KEY itself, but including timestamp), lowered case, in alphabetic order<br> * 2) Add an extra Key if not null (from ARG_X_AUTH_INTERNALKEY)<br> * 3) Compute an hash (SHA-1 or SHA-256)<br> * 4) Compare this hash with ARG_X_AUTH_KEY<br> * * @param hmacSha256 * SHA-256 key to create the signature * @param extraKey * will be added as ARG_X_AUTH_INTERNALKEY might be null * @param maxInterval * ARG_X_AUTH_TIMESTAMP will be tested if value > 0 * @throws HttpInvalidAuthenticationException * if the authentication failed */ public void checkBaseAuthent(HmacSha256 hmacSha256, String extraKey, long maxInterval) throws HttpInvalidAuthenticationException { TreeMap<String, String> treeMap = new TreeMap<String, String>(); String argPath = getUri(); ObjectNode arguri = getUriArgs(); if (arguri == null) { throw new HttpInvalidAuthenticationException("Not enough argument"); } Iterator<Entry<String, JsonNode>> iterator = arguri.fields(); DateTime dateTime = new DateTime(); DateTime received = null; while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); String key = entry.getKey(); if (key.equalsIgnoreCase(REST_ROOT_FIELD.ARG_X_AUTH_KEY.field)) { continue; } JsonNode values = entry.getValue(); if (key.equalsIgnoreCase(REST_ROOT_FIELD.ARG_X_AUTH_TIMESTAMP.field)) { received = DateTime.parse(values.asText()); } String keylower = key.toLowerCase(); if (values != null) { String val = null; if (values.isArray()) { JsonNode jsonNode = values.get(values.size() - 1); val = jsonNode.asText(); } else { val = values.asText(); } treeMap.put(keylower, val); } } if (received == null) { String date = getXAuthTimestamp(); received = DateTime.parse(date); treeMap.put(REST_ROOT_FIELD.ARG_X_AUTH_TIMESTAMP.field.toLowerCase(), date); } String user = getXAuthUser(); if (user != null && !user.isEmpty()) { treeMap.put(REST_ROOT_FIELD.ARG_X_AUTH_USER.field.toLowerCase(), user); } if (maxInterval > 0 && received != null) { Duration duration = new Duration(received, dateTime); if (Math.abs(duration.getMillis()) >= maxInterval) { throw new HttpInvalidAuthenticationException( "timestamp is not compatible with the maximum delay allowed"); } } else if (maxInterval > 0) { throw new HttpInvalidAuthenticationException("timestamp absent while required"); } String key = computeKey(hmacSha256, extraKey, treeMap, argPath); if (!key.equalsIgnoreCase(getXAuthKey())) { throw new HttpInvalidAuthenticationException("Invalid Authentication Key"); } }