private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable Long componentId) { return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setResourceId(componentId); }
@CheckForNull public PropertyDto selectProjectProperty(DbSession dbSession, long componentId, String propertyKey) { return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setResourceId(componentId)); }
private PropertyDto toProperty(SetRequest request, Optional<ComponentDto> component) { String key = persistedKey(request); String value = persistedValue(request); PropertyDto property = new PropertyDto() .setKey(key) .setValue(value); if (component.isPresent()) { property.setResourceId(component.get().getId()); } return property; }
/** * Remove a favorite to the user. * @throws IllegalArgumentException if the component is not a favorite */ public void remove(DbSession dbSession, ComponentDto component, @Nullable Integer userId) { if (userId == null) { return; } int result = dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setResourceId(component.getId()) .setUserId(userId)); checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey()); } }
public void associateProject(DbSession dbSession, ComponentDto project, QualityGateDto qualityGate) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(SONAR_QUALITYGATE_PROPERTY) .setResourceId(project.getId()) .setValue(String.valueOf(qualityGate.getId()))); }
@Test public void testEquals() { assertThat(new PropertyDto().setKey("123").setResourceId(123L)).isEqualTo(new PropertyDto().setKey("123").setResourceId(123L)); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new PropertyDto().setKey("123").setResourceId(123L)); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(null); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new Object()); }
private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Integer userId) { PropertyDto propertyDto = new PropertyDto() .setKey(key) .setValue(value); if (componentId != null) { propertyDto.setResourceId(componentId); } if (userId != null) { propertyDto.setUserId(userId); } return propertyDto; }
@Test public void testHashCode() { assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode()).isNotNull(); assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode()) .isEqualTo(new PropertyDto().setKey("123").setResourceId(123L).hashCode()); }
private void insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) { PropertyDto dto = new PropertyDto().setKey(key) .setResourceId(resourceId) .setUserId(userId) .setValue(value); db.properties().insertProperty(dto); } }
private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) { PropertyDto dto = new PropertyDto().setKey(key) .setResourceId(resourceId) .setUserId(userId) .setValue(value); db.properties().insertProperty(dto); return (long) db.selectFirst(session, "select id as \"id\" from properties" + " where prop_key='" + key + "'" + " and user_id" + (userId == null ? " is null" : "='" + userId + "'") + " and resource_id" + (resourceId == null ? " is null" : "='" + resourceId + "'")).get("id"); }
@Test public void testToString() { assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setResourceId(123L).setUserId(456).toString()).isEqualTo("PropertyDto{foo:bar, value, 123, 456}"); }
private void insertPropertyFor(ComponentDto... components) { Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto() .setKey(randomAlphabetic(3)) .setValue(randomAlphabetic(3)) .setResourceId(componentDto.getId()))); }
public void associateProjectToQualityGate(ComponentDto component, QualityGateDto qualityGate) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey("sonar.qualitygate") .setResourceId(component.getId()) .setValue(String.valueOf(qualityGate.getId()))); db.commit(); }
private void associateProjectToQualityGate(ComponentDto project, QualityGateDto qualityGate) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setResourceId(project.getId()) .setValue(qualityGate.getId().toString()) .setKey(SONAR_QUALITYGATE_PROPERTY)); db.commit(); }
private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) { db.properties().insertProperties(new PropertyDto().setKey(propertyKey).setValue(propertyValue).setResourceId(project.getId())); } }
public void add(ComponentDto componentDto, int userId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setUserId(userId) .setResourceId(componentDto.getId())); dbSession.commit(); }
private void addFavourite(ComponentDto project) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(userSession.getUserId())); dbSession.commit(); }
@Test public void deactivate_user_deletes_his_default_assignee_settings() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(project.getId())); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(anotherProject.getId())); db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setResourceId(anotherProject.getId())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setKey("sonar.issues.defaultAssigneeLogin").build(), db.getSession())).isEmpty(); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().build(), db.getSession())).extracting(PropertyDto::getKey).containsOnly("other"); }
@Test public void deactivate_user_deletes_his_properties() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty(); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty(); }
@Test public void return_component_info_with_favourite() { ComponentDto project = insertOrganizationAndProject(); UserDto user = db.users().insertUser("obiwan"); propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId())); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); executeAndVerify(project.getDbKey(), "return_component_info_with_favourite.json"); }