<commit_before>/*
 * Copyright 2017 <NAME>
 *
 * 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.
 */

package com.github.triceo.robozonky.installer.panels;

import java.util.Optional;
import java.util.function.Supplier;

import com.github.triceo.robozonky.api.confirmations.ConfirmationProvider;
import com.github.triceo.robozonky.common.extensions.Checker;
import com.github.triceo.robozonky.common.extensions.ConfirmationProviderLoader;
import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.installer.DataValidator;

public class ZonkoidSettingsValidator implements DataValidator {

    private final Supplier<Optional<ConfirmationProvider>> zonkoidSupplier;

    ZonkoidSettingsValidator() {
        this(() -> ConfirmationProviderLoader.load("zonkoid"));
    }

    /**
     * This constructor exists for testing purposes.
     * @param zonkoidSupplier Confirmation provider for this class.
     */
    ZonkoidSettingsValidator(final Supplier<Optional<ConfirmationProvider>> zonkoidSupplier) {
        this.zonkoidSupplier = zonkoidSupplier;
    }

    @Override
    public DataValidator.Status validateData(final InstallData installData) {
        return zonkoidSupplier.get()
                .map(zonkoid -> {
                    final String username = Variables.ZONKY_USERNAME.getValue(installData);
                    final char[] token = Variables.ZONKOID_TOKEN.getValue(installData).toCharArray();
                    return Checker.confirmations(zonkoid, username, token)
                            .map(result -> result ? DataValidator.Status.OK : DataValidator.Status.WARNING)
                            .orElse(DataValidator.Status.ERROR);
                }).orElse(DataValidator.Status.ERROR);
    }

    @Override
    public String getErrorMessageId() {
        return "Nepodařilo se odeslat notifikaci do mobilní aplikace. " +
                "Kod nebylo možné ověřit.";
    }

    @Override
    public String getWarningMessageId() {
        return "Došlo k chybě při kontaktování serveru Zonkoid. " +
                "Budete-li pokračovat, mobilní notifikace nemusí fungovat správně.";
    }

    @Override
    public boolean getDefaultAnswer() {
        return false;
    }
}
<commit_msg>Make constructor in installer available again<commit_after>/*
 * Copyright 2017 <NAME>
 *
 * 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.
 */

package com.github.triceo.robozonky.installer.panels;

import java.util.Optional;
import java.util.function.Supplier;

import com.github.triceo.robozonky.api.confirmations.ConfirmationProvider;
import com.github.triceo.robozonky.common.extensions.Checker;
import com.github.triceo.robozonky.common.extensions.ConfirmationProviderLoader;
import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.installer.DataValidator;

public class ZonkoidSettingsValidator implements DataValidator {

    private final Supplier<Optional<ConfirmationProvider>> zonkoidSupplier;

    public ZonkoidSettingsValidator() {
        this(() -> ConfirmationProviderLoader.load("zonkoid"));
    }

    /**
     * This constructor exists for testing purposes.
     * @param zonkoidSupplier Confirmation provider for this class.
     */
    ZonkoidSettingsValidator(final Supplier<Optional<ConfirmationProvider>> zonkoidSupplier) {
        this.zonkoidSupplier = zonkoidSupplier;
    }

    @Override
    public DataValidator.Status validateData(final InstallData installData) {
        return zonkoidSupplier.get()
                .map(zonkoid -> {
                    final String username = Variables.ZONKY_USERNAME.getValue(installData);
                    final char[] token = Variables.ZONKOID_TOKEN.getValue(installData).toCharArray();
                    return Checker.confirmations(zonkoid, username, token)
                            .map(result -> result ? DataValidator.Status.OK : DataValidator.Status.WARNING)
                            .orElse(DataValidator.Status.ERROR);
                }).orElse(DataValidator.Status.ERROR);
    }

    @Override
    public String getErrorMessageId() {
        return "Nepodařilo se odeslat notifikaci do mobilní aplikace. " +
                "Kod nebylo možné ověřit.";
    }

    @Override
    public String getWarningMessageId() {
        return "Došlo k chybě při kontaktování serveru Zonkoid. " +
                "Budete-li pokračovat, mobilní notifikace nemusí fungovat správně.";
    }

    @Override
    public boolean getDefaultAnswer() {
        return false;
    }
}

{'fraction_non_alphanumeric': 0.08374116367591082, 'fraction_numerical': 0.0029001268805510243, 'mean_word_length': 3.090437361008154, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '6208995', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1530, 'n_words': 398}