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());
}
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));
}
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;
}
Aggregations