Search in sources :

Example 11 with ERROR

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;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 12 with ERROR

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())));
}
Also used : AtomicMode(org.hisp.dhis.dxf2.metadata.AtomicMode) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) RenderService(org.hisp.dhis.render.RenderService) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) UserAccess(org.hisp.dhis.user.sharing.UserAccess) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Map(java.util.Map) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserService(org.hisp.dhis.user.UserService) RenderFormat(org.hisp.dhis.render.RenderFormat) IOException(java.io.IOException) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with ERROR

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"));
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with ERROR

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));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach) UserService(org.hisp.dhis.user.UserService) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) SchemaService(org.hisp.dhis.schema.SchemaService) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) Collections.singleton(java.util.Collections.singleton) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Status(org.hisp.dhis.feedback.Status) InputStream(java.io.InputStream) CsvImportService(org.hisp.dhis.dxf2.csv.CsvImportService) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with ERROR

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());
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 Test (org.junit.jupiter.api.Test)25 User (org.hisp.dhis.user.User)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 IOException (java.io.IOException)15 Event (org.hisp.dhis.dxf2.events.event.Event)14 List (java.util.List)12 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ArrayList (java.util.ArrayList)6 FileResource (org.hisp.dhis.fileresource.FileResource)6 SchemaService (org.hisp.dhis.schema.SchemaService)6 UserService (org.hisp.dhis.user.UserService)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 InputStream (java.io.InputStream)4