use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateDataElementsUID.
@Test
void testUpdateDataElementsUID() throws IOException {
defaultSetup();
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_update1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setPreheatMode(PreheatMode.REFERENCE);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
assertEquals(4, dataElementMap.size());
assertNotNull(userGroup);
ObjectBundle bundle = objectBundleService.create(params);
objectBundleValidationService.validate(bundle);
objectBundleService.commit(bundle);
DataElement dataElementA = dataElementMap.get("deabcdefghA");
DataElement dataElementB = dataElementMap.get("deabcdefghB");
DataElement dataElementC = dataElementMap.get("deabcdefghC");
DataElement dataElementD = dataElementMap.get("deabcdefghD");
assertNotNull(dataElementA);
assertNotNull(dataElementB);
assertNotNull(dataElementC);
assertNotNull(dataElementD);
assertEquals("DEA", dataElementA.getName());
assertEquals("DEB", dataElementB.getName());
assertEquals("DEC", dataElementC.getName());
assertEquals("DED", dataElementD.getName());
assertEquals("DECA", dataElementA.getCode());
assertEquals("DECB", dataElementB.getCode());
assertEquals("DECC", dataElementC.getCode());
assertEquals("DECD", dataElementD.getCode());
assertEquals("DESA", dataElementA.getShortName());
assertEquals("DESB", dataElementB.getShortName());
assertEquals("DESC", dataElementC.getShortName());
assertEquals("DESD", dataElementD.getShortName());
assertEquals("DEDA", dataElementA.getDescription());
assertEquals("DEDB", dataElementB.getDescription());
assertEquals("DEDC", dataElementC.getDescription());
assertEquals("DEDD", dataElementD.getDescription());
assertEquals(1, dataElementA.getUserGroupAccesses().size());
assertEquals(0, dataElementB.getUserGroupAccesses().size());
assertEquals(1, dataElementC.getUserGroupAccesses().size());
assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class MessageConversationController method getUsersToMessageConversation.
private Set<User> getUsersToMessageConversation(MessageConversation messageConversation, Set<User> users) throws WebMessageException {
Set<User> usersToMessageConversation = Sets.newHashSet();
for (OrganisationUnit ou : messageConversation.getOrganisationUnits()) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou.getUid());
if (organisationUnit == null) {
throw new WebMessageException(conflict("Organisation Unit does not exist: " + ou.getUid()));
}
usersToMessageConversation.addAll(organisationUnit.getUsers());
}
for (User u : users) {
User user = userService.getUser(u.getUid());
if (user == null) {
throw new WebMessageException(conflict("User does not exist: " + u.getUid()));
}
usersToMessageConversation.add(user);
}
for (UserGroup ug : messageConversation.getUserGroups()) {
UserGroup userGroup = userGroupService.getUserGroup(ug.getUid());
if (userGroup == null) {
throw new WebMessageException(notFound("User Group does not exist: " + ug.getUid()));
}
usersToMessageConversation.addAll(userGroup.getMembers());
}
return usersToMessageConversation;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class UserControllerTest method setUp.
@BeforeEach
public void setUp() {
userGroup1 = new UserGroup();
userGroup1.setUid("abc1");
userGroup2 = new UserGroup();
userGroup2.setUid("abc2");
currentUser = new User();
currentUser.setId(1000);
currentUser.setUid("def1");
user = new User();
user.setId(1001);
user.setUid("def2");
parsedUser = new User();
parsedUser.setUid("def2");
parsedUser.setGroups(new HashSet<>(Arrays.asList(userGroup1, userGroup2)));
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateImmutableCreatedByField.
@Test
void testUpdateImmutableCreatedByField() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
User userB = createUser("B", "ALL");
userB.setUid("userabcdefB");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userA);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateUserGroupWithoutCreatedUserProperty.
@Test
void testUpdateUserGroupWithoutCreatedUserProperty() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
User userB = createUser("B", "ALL");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userB);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
}
Aggregations