<commit_before>/*
 * This file is part of LibrePlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.libreplan.business.common.entities;

import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.BaseEntity;

/**
 * Application configuration variables.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public class Configuration extends BaseEntity {

    public static Configuration create() {
        return create(new Configuration());
    }

    private BaseCalendar defaultCalendar;

    private String companyCode;

    private Boolean generateCodeForCriterion = true;

    private Boolean generateCodeForLabel = true;

    private Boolean generateCodeForWorkReport = true;

    private Boolean generateCodeForResources = true;

    private Boolean generateCodeForTypesOfWorkHours = true;

    private Boolean generateCodeForMaterialCategories = true;

    private Boolean generateCodeForUnitTypes = true;

    private Boolean generateCodeForBaseCalendars = true;

    private Boolean monteCarloMethodTabVisible = false;

    private Boolean generateCodeForWorkReportType = true;

    private Boolean generateCodeForCalendarExceptionType = true;

    private Boolean generateCodeForCostCategory = true;

    private Boolean changedDefaultAdminPassword = false;

    private Boolean changedDefaultUserPassword = false;

    private Boolean changedDefaultWsreaderPassword = false;

    private Boolean changedDefaultWswriterPassword = false;

    private Boolean autocompleteLogin = true;

    private ProgressType progressType = ProgressType.SPREAD_PROGRESS;

    private String companyLogoURL = "";

    private Boolean scenariosVisible = false;

    private LDAPConfiguration ldapConfiguration;

    public void setDefaultCalendar(BaseCalendar defaultCalendar) {
        this.defaultCalendar = defaultCalendar;
    }

    @NotNull(message = "default calendar not specified")
    public BaseCalendar getDefaultCalendar() {
        return defaultCalendar;
    }

    public void setCompanyCode(String companyCode) {
        if (companyCode != null) {
            companyCode = companyCode.trim();
        }
        this.companyCode = companyCode;
    }

    @NotEmpty(message = "company code not specified")
    public String getCompanyCode() {
        return companyCode;
    }

    @AssertTrue(message = "company code must not contain white spaces")
    public boolean checkConstraintCompanyCodeWithoutWhiteSpaces() {
        if ((companyCode == null) || (companyCode.isEmpty())) {
            return false;
        }
        return !companyCode.contains(" ");
    }

    @AssertTrue(message = "host not specified")
    public boolean checkConstraintLdapHostWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapHost())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "port not specified")
    public boolean checkConstraintLdapPortWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapPort())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "base not specified")
    public boolean checkConstraintLdapBaseWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapBase())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "userDn not specified")
    public boolean checkConstraintLdapUserDnWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapUserDn())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "userId not specified")
    public boolean checkConstraintLdapUserIdWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapUserId())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "password not specified")
    public boolean checkConstraintLdapPasswordWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapPassword())) {
                return false;
            }
        }
        return true;
    }

    public void setGenerateCodeForCriterion(Boolean generateCodeForCriterion) {
        this.generateCodeForCriterion = generateCodeForCriterion;
    }

    public Boolean getGenerateCodeForCriterion() {<commit_msg>Bug #1332: Fix problem allowing to set empty values for userDn and password<commit_after>/*
 * This file is part of LibrePlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.libreplan.business.common.entities;

import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.BaseEntity;

/**
 * Application configuration variables.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public class Configuration extends BaseEntity {

    public static Configuration create() {
        return create(new Configuration());
    }

    private BaseCalendar defaultCalendar;

    private String companyCode;

    private Boolean generateCodeForCriterion = true;

    private Boolean generateCodeForLabel = true;

    private Boolean generateCodeForWorkReport = true;

    private Boolean generateCodeForResources = true;

    private Boolean generateCodeForTypesOfWorkHours = true;

    private Boolean generateCodeForMaterialCategories = true;

    private Boolean generateCodeForUnitTypes = true;

    private Boolean generateCodeForBaseCalendars = true;

    private Boolean monteCarloMethodTabVisible = false;

    private Boolean generateCodeForWorkReportType = true;

    private Boolean generateCodeForCalendarExceptionType = true;

    private Boolean generateCodeForCostCategory = true;

    private Boolean changedDefaultAdminPassword = false;

    private Boolean changedDefaultUserPassword = false;

    private Boolean changedDefaultWsreaderPassword = false;

    private Boolean changedDefaultWswriterPassword = false;

    private Boolean autocompleteLogin = true;

    private ProgressType progressType = ProgressType.SPREAD_PROGRESS;

    private String companyLogoURL = "";

    private Boolean scenariosVisible = false;

    private LDAPConfiguration ldapConfiguration;

    public void setDefaultCalendar(BaseCalendar defaultCalendar) {
        this.defaultCalendar = defaultCalendar;
    }

    @NotNull(message = "default calendar not specified")
    public BaseCalendar getDefaultCalendar() {
        return defaultCalendar;
    }

    public void setCompanyCode(String companyCode) {
        if (companyCode != null) {
            companyCode = companyCode.trim();
        }
        this.companyCode = companyCode;
    }

    @NotEmpty(message = "company code not specified")
    public String getCompanyCode() {
        return companyCode;
    }

    @AssertTrue(message = "company code must not contain white spaces")
    public boolean checkConstraintCompanyCodeWithoutWhiteSpaces() {
        if ((companyCode == null) || (companyCode.isEmpty())) {
            return false;
        }
        return !companyCode.contains(" ");
    }

    @AssertTrue(message = "host not specified")
    public boolean checkConstraintLdapHostWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapHost())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "port not specified")
    public boolean checkConstraintLdapPortWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapPort())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "base not specified")
    public boolean checkConstraintLdapBaseWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapBase())) {
                return false;
            }
        }
        return true;
    }

    @AssertTrue(message = "userId not specified")
    public boolean checkConstraintLdapUserIdWithoutWhiteSpaces() {
        if (getLdapConfiguration().getLdapAuthEnabled()) {
            if (StringUtils.isBlank(getLdapConfiguration().getLdapUserId())) {
                return false;
            }
        }
        return true;
    }

    public void setGenerateCodeForCriterion(Boolean generateCodeForCriterion) {
        this.generateCodeForCriterion = generateCodeForCriterion;
    }

    public Boolean getGenerateCodeForCriterion() {
{'fraction_non_alphanumeric': 0.07797340998922027, 'fraction_numerical': 0.003413582464965864, 'mean_word_length': 3.1900639819345127, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '3877521', 'n_tokens_mistral': 2863, 'n_tokens_neox': 2799, 'n_words': 802}