use of org.apache.commons.lang3.time.DateUtils.parseDate in project commons-lang by apache.
the class DateFormatUtilsTest method testLang530.
@SystemDefaults(timezone = "UTC")
@Test
public void testLang530() throws ParseException {
final Date d = new Date();
final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
final Date d2 = DateUtils.parseDate(isoDateStr, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
// the format loses milliseconds so have to reintroduce them
assertEquals("Date not equal to itself ISO formatted and parsed", d.getTime(), d2.getTime() + d.getTime() % 1000);
}
use of org.apache.commons.lang3.time.DateUtils.parseDate in project dwoss by gg-net.
the class ReportLineEaoIT method make.
private ReportLine make(String isoDate, DocumentType docType, PositionType posType, double price) throws ParseException {
Date date = DateUtils.parseDate(isoDate, "yyyy-MM-dd");
ReportLine line = ReportLine.builder().name("PositionName").description("PositionDescription").dossierId(1).dossierIdentifier("DW1").documentType(docType).documentId(1).documentIdentifier("RE1").positionType(posType).customerId(1).amount(1).tax(0.19).price(price).uniqueUnitId(1).build();
line.setActual(date);
line.setReportingDate(date);
line.setContractor(DELL);
line.setSalesChannel(RETAILER);
return line;
}
use of org.apache.commons.lang3.time.DateUtils.parseDate in project dwoss by gg-net.
the class ReportLineEaoIT method testFindByUniqueUnitId.
@Test
public void testFindByUniqueUnitId() throws Exception {
String ISO = "yyyy-MM-dd";
Date d1 = DateUtils.parseDate("2010-01-01", ISO);
ReportLine line1 = new ReportLine("PersName1", "This is a TestDescription1", 137, "DW0037", 3, "RE0008", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line1.setReportingDate(DateUtils.parseDate("2009-01-01", ISO));
line1.setUniqueUnitId(10);
ReportLine line2 = new ReportLine("PersName2", "This is a TestDescription2", 1337, "DW0013", 3, "RE001", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line2.setReportingDate(DateUtils.parseDate("2009-07-10", ISO));
line2.setUniqueUnitId(10);
ReportLine line3 = new ReportLine("PersName3", "This is a TestDescription3", 13, "DW1337", 3, "RE0003", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line3.setReportingDate(d1);
utx.begin();
em.joinTransaction();
em.persist(line1);
em.persist(line2);
em.persist(line3);
utx.commit();
utx.begin();
em.joinTransaction();
List<ReportLine> rls = new ReportLineEao(em).findByUniqueUnitId(10);
assertEquals(2, rls.size());
rls = new ReportLineEao(em).findByUniqueUnitId(1);
assertTrue(rls.isEmpty());
utx.commit();
}
use of org.apache.commons.lang3.time.DateUtils.parseDate in project dwoss by gg-net.
the class ReportLineEaoIT method testFindFromTillUnreportedUnit.
@Test
public void testFindFromTillUnreportedUnit() throws Exception {
String ISO = "yyyy-MM-dd";
ReportLine line1 = new ReportLine("PersName1", "This is a TestDescription1", 137, "DW0037", 3, "RE0008", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line1.setReportingDate(DateUtils.parseDate("2009-01-01", ISO));
line1.setUniqueUnitId(10);
line1.setContractor(TradeName.DELL);
ReportLine line2 = new ReportLine("PersName2", "This is a TestDescription2", 1337, "DW0013", 3, "RE001", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line2.setReportingDate(DateUtils.parseDate("2010-01-01", ISO));
line2.setUniqueUnitId(10);
line2.setContractor(TradeName.DELL);
ReportLine line3 = new ReportLine("PersName3", "This is a TestDescription3", 13, "DW1337", 3, "RE0003", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line3.setReportingDate(DateUtils.parseDate("2011-01-01", ISO));
line3.setContractor(TradeName.DELL);
ReportLine line4 = new ReportLine("PersName3", "This is a TestDescription3", 13, "DW1337", 3, "RE0003", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
line4.setReportingDate(DateUtils.parseDate("2012-01-01", ISO));
line4.setContractor(TradeName.OTTO);
Report r = new Report("KW201301", DELL, DateUtils.parseDate("2009-01-01", ISO), DateUtils.parseDate("2009-01-07", ISO));
r.add(line3);
utx.begin();
em.joinTransaction();
em.persist(line1);
em.persist(line2);
em.persist(line3);
em.persist(line4);
em.persist(r);
utx.commit();
ReportLineEao reportLineEao = new ReportLineEao(em);
utx.begin();
em.joinTransaction();
List<ReportLine> rls = reportLineEao.findUnreportedUnits(DELL, DateUtils.parseDate("2008-12-31", ISO), DateUtils.parseDate("2010-12-31", ISO));
assertEquals(2, rls.size());
rls = reportLineEao.findUnreportedUnits(OTTO, DateUtils.parseDate("2009-12-31", ISO), DateUtils.parseDate("2013-12-31", ISO));
assertEquals(1, rls.size());
utx.commit();
}
use of org.apache.commons.lang3.time.DateUtils.parseDate in project dhis2-core by dhis2.
the class DefaultTrackedEntityAttributeService method validateValueType.
@Override
@Transactional(readOnly = true)
public String validateValueType(TrackedEntityAttribute trackedEntityAttribute, String value) {
Assert.notNull(trackedEntityAttribute, "tracked entity attribute is required");
ValueType valueType = trackedEntityAttribute.getValueType();
String errorValue = StringUtils.substring(value, 0, 30);
if (value.length() > VALUE_MAX_LENGTH) {
return "Value length is greater than 50000 chars for attribute " + trackedEntityAttribute.getUid();
}
if (ValueType.NUMBER == valueType && !MathUtils.isNumeric(value)) {
return "Value '" + errorValue + "' is not a valid numeric type for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.BOOLEAN == valueType && !MathUtils.isBool(value)) {
return "Value '" + errorValue + "' is not a valid boolean type for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.DATE == valueType && DateUtils.parseDate(value) == null) {
return "Value '" + errorValue + "' is not a valid date type for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.TRUE_ONLY == valueType && !"true".equals(value)) {
return "Value '" + errorValue + "' is not true (true-only type) for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.USERNAME == valueType) {
if (userService.getUserByUsername(value) == null) {
return "Value '" + errorValue + "' is not a valid username for attribute " + trackedEntityAttribute.getUid();
}
} else if (ValueType.DATE == valueType && !DateUtils.dateIsValid(value)) {
return "Value '" + errorValue + "' is not a valid date for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.DATETIME == valueType && !DateUtils.dateTimeIsValid(value)) {
return "Value '" + errorValue + "' is not a valid datetime for attribute " + trackedEntityAttribute.getUid();
} else if (ValueType.IMAGE == valueType) {
return validateImage(value);
} else if (null != trackedEntityAttribute.getOptionSet() && trackedEntityAttribute.getOptionSet().getOptions().stream().filter(Objects::nonNull).noneMatch(o -> o.getCode().equalsIgnoreCase(value))) {
return "Value '" + errorValue + "' is not a valid option for attribute " + trackedEntityAttribute.getUid() + " and option set " + trackedEntityAttribute.getOptionSet().getUid();
} else if (ValueType.FILE_RESOURCE == valueType && fileResourceService.getFileResource(value) == null) {
return "Value '" + value + "' is not a valid file resource.";
} else if (ValueType.ORGANISATION_UNIT == valueType && organisationUnitService.getOrganisationUnit(value) == null) {
return "Value '" + value + "' is not a valid organisation unit.";
}
return null;
}
Aggregations