Java Code Examples for javax.xml.bind.DatatypeConverter#parseDateTime()
The following examples show how to use
javax.xml.bind.DatatypeConverter#parseDateTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TravisApiTest.java From jandy with GNU General Public License v3.0 | 6 votes |
@Test public void testGetBuild() throws Exception { long buildId = 79083233; server.expect(requestTo("https://api.travis-ci.org/builds/"+buildId)) .andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, "application/vnd.travis-ci.2+json")) .andRespond(withSuccess(output, MediaType.APPLICATION_JSON_UTF8)); TResult result = client.getBuild(79083233); System.out.println(result); Calendar calendar = DatatypeConverter.parseDateTime((String)result.getBuild().getStartedAt()); PrettyTime p = new PrettyTime(Locale.ENGLISH); System.out.println(p.format(calendar)); assertThat(result.getBuild().getCommitId(), is(result.getCommit().getId())); assertThat(result.getCommit().getId(), is(22542817L)); assertThat(result.getCommit().getMessage(), is("add depedency of icu4j")); assertThat(result.getCommit().getCommitterName(), is("JCooky")); }
Example 2
Source File: AssertionContentVerifier.java From development with Apache License 2.0 | 6 votes |
/** * Verify that the NotOnOrAfter attribute in any bearer * <SubjectConfirmationData> has not passed, subject to allowable clock skew * between the providers * * @throws AssertionValidationException */ void verifyAssertionExpirationDate(Node nodeAssertion, Node nodeConfirmationData) throws AssertionValidationException { Calendar expirationDate = DatatypeConverter.parseDateTime(XMLConverter .getStringAttValue(nodeConfirmationData, SamlXmlTags.ATTRIBUTE_NOT_ON_OR_AFTER)); if (now.equals(expirationDate) || now.after(expirationDate)) { String assertionId = XMLConverter.getStringAttValue(nodeAssertion, SamlXmlTags.ATTRIBUTE_ID); AssertionValidationException exception = new AssertionValidationException( String.format("Assertion (id=%s) expired", assertionId), AssertionValidationException.ReasonEnum.ASSERTION_EXPIRED, new String[] { assertionId }); throw exception; } }
Example 3
Source File: TestBiTemporal.java From java-client-api with Apache License 2.0 | 6 votes |
@Test // Test LSQT Query using temporalLsqtQuery. Do the query as REST reader public void testLsqtQuery() throws Exception { ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); // Read documents based on document URI and ALN Contains. We are just // looking for count of documents to be correct String docId = "javaSingleJSONDoc.json"; Calendar insertTime = DatatypeConverter .parseDateTime("2005-01-01T00:00:01"); insertJSONSingleDocument(temporalLsqtCollectionName, docId, null, null, insertTime); Calendar updateTime = DatatypeConverter .parseDateTime("2010-01-01T00:00:01"); updateJSONSingleDocument(temporalLsqtCollectionName, docId, null, updateTime); Thread.sleep(2000); validateLSQTQueryData(readerClient); }
Example 4
Source File: BitemporalTest.java From java-client-api with Apache License 2.0 | 6 votes |
@Test public void a_testCreate() throws Exception { String contents = "<test>" + "<system-start></system-start>" + "<system-end></system-end>" + "<valid-start>2014-08-19T00:00:00Z</valid-start>" + "<valid-end>2014-08-19T00:00:01Z</valid-end>" + "</test>"; TemporalDescriptor desc = docMgr.create(docMgr.newDocumentUriTemplate("xml"), null, new StringHandle(contents), null, null, temporalCollection); assertNotNull("Missing TemporalDescriptor from create", desc); assertNotNull(desc.getUri()); assertTrue(desc.getUri().endsWith(".xml")); String lastWriteTimestamp = desc.getTemporalSystemTime(); Calendar lastWriteTime = DatatypeConverter.parseDateTime(lastWriteTimestamp); assertNotNull(lastWriteTime); }
Example 5
Source File: ValueMeaningImpl.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
@Override public Calendar getValueMeaningBeginDate() { RDFNode valueMeaningBeginDate = getPropertyValue(mdrDatabase .getVocabulary().valueMeaningBeginDate); return DatatypeConverter.parseDateTime(valueMeaningBeginDate .asLiteral().getLexicalForm()); }
Example 6
Source File: IsoDateFormatValidator.java From zephyr with Apache License 2.0 | 5 votes |
@Override public boolean isValid(String value) { try { /* initial formats we're concerned about YYYY-MM-DDTHH:MM:SSZ YYYY-MM-DDTHH:MM:SS.SSSZ */ DatatypeConverter.parseDateTime(value); return true; } catch (IllegalArgumentException iae) { return false; } }
Example 7
Source File: ValueMeaningImpl.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
@Override public Calendar getValueMeaningEndDate() { RDFNode valueMeaningEndDate = getPropertyValue(mdrDatabase .getVocabulary().valueMeaningEndDate); if (valueMeaningEndDate == null) { logger.debug("ValueMeaning does not have endDate"); return null; } return DatatypeConverter.parseDateTime(valueMeaningEndDate.asLiteral() .getLexicalForm()); }
Example 8
Source File: TestBiTemporal.java From java-client-api with Apache License 2.0 | 5 votes |
@Test // Test LSQT Query using temporalLsqtQuery. Do the query as REST admin public void testLsqtQueryAsAdmin() throws Exception { ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); // Read documents based on document URI and ALN Contains. We are just // looking for count of documents to be correct String docId = "javaSingleJSONDoc.json"; Calendar insertTime = DatatypeConverter .parseDateTime("2005-01-01T00:00:01"); JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle( "2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON", docId); JSONDocumentManager docMgr = writerClient.newJSONDocumentManager(); docMgr.setMetadataCategories(Metadata.ALL); // put meta-data DocumentMetadataHandle mh = setMetadata(false); docMgr.write(docId, mh, handle, null, null, temporalLsqtCollectionName, insertTime); Calendar updateTime = DatatypeConverter .parseDateTime("2010-01-01T00:00:01"); docMgr.write(docId, mh, handle, null, null, temporalLsqtCollectionName, updateTime); Thread.sleep(2000); validateLSQTQueryData(writerClient); }
Example 9
Source File: ValueConverter.java From java-client-api with Apache License 2.0 | 5 votes |
static public Date StringToDate(String value) { if (value == null || value.length() == 0) { return null; } try { Calendar cal = DatatypeConverter.parseDateTime(value); return cal.getTime(); } catch(Exception e) { throw new IllegalArgumentException("Could not convert to Date: "+value, e); } }
Example 10
Source File: CloverDateTimeConvertor.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
public static Date parseXsdDateTimeToDate(String value) throws DataConversionException { Date result = null; String valueType = Date.class.getName(); try { Calendar calendar = DatatypeConverter.parseDateTime(value); result = calendar.getTime(); } catch(Exception e) { if (result != null) valueType = result.getClass().getName(); logger.fatal("Unable to parse xsd:dateTime to "+valueType+".",e); throw new DataConversionException("Unable to parse xsd:dateTime to "+valueType+".", e); } return result; }
Example 11
Source File: YTimerParameters.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public boolean parseYTimerType(Element eTimerTypeValue) throws IllegalArgumentException { XNode node = new XNodeParser(true).parse(eTimerTypeValue); if (node == null) throw new IllegalArgumentException("Invalid YTimerType XML"); String triggerStr = node.getChildText("trigger"); if (triggerStr == null) throw new IllegalArgumentException("Missing 'trigger' parameter"); // throws IllegalArgumentException if triggerStr is not a valid Trigger YWorkItemTimer.Trigger trigger = YWorkItemTimer.Trigger.valueOf(triggerStr); String expiry = node.getChildText("expiry"); if (expiry == null) throw new IllegalArgumentException("Missing 'expiry' parameter"); setWorkDaysOnly(node.getChild("workdays") != null); if (expiry.startsWith("P")) { // duration types start with P Duration duration = StringUtil.strToDuration(expiry); if (duration == null) throw new IllegalArgumentException("Malformed duration value"); set(trigger, duration); return true; } try { // test for xsd datetime Calendar calendar = DatatypeConverter.parseDateTime(expiry); set(trigger, calendar.getTime()); return true; } catch (IllegalArgumentException pe) { // do nothing here - trickle down } long time = StringUtil.strToLong(expiry, -1); // test for long if (time < 0) throw new IllegalArgumentException("Malformed expiry value"); set(trigger, new Date(time)); return true; }
Example 12
Source File: AdministrationRecordImpl.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
@Override public Calendar getEffectiveDate() { RDFNode effectiveDate = getPropertyValue(mdrDatabase.getVocabulary().effectiveDate); if (effectiveDate == null) { logger.debug("AdministrationRecord does not have effectiveDate"); return null; } return DatatypeConverter.parseDateTime(effectiveDate.asLiteral() .getLexicalForm()); }
Example 13
Source File: PermissibleValueImpl.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
@Override public Calendar getPermissibleValueBeginDate() { RDFNode permissibleValueBeginDate = getPropertyValue(mdrDatabase .getVocabulary().permissibleValueBeginDate); return DatatypeConverter.parseDateTime(permissibleValueBeginDate .asLiteral().getLexicalForm()); }
Example 14
Source File: ValueConverter.java From java-client-api with Apache License 2.0 | 4 votes |
static public Object convertToJava(String type, String value) { if ("xs:anySimpleType".equals(type)) return DatatypeConverter.parseAnySimpleType(value); if ("xs:base64Binary".equals(type)) return DatatypeConverter.parseBase64Binary(value); if ("xs:boolean".equals(type)) return StringToBoolean(value); if ("xs:byte".equals(type)) return DatatypeConverter.parseByte(value); if ("xs:date".equals(type)) return DatatypeConverter.parseDate(value); if ("xs:dateTime".equals(type)) return DatatypeConverter.parseDateTime(value); if ("xs:dayTimeDuration".equals(type)) return Utilities.getDatatypeFactory().newDurationDayTime(value); if ("xs:decimal".equals(type)) return DatatypeConverter.parseDecimal(value); if ("xs:double".equals(type)) return StringToDouble(value); if ("xs:duration".equals(type)) return Utilities.getDatatypeFactory().newDuration(value); if ("xs:float".equals(type)) return StringToFloat(value); if ("xs:int".equals(type)) return StringToInteger(value); if ("xs:integer".equals(type)) return DatatypeConverter.parseInteger(value); if ("xs:long".equals(type)) return StringToLong(value); if ("xs:short".equals(type)) return DatatypeConverter.parseShort(value); if ("xs:string".equals(type)) return DatatypeConverter.parseString(value); if ("xs:time".equals(type)) return DatatypeConverter.parseTime(value); if ("xs:unsignedInt".equals(type)) return DatatypeConverter.parseUnsignedInt(value); if ("xs:unsignedLong".equals(type)) { BigInteger bi = DatatypeConverter.parseInteger(value); if (bi.compareTo(MAX_UNSIGNED_LONG) < 0) { return bi.longValue(); } else { return bi; } } if ("xs:unsignedShort".equals(type)) return DatatypeConverter.parseUnsignedShort(value); if ("xs:yearMonthDuration".equals(type)) return Utilities.getDatatypeFactory().newDurationYearMonth(value); return value; }
Example 15
Source File: CalendarConverter.java From vraptor4 with Apache License 2.0 | 4 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String value = reader.getValue(); return DatatypeConverter.parseDateTime(value); }
Example 16
Source File: TestBiTempMetaValues.java From java-client-api with Apache License 2.0 | 4 votes |
@Test /* * Test bitemporal protections - NOWIPE With transaction. */ public void testProtectWipe() throws Exception { System.out.println("Inside testProtectWipe"); ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); Calendar insertTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:01"); Calendar updateTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:11"); String docId = "javaSingleJSONDoc.json"; JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle("2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON", docId ); JSONDocumentManager docMgr = writerClient.newJSONDocumentManager(); docMgr.write(docId, null, handle, null, null, temporalLsqtCollectionName, insertTime); Thread.sleep(5000); // Protect document for 60 sec. Use Duration. docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOWIPE, DatatypeFactory.newInstance().newDuration("PT60S")); JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle( "2003-01-01T00:00:00", "2012-12-31T23:59:59", "1999 Skyway Park - Updated - JSON", docId); docMgr.write(docId, null, handleUpd, null, null, temporalLsqtCollectionName, updateTime); StringBuilder str = new StringBuilder(); try { docMgr.wipe(docId, temporalLsqtCollectionName); } catch (Exception ex) { str.append(ex.getMessage()); System.out.println("Exception when delete within 60 sec is " + str.toString()); } assertTrue("Did not receive Expected Exception, Expecting TEMPORAL-PROTECTED, received " + str.toString(), str.toString().contains("TEMPORAL-PROTECTED")); JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager(); DocumentPage readResults = jsonDocMgr.read(docId); String content = jsonDocMgr.read(docId, new StringHandle()).get(); assertTrue("Wrong number of results", content.contains("1999 Skyway Park - Updated - JSON")); // Sleep for 60 secs and try to delete the same docId. Thread.sleep(60000); Transaction t1 = writerClient.openTransaction(); // TODO replace get with search and verify the system end time for the // document \ // temporal document will not be deleted from DB and using get will only // return the latest docuemnt. docMgr.wipe(docId, t1, temporalLsqtCollectionName); Thread.sleep(5000); t1.commit(); readResults = jsonDocMgr.read(docId); System.out.println("Number of results = " + readResults.size()); assertEquals("Wrong number of results", 0, readResults.size()); }
Example 17
Source File: TestSandBox.java From java-client-api with Apache License 2.0 | 4 votes |
@Test /* * Test bitemporal protections - NOUPDATE With transaction. */ public void testProtectUpdateInTransaction() throws Exception { System.out.println("Inside testProtectUpdateInTransaction"); ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); Calendar insertTime = DatatypeConverter .parseDateTime("2005-01-01T00:00:01"); Calendar updateTime = DatatypeConverter .parseDateTime("2005-01-01T00:00:11"); String docId = "javaSingleJSONDoc.json"; JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle( "2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON", docId); JSONDocumentManager docMgr = writerClient.newJSONDocumentManager(); Transaction t1 = writerClient.openTransaction(); Transaction t2 = null; docMgr.write("javaSingleJSONDocV1.json", docId, null, handle, null, t1, temporalLsqtCollectionName, insertTime); // Protect document for 30 sec from delete and update. Use Duration. docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOUPDATE, DatatypeFactory.newInstance().newDuration("PT30S"), t1); JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle( "2003-01-01T00:00:00", "2008-12-31T23:59:59", "1999 Skyway Park - Updated - JSON", docId); StringBuilder str = new StringBuilder(); try { docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime); } catch (Exception ex) { str.append(ex.getMessage()); System.out.println("Exception when update within 30 sec is " + str.toString()); } assertTrue( "Doc should not be updated", str.toString().contains( "The document javaSingleJSONDoc.json is protected noUpdate")); try { // Sleep for 40 secs and try to update the same docId. Thread.sleep(40000); docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime); Thread.sleep(5000); JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager(); DocumentPage readResults = jsonDocMgr.read(t1, docId); System.out.println("Number of results = " + readResults.size()); assertEquals("Wrong number of results", 1, readResults.size()); QueryManager queryMgr = writerClient.newQueryManager(); StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition termQuery = sqb .collection(temporalLsqtCollectionName); t1.commit(); long start = 1; t2 = writerClient.openTransaction(); DocumentPage termQueryResults = docMgr.search(termQuery, start, t2); System.out.println("Number of results = " + termQueryResults.getTotalSize()); assertEquals("Wrong number of results", 4, termQueryResults.getTotalSize()); } catch (Exception e) { System.out.println("Exception when update within 30 sec is " + e.getMessage()); } finally { if (t2 != null) t2.rollback(); writerClient.release(); } }
Example 18
Source File: ImmobiliareItUtils.java From OpenEstate-IO with Apache License 2.0 | 4 votes |
public static boolean isValidDateUpdatedType(Calendar value) { final Calendar min = DatatypeConverter.parseDateTime("2000-12-31T00:00:00"); return value != null && !value.before(min); }
Example 19
Source File: DatumBuilder.java From xml-avro with Apache License 2.0 | 4 votes |
private static long parseDateTime(String text) { Calendar c = DatatypeConverter.parseDateTime(text); c.setTimeZone(defaultTimeZone); return c.getTimeInMillis(); }
Example 20
Source File: TestBiTempMetaValues.java From java-client-api with Apache License 2.0 | 4 votes |
@Ignore /* * Test bitemporal protections - NOUPDATE With different transactions. Write * doc in T1. Protect in T2. Update doc in T1 within 30 sec duration. TODO * Wait for Git #542 */ public void testProtectUpdateInDiffTransactions() throws Exception { System.out.println("Inside testProtectUpdateInDiffTransactions"); ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); Calendar insertTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:01"); Calendar updateTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:11"); Transaction t1 = writerClient.openTransaction(); Transaction t2 = writerClient.openTransaction(); String docId = "javaSingleJSONDoc.json"; JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle("2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON", docId ); JSONDocumentManager docMgr = writerClient.newJSONDocumentManager(); docMgr.write("javaSingleJSONDocV1.json", docId, null, handle, null, t1, temporalLsqtCollectionName, insertTime); // Protect document for 30 sec from delete and update. Use Duration. Use T2 docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOUPDATE, DatatypeFactory.newInstance().newDuration("PT30S"), t2); JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle( "2003-01-01T00:00:00", "2008-12-31T23:59:59", "1999 Skyway Park - Updated - JSON", docId); StringBuilder str = new StringBuilder(); try { // Use t1 to write docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime); } catch (Exception ex) { str.append(ex.getMessage()); System.out.println("Exception when update within 30 sec is " + str.toString()); } // TODO Yet to know what exception message will be. #542 // assertTrue("Doc should not be updated", // str.toString().contains("The document javaSingleJSONDoc.json is protected noUpdate")); // Sleep for 40 secs and try to update the same docId. Thread.sleep(40000); docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime); Thread.sleep(5000); JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager(); DocumentPage readResults = jsonDocMgr.read(t1, docId); System.out.println("Number of results = " + readResults.size()); assertEquals("Wrong number of results", 1, readResults.size()); QueryManager queryMgr = writerClient.newQueryManager(); StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition termQuery = sqb.collection(temporalLsqtCollectionName); long start = 1; DocumentPage termQueryResults = docMgr.search(termQuery, start, t1); System.out .println("Number of results = " + termQueryResults.getTotalSize()); assertEquals("Wrong number of results", 4, termQueryResults.getTotalSize()); t1.rollback(); t2.rollback(); }