<commit_before>package com.sequenceiq.cloudbreak.conf;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import com.sequenceiq.cloudbreak.domain.Blueprint;
import com.sequenceiq.cloudbreak.domain.Company;
import com.sequenceiq.cloudbreak.domain.User;
import com.sequenceiq.cloudbreak.domain.UserRole;
import com.sequenceiq.cloudbreak.domain.UserStatus;
import com.sequenceiq.cloudbreak.repository.CompanyRepository;
import com.sequenceiq.cloudbreak.service.blueprint.DefaultBlueprintLoaderService;

@Component
public class UserInitializer implements InitializingBean {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserInitializer.class);

    @Value("${cb.hbm2ddl.strategy:update}")
    private String hbm2ddlStrategy;

    @Value("${cb.default.user.email:<EMAIL>}")
    private String defaultUserEmail;

    @Value("${cb.default.user.firstname:Firstname}")
    private String defaultUserFirstName;

    @Value("${cb.default.user.lastname:Lastname}")
    private String defaultUserLastName;

    @Value("${cb.default.user.password:<PASSWORD>}")
    private String defaultUserPassword;

    @Value("${cb.default.company.name:SequenceIQ}")
    private String defaultCompanyName;

    @Autowired
    private CompanyRepository companyRepository;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private DefaultBlueprintLoaderService defaultBlueprintLoaderService;

    @Override
    public void afterPropertiesSet() throws Exception {
        if ("create".equals(hbm2ddlStrategy) || "create-drop".equals(hbm2ddlStrategy)) {
            Company company = new Company();
            company.setName(defaultCompanyName);

            User user = new User();
            user.setEmail(defaultUserEmail);
            user.setFirstName(defaultUserFirstName);
            user.setLastName(defaultUserLastName);
            user.setPassword(passwordEncoder.encode(defaultUserPassword));
            user.setStatus(UserStatus.ACTIVE);
            user.setCompany(company);
            user.getUserRoles().add(UserRole.DEPLOYER);<commit_msg>CLOUD-179 fixed default values<commit_after>package com.sequenceiq.cloudbreak.conf;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import com.sequenceiq.cloudbreak.domain.Blueprint;
import com.sequenceiq.cloudbreak.domain.Company;
import com.sequenceiq.cloudbreak.domain.User;
import com.sequenceiq.cloudbreak.domain.UserRole;
import com.sequenceiq.cloudbreak.domain.UserStatus;
import com.sequenceiq.cloudbreak.repository.CompanyRepository;
import com.sequenceiq.cloudbreak.service.blueprint.DefaultBlueprintLoaderService;

@Component
public class UserInitializer implements InitializingBean {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserInitializer.class);

    @Value("${cb.hbm2ddl.strategy:update}")
    private String hbm2ddlStrategy;

    @Value("${cb.default.user.email}")
    private String defaultUserEmail;

    @Value("${cb.default.user.firstname}")
    private String defaultUserFirstName;

    @Value("${cb.default.user.lastname}")
    private String defaultUserLastName;

    @Value("${cb.default.user.password}")
    private String defaultUserPassword;

    @Value("${cb.default.company.name}")
    private String defaultCompanyName;

    @Autowired
    private CompanyRepository companyRepository;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private DefaultBlueprintLoaderService defaultBlueprintLoaderService;

    @Override
    public void afterPropertiesSet() throws Exception {
        if ("create".equals(hbm2ddlStrategy) || "create-drop".equals(hbm2ddlStrategy)) {
            Company company = new Company();
            company.setName(defaultCompanyName);

            User user = new User();
            user.setEmail(defaultUserEmail);
            user.setFirstName(defaultUserFirstName);
            user.setLastName(defaultUserLastName);
            user.setPassword(passwordEncoder.encode(default<PASSWORD>));
            user.setStatus(UserStatus.ACTIVE);
            user.setCompany(company);
            user.getUserRoles().add(UserRole.DEPLOYER);
{'fraction_non_alphanumeric': 0.09987463435018805, 'fraction_numerical': 0.0031341412452987882, 'mean_word_length': 4.508630609896433, 'pattern_counts': {'":': 0, '<': 6, '<?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': '7059417', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1298, 'n_words': 212}