AttributeOptionComboDateCheck implements Checker { @Override public ImportSummary check( ImmutableEvent event, WorkContext ctx ) { CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get( event.getUid() ); Date executionDate = null; if ( event.getEventDate() != null ) { executionDate = DateUtils.parseDate( event.getEventDate() ); } Date dueDate = new Date(); if ( event.getDueDate() != null ) { dueDate = DateUtils.parseDate( event.getDueDate() ); } Date eventDate = executionDate != null ? executionDate : dueDate; if ( eventDate == null ) { return error( "Event date can not be empty", event.getEvent() ); } for ( CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions() ) { if ( categoryOption.getStartDate() != null && eventDate.compareTo( categoryOption.getStartDate() ) < 0 ) { return error( "Event date " + getMediumDateString( eventDate ) + " is before start date " + getMediumDateString( categoryOption.getStartDate() ) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent() ); } if ( categoryOption.getEndDate() != null && eventDate.compareTo( categoryOption.getEndDate() ) > 0 ) { return error( "Event date " + getMediumDateString( eventDate ) + " is after end date " + getMediumDateString( categoryOption.getEndDate() ) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent() ); } } return success(); }  @Override ImportSummary check( ImmutableEvent event, WorkContext ctx );  }
@Test public void failOnCategoryOptionStartDateBeforeEventDate() { event.setEventDate( "2019-05-01" ); event.setDueDate( "2019-05-10" ); CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo( "2020-01-01", true ); mockContext( categoryOptionCombo ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), this.workContext ); assertHasError( importSummary, event, "Event date 2019-05-01 is before start date 2020-01-01 for attributeOption 'test'" ); }
@Test public void failOnCategoryOptionEndDateBeforeEventDate() { event.setEventDate( "2019-05-01" ); event.setDueDate( "2019-05-10" ); CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo( "2019-04-01", false ); mockContext( categoryOptionCombo ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), this.workContext ); assertHasError( importSummary, event, "Event date 2019-05-01 is after end date 2019-04-01 for attributeOption 'test'" ); }