<commit_before>/*
 * Copyright 2003 - 2020 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.esjp.sales.document;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.efaps.admin.datamodel.Dimension;
import org.efaps.admin.datamodel.Dimension.UoM;
import org.efaps.admin.datamodel.Type;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsApplication;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.program.esjp.Listener;
import org.efaps.admin.ui.Command;
import org.efaps.db.Instance;
import org.efaps.db.MultiPrintQuery;
import org.efaps.db.PrintQuery;
import org.efaps.db.QueryBuilder;
import org.efaps.db.SelectBuilder;
import org.efaps.esjp.ci.CIERP;
import org.efaps.esjp.ci.CIProducts;
import org.efaps.esjp.ci.CISales;
import org.efaps.esjp.common.listener.ITypedClass;
import org.efaps.esjp.common.properties.PropertiesUtil;
import org.efaps.esjp.db.InstanceUtils;
import org.efaps.esjp.erp.AbstractPositionWarning;
import org.efaps.esjp.erp.AbstractWarning;
import org.efaps.esjp.erp.IWarning;
import org.efaps.esjp.erp.NumberFormatter;
import org.efaps.esjp.erp.WarningUtil;
import org.efaps.esjp.products.Storage;
import org.efaps.esjp.products.Storage_Base.ClosureWarning;
import org.efaps.esjp.products.util.Products;
import org.efaps.esjp.sales.Calculator;
import org.efaps.esjp.sales.listener.IOnValidation;
import org.efaps.esjp.sales.util.Sales;
import org.efaps.util.EFapsException;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author The eFaps Team
 */
