Search in sources :

Example 1 with CategoryService

use of org.hisp.dhis.category.CategoryService in project dhis2-core by dhis2.

the class DefaultDataValueSetService method createDataValueSetImportContext.

private ImportContext createDataValueSetImportContext(ImportOptions options, DataValueSet data) {
    options = ObjectUtils.firstNonNull(options, ImportOptions.getDefaultImportOptions());
    final User currentUser = currentUserService.getCurrentUser();
    boolean auditEnabled = config.isEnabled(CHANGELOG_AGGREGATE);
    boolean hasSkipAuditAuth = currentUser != null && currentUser.isAuthorized(Authorities.F_SKIP_DATA_IMPORT_AUDIT);
    boolean skipAudit = (options.isSkipAudit() && hasSkipAuditAuth) || !auditEnabled;
    SystemSettingManager settings = systemSettingManager;
    IdScheme dataElementIdScheme = createIdScheme(data.getDataElementIdSchemeProperty(), options, IdSchemes::getDataElementIdScheme);
    IdScheme orgUnitIdScheme = createIdScheme(data.getOrgUnitIdSchemeProperty(), options, IdSchemes::getOrgUnitIdScheme);
    IdScheme categoryOptComboIdScheme = createIdScheme(data.getCategoryOptionComboIdSchemeProperty(), options, IdSchemes::getCategoryOptionComboIdScheme);
    IdScheme dataSetIdScheme = createIdScheme(data.getDataSetIdSchemeProperty(), options, IdSchemes::getDataSetIdScheme);
    return ImportContext.builder().importOptions(options).summary(new ImportSummary().setImportOptions(options)).isIso8601(calendarService.getSystemCalendar().isIso8601()).skipLockExceptionCheck(!lockExceptionStore.anyExists()).i18n(i18nManager.getI18n()).currentUser(currentUser).currentOrgUnits(currentUserService.getCurrentUserOrganisationUnits()).hasSkipAuditAuth(hasSkipAuditAuth).skipAudit(skipAudit).idScheme(createIdScheme(data.getIdSchemeProperty(), options, IdSchemes::getIdScheme)).dataElementIdScheme(dataElementIdScheme).orgUnitIdScheme(orgUnitIdScheme).categoryOptComboIdScheme(categoryOptComboIdScheme).dataSetIdScheme(dataSetIdScheme).strategy(data.getStrategy() != null ? ImportStrategy.valueOf(data.getStrategy()) : options.getImportStrategy()).dryRun(data.getDryRun() != null ? data.getDryRun() : options.isDryRun()).skipExistingCheck(options.isSkipExistingCheck()).strictPeriods(options.isStrictPeriods() || settings.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_PERIODS)).strictDataElements(options.isStrictDataElements() || settings.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_DATA_ELEMENTS)).strictCategoryOptionCombos(options.isStrictCategoryOptionCombos() || settings.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_CATEGORY_OPTION_COMBOS)).strictAttrOptionCombos(options.isStrictAttributeOptionCombos() || settings.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_ATTRIBUTE_OPTION_COMBOS)).strictOrgUnits(options.isStrictOrganisationUnits() || settings.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_ORGANISATION_UNITS)).requireCategoryOptionCombo(options.isRequireCategoryOptionCombo() || settings.getBoolSetting(SettingKey.DATA_IMPORT_REQUIRE_CATEGORY_OPTION_COMBO)).requireAttrOptionCombo(options.isRequireAttributeOptionCombo() || settings.getBoolSetting(SettingKey.DATA_IMPORT_REQUIRE_ATTRIBUTE_OPTION_COMBO)).forceDataInput(inputUtils.canForceDataInput(currentUser, options.isForce())).dataElementCallable(new IdentifiableObjectCallable<>(identifiableObjectManager, DataElement.class, dataElementIdScheme, null)).orgUnitCallable(new IdentifiableObjectCallable<>(identifiableObjectManager, OrganisationUnit.class, orgUnitIdScheme, trimToNull(data.getOrgUnit()))).categoryOptionComboCallable(new CategoryOptionComboAclCallable(categoryService, categoryOptComboIdScheme, null)).attributeOptionComboCallable(new CategoryOptionComboAclCallable(categoryService, categoryOptComboIdScheme, null)).periodCallable(new PeriodCallable(periodService, null, trimToNull(data.getPeriod()))).dataValueBatchHandler(batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init()).auditBatchHandler(skipAudit ? null : batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class).init()).singularNameForType(klass -> schemaService.getDynamicSchema(klass).getSingular()).build();
}
Also used : DataValueAuditBatchHandler(org.hisp.dhis.jdbc.batchhandler.DataValueAuditBatchHandler) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) CategoryService(org.hisp.dhis.category.CategoryService) Authorities(org.hisp.dhis.security.Authorities) ValidationUtils.dataValueIsZeroAndInsignificant(org.hisp.dhis.system.util.ValidationUtils.dataValueIsZeroAndInsignificant) Date(java.util.Date) PeriodService(org.hisp.dhis.period.PeriodService) ValidationUtils(org.hisp.dhis.system.util.ValidationUtils) CompleteDataSetRegistrationService(org.hisp.dhis.dataset.CompleteDataSetRegistrationService) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) IdentifiableProperty(org.hisp.dhis.common.IdentifiableProperty) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) XMLFactory(org.hisp.staxwax.factory.XMLFactory) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Period(org.hisp.dhis.period.Period) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) CollectionUtils.isEmpty(org.hisp.dhis.commons.collection.CollectionUtils.isEmpty) DxfNamespaces(org.hisp.dhis.common.DxfNamespaces) CHANGELOG_AGGREGATE(org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_AGGREGATE) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) StreamUtils.wrapAndCheckCompressionFormat(org.hisp.dhis.commons.util.StreamUtils.wrapAndCheckCompressionFormat) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) WARN(org.hisp.dhis.system.notification.NotificationLevel.WARN) SchemaService(org.hisp.dhis.schema.SchemaService) Objects(java.util.Objects) SimpleNode(org.hisp.dhis.node.types.SimpleNode) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Clock(org.hisp.dhis.system.util.Clock) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Writer(java.io.Writer) AclService(org.hisp.dhis.security.acl.AclService) RootNode(org.hisp.dhis.node.types.RootNode) BatchHandlerFactory(org.hisp.quick.BatchHandlerFactory) CollectionNode(org.hisp.dhis.node.types.CollectionNode) BatchHandlerFactoryTarget(org.hisp.dhis.common.BatchHandlerFactoryTarget) DataSet(org.hisp.dhis.dataset.DataSet) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate) Callable(java.util.concurrent.Callable) BooleanUtils(org.apache.commons.lang3.BooleanUtils) AuditType(org.hisp.dhis.common.AuditType) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) PeriodCallable(org.hisp.dhis.system.callable.PeriodCallable) Notifier(org.hisp.dhis.system.notification.Notifier) DataValueService(org.hisp.dhis.datavalue.DataValueService) DataValueBatchHandler(org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler) CategoryOptionComboAclCallable(org.hisp.dhis.system.callable.CategoryOptionComboAclCallable) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) I18nManager(org.hisp.dhis.i18n.I18nManager) DataValueAuditBatchHandler(org.hisp.dhis.jdbc.batchhandler.DataValueAuditBatchHandler) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) OutputStream(java.io.OutputStream) CsvUtils(org.hisp.dhis.system.util.CsvUtils) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) IdSchemes(org.hisp.dhis.common.IdSchemes) FileResource(org.hisp.dhis.fileresource.FileResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CalendarService(org.hisp.dhis.calendar.CalendarService) INFO(org.hisp.dhis.system.notification.NotificationLevel.INFO) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectUtils(org.hisp.dhis.util.ObjectUtils) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) LockExceptionStore(org.hisp.dhis.dataset.LockExceptionStore) CurrentUserService(org.hisp.dhis.user.CurrentUserService) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) DataValue(org.hisp.dhis.datavalue.DataValue) SettingKey(org.hisp.dhis.setting.SettingKey) AllArgsConstructor(lombok.AllArgsConstructor) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) IdScheme(org.hisp.dhis.common.IdScheme) DateUtils(org.hisp.dhis.util.DateUtils) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) User(org.hisp.dhis.user.User) DataValueBatchHandler(org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler) IdSchemes(org.hisp.dhis.common.IdSchemes) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CategoryOptionComboAclCallable(org.hisp.dhis.system.callable.CategoryOptionComboAclCallable) PeriodCallable(org.hisp.dhis.system.callable.PeriodCallable) IdScheme(org.hisp.dhis.common.IdScheme) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) DataElement(org.hisp.dhis.dataelement.DataElement) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager)

