public GroupDto create(DbSession dbSession, String organizationUuid) { Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); return defaultGroup; }
@Test public void setDefaultGroupId_throws_NPE_when_default_group_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("Default group cannot be null"); underTest.setDefaultGroupId(dbSession, "uuid", null); }
@Test public void getDefaultGroupId_returns_data_when_default_group_id_is_not_null() { when(system2.now()).thenReturn(DATE_3); insertOrganization(ORGANIZATION_DTO_1); underTest.setDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid(), GroupTesting.newGroupDto().setId(10)); Optional<Integer> optional = underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid()); assertThat(optional).isNotEmpty(); assertThat(optional.get()).isEqualTo(10); verifyOrganizationUpdatedAt(ORGANIZATION_DTO_1.getUuid(), DATE_3); }
@Test public void setDefaultGroupId_throws_NPE_when_uuid_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("uuid can't be null"); underTest.setDefaultGroupId(dbSession, null, GroupTesting.newGroupDto().setId(10)); }
@Test public void setDefaultGroupId_throws_NPE_when_default_group_id_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("Default group id cannot be null"); underTest.setDefaultGroupId(dbSession, "uuid", GroupTesting.newGroupDto().setId(null)); }
public GroupDto insertDefaultGroup(GroupDto dto) { String organizationUuid = dto.getOrganizationUuid(); db.getDbClient().organizationDao().getDefaultGroupId(db.getSession(), organizationUuid) .ifPresent(groupId -> { throw new IllegalArgumentException(format("Organization '%s' has already a default group", organizationUuid)); }); db.getDbClient().groupDao().insert(db.getSession(), dto); db.getDbClient().organizationDao().setDefaultGroupId(db.getSession(), organizationUuid, dto); db.commit(); return dto; }
private void setDefaultGroupId(GroupDto defaultGroup) { db.getDbClient().organizationDao().setDefaultGroupId(db.getSession(), db.getDefaultOrganization().getUuid(), defaultGroup); db.commit(); }
public GroupDto create(DbSession dbSession, String organizationUuid) { Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); return defaultGroup; }