<commit_before>package ee.tuleva.onboarding.aml;

import ee.tuleva.onboarding.auth.principal.Person;
import ee.tuleva.onboarding.epis.contact.UserPreferences;
import ee.tuleva.onboarding.user.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class AmlService {

    private final AmlCheckRepository amlCheckRepository;

    public void checkUserAfterLogin(User user, Person person) {
        addCheckIfMissing(user, AmlCheckType.DOCUMENT, true);
        addSkNameCheckIfMissing(user, person);
    }

    private void addSkNameCheckIfMissing(User user, Person person) {
        if (!hasCheck(user, AmlCheckType.SK_NAME)) {
            addCheck(user, AmlCheckType.SK_NAME,
                personDataMatches(user, person.getFirstName(), person.getLastName(), person.getPersonalCode()));
        }
    }

    public void addPensionRegistryNameCheckIfMissing(User user, UserPreferences userPreferences) {
        if (!hasCheck(user, AmlCheckType.PENSION_REGISTRY_NAME)) {
            addCheck(user, AmlCheckType.PENSION_REGISTRY_NAME,
                personDataMatches(user,
                    userPreferences.getFirstName(),
                    userPreferences.getLastName(),
                    userPreferences.getPersonalCode()));
        }
    }

    private boolean personDataMatches(User user, String firstName, String lastName, String personalCode) {
        if (!user.getFirstName().toLowerCase().equals(firstName.toLowerCase())) {
            return false;
        }
        if (!user.getLastName().toLowerCase().equals(lastName.toLowerCase())) {
            return false;
        }
        return user.getPersonalCode().equals(personalCode);
    }

    public void addCheckIfMissing(User user, AmlCheckType type, Boolean success) {
        if (!hasCheck(user, type)) {
            addCheck(user, type, success);
        }<commit_msg>Null safe equals<commit_after>package ee.tuleva.onboarding.aml;

import ee.tuleva.onboarding.auth.principal.Person;
import ee.tuleva.onboarding.epis.contact.UserPreferences;
import ee.tuleva.onboarding.user.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class AmlService {

    private final AmlCheckRepository amlCheckRepository;

    public void checkUserAfterLogin(User user, Person person) {
        addCheckIfMissing(user, AmlCheckType.DOCUMENT, true);
        addSkNameCheckIfMissing(user, person);
    }

    private void addSkNameCheckIfMissing(User user, Person person) {
        if (!hasCheck(user, AmlCheckType.SK_NAME)) {
            addCheck(user, AmlCheckType.SK_NAME,
                personDataMatches(user, person.getFirstName(), person.getLastName(), person.getPersonalCode()));
        }
    }

    public void addPensionRegistryNameCheckIfMissing(User user, UserPreferences userPreferences) {
        if (!hasCheck(user, AmlCheckType.PENSION_REGISTRY_NAME)) {
            addCheck(user, AmlCheckType.PENSION_REGISTRY_NAME,
                personDataMatches(user,
                    userPreferences.getFirstName(),
                    userPreferences.getLastName(),
                    userPreferences.getPersonalCode()));
        }
    }

    private boolean personDataMatches(User user, String firstName, String lastName, String personalCode) {
        if (!StringUtils.equalsIgnoreCase(user.getFirstName(), firstName)) {
            return false;
        }
        if (!StringUtils.equalsIgnoreCase(user.getLastName(), lastName)) {
            return false;
        }
        return StringUtils.equalsIgnoreCase(user.getPersonalCode(), personalCode);
    }

    public void addCheckIfMissing(User user, AmlCheckType type, Boolean success) {
        if (!hasCheck(user, type)) {
            addCheck(user, type, success);
        }
{'fraction_non_alphanumeric': 0.0946247213277186, 'fraction_numerical': 0.0017339608620262571, 'mean_word_length': 3.241596638655462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4819612', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1140, 'n_words': 209}