<commit_before>/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.data.util;

import org.spongepowered.api.data.DataRegistration;
import org.spongepowered.api.data.DataRegistrationNotFoundException;
import org.spongepowered.api.data.DataView;
import org.spongepowered.api.data.persistence.DataContentUpdater;
import org.spongepowered.common.data.SpongeManipulatorRegistry;

public class LegacyCustomDataClassContentUpdater implements DataContentUpdater{

    @Override
    public int getInputVersion() {
        return DataVersions.Data.CLASS_BASED_CUSTOM_DATA;
    }

    @Override
    public int getOutputVersion() {
        return DataVersions.Data.CUSTOM_DATA_WITH_DATA_IDS;
    }

    @SuppressWarnings("deprecation")
    @Override
    public DataView update(DataView content) {
        final String className = content.getString(DataQueries.DATA_CLASS).get();

        final DataRegistration<?, ?> registration = SpongeManipulatorRegistry.getInstance().getRegistrationForLegacyId(className)
                .orElseThrow(() -> new DataRegistrationNotFoundException(className));
        content.set(DataQueries.DATA_ID, registration.getId());
        content.remove(DataQueries.DATA_CLASS);
        return content;
    }
}
<commit_msg>Don't throw when a data registration can not be found during legacy class migration<commit_after>/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.data.util;

import org.spongepowered.api.data.DataRegistration;
import org.spongepowered.api.data.DataView;
import org.spongepowered.api.data.persistence.DataContentUpdater;
import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.data.SpongeManipulatorRegistry;

import java.util.Optional;

public class LegacyCustomDataClassContentUpdater implements DataContentUpdater {

    @Override
    public int getInputVersion() {
        return DataVersions.Data.CLASS_BASED_CUSTOM_DATA;
    }

    @Override
    public int getOutputVersion() {
        return DataVersions.Data.CUSTOM_DATA_WITH_DATA_IDS;
    }

    @SuppressWarnings("deprecation")
    @Override
    public DataView update(DataView content) {
        final String className = content.getString(DataQueries.DATA_CLASS).get();

        final Optional<DataRegistration<?, ?>> registration = SpongeManipulatorRegistry.getInstance().getRegistrationForLegacyId(className);
        if (!registration.isPresent()) {
            SpongeImpl.getLogger().warn("Could not find data registration for class '{}' - ignoring", className);
            return content;
        }
        content.set(DataQueries.DATA_ID, registration.get().getId());
        content.remove(DataQueries.DATA_CLASS);
        return content;
    }
}

{'fraction_non_alphanumeric': 0.07535046728971963, 'fraction_numerical': 0.0, 'mean_word_length': 4.247191011235955, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2148601', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1305, 'n_words': 491}