EventGeometryCheck implements Checker { @Override public ImportSummary check( ImmutableEvent event, WorkContext ctx ) { IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme(); ProgramStage programStage = ctx.getProgramStage( scheme, event.getProgramStage() ); if ( Objects.nonNull( event.getGeometry() ) && programStageFeatureCompatibleWithEventGeometry( event, programStage ) ) { return new ImportSummary( ImportStatus.ERROR, "Geometry (" + event.getGeometry().getGeometryType() + ") does not conform to the feature type (" + programStage.getFeatureType().value() + ") specified for the program stage: " + programStage.getUid() ).setReference( event.getEvent() ).incrementIgnored(); } return success(); }  @Override ImportSummary check( ImmutableEvent event, WorkContext ctx );  }
@Test public void allowEventWithNoGeometry() { ProgramStage programStage = createProgramStage(); when( workContext.getProgramStage( programStageIdScheme, event.getProgramStage() ) ).thenReturn( programStage ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertNoError( importSummary ); }
@Test public void failOnEventWithGeometryAndProgramStageWithNoGeometry() { event.setGeometry( createRandomPoint() ); ProgramStage programStage = createProgramStage(); programStage.setFeatureType( FeatureType.NONE ); when( workContext.getProgramStage( programStageIdScheme, event.getProgramStage() ) ).thenReturn( programStage ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, "Geometry (Point) does not conform to the feature type (None) specified for the program stage: " + programStage.getUid() ); }