@EFapsUUID("6ccd0664-cf7a-478f-b356-d8ec9c140b20")
@EFapsApplication("eFapsApp-Sales")
public abstract class Validation_Base
    extends AbstractDocument
{

    /**
     * Enum for enabling standard validations.
     */
    public enum Validations
    {
        /** Basic validation for Positions. */
        POSITION,
        /** Basic validation for Positions. */
        DUPLICATEDPOSITION,
        /** Validate that only one product is selected. */
        ONLYONEPRODUCT,
        /** Validate Quantity in Stock. */
        QUANTITYINSTOCK,
        /** Validate Quantity in Stock for a Document Instance in Background. */
        QUANTITYINSTOCK4DOC,
        /** Validate that Quantity is greater than zero. */
        QUANTITYGREATERZERO,
        /** Validate that Amount is greater than zero. */
        AMOUNTGREATERZERO,
        /** Validate that Amount is greater than zero. */
        TOTALGREATERZERO,
        /** Validate the Name. */
        NAME,
        /** Validate the Serial Name. */
        SERIAL,
        /** Present always a warning "Are you sure". */
        AREYOUSURE,
        /** Validate the selected products for Individual. */
        INDIVIDUAL,
        /**
         * Validate that the given date is after the last Closure date for given
         * Storages.
         */
        STOCKCLOSURE,
        /** Validate the maximum number of lines in the document */
        MAXLINES;
    }

    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(Validation.class);

    /**
     * @param _parameter parameter as passed by the eFasp API
     * @param _doc the document calling the evaluation
     * @return Return with the result
     * @throws EFapsException on error
     */
    public Return validate(final Parameter _parameter,
                           final ITypedClass _doc)
        throws EFapsException
    {
        return validate(_parameter, _doc, null);
    }

    public Collection<Validations> getValidations(final Parameter _parameter, final Properties _validationProperties)
        throws EFapsException
    {
        final List<Validations> ret = new ArrayList<>();
        final var validations = _validationProperties == null ? analyseProperty(_parameter, "Validation")
                        : analyseProperty(_parameter, _validationProperties, "Validation");
        for (final String validation : validations.values()) {
            final var val = EnumUtils.getEnum(Validations.class, validation);
            if (val != null) {<commit_msg>Update validation<commit_after>/*
 * Copyright 2003 - 2020 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.esjp.sales.document;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.efaps.admin.datamodel.Dimension;
import org.efaps.admin.datamodel.Dimension.UoM;
import org.efaps.admin.datamodel.Type;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsApplication;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.program.esjp.Listener;
import org.efaps.admin.ui.Command;
import org.efaps.db.Instance;
import org.efaps.db.MultiPrintQuery;
import org.efaps.db.PrintQuery;
import org.efaps.db.QueryBuilder;
import org.efaps.db.SelectBuilder;
import org.efaps.esjp.ci.CIERP;
import org.efaps.esjp.ci.CIProducts;
import org.efaps.esjp.ci.CISales;
import org.efaps.esjp.common.listener.ITypedClass;
import org.efaps.esjp.common.properties.PropertiesUtil;
import org.efaps.esjp.db.InstanceUtils;
import org.efaps.esjp.erp.AbstractPositionWarning;
import org.efaps.esjp.erp.AbstractWarning;
import org.efaps.esjp.erp.IWarning;
import org.efaps.esjp.erp.NumberFormatter;
import org.efaps.esjp.erp.WarningUtil;
import org.efaps.esjp.products.Storage;
import org.efaps.esjp.products.Storage_Base.ClosureWarning;
import org.efaps.esjp.products.util.Products;
import org.efaps.esjp.sales.Calculator;
import org.efaps.esjp.sales.listener.IOnValidation;
import org.efaps.esjp.sales.util.Sales;
import org.efaps.util.EFapsException;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author The eFaps Team
 */
@EFapsUUID("6ccd0664-cf7a-478f-b356-d8ec9c140b20")
@EFapsApplication("eFapsApp-Sales")
public abstract class Validation_Base
    extends AbstractDocument
{

    /**
     * Enum for enabling standard validations.
     */
    public enum Validations
    {
        /** Basic validation for Positions. */
        POSITION,
        /** Basic validation for Positions. */
        DUPLICATEDPOSITION,
        /** Validate that only one product is selected. */
        ONLYONEPRODUCT,
        /** Validate Quantity in Stock. */
        QUANTITYINSTOCK,
        /** Validate Quantity in Stock for a Document Instance in Background. */
        QUANTITYINSTOCK4DOC,
        /** Validate that Quantity is greater than zero. */
        QUANTITYGREATERZERO,
        /** Validate that Amount is greater than zero. */
        AMOUNTGREATERZERO,
        /** Validate that Amount is greater than zero. */
        TOTALGREATERZERO,
        /** Validate the Name. */
        NAME,
        /** Validate the Serial Name. */
        SERIAL,
        /** Present always a warning "Are you sure". */
        AREYOUSURE,
        /** Validate the selected products for Individual. */
        INDIVIDUAL,
        /**
         * Validate that the given date is after the last Closure date for given
         * Storages.
         */
        STOCKCLOSURE,
        /** Validate the maximum number of lines in the document */
        MAXLINES;
    }

    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(Validation.class);

    /**
     * @param _parameter parameter as passed by the eFasp API
     * @param _doc the document calling the evaluation
     * @return Return with the result
     * @throws EFapsException on error
     */
    public Return validate(final Parameter _parameter,
                           final ITypedClass _doc)
        throws EFapsException
    {
        return validate(_parameter, _doc, PropertiesUtil.getProperties(_parameter));
    }

    public Collection<Validations> getValidations(final Parameter _parameter, final Properties _validationProperties)
        throws EFapsException
    {
        final List<Validations> ret = new ArrayList<>();
        final var validations = PropertiesUtil.analyseProperty(_validationProperties, "Validation", 0);
        for (final String validation : validations.values()) {
            final var val = EnumUtils.getEnum(Validations.class, validation);
            if (val != null) {
{'fraction_non_alphanumeric': 0.09688281700981335, 'fraction_numerical': 0.007215701366172792, 'mean_word_length': 3.210206561360875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '534422', 'n_tokens_mistral': 3172, 'n_tokens_neox': 3037, 'n_words': 807}