<commit_before>package uk.ac.ox.oucs.oauth.dao;

import org.sakaiproject.component.api.ServerConfigurationService;
import uk.ac.ox.oucs.oauth.domain.Consumer;

import java.util.*;

/**
 * @author <NAME>
 */
public class ServerConfigConsumerDao implements ConsumerDao {
    private Map<String, Consumer> consumers;

    public ServerConfigConsumerDao(ServerConfigurationService serverConfig) {
        Collection<String> consumerKeys = getStringsOrSplit("oauth.consumers", serverConfig);
        consumers = new HashMap<String, Consumer>(consumerKeys.size());
        for (String consumerKey : consumerKeys) {
            Consumer consumer = new Consumer();
            consumer.setId(consumerKey);
            consumer.setName(serverConfig.getString("oauth." + consumerKey + ".name", null));
            consumer.setDescription(serverConfig.getString("oauth." + consumerKey + ".description", null));
            consumer.setURL(serverConfig.getString("oauth." + consumerKey + ".url", null));
            consumer.setCallbackURL(serverConfig.getString("oauth." + consumerKey + ".callbackURL", null));
            consumer.setSecret(serverConfig.getString("oauth." + consumerKey + ".secret"));
            consumer.setAccessorSecret(serverConfig.getString("oauth." + consumerKey + ".accessorsecret", null));
            consumer.setDefaultValidity(serverConfig.getInt("oauth." + consumerKey + ".validity", 0));
            consumer.setRights(new HashSet<String>(getStringsOrSplit("oauth." + consumerKey + ".rights", serverConfig)));

            consumers.put(consumerKey, consumer);
        }
    }

    private static Collection<String> getStringsOrSplit(String name, ServerConfigurationService serverConfig) {
        String stringValue = serverConfig.getString(name, null);
        String[] values;
        if (stringValue != null)
            values = stringValue.split(",");
        else
            values = serverConfig.getStrings(name);

        return (values != null) ? Arrays.asList(values) : Collections.<String>emptyList();
    }

    @Override
    public void create(Consumer consumer) {
        throw new UnsupportedOperationException("Can't create a consumer in the server config");
    }

    @Override
    public Consumer get(String consumerId) {
        return consumers.get(consumerId);
    }

    @Override
    public Consumer update(Consumer consumer) {
        throw new UnsupportedOperationException("Can't update a consumer in the server config");
    }

    @Override
    public void remove(Consumer consumer) {
        throw new UnsupportedOperationException("Can't remove a consumer in the server config");
    }

    @Override
    public Collection<Consumer> getAll() {
        return consumers.values();
    }
}
<commit_msg>Allow setting the record mode property in the config.<commit_after>package uk.ac.ox.oucs.oauth.dao;

import org.sakaiproject.component.api.ServerConfigurationService;
import uk.ac.ox.oucs.oauth.domain.Consumer;

import java.util.*;

/**
 * @author <NAME>
 */
public class ServerConfigConsumerDao implements ConsumerDao {
    private Map<String, Consumer> consumers;

    public ServerConfigConsumerDao(ServerConfigurationService serverConfig) {
        Collection<String> consumerKeys = getStringsOrSplit("oauth.consumers", serverConfig);
        consumers = new HashMap<String, Consumer>(consumerKeys.size());
        for (String consumerKey : consumerKeys) {
            Consumer consumer = new Consumer();
            consumer.setId(consumerKey);
            consumer.setName(serverConfig.getString("oauth." + consumerKey + ".name", null));
            consumer.setDescription(serverConfig.getString("oauth." + consumerKey + ".description", null));
            consumer.setURL(serverConfig.getString("oauth." + consumerKey + ".url", null));
            consumer.setCallbackURL(serverConfig.getString("oauth." + consumerKey + ".callbackURL", null));
            consumer.setSecret(serverConfig.getString("oauth." + consumerKey + ".secret"));
            consumer.setAccessorSecret(serverConfig.getString("oauth." + consumerKey + ".accessorsecret", null));
            consumer.setDefaultValidity(serverConfig.getInt("oauth." + consumerKey + ".validity", 0));
            consumer.setRights(new HashSet<String>(getStringsOrSplit("oauth." + consumerKey + ".rights", serverConfig)));
            consumer.setRecordModeEnabled(serverConfig.getBoolean("oauth." + consumerKey + ".record", false));

            consumers.put(consumerKey, consumer);
        }
    }

    private static Collection<String> getStringsOrSplit(String name, ServerConfigurationService serverConfig) {
        String stringValue = serverConfig.getString(name, null);
        String[] values;
        if (stringValue != null)
            values = stringValue.split(",");
        else
            values = serverConfig.getStrings(name);

        return (values != null) ? Arrays.asList(values) : Collections.<String>emptyList();
    }

    @Override
    public void create(Consumer consumer) {
        throw new UnsupportedOperationException("Can't create a consumer in the server config");
    }

    @Override
    public Consumer get(String consumerId) {
        return consumers.get(consumerId);
    }

    @Override
    public Consumer update(Consumer consumer) {
        throw new UnsupportedOperationException("Can't update a consumer in the server config");
    }

    @Override
    public void remove(Consumer consumer) {
        throw new UnsupportedOperationException("Can't remove a consumer in the server config");
    }

    @Override
    public Collection<Consumer> getAll() {
        return consumers.values();
    }
}

{'fraction_non_alphanumeric': 0.11366448647693124, 'fraction_numerical': 0.00035354428142124803, 'mean_word_length': 3.392857142857143, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944790', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1405, 'n_words': 326}