<commit_before>package org.keycloak.connections.mongo.updater.impl.updates;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import org.keycloak.models.KeycloakSession;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class Update1_2_0_RC1 extends Update {

    @Override
    public String getId() {
        return "1.2.0.RC1";
    }

    @Override
    public void update(KeycloakSession session) {
        convertApplicationsToClients();
        convertOAuthClientsToClients();

        db.getCollection("realms").update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("adminAppId", "clientId")), false, true);

    }

    private void convertApplicationsToClients() {
        DBCollection applications = db.getCollection("applications");
        applications.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", false)), false, true);
        applications.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
        renameCollection("applications", "clients");
        log.debugv("Converted applications to clients");

        DBCollection roles = db.getCollection("roles");
        roles.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("applicationId", "clientId")), false, true);
        log.debugv("Renamed roles.applicationId to roles.clientId");
    }

    private void convertOAuthClientsToClients() {
        DBCollection clients = db.getCollection("clients");
        DBCollection oauthClients = db.getCollection("oauthClients");
        oauthClients.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
        oauthClients.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", true)), false, true);

        DBCursor curs = oauthClients.find();
        while (curs.hasNext()) {
            clients.insert(curs.next());
        }

        oauthClients.drop();
        log.debugv("Converted oauthClients to clients");
    }

}<commit_msg>KEYCLOAK-1187<commit_after>package org.keycloak.connections.mongo.updater.impl.updates;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import org.keycloak.models.KeycloakSession;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class Update1_2_0_RC1 extends Update {

    @Override
    public String getId() {
        return "1.2.0.RC1";
    }

    @Override
    public void update(KeycloakSession session) {
        convertApplicationsToClients();
        convertOAuthClientsToClients();

        db.getCollection("realms").update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("adminAppId", "clientId")), false, true);

    }

    private void convertApplicationsToClients() {
        DBCollection applications = db.getCollection("applications");
        applications.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", false)), false, true);
        applications.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
        renameCollection("applications", "clients");
        log.debugv("Converted applications to clients");

        DBCollection roles = db.getCollection("roles");
        roles.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("applicationId", "clientId")), false, true);
        log.debugv("Renamed roles.applicationId to roles.clientId");

        db.getCollection("clients").dropIndex("realmId_1_name_1");
        ensureIndex("clients", new String[]{"realmId", "clientId"}, true, false);

    }

    private void convertOAuthClientsToClients() {
        DBCollection clients = db.getCollection("clients");
        DBCollection oauthClients = db.getCollection("oauthClients");
        oauthClients.update(new BasicDBObject(), new BasicDBObject("$rename", new BasicDBObject("name", "clientId")), false, true);
        oauthClients.update(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject("consentRequired", true)), false, true);

        DBCursor curs = oauthClients.find();
        while (curs.hasNext()) {
            clients.insert(curs.next());
        }

        oauthClients.drop();
        log.debugv("Converted oauthClients to clients");
    }

}
{'fraction_non_alphanumeric': 0.13553607552258934, 'fraction_numerical': 0.004944931445268599, 'mean_word_length': 4.132641291810842, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2411045', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1286, 'n_words': 255}