ProgramStageObjectBundleHook extends AbstractObjectBundleHook { @Override public <T extends IdentifiableObject> List<ErrorReport> validate( T object, ObjectBundle bundle ) { if ( object == null || !object.getClass().isAssignableFrom( ProgramStage.class ) ) { return new ArrayList<>(); } ProgramStage programStage = ( ProgramStage ) object; List<ErrorReport> errors = new ArrayList<>(); if ( programStage.getNextScheduleDate() != null ) { DataElement nextScheduleDate = bundle.getPreheat().get( bundle.getPreheatIdentifier(), DataElement.class, programStage.getNextScheduleDate().getUid() ); if ( !programStage.getDataElements().contains( programStage.getNextScheduleDate() ) || nextScheduleDate == null || !nextScheduleDate.getValueType().equals( ValueType.DATE ) ) { errors.add( new ErrorReport( ProgramStage.class, ErrorCode.E6001, programStage.getUid(), programStage.getNextScheduleDate().getUid() ) ); } } errors.addAll( validateProgramStageDataElementsAcl( programStage, bundle ) ); return errors; } ProgramStageObjectBundleHook( AclService aclService ); @Override List<ErrorReport> validate( T object, ObjectBundle bundle ); @Override void postCreate( T object, ObjectBundle bundle );  }
@Test public void testValidateDataElementAcl() { ObjectBundleParams objectBundleParams = new ObjectBundleParams(); objectBundleParams.setPreheatIdentifier( PreheatIdentifier.UID ); objectBundleParams.setUser( user ); ObjectBundle bundle = new ObjectBundle( objectBundleParams, preheat, Collections .singletonMap( OptionSet.class, Collections.singletonList( programStage ) ) ); List<ErrorReport> errors = subject.validate( programStage, bundle ); Assert.assertEquals( 1, errors.size() ); Assert.assertEquals( ErrorCode.E3012, errors.get( 0 ).getErrorCode() ); }