Search in sources :

Example 1 with PeriodService

use of org.hisp.dhis.period.PeriodService 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1 Function (java.util.function.Function)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 StringUtils.trimToNull (org.apache.commons.lang3.StringUtils.trimToNull)1 CalendarService (org.hisp.dhis.calendar.CalendarService)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CategoryService (org.hisp.dhis.category.CategoryService)1 AuditType (org.hisp.dhis.common.AuditType)1 BatchHandlerFactoryTarget (org.hisp.dhis.common.BatchHandlerFactoryTarget)1