use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DefaultDataValueSetService method saveDataValueSet.
@Override
public ImportSummary saveDataValueSet(InputStream in, ImportOptions importOptions, TaskId id) {
try {
in = StreamUtils.wrapAndCheckCompressionFormat(in);
DataValueSet dataValueSet = new StreamingXmlDataValueSet(XMLFactory.getXMLReader(in));
return saveDataValueSet(importOptions, id, dataValueSet);
} catch (Exception ex) {
log.error(DebugUtils.getStackTrace(ex));
notifier.notify(id, ERROR, "Process failed: " + ex.getMessage(), true);
return new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage());
}
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class SpringDataValueSetStore method writeDataValueSet.
private void writeDataValueSet(String sql, DataExportParams params, Date completeDate, final DataValueSet dataValueSet) {
if (params.isSingleDataValueSet()) {
IdSchemes idScheme = params.getOutputIdSchemes() != null ? params.getOutputIdSchemes() : new IdSchemes();
IdScheme ouScheme = idScheme.getOrgUnitIdScheme();
IdScheme dataSetScheme = idScheme.getDataSetIdScheme();
dataValueSet.setDataSet(params.getFirstDataSet().getPropertyValue(dataSetScheme));
dataValueSet.setCompleteDate(getLongGmtDateString(completeDate));
dataValueSet.setPeriod(params.getFirstPeriod().getIsoDate());
dataValueSet.setOrgUnit(params.getFirstOrganisationUnit().getPropertyValue(ouScheme));
}
final Calendar calendar = PeriodType.getCalendar();
jdbcTemplate.query(sql, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
DataValue dataValue = dataValueSet.getDataValueInstance();
PeriodType pt = PeriodType.getPeriodTypeByName(rs.getString("ptname"));
boolean deleted = rs.getBoolean("deleted");
dataValue.setDataElement(rs.getString("deid"));
dataValue.setPeriod(pt.createPeriod(rs.getDate("pestart"), calendar).getIsoDate());
dataValue.setOrgUnit(rs.getString("ouid"));
dataValue.setCategoryOptionCombo(rs.getString("cocid"));
dataValue.setAttributeOptionCombo(rs.getString("aocid"));
dataValue.setValue(rs.getString("value"));
dataValue.setStoredBy(rs.getString("storedby"));
dataValue.setCreated(getLongGmtDateString(rs.getTimestamp("created")));
dataValue.setLastUpdated(getLongGmtDateString(rs.getTimestamp("lastupdated")));
dataValue.setComment(rs.getString("comment"));
dataValue.setFollowup(rs.getBoolean("followup"));
if (deleted) {
dataValue.setDeleted(deleted);
}
dataValue.close();
}
});
dataValueSet.close();
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet 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();
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class PdfDataEntryFormUtil method getDataValueSet.
/**
* Creates data value set from Input Stream (PDF) for PDF data import
*/
public static DataValueSet getDataValueSet(InputStream in) {
PdfReader reader = null;
DataValueSet dataValueSet = new DataValueSet();
List<org.hisp.dhis.dxf2.datavalue.DataValue> dataValueList = new ArrayList<>();
try {
reader = new PdfReader(in);
AcroFields form = reader.getAcroFields();
if (form != null) {
// Process OrgUnitUID and PeriodID from the PDF Form
String orgUnitUid = form.getField(PdfDataEntryFormUtil.LABELCODE_ORGID).trim();
String periodId = form.getField(PdfDataEntryFormUtil.LABELCODE_PERIODID).trim();
if (periodId == null || periodId.isEmpty()) {
throw new InvalidIdentifierReferenceException(ERROR_EMPTY_PERIOD);
}
if (orgUnitUid == null || orgUnitUid.isEmpty()) {
throw new InvalidIdentifierReferenceException(ERROR_EMPTY_ORG_UNIT);
}
Period period = PeriodType.getPeriodFromIsoString(periodId);
if (period == null) {
throw new InvalidIdentifierReferenceException(ERROR_INVALID_PERIOD + periodId);
}
// Loop Through the Fields and get data.
@SuppressWarnings("unchecked") Set<String> fldNames = form.getFields().keySet();
for (String fldName : fldNames) {
if (fldName.startsWith(PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD)) {
String[] strArrFldName = fldName.split("_");
org.hisp.dhis.dxf2.datavalue.DataValue dataValue = new org.hisp.dhis.dxf2.datavalue.DataValue();
dataValue.setDataElement(strArrFldName[1]);
dataValue.setCategoryOptionCombo(strArrFldName[2]);
dataValue.setOrgUnit(orgUnitUid);
dataValue.setPeriod(period.getIsoDate());
dataValue.setValue(fieldValueFormat(strArrFldName, form.getField(fldName)));
dataValue.setStoredBy(DATAVALUE_IMPORT_STOREBY);
dataValue.setComment(DATAVALUE_IMPORT_COMMENT);
dataValue.setFollowup(false);
dataValue.setLastUpdated(DateUtils.getMediumDateString());
dataValueList.add(dataValue);
}
}
dataValueSet.setDataValues(dataValueList);
} else {
throw new RuntimeException("Could not generate PDF AcroFields form from input");
}
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (reader != null) {
reader.close();
}
}
return dataValueSet;
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataSetOrgUnitExists.
@Test
void testValidateDataSetOrgUnitExists() {
when(aclService.canDataRead(any(), any())).thenReturn(true);
DataValueSet dataValueSet = new DataValueSet();
dataValueSet.setOrgUnit(CodeGenerator.generateUid());
ImportContext context = createMinimalImportContext(null).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
assertTrue(validator.abortDataSetImport(dataValueSet, context, dataSetContext));
assertConflict(ErrorCode.E7603, "Org unit not found or not accessible: `<object1>`", context, dataValueSet.getOrgUnit(), dataValueSet.getDataSet());
}
Aggregations