Example 2 with CategoryService

use of org.hisp.dhis.category.CategoryService in project dhis2-core by dhis2.

the class DefaultPredictionService method predict.

@Override
public void predict(Predictor predictor, Date startDate, Date endDate, PredictionSummary predictionSummary) {
    Expression generator = predictor.getGenerator();
    Expression skipTest = predictor.getSampleSkipTest();
    DataElement outputDataElement = predictor.getOutput();
    DataType expressionDataType = DataType.fromValueType(outputDataElement.getValueType());
    Map<DimensionalItemId, DimensionalItemObject> outputPeriodItemMap = new HashMap<>();
    Map<DimensionalItemId, DimensionalItemObject> sampledItemMap = new HashMap<>();
    expressionService.getExpressionDimensionalItemMaps(generator.getExpression(), PREDICTOR_EXPRESSION, expressionDataType, outputPeriodItemMap, sampledItemMap);
    Set<String> orgUnitGroupIds = expressionService.getExpressionOrgUnitGroupIds(generator.getExpression(), PREDICTOR_EXPRESSION);
    if (skipTest != null) {
        expressionService.getExpressionDimensionalItemMaps(skipTest.getExpression(), PREDICTOR_SKIP_TEST, DataType.BOOLEAN, sampledItemMap, sampledItemMap);
        orgUnitGroupIds.addAll(expressionService.getExpressionOrgUnitGroupIds(skipTest.getExpression(), PREDICTOR_SKIP_TEST));
    }
    Map<String, OrganisationUnitGroup> orgUnitGroupMap = orgUnitGroupIds.stream().map(organisationUnitGroupService::getOrganisationUnitGroup).filter(Objects::nonNull).collect(Collectors.toMap(OrganisationUnitGroup::getUid, g -> g));
    Map<DimensionalItemId, DimensionalItemObject> itemMap = new HashMap<>(outputPeriodItemMap);
    itemMap.putAll(sampledItemMap);
    Set<DimensionalItemObject> outputPeriodItems = new HashSet<>(outputPeriodItemMap.values());
    Set<DimensionalItemObject> sampledItems = new HashSet<>(sampledItemMap.values());
    Set<DimensionalItemObject> items = new HashSet<>(itemMap.values());
    List<Period> outputPeriods = getPeriodsBetweenDates(predictor.getPeriodType(), startDate, endDate);
    Set<Period> existingOutputPeriods = getExistingPeriods(outputPeriods);
    ListMap<Period, Period> samplePeriodsMap = getSamplePeriodsMap(outputPeriods, predictor);
    Set<Period> allSamplePeriods = samplePeriodsMap.uniqueValues();
    Set<Period> analyticsQueryPeriods = getAnalyticsQueryPeriods(sampledItems, allSamplePeriods, outputPeriodItems, existingOutputPeriods);
    Set<Period> dataValueQueryPeriods = getDataValueQueryPeriods(analyticsQueryPeriods, existingOutputPeriods);
    outputPeriods = periodService.reloadPeriods(outputPeriods);
    CategoryOptionCombo defaultCategoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    CategoryOptionCombo outputOptionCombo = predictor.getOutputCombo() == null ? defaultCategoryOptionCombo : predictor.getOutputCombo();
    DataElementOperand outputDataElementOperand = new DataElementOperand(outputDataElement, outputOptionCombo);
    Date now = new Date();
    boolean requireData = generator.getMissingValueStrategy() != NEVER_SKIP && (!items.isEmpty());
    DimensionalItemObject forwardReference = addOuputToItems(outputDataElementOperand, items);
    Set<OrganisationUnit> currentUserOrgUnits = new HashSet<>();
    String storedBy = "system-process";
    User currentUser = currentUserService.getCurrentUser();
    if (currentUser != null) {
        currentUserOrgUnits = currentUser.getOrganisationUnits();
        storedBy = currentUser.getUsername();
    }
    PredictionDataConsolidator consolidator = new PredictionDataConsolidator(items, predictor.getOrganisationUnitDescendants().equals(DESCENDANTS), new PredictionDataValueFetcher(dataValueService, categoryService), new PredictionAnalyticsDataFetcher(analyticsService, categoryService));
    PredictionWriter predictionWriter = new PredictionWriter(dataValueService, batchHandlerFactory);
    predictionWriter.init(existingOutputPeriods, predictionSummary);
    predictionSummary.incrementPredictors();
    for (OrganisationUnitLevel orgUnitLevel : predictor.getOrganisationUnitLevels()) {
        List<OrganisationUnit> orgUnits = organisationUnitService.getOrganisationUnitsAtOrgUnitLevels(Lists.newArrayList(orgUnitLevel), currentUserOrgUnits);
        consolidator.init(currentUserOrgUnits, orgUnitLevel.getLevel(), orgUnits, dataValueQueryPeriods, analyticsQueryPeriods, existingOutputPeriods, outputDataElementOperand);
        PredictionData data;
        while ((data = consolidator.getData()) != null) {
            List<DataValue> predictions = new ArrayList<>();
            List<PredictionContext> contexts = PredictionContextGenerator.getContexts(outputPeriods, data.getValues(), defaultCategoryOptionCombo);
            for (PredictionContext c : contexts) {
                List<Period> samplePeriods = new ArrayList<>(samplePeriodsMap.get(c.getOutputPeriod()));
                samplePeriods.removeAll(getSkippedPeriods(allSamplePeriods, itemMap, c.getPeriodValueMap(), skipTest, orgUnitGroupMap, data.getOrgUnit()));
                if (requireData && !dataIsPresent(outputPeriodItems, c.getValueMap(), sampledItems, samplePeriods, c.getPeriodValueMap())) {
                    continue;
                }
                Object value = expressionService.getExpressionValue(ExpressionParams.builder().expression(predictor.getGenerator().getExpression()).parseType(PREDICTOR_EXPRESSION).dataType(expressionDataType).itemMap(itemMap).valueMap(c.getValueMap()).orgUnitGroupMap(orgUnitGroupMap).days(c.getOutputPeriod().getDaysInPeriod()).missingValueStrategy(generator.getMissingValueStrategy()).orgUnit(data.getOrgUnit()).samplePeriods(samplePeriods).periodValueMap(c.getPeriodValueMap()).build());
                if (value != null || generator.getMissingValueStrategy() == NEVER_SKIP) {
                    String valueString = formatPrediction(value, outputDataElement);
                    if (valueString != null) {
                        DataValue prediction = new DataValue(outputDataElement, c.getOutputPeriod(), data.getOrgUnit(), outputOptionCombo, c.getAttributeOptionCombo(), valueString, storedBy, now, null);
                        carryPredictionForward(prediction, contexts, forwardReference);
                        predictions.add(prediction);
                    }
                }
            }
            predictionWriter.write(predictions, data.getOldPredictions());
        }
    }
    predictionWriter.flush();
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) Date(java.util.Date) DataType(org.hisp.dhis.analytics.DataType) PeriodService(org.hisp.dhis.period.PeriodService) PREDICTOR_SKIP_TEST(org.hisp.dhis.expression.ParseType.PREDICTOR_SKIP_TEST) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) StringUtils(org.apache.commons.lang3.StringUtils) PredictorJobParameters(org.hisp.dhis.scheduling.parameters.PredictorJobParameters) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Map(java.util.Map) ExpressionParams(org.hisp.dhis.expression.ExpressionParams) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Period(org.hisp.dhis.period.Period) OrganisationUnitGroupService(org.hisp.dhis.organisationunit.OrganisationUnitGroupService) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) AnalyticsServiceTarget(org.hisp.dhis.analytics.AnalyticsServiceTarget) Set(java.util.Set) PREDICTOR_EXPRESSION(org.hisp.dhis.expression.ParseType.PREDICTOR_EXPRESSION) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) DESCENDANTS(org.hisp.dhis.common.OrganisationUnitDescendants.DESCENDANTS) BatchHandlerFactory(org.hisp.quick.BatchHandlerFactory) ListMap(org.hisp.dhis.common.ListMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) Notifier(org.hisp.dhis.system.notification.Notifier) NEVER_SKIP(org.hisp.dhis.expression.MissingValueStrategy.NEVER_SKIP) ExpressionService(org.hisp.dhis.expression.ExpressionService) PredictionFormatter.formatPrediction(org.hisp.dhis.predictor.PredictionFormatter.formatPrediction) DataValueService(org.hisp.dhis.datavalue.DataValueService) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) CurrentUserService(org.hisp.dhis.user.CurrentUserService) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Expression(org.hisp.dhis.expression.Expression) AllArgsConstructor(lombok.AllArgsConstructor) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) AnalyticsService(org.hisp.dhis.analytics.AnalyticsService) DateUtils(org.hisp.dhis.util.DateUtils) MapMap(org.hisp.dhis.common.MapMap) Transactional(org.springframework.transaction.annotation.Transactional) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) DataValue(org.hisp.dhis.datavalue.DataValue) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataType(org.hisp.dhis.analytics.DataType) HashSet(java.util.HashSet) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) Date(java.util.Date) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Expression(org.hisp.dhis.expression.Expression) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 3 with CategoryService

