class ResourceSetLabelRegistration {

    void updateLabelsForExistingResourceSet(ResourceSetDescription resourceSet) {
        JsonValue newLabels = resourceSet.getDescription().get(OAuth2Constants.ResourceSets.LABELS);
        if (newLabels.isNull()) {
            newLabels = json(array());
        }
        Collection<String> addedLabels = new HashSet<>(newLabels.asSet(String.class));
        try {
            Set<ResourceSetLabel> labels = labelsStore.forResourceSet(resourceSet.getRealm(),
                    resourceSet.getResourceOwnerId(), resourceSet.getId(), true);
            Collection<String> removedLabels = new HashSet<>();
            for (ResourceSetLabel label : labels) {
                String labelName = label.getName().substring(label.getName().lastIndexOf("/") + 1);
                if (!addedLabels.remove(labelName)) {
                    removedLabels.add(labelName);
                }
            }

            updateLabels(resourceSet, addedLabels, removedLabels);
        } catch (ResourceException e) {
            logger.error("Failed to find current labels on resource set: {}", resourceSet.getId(), e);
        }
    }

    @Inject public  ResourceSetLabelRegistration(UmaLabelsStore labelsStore);

}