@Test public void update_does_not_fail_if_specified_row_does_not_exist() { underTest.update(dbSession, ORGANIZATION_DTO_1); }
@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 update_fails_with_NPE_if_OrganizationDto_is_null() { expectDtoCanNotBeNull(); underTest.update(dbSession, null); }
@Test public void update_with_same_information_succeeds_but_has_no_effect() { OrganizationDto organizationDto = newOrganizationDto(); insertOrganization(organizationDto); underTest.update(dbSession, organizationDto); dbSession.commit(); Map<String, Object> row = selectSingleRow(); assertThat(row.get("uuid")).isEqualTo(organizationDto.getUuid()); assertThat(row.get("key")).isEqualTo(organizationDto.getKey()); assertThat(row.get("name")).isEqualTo(organizationDto.getName()); assertThat(row.get("description")).isEqualTo(organizationDto.getDescription()); assertThat(row.get("url")).isEqualTo(organizationDto.getUrl()); assertThat(row.get("avatarUrl")).isEqualTo(organizationDto.getAvatarUrl()); assertThat(row.get("subscription")).isEqualTo(organizationDto.getSubscription().name()); assertThat(row.get("createdAt")).isEqualTo(organizationDto.getCreatedAt()); assertThat(row.get("updatedAt")).isEqualTo(organizationDto.getUpdatedAt()); }
public void setDefaultQualityGate(OrganizationDto organization, QualityGateDto qualityGate) { dbClient.organizationDao().update(dbSession, organization.setDefaultQualityGateUuid(qualityGate.getUuid())); dbSession.commit(); }
@Test public void update_fails_if_name_is_null() { insertOrganization(ORGANIZATION_DTO_1); expectedException.expect(PersistenceException.class); underTest.update(dbSession, copyOf(ORGANIZATION_DTO_1).setName(null)); }
@Override public void handle(Request request, Response response) { Long id = parseId(request, PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); QualityGateDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, id); organization.setDefaultQualityGateUuid(qualityGate.getUuid()); dbClient.organizationDao().update(dbSession, organization); dbSession.commit(); } response.noContent(); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { organizationFlags.checkEnabled(dbSession); String key = request.mandatoryParam(PARAM_KEY); UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest( request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt)))); OrganizationDto dto = getDto(dbSession, key); userSession.checkPermission(ADMINISTER, dto); dto.setName(updateRequest.getName().or(dto::getName)) .setDescription(updateRequest.getDescription().or(dto::getDescription)) .setUrl(updateRequest.getUrl().or(dto::getUrl)) .setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl)); dbClient.organizationDao().update(dbSession, dto); dbSession.commit(); writeResponse(request, response, dto); } }
@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)); }
@Override public void handle(Request request, Response response) { Long id = parseId(request, PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); QualityGateDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, id); organization.setDefaultQualityGateUuid(qualityGate.getUuid()); dbClient.organizationDao().update(dbSession, organization); dbSession.commit(); } response.noContent(); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { organizationFlags.checkEnabled(dbSession); String key = request.mandatoryParam(PARAM_KEY); UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest( request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt)))); OrganizationDto dto = getDto(dbSession, key); userSession.checkPermission(ADMINISTER, dto); dto.setName(updateRequest.getName().or(dto::getName)) .setDescription(updateRequest.getDescription().or(dto::getDescription)) .setUrl(updateRequest.getUrl().or(dto::getUrl)) .setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl)); dbClient.organizationDao().update(dbSession, dto); dbSession.commit(); writeResponse(request, response, dto); } }