DataValidator { void validateAttributeOptionCombo( final CategoryOptionCombo attributeOptionCombo, final Period period, final DataSet dataSet, final DataElement dataElement ) throws WebMessageException { for ( CategoryOption option : attributeOptionCombo.getCategoryOptions() ) { if ( option.getStartDate() != null && period.getEndDate().before( option.getStartDate() ) ) { throw new WebMessageException( conflict( "Period " + period.getIsoDate() + " is before start date " + i18nManager.getI18nFormat().formatDate( option.getStartDate() ) + " for attributeOption '" + option.getName() + "'" ) ); } if ( option.getEndDate() != null && period.getStartDate().after( option.getAdjustedEndDate( dataSet, dataElement ) ) ) { throw new WebMessageException( conflict( "Period " + period.getIsoDate() + " is after end date " + i18nManager.getI18nFormat().formatDate( option.getAdjustedEndDate( dataSet, dataElement ) ) + " for attributeOption '" + option.getName() + "'" ) ); } } } DataValidator( final CategoryService categoryService, final OrganisationUnitService organisationUnitService,
        final DataSetService dataSetService, final IdentifiableObjectManager idObjectManager,
        final InputUtils inputUtils, final FileResourceService fileResourceService, final I18nManager i18nManager,
        final CalendarService calendarService, final AggregateAccessManager accessManager );   }
@Test public void testValidateAttributeOptionComboWithValidData() throws WebMessageException { dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, null ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, null, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodMar, dataSetA, dataElementA ); categoryOptionA.setStartDate( jan15 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, null ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, null, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodMar, dataSetA, dataElementA ); categoryOptionA.setEndDate( jan15 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, null ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, null, dataElementA ); dataSetA.setOpenPeriodsAfterCoEndDate( 1 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, dataSetA, dataElementA ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, dataSetA, null ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, null, dataElementA ); }
@Test( expected = WebMessageException.class ) public void testValidateAttributeOptionComboWithEarlyData() throws WebMessageException { categoryOptionA.setStartDate( feb15 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodJan, dataSetA, dataElementA ); }
@Test( expected = WebMessageException.class ) public void testValidateAttributeOptionComboWithLateData() throws WebMessageException { categoryOptionA.setEndDate( jan15 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodFeb, null, dataElementA ); }
@Test( expected = WebMessageException.class ) public void testValidateAttributeOptionComboWithLateAdjustedData() throws WebMessageException { categoryOptionA.setEndDate( jan15 ); dataSetA.setOpenPeriodsAfterCoEndDate( 1 ); dataValidator.validateAttributeOptionCombo( optionComboA, periodMar, dataSetA, dataElementA ); }