Search in sources :

Example 1 with DataElementCategoryService

use of org.hisp.dhis.dataelement.DataElementCategoryService in project dhis2-core by dhis2.

the class Validator method validate.

/**
     * Evaluates validation rules for a collection of organisation units. This
     * method breaks the job down by organisation unit. It assigns the
     * evaluation for each organisation unit to a task that can be evaluated
     * independently in a multi-threaded environment.
     * 
     * @return a collection of any validations that were found
     */
public static Collection<ValidationResult> validate(ValidationRunContext context, ApplicationContext applicationContext) {
    DataElementCategoryService categoryService = (DataElementCategoryService) applicationContext.getBean(DataElementCategoryService.class);
    int threadPoolSize = getThreadPoolSize(context);
    ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
    for (OrganisationUnit orgUnit : context.getOrgUnits()) {
        ValidationTask task = (ValidationTask) applicationContext.getBean(DataValidationTask.NAME);
        task.init(orgUnit, context);
        executor.execute(task);
    }
    executor.shutdown();
    try {
        executor.awaitTermination(6, TimeUnit.HOURS);
    } catch (InterruptedException e) {
        executor.shutdownNow();
    }
    reloadAttributeOptionCombos(context.getValidationResults(), categoryService);
    return context.getValidationResults();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ExecutorService(java.util.concurrent.ExecutorService) DataElementCategoryService(org.hisp.dhis.dataelement.DataElementCategoryService)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 DataElementCategoryService (org.hisp.dhis.dataelement.DataElementCategoryService)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1