<commit_before>package ee.tuleva.onboarding.auth.principal;

import ee.tuleva.onboarding.user.User;
import ee.tuleva.onboarding.user.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.text.WordUtils;
import org.springframework.security.oauth2.common.exceptions.InvalidRequestException;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@Slf4j
@RequiredArgsConstructor
public class PrincipalService {

    private final UserService userService;

    public AuthenticatedPerson getFrom(Person person) {

        Optional<User> userOptional = userService.findByPersonalCode(person.getPersonalCode());

        User user = userOptional.orElse(userService.createNewUser(
                User.builder()
                        .firstName(WordUtils.capitalizeFully(person.getFirstName()))
                        .lastName(WordUtils.capitalizeFully(person.getLastName()))
                        .personalCode(person.getPersonalCode())
                        .active(true)
                        .build()
        ));

        if (!user.getActive()) {
            log.info("Failed to login inactive user with personal code {}", person.getPersonalCode());
            throw new InvalidRequestException("INACTIVE_USER");
        }

        return AuthenticatedPerson.builder()
                .firstName(person.getFirstName())
                .lastName(person.getLastName())
                .personalCode(person.getPersonalCode())
                .userId(user.getId())
                .build();

    }

}
<commit_msg>Fixes a bug where line is optional orelse got executed<commit_after>package ee.tuleva.onboarding.auth.principal;

import ee.tuleva.onboarding.user.User;
import ee.tuleva.onboarding.user.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.text.WordUtils;
import org.springframework.security.oauth2.common.exceptions.InvalidRequestException;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@Slf4j
@RequiredArgsConstructor
public class PrincipalService {

    private final UserService userService;

    public AuthenticatedPerson getFrom(Person person) {

        Optional<User> userOptional = userService.findByPersonalCode(person.getPersonalCode());

        User user = userOptional.orElseGet(() -> createUser(person));

        if (!user.getActive()) {
            log.info("Failed to login inactive user with personal code {}", person.getPersonalCode());
            throw new InvalidRequestException("INACTIVE_USER");
        }

        return AuthenticatedPerson.builder()
                .firstName(person.getFirstName())
                .lastName(person.getLastName())
                .personalCode(person.getPersonalCode())
                .userId(user.getId())
                .build();

    }

    private User createUser(Person person) {
        return userService.createNewUser(
                User.builder()
                        .firstName(WordUtils.capitalizeFully(person.getFirstName()))
                        .lastName(WordUtils.capitalizeFully(person.getLastName()))
                        .personalCode(person.getPersonalCode())
                        .active(true)
                        .build()
        );
    }

}

{'fraction_non_alphanumeric': 0.09913664781184876, 'fraction_numerical': 0.002977076510866329, 'mean_word_length': 2.6129032258064515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3404372', 'n_tokens_mistral': 934, 'n_tokens_neox': 876, 'n_words': 146}