@Test public void testDate() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); OffsetDateTime offsetDateTime = null; ScientificName scientificName = new ScientificName(); scientificName.setFullScientificName("Cleyera japonica"); scientificName.setGenusOrMonomial("Cleyera"); scientificName.setSpecificEpithet("japonica"); scientificName.setAuthor("Plabon"); scientificName.setScientificNameGroup("cleyera japonica"); CrsSpecimenTransformer crsSpecimenTransformer = new CrsSpecimenTransformer(etlStatistics); CrsExtractor extractor = new CrsExtractor(specimenFile, etlStatistics); outerloop: for (XMLRecordInfo extracted : extractor) { Element elemet = extracted.getRecord(); List<Element> elems = DOMUtil.getDescendants(elemet, "ncrsDetermination"); for (Element element : elems) { Object dateObj = ReflectionUtil.call(crsSpecimenTransformer, "date", new Class[] {Element.class, String.class}, new Object[] {element, "abcd:IdentificationDate"}); offsetDateTime = (OffsetDateTime) dateObj; if (offsetDateTime != null) break outerloop; } } String expectedOffsetTime = "1980-11-22T00:00Z"; assertEquals(expectedOffsetTime, offsetDateTime.toString()); }
private OffsetDateTime date(Element e, String tag) { String s = val(e, tag); if (s == null) return null; char[] chars = new char[8]; Arrays.fill(chars, '0'); for (int i = 0; i < s.length(); ++i) chars[i] = s.charAt(i); if (chars[4] == '0' && chars[5] == '0') chars[5] = '1'; if (chars[6] == '0' && chars[7] == '0') chars[7] = '1'; ESDateInput input = new ESDateInput(String.valueOf(chars)); OffsetDateTime odt = input.parseAsLocalDate(formatter); if (odt == null && !suppressErrors) { warn(MSG_BAD_DATE, tag, s); } return odt; }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private OffsetDateTime date(Element e, String tag) { String s = val(e, tag); if (s == null) return null; char[] chars = new char[8]; Arrays.fill(chars, '0'); for (int i = 0; i < s.length(); ++i) chars[i] = s.charAt(i); if (chars[4] == '0' && chars[5] == '0') chars[5] = '1'; if (chars[6] == '0' && chars[7] == '0') chars[7] = '1'; ESDateInput input = new ESDateInput(String.valueOf(chars)); OffsetDateTime odt = input.parseAsLocalDate(formatter); if (odt == null && !suppressErrors) { warn(MSG_BAD_DATE, tag, s); } return odt; } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private OffsetDateTime date(Element e, String tag) { String s = val(e, tag); if (s == null) return null; char[] chars = new char[8]; Arrays.fill(chars, '0'); for (int i = 0; i < s.length(); ++i) chars[i] = s.charAt(i); if (chars[4] == '0' && chars[5] == '0') chars[5] = '1'; if (chars[6] == '0' && chars[7] == '0') chars[7] = '1'; ESDateInput input = new ESDateInput(String.valueOf(chars)); OffsetDateTime odt = input.parseAsLocalDate(formatter); if (odt == null && !suppressErrors) { warn(MSG_BAD_DATE, tag, s); } return odt; } CrsSpecimenTransformer(ETLStatistics stats); }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private OffsetDateTime date(Element e, String tag) { String s = val(e, tag); if (s == null) return null; char[] chars = new char[8]; Arrays.fill(chars, '0'); for (int i = 0; i < s.length(); ++i) chars[i] = s.charAt(i); if (chars[4] == '0' && chars[5] == '0') chars[5] = '1'; if (chars[6] == '0' && chars[7] == '0') chars[7] = '1'; ESDateInput input = new ESDateInput(String.valueOf(chars)); OffsetDateTime odt = input.parseAsLocalDate(formatter); if (odt == null && !suppressErrors) { warn(MSG_BAD_DATE, tag, s); } return odt; } CrsSpecimenTransformer(ETLStatistics stats);  }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private OffsetDateTime date(Element e, String tag) { String s = val(e, tag); if (s == null) return null; char[] chars = new char[8]; Arrays.fill(chars, '0'); for (int i = 0; i < s.length(); ++i) chars[i] = s.charAt(i); if (chars[4] == '0' && chars[5] == '0') chars[5] = '1'; if (chars[6] == '0' && chars[7] == '0') chars[7] = '1'; ESDateInput input = new ESDateInput(String.valueOf(chars)); OffsetDateTime odt = input.parseAsLocalDate(formatter); if (odt == null && !suppressErrors) { warn(MSG_BAD_DATE, tag, s); } return odt; } CrsSpecimenTransformer(ETLStatistics stats);   }