private OrganizationDto copyOf(OrganizationDto organizationDto) { return new OrganizationDto() .setUuid(organizationDto.getUuid()) .setKey(organizationDto.getKey()) .setName(organizationDto.getName()) .setDescription(organizationDto.getDescription()) .setUrl(organizationDto.getUrl()) .setDefaultQualityGateUuid(organizationDto.getDefaultQualityGateUuid()) .setSubscription(organizationDto.getSubscription()) .setAvatarUrl(organizationDto.getAvatarUrl()); }
private void verifyOrganization(OrganizationDto dto, OrganizationDto expected) { assertThat(dto.getUuid()).isEqualTo(expected.getUuid()); assertThat(dto.getKey()).isEqualTo(expected.getKey()); assertThat(dto.getName()).isEqualTo(expected.getName()); assertThat(dto.getDescription()).isEqualTo(expected.getDescription()); assertThat(dto.getUrl()).isEqualTo(expected.getUrl()); assertThat(dto.isGuarded()).isEqualTo(expected.isGuarded()); assertThat(dto.getAvatarUrl()).isEqualTo(expected.getAvatarUrl()); assertThat(dto.getSubscription()).isEqualTo(expected.getSubscription()); assertThat(dto.getCreatedAt()).isEqualTo(expected.getCreatedAt()); assertThat(dto.getUpdatedAt()).isEqualTo(expected.getUpdatedAt()); }
public OrganizationDto toDto() { return new OrganizationDto() .setName(name) .setKey(key) .setUuid(uuid) .setDefaultQualityGateUuid(defaultQualityGateUuid); }
Organization.Builder toOrganization(OrganizationDto dto) { Organization.Builder builder = Organization.newBuilder(); builder .setName(dto.getName()) .setKey(dto.getKey()) .setGuarded(dto.isGuarded()); ofNullable(dto.getDescription()).ifPresent(builder::setDescription); ofNullable(dto.getUrl()).ifPresent(builder::setUrl); ofNullable(dto.getAvatarUrl()).ifPresent(builder::setAvatar); return builder; } }
private static DefaultOrganization toDefaultOrganization(OrganizationDto organizationDto) { return DefaultOrganization.newBuilder() .setUuid(organizationDto.getUuid()) .setKey(organizationDto.getKey()) .setName(organizationDto.getName()) .setCreatedAt(organizationDto.getCreatedAt()) .setUpdatedAt(organizationDto.getUpdatedAt()) .build(); }
void checkCanUpdateProjectsVisibility(OrganizationDto organizationDto, boolean newProjectsPrivate) { try { BillingValidations.Organization organization = new BillingValidations.Organization(organizationDto.getKey(), organizationDto.getUuid(), organizationDto.getName()); billingValidations.checkCanUpdateProjectVisibility(organization, newProjectsPrivate); } catch (BillingValidations.BillingValidationsException e) { throw new IllegalArgumentException(e.getMessage()); } } }
static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, OrganizationDto organizationDto, Optional<SnapshotDto> lastAnalysis) { checkArgument( Objects.equals(dto.getOrganizationUuid(), organizationDto.getUuid()), "OrganizationUuid (%s) of ComponentDto to convert to Ws Component is not the same as the one (%s) of the specified OrganizationDto", dto.getOrganizationUuid(), organizationDto.getUuid()); return componentDtoToWsComponent(dto, organizationDto.getKey(), lastAnalysis); }
private OrganizationDto insertOrganization(DbSession dbSession, NewOrganization newOrganization, QualityGateDto builtInQualityGate, Consumer<OrganizationDto>... extendCreation) { OrganizationDto res = new OrganizationDto() .setUuid(uuidFactory.create()) .setName(newOrganization.getName()) .setKey(newOrganization.getKey()) .setDescription(newOrganization.getDescription()) .setUrl(newOrganization.getUrl()) .setDefaultQualityGateUuid(builtInQualityGate.getUuid()) .setAvatarUrl(newOrganization.getAvatar()) .setSubscription(FREE); Arrays.stream(extendCreation).forEach(c -> c.accept(res)); dbClient.organizationDao().insert(dbSession, res, false); return res; }
private SearchGroupsQuery(Builder builder) { this.organizationUuid = builder.organization.getUuid(); this.qProfileUuid = builder.profile.getKee(); this.query = builder.query; this.membership = builder.membership; this.querySqlLowercase = query == null ? null : buildLikeValue(query, BEFORE_AND_AFTER).toLowerCase(Locale.ENGLISH); }
@Test public void update_personal_organization() { OrganizationDto organization = db.organizations().insert(o -> o.setKey("old login")); when(organizationValidation.generateKeyFrom("new_login")).thenReturn("new_login"); underTest.updateOrganizationKey(dbSession, organization, "new_login"); OrganizationDto organizationReloaded = dbClient.organizationDao().selectByUuid(dbSession, organization.getUuid()).get(); assertThat(organizationReloaded.getKey()).isEqualTo("new_login"); }
private String getOrganizationKey(DbSession dbSession, ComponentDto component) { String organizationUuid = component.getOrganizationUuid(); return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid) .orElseThrow(() -> new IllegalStateException("Unknown organization: " + organizationUuid)) .getKey(); }
/** * Owners group has an hard coded name, a description based on the organization's name and has all global permissions. */ private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) { GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(OWNERS_GROUP_NAME) .setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName()))); permissionService.getAllOrganizationPermissions().forEach(p -> addPermissionToGroup(dbSession, group, p)); return group; }
@Override public void updateOrganizationKey(DbSession dbSession, OrganizationDto organization, String newKey) { String sanitizedKey = organizationValidation.generateKeyFrom(newKey); if (organization.getKey().equals(sanitizedKey)) { return; } checkKey(dbSession, sanitizedKey); dbClient.organizationDao().update(dbSession, organization.setKey(sanitizedKey)); }
@Test public void throw_ForbiddenException_if_unknown_organization() { OrganizationDto org = new OrganizationDto().setName("Unknown organization").setKey("unknown_key"); userSession.logIn(); expectedException.expect(NotFoundException.class); expectedException.expectMessage("No organization with key 'unknown_key'"); executeRequest(Optional.of(org), "Default"); }
private void insertDefaultOrganization() { defaultOrganization = OrganizationTesting.newOrganizationDto().setUuid(defaultOrganizationUuid); try (DbSession dbSession = db.getMyBatis().openSession(false)) { client.organizationDao().insert(dbSession, defaultOrganization, false); client.internalPropertiesDao().save(dbSession, "organization.default", defaultOrganization.getUuid()); dbSession.commit(); } }
@Test public void countByQuery() { insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid3").setKey("key-3")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid1").setKey("key-1")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid2").setKey("key-2")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid5").setKey("key-5")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid4").setKey("key-4")); assertThat(underTest.countByQuery(dbSession, returnAll())).isEqualTo(5); assertThat(underTest.countByQuery(dbSession, newQueryWithKeys("key-1", "key-2"))).isEqualTo(2); assertThat(underTest.countByQuery(dbSession, newQueryWithKeys("unknown"))).isZero(); }
@Test public void selectByOrganization() { OrganizationDto organization = db.organizations().insert(); db.getDbClient().almAppInstallDao().insertOrUpdate(db.getSession(), ALM.GITHUB, "the-owner", false, "123456", null); // could be improved, insertOrUpdate should return the DTO with its uuid Optional<AlmAppInstallDto> install = db.getDbClient().almAppInstallDao().selectByOwnerId(db.getSession(), ALM.GITHUB, "the-owner"); db.getDbClient().organizationAlmBindingDao().insert(db.getSession(), organization, install.get(), "xxx", "xxx"); db.commit(); assertThat(underTest.selectByOrganization(db.getSession(), GITHUB, organization).get().getUuid()).isEqualTo(install.get().getUuid()); assertThat(underTest.selectByOrganization(db.getSession(), BITBUCKETCLOUD, organization)).isEmpty(); assertThat(underTest.selectByOrganization(db.getSession(), GITHUB, new OrganizationDto().setUuid("other-organization"))).isEmpty(); }
@Test public void getDefaultGroupId_returns_empty_when_default_group_id_is_null() { insertOrganization(ORGANIZATION_DTO_1.setDefaultGroupId(null)); assertThat(underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty(); }