<commit_before>/*
 * This file is part of Dependency-Track.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * Copyright (c) <NAME>. All Rights Reserved.
 */
package org.dependencytrack.upgrade.v370;

import alpine.logging.Logger;
import alpine.persistence.AlpineQueryManager;
import alpine.upgrade.AbstractUpgradeItem;
import alpine.util.DbUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class v370Updater extends AbstractUpgradeItem {

    private static final Logger LOGGER = Logger.getLogger(v370Updater.class);
    private static final String STMT_1 = "SELECT \"ID\" FROM \"PERMISSION\" WHERE \"NAME\" = 'SCAN_UPLOAD'";
    private static final String STMT_2 = "DELETE FROM \"TEAMS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_3 = "DELETE FROM \"LDAPUSERS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_4 = "DELETE FROM \"MANAGEDUSERS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_5 = "DELETE FROM \"PERMISSION\" WHERE \"ID\" = %d";
    private static final String STMT_6 = "DELETE FROM \"SCANS_COMPONENTS\"";
    private static final String STMT_7 = "UPDATE \"PROJECT\" SET \"LAST_SCAN_IMPORTED\" = NULL";
    private static final String STMT_8 = "DELETE FROM \"CONFIGPROPERTY\" WHERE \"GROUPNAME\" = 'artifact' AND \"PROPERTYNAME\" = 'dependencycheck.enabled'";
    private static final String STMT_9 = "UPDATE \"COMPONENT\" SET \"INTERNAL\" = TRUE WHERE \"INTERNAL\" IS NULL";
    private static final String STMT_9_ALT = "UPDATE \"COMPONENT\" SET \"INTERNAL\" = 1 WHERE \"INTERNAL\" IS NULL";

    @Override
    public String getSchemaVersion() {
        return "3.7.0";
    }

    @Override
    public void executeUpgrade(final AlpineQueryManager alpineQueryManager, final Connection connection) throws Exception {
        LOGGER.info("Updating existing components to be non-internal");
        try {<commit_msg>#303 - Fixed upgrade statement to ensure all components are not internal on upgrades<commit_after>/*
 * This file is part of Dependency-Track.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * Copyright (c) <NAME>. All Rights Reserved.
 */
package org.dependencytrack.upgrade.v370;

import alpine.logging.Logger;
import alpine.persistence.AlpineQueryManager;
import alpine.upgrade.AbstractUpgradeItem;
import alpine.util.DbUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class v370Updater extends AbstractUpgradeItem {

    private static final Logger LOGGER = Logger.getLogger(v370Updater.class);
    private static final String STMT_1 = "SELECT \"ID\" FROM \"PERMISSION\" WHERE \"NAME\" = 'SCAN_UPLOAD'";
    private static final String STMT_2 = "DELETE FROM \"TEAMS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_3 = "DELETE FROM \"LDAPUSERS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_4 = "DELETE FROM \"MANAGEDUSERS_PERMISSIONS\" WHERE \"PERMISSION_ID\" = %d";
    private static final String STMT_5 = "DELETE FROM \"PERMISSION\" WHERE \"ID\" = %d";
    private static final String STMT_6 = "DELETE FROM \"SCANS_COMPONENTS\"";
    private static final String STMT_7 = "UPDATE \"PROJECT\" SET \"LAST_SCAN_IMPORTED\" = NULL";
    private static final String STMT_8 = "DELETE FROM \"CONFIGPROPERTY\" WHERE \"GROUPNAME\" = 'artifact' AND \"PROPERTYNAME\" = 'dependencycheck.enabled'";
    private static final String STMT_9 = "UPDATE \"COMPONENT\" SET \"INTERNAL\" = FALSE WHERE \"INTERNAL\" IS NULL";
    private static final String STMT_9_ALT = "UPDATE \"COMPONENT\" SET \"INTERNAL\" = 0 WHERE \"INTERNAL\" IS NULL";

    @Override
    public String getSchemaVersion() {
        return "3.7.0";
    }

    @Override
    public void executeUpgrade(final AlpineQueryManager alpineQueryManager, final Connection connection) throws Exception {
        LOGGER.info("Updating existing components to be non-internal");
        try {
{'fraction_non_alphanumeric': 0.10491419656786272, 'fraction_numerical': 0.01189547581903276, 'mean_word_length': 3.994157740993184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1563998', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1446, 'n_words': 532}