Search in sources :

Example 1 with NONE

use of org.hisp.dhis.dxf2.metadata.AtomicMode.NONE in project dhis2-core by dhis2.

the class EventGeometryCheckTest method failOnEventWithGeometryAndProgramStageWithNoGeometry.

@Test
void failOnEventWithGeometryAndProgramStageWithNoGeometry() {
    event.setGeometry(createRandomPoint());
    ProgramStage programStage = createProgramStage();
    programStage.setFeatureType(FeatureType.NONE);
    when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(importSummary, event, "Geometry (Point) does not conform to the feature type (None) specified for the program stage: " + programStage.getUid());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStage(org.hisp.dhis.program.ProgramStage) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 2 with NONE

use of org.hisp.dhis.dxf2.metadata.AtomicMode.NONE in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testUpdateWithPersistedObjectsRequiresValidReferencesUID.

@Test
void testUpdateWithPersistedObjectsRequiresValidReferencesUID() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate7.json").getInputStream(), RenderFormat.JSON);
    defaultSetup();
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setPreheatIdentifier(PreheatIdentifier.UID);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setAtomicMode(NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
    assertNotEquals(0, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
    assertEquals(0, bundle.getObjectsCount(DataElement.class));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) 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 3 with NONE

use of org.hisp.dhis.dxf2.metadata.AtomicMode.NONE in project dhis2-core by dhis2.

the class UserSettingController method getUser.

/**
 * Tries to find a user based on the uid or username. If none is supplied,
 * currentUser will be returned. If uid or username is found, it will also
 * make sure the current user has access to the user.
 *
 * @param uid the user uid
 * @param username the user username
 * @return the user found with uid or username, or current user if no uid or
 *         username was specified
 * @throws WebMessageException throws an exception if user was not found, or
 *         current user don't have access
 */
private User getUser(String uid, String username) throws WebMessageException {
    User currentUser = currentUserService.getCurrentUser();
    User user;
    if (uid == null && username == null) {
        return currentUser;
    }
    if (uid != null) {
        user = userService.getUser(uid);
    } else {
        user = userService.getUserByUsername(username);
    }
    if (user == null) {
        throw new WebMessageException(conflict("Could not find user '" + ObjectUtils.firstNonNull(uid, username) + "'"));
    } else {
        Set<String> userGroups = user.getGroups().stream().map(UserGroup::getUid).collect(Collectors.toSet());
        if (!userService.canAddOrUpdateUser(userGroups) && !currentUser.canModifyUser(user)) {
            throw new WebMessageException(unauthorized("You are not authorized to access user: " + user.getUsername()));
        }
    }
    return user;
}
Also used : User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException)

Aggregations

Test (org.junit.jupiter.api.Test)2 List (java.util.List)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)1 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 User (org.hisp.dhis.user.User)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1