<commit_before>package org.incode.eurocommercial.ecpcrm.module.api.service.vm.websiteusercarddisable;

import com.google.common.base.Strings;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.incode.eurocommercial.ecpcrm.module.api.dom.authentication.AuthenticationDevice;
import org.incode.eurocommercial.ecpcrm.module.api.service.ApiService;
import org.incode.eurocommercial.ecpcrm.module.api.service.Result;
import org.incode.eurocommercial.ecpcrm.module.api.service.vm.AbstractRequestViewModel;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.Card;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.CardRepository;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.CardStatus;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.user.User;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.user.UserRepository;

import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;

@NoArgsConstructor(force = true)
@AllArgsConstructor
public class WebsiteUserCardDisableRequestViewModel extends AbstractRequestViewModel {
    @Getter
    @SerializedName("check_code")
    private final String checkCode;

    @Getter
    private final String email;

    @Override
    public Result isValid(AuthenticationDevice device, User user){
        if (Strings.isNullOrEmpty(getCheckCode()) || Strings.isNullOrEmpty(getEmail())) {
            return Result.error(Result.STATUS_INVALID_PARAMETER, "Invalid parameter");
        }
        System.out.println(ApiService.computeCheckCode(getEmail()));

        user = userRepository.findByExactEmailAndCenter(getEmail(), device.getCenter());
        if(user == null){
            return Result.error(Result.STATUS_INVALID_USER, "Invalid user");
        }

        if (!getCheckCode().equals(ApiService.computeCheckCode(getEmail()))) {
            return Result.error(Result.STATUS_INCORRECT_CHECK_CODE, "Incorrect check code");
        }

        List<Card> cards = cardRepository.findByOwner(user);
        List<Card> enabledCards = cards
                .stream()
                .filter(card -> card.getStatus() == CardStatus.ENABLED)
                .collect(Collectors.toList());

        enabledCards.forEach(card -> card.setStatus(CardStatus.DISABLED));

        return Result.ok();
    }

    @Inject
    UserRepository userRepository;

    @Inject
    CardRepository cardRepository;
}<commit_msg>ECPCRM-195: removing print<commit_after>package org.incode.eurocommercial.ecpcrm.module.api.service.vm.websiteusercarddisable;

import com.google.common.base.Strings;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.incode.eurocommercial.ecpcrm.module.api.dom.authentication.AuthenticationDevice;
import org.incode.eurocommercial.ecpcrm.module.api.service.ApiService;
import org.incode.eurocommercial.ecpcrm.module.api.service.Result;
import org.incode.eurocommercial.ecpcrm.module.api.service.vm.AbstractRequestViewModel;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.Card;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.CardRepository;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.card.CardStatus;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.user.User;
import org.incode.eurocommercial.ecpcrm.module.loyaltycards.dom.user.UserRepository;

import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;

@NoArgsConstructor(force = true)
@AllArgsConstructor
public class WebsiteUserCardDisableRequestViewModel extends AbstractRequestViewModel {
    @Getter
    @SerializedName("check_code")
    private final String checkCode;

    @Getter
    private final String email;

    @Override
    public Result isValid(AuthenticationDevice device, User user){
        if (Strings.isNullOrEmpty(getCheckCode()) || Strings.isNullOrEmpty(getEmail())) {
            return Result.error(Result.STATUS_INVALID_PARAMETER, "Invalid parameter");
        }

        user = userRepository.findByExactEmailAndCenter(getEmail(), device.getCenter());
        if(user == null){
            return Result.error(Result.STATUS_INVALID_USER, "Invalid user");
        }

        if (!getCheckCode().equals(ApiService.computeCheckCode(getEmail()))) {
            return Result.error(Result.STATUS_INCORRECT_CHECK_CODE, "Incorrect check code");
        }

        List<Card> cards = cardRepository.findByOwner(user);
        List<Card> enabledCards = cards
                .stream()
                .filter(card -> card.getStatus() == CardStatus.ENABLED)
                .collect(Collectors.toList());

        enabledCards.forEach(card -> card.setStatus(CardStatus.DISABLED));

        return Result.ok();
    }

    @Inject
    UserRepository userRepository;

    @Inject
    CardRepository cardRepository;
}
{'fraction_non_alphanumeric': 0.10555555555555556, 'fraction_numerical': 0.0005952380952380953, 'mean_word_length': 4.2184265010351965, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1925675', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1478, 'n_words': 215}