/** * 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()); } }
/** * Remove a notification from a user. */ public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); Long projectId = project == null ? null : project.getId(); List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() .setKey(key) .setComponentId(projectId) .setUserId(user.getId()) .build(), dbSession).stream() .filter(notificationScope(project)) .collect(MoreCollectors.toList()); checkArgument(!existingNotification.isEmpty() && PROP_NOTIFICATION_VALUE.equals(existingNotification.get(0).getValue()), "Notification doesn't exist"); dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(key) .setUserId(user.getId()) .setValue(PROP_NOTIFICATION_VALUE) .setResourceId(projectId)); }
/** * Remove a notification from a user. */ public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); Long projectId = project == null ? null : project.getId(); List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() .setKey(key) .setComponentId(projectId) .setUserId(user.getId()) .build(), dbSession).stream() .filter(notificationScope(project)) .collect(MoreCollectors.toList()); checkArgument(!existingNotification.isEmpty() && PROP_NOTIFICATION_VALUE.equals(existingNotification.get(0).getValue()), "Notification doesn't exist"); dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(key) .setUserId(user.getId()) .setValue(PROP_NOTIFICATION_VALUE) .setResourceId(projectId)); }
/** * Remove a favorite to the user. * @throws BadRequestException 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)); checkRequest(result == 1, "Component '%s' is not a favorite", component.getDbKey()); } }