private Set<String> loadUserOrganizations(@Nullable UserDto assignee) { if (assignee == null) { return Collections.emptySet(); } try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, assignee.getId()); } }
private void loadOrganizations(DbSession dbSession, SearchResponseData result) { Collection<ComponentDto> components = result.getComponents(); dbClient.organizationDao().selectByUuids( dbSession, components.stream().map(ComponentDto::getOrganizationUuid).collect(MoreCollectors.toSet())) .forEach(result::addOrganization); if (userSession.isLoggedIn()) { result.setUserOrganizationUuids(dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, userSession.getUserId())); } }
@Test public void select_organization_uuids_by_user_id() { OrganizationDto organizationDto1 = db.organizations().insert(); OrganizationDto organizationDto2 = db.organizations().insert(); OrganizationDto organizationDto3 = db.organizations().insert(); underTest.insert(dbSession, create(organizationDto1.getUuid(), 512)); underTest.insert(dbSession, create(organizationDto2.getUuid(), 512)); assertThat(underTest.selectOrganizationUuidsByUser(dbSession, 512)).containsOnly(organizationDto1.getUuid(), organizationDto2.getUuid()) .doesNotContain(organizationDto3.getUuid()); assertThat(underTest.selectOrganizationUuidsByUser(dbSession, 123)).isEmpty(); }
private Set<String> loadUserOrganizations(@Nullable UserDto assignee) { if (assignee == null) { return Collections.emptySet(); } try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, assignee.getId()); } }