use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class AttributeOptionComboAclCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
ImportSummary importSummary = new ImportSummary();
TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
ImportOptions importOptions = ctx.getImportOptions();
CategoryOptionCombo categoryOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), categoryOptionCombo);
if (!errors.isEmpty()) {
importSummary.setStatus(ImportStatus.ERROR);
errors.forEach(error -> importSummary.addConflict("CategoryOptionCombo", error));
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testUpdateUsersRunsSchemaValidation.
@Test
void testUpdateUsersRunsSchemaValidation() throws IOException {
createUserAndInjectSecurityContext(true);
ObjectBundleParams params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.CREATE, AtomicMode.NONE, "dxf2/users.json");
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertEquals(1, validate.getErrorReportsCountByCode(UserAuthorityGroup.class, ErrorCode.E5003));
objectBundleService.commit(bundle);
params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.UPDATE, AtomicMode.NONE, "dxf2/users_illegal_update.json");
bundle = objectBundleService.create(params);
ObjectBundleValidationReport report = objectBundleValidationService.validate(bundle);
assertEquals(1, report.getErrorReportsCountByCode(User.class, ErrorCode.E4003));
assertTrue(report.hasErrorReport(error -> "email".equals(error.getErrorProperty()) && "Property `email` requires a valid email address, was given `notAnEmail`.".equals(error.getMessage())));
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class ObjectBundleServiceImportReportModeTest method testImportReportModeErrorNotOwner.
@Test
void testImportReportModeErrorNotOwner() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_no_defaults.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
assertFalse(objectBundleValidationService.validate(bundle).hasErrorReports());
objectBundleService.commit(bundle);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_update_not_owner.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setImportReportMode(ImportReportMode.ERRORS_NOT_OWNER);
params.setObjects(metadata);
bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.hasErrorReports());
assertEquals(4, validate.getErrorReportsCount());
validate.forEachErrorReport(errorReport -> assertEquals(ErrorCode.E5006, errorReport.getErrorCode(), "Invalid error code, expected E5006"));
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveLacksWriteAuthority.
@Test
void testOrgUnitImport_MoveLacksWriteAuthority() throws Exception {
createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE");
ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
assertEquals(Status.ERROR, report.getStatus());
assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1521));
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class DataValueCheckTest method verifyValidationFailOnJsonSerializationError.
@Test
void verifyValidationFailOnJsonSerializationError() throws JsonProcessingException {
ObjectMapper localObjectMapper = mock(ObjectMapper.class);
when(serviceDelegator.getJsonMapper()).thenReturn(localObjectMapper);
when(localObjectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonProcessingException("Error") {
});
event.setProgramStage("prgstg1");
DataElement de1 = addToDataElementMap(createDataElement('A'));
final Program programA = createProgram('A');
final ProgramStage programStageA = createProgramStage('A', programA);
programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
when(workContext.getProgramStage(IdScheme.UID, "prgstg1")).thenReturn(programStageA);
addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"));
DataValue dv1 = createDataValue(de1.getUid(), "1");
event.setDataValues(Sets.newHashSet(dv1));
final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
assertHasError(summary, event, null);
assertHasConflict(summary, "Invalid data value found.", de1.getUid());
}
Aggregations