use of org.hisp.dhis.category.CategoryService in project dhis2-core by dhis2.

the class EventAnalyticsDimensionsServiceTest method setup.

@BeforeEach
void setup() {
    ProgramStageService programStageService = mock(ProgramStageService.class);
    CategoryService categoryService = mock(CategoryService.class);
    Program program = mock(Program.class);
    ProgramStage programStage = mock(ProgramStage.class);
    when(programStageService.getProgramStage(any())).thenReturn(programStage);
    when(programStage.getProgram()).thenReturn(program);
    when(program.getDataElements()).thenReturn(allValueTypeDataElements());
    when(program.getProgramIndicators()).thenReturn(Collections.emptySet());
    when(program.getTrackedEntityAttributes()).thenReturn(allValueTypeTEAs());
    eventAnalyticsDimensionsService = new DefaultEventAnalyticsDimensionsService(programStageService, categoryService);
}
Also used : Program(org.hisp.dhis.program.Program) ProgramStageService(org.hisp.dhis.program.ProgramStageService) CategoryService(org.hisp.dhis.category.CategoryService) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CategoryService

use of org.hisp.dhis.category.CategoryService 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.
 * <p/>
 * Return early with no results if there are no organisation units or no
 * validation rules.
 *
 * @return a collection of any validations that were found
 */
public static List<ValidationResult> validate(ValidationRunContext context, ApplicationContext applicationContext, AnalyticsService analyticsService) {
    CategoryService categoryService = applicationContext.getBean(CategoryService.class);
    int threadPoolSize = getThreadPoolSize(context);
    if (threadPoolSize == 0 || context.getPeriodTypeXs().isEmpty()) {
        return new ArrayList<>(context.getValidationResults());
    }
    ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
    List<List<OrganisationUnit>> orgUnitLists = Lists.partition(context.getOrgUnits(), ValidationRunContext.ORG_UNITS_PER_TASK);
    for (List<OrganisationUnit> orgUnits : orgUnitLists) {
        ValidationTask task = (ValidationTask) applicationContext.getBean(DataValidationTask.NAME);
        task.init(orgUnits, context, analyticsService);
        executor.execute(task);
    }
    executor.shutdown();
    try {
        executor.awaitTermination(6, TimeUnit.HOURS);
    } catch (InterruptedException e) {
        executor.shutdownNow();
    }
    reloadAttributeOptionCombos(context.getValidationResults(), categoryService);
    return new ArrayList<>(context.getValidationResults());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) ArrayList(java.util.ArrayList) CategoryService(org.hisp.dhis.category.CategoryService)

Aggregations

CategoryService (org.hisp.dhis.category.CategoryService)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)2 DebugUtils (org.hisp.dhis.commons.util.DebugUtils)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataValue (org.hisp.dhis.datavalue.DataValue)2 DataValueService (org.hisp.dhis.datavalue.DataValueService)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 OrganisationUnitService (org.hisp.dhis.organisationunit.OrganisationUnitService)2 Period (org.hisp.dhis.period.Period)2 PeriodService (org.hisp.dhis.period.PeriodService)2 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)2