Search in sources :

Example 1 with DateUtils.parseDate

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);
}
Also used : Date(java.util.Date) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 2 with DateUtils.parseDate

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;
}
Also used : SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate)

Example 3 with DateUtils.parseDate

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();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test)

Example 4 with DateUtils.parseDate

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();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test)

Example 5 with DateUtils.parseDate

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;
}
Also used : java.util(java.util) QueryItem(org.hisp.dhis.common.QueryItem) ValueType(org.hisp.dhis.common.ValueType) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ProgramTrackedEntityAttributeStore(org.hisp.dhis.program.ProgramTrackedEntityAttributeStore) StringUtils(org.apache.commons.lang3.StringUtils) Program(org.hisp.dhis.program.Program) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Service(org.springframework.stereotype.Service) ImageIO(javax.imageio.ImageIO) User(org.hisp.dhis.user.User) UserService(org.hisp.dhis.user.UserService) ImmutableSet(com.google.common.collect.ImmutableSet) FileResource(org.hisp.dhis.fileresource.FileResource) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) QueryOperator(org.hisp.dhis.common.QueryOperator) Collectors(java.util.stream.Collectors) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CurrentUserService(org.hisp.dhis.user.CurrentUserService) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) AclService(org.hisp.dhis.security.acl.AclService) ProgramService(org.hisp.dhis.program.ProgramService) MathUtils(org.hisp.dhis.system.util.MathUtils) DateUtils(org.hisp.dhis.util.DateUtils) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ValueType(org.hisp.dhis.common.ValueType) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SimpleReportLine (eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine)3 DateUtils.parseDate (org.apache.commons.lang3.time.DateUtils.parseDate)3 Test (org.junit.Test)3 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 java.util (java.util)1 Date (java.util.Date)1 Collectors (java.util.stream.Collectors)1 ImageIO (javax.imageio.ImageIO)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SystemDefaults (org.apache.commons.lang3.test.SystemDefaults)1 QueryItem (org.hisp.dhis.common.QueryItem)1 QueryOperator (org.hisp.dhis.common.QueryOperator)1 ValueType (org.hisp.dhis.common.ValueType)1 FileResource (org.hisp.dhis.fileresource.FileResource)1 FileResourceService (org.hisp.dhis.fileresource.FileResourceService)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitService (org.hisp.dhis.organisationunit.OrganisationUnitService)1 Program (org.hisp.dhis.program.Program)1