DefaultCompleteDataSetRegistrationExchangeService implements CompleteDataSetRegistrationExchangeService { public void validate( ExportParams params ) throws IllegalQueryException { ErrorMessage error = null; if ( params == null ) { throw new IllegalQueryException( ErrorCode.E2000 ); } if ( params.getDataSets().isEmpty() ) { error = new ErrorMessage( ErrorCode.E2013 ); } if ( !params.hasPeriods() && !params.hasStartEndDate() && !params.hasCreated() && !params.hasCreatedDuration() ) { error = new ErrorMessage( ErrorCode.E2002 ); } if ( params.hasPeriods() && params.hasStartEndDate() ) { error = new ErrorMessage( ErrorCode.E2003 ); } if ( params.hasStartEndDate() && params.getStartDate().after( params.getEndDate() ) ) { error = new ErrorMessage( ErrorCode.E2004 ); } if ( params.hasCreatedDuration() && DateUtils.getDuration( params.getCreatedDuration() ) == null ) { error = new ErrorMessage( ErrorCode.E2005 ); } if ( !params.hasOrganisationUnits() && !params.hasOrganisationUnitGroups() ) { error = new ErrorMessage( ErrorCode.E2006 ); } if ( params.isIncludeChildren() && params.hasOrganisationUnitGroups() ) { error = new ErrorMessage( ErrorCode.E2007 ); } if ( params.isIncludeChildren() && !params.hasOrganisationUnits() ) { error = new ErrorMessage( ErrorCode.E2008 ); } if ( params.hasLimit() && params.getLimit() < 0 ) { error = new ErrorMessage( ErrorCode.E2009 ); } if ( error != null ) { log.warn( String.format( "Complete data set registration validation failed, code: '%s', message: '%s'", error.getErrorCode(), error.getMessage() ) ); throw new IllegalQueryException( error ); } limitToValidIdSchemes( params ); } DefaultCompleteDataSetRegistrationExchangeService(
        CompleteDataSetRegistrationExchangeStore cdsrStore,
        IdentifiableObjectManager idObjManager,
        OrganisationUnitService orgUnitService,
        Notifier notifier,
        I18nManager i18nManager,
        BatchHandlerFactory batchHandlerFactory,
        SystemSettingManager systemSettingManager,
        CategoryService categoryService,
        PeriodService periodService,
        CurrentUserService currentUserService,
        CompleteDataSetRegistrationService registrationService,
        InputUtils inputUtils,
        AggregateAccessManager accessManager,
        DataSetNotificationEventPublisher notificationPublisher,
        MessageService messageService,
        ObjectMapper jsonMapper ); @Override ExportParams paramsFromUrl( Set<String> dataSets, Set<String> orgUnits, Set<String> orgUnitGroups,
        Set<String> periods, Date startDate, Date endDate, boolean includeChildren, Date created,
        String createdDuration, Integer limit, IdSchemes idSchemes ); @Override void writeCompleteDataSetRegistrationsXml( ExportParams params, OutputStream out ); @Override void writeCompleteDataSetRegistrationsJson( ExportParams params, OutputStream out ); @Override void writeCompleteDataSetRegistrationsJson( Date lastUpdated, OutputStream outputStream,
        IdSchemes idSchemes ); @Override ImportSummary saveCompleteDataSetRegistrationsXml( InputStream in, ImportOptions importOptions ); @Override ImportSummary saveCompleteDataSetRegistrationsXml( InputStream in, ImportOptions importOptions, JobConfiguration jobId ); @Override ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions ); @Override ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions, JobConfiguration jobId ); void validate( ExportParams params );  }
@Test public void testValidateAssertMissingDataSet() { DhisConvenienceTest.assertIllegalQueryEx( exception, ErrorCode.E2013 ); ExportParams params = new ExportParams() .setOrganisationUnits( Sets.newHashSet( new OrganisationUnit() ) ) .setPeriods( Sets.newHashSet( new Period() ) ); subject.validate( params ); }