Search in sources :

Example 1 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.

the class RestrictionHandlerImpl method checkRestriction.

@Override
public synchronized String checkRestriction(Contract contract, String clientIp, ScopeEnum scope) {
    String decision = TgolKeyStore.ACT_ALLOWED;
    Set<OptionElement> optionElementSet = (Set<OptionElement>) contract.getOptionElementSet();
    if (optionElementSet.isEmpty()) {
        return decision;
    }
    for (OptionElement optionElement : optionElementSet) {
        RestrictionVoter restrictionVoter = chooseRestrictionVoter(optionElement);
        if (restrictionVoter != null) {
            decision = restrictionVoter.checkRestriction(contract, optionElement, clientIp, scope);
        }
        if (!decision.equalsIgnoreCase(TgolKeyStore.ACT_ALLOWED)) {
            break;
        }
    }
    return decision;
}
Also used : Set(java.util.Set) OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 2 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.

the class AuditSetUpFormFieldHelper method activateSelectFormField.

/**
     * This method enables/disables a select form field element regarding the
     * activation / restriction strategy. If a SelectFormField is set as enabled
     * by default and has a set restrictionCode, it can be disabled. If a
     * SelectFormField is set as disabled by default and has a set
     * activationCode, it can be enabled.
     *
     * @param selectFormField
     * @param optionElementSet
     */
private static void activateSelectFormField(SelectFormField selectFormField, Collection<OptionElement> optionElementSet) {
    boolean enableElements = true;
    OptionElement optionElement = null;
    if (StringUtils.isNotEmpty(selectFormField.getRestrictionCode())) {
        optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getRestrictionCode());
        enableElements = false;
    } else if (StringUtils.isNotEmpty(selectFormField.getActivationCode())) {
        optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getActivationCode());
    }
    if (optionElement != null) {
        String[] optionValues = optionElement.getValue().split(";");
        boolean isSelectFormFieldHasDefault = false;
        for (String optionValue : optionValues) {
            List<SelectElement> sel = selectFormField.getSelectElementMap().get(optionValue);
            for (SelectElement se : sel) {
                se.setEnabled(enableElements);
                // By option mechanism, we can set an SelectElement as default.
                if (!isSelectFormFieldHasDefault) {
                    isSelectFormFieldHasDefault = setSelectElementAsDefault(se, optionElementSet);
                }
            }
        }
        // is set as default
        if (!isSelectFormFieldHasDefault) {
            setFirstSelectElementAsDefault(selectFormField.getSelectElementMap());
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement) OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 3 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.

the class AuditSetUpFormFieldHelper method applyRestrictionToAuditSetUpFormField.

/**
     * A restriction can be applied to an AuditSetUpFormField when an option
     * matches with a parameter (by its code). In this case, regarding the type
     * of the FormField, the value of the option override the default
     *
     * @param ap
     * @param optionElementSet
     */
public static void applyRestrictionToAuditSetUpFormField(AuditSetUpFormField ap, Collection<OptionElement> optionElementSet) {
    if (ap.getFormField() instanceof NumericalFormField) {
        OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
        if (optionElement != null) {
            ((NumericalFormField) ap.getFormField()).setMaxValue(optionElement.getValue());
            ((NumericalFormField) ap.getFormField()).setValue(optionElement.getValue());
        }
    } else if (ap.getFormField() instanceof SelectFormField) {
        activateSelectFormField((SelectFormField) ap.getFormField(), optionElementSet);
    } else if (ap.getFormField() instanceof TextualFormField) {
        OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
        if (optionElement != null) {
            ((TextualFormField) ap.getFormField()).setValue(optionElement.getValue());
        }
    }
}
Also used : TextualFormField(org.asqatasun.webapp.form.TextualFormField) OptionElement(org.asqatasun.webapp.entity.option.OptionElement) NumericalFormField(org.asqatasun.webapp.form.NumericalFormField) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Example 4 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.

the class AuditLauncherController method setUserParameters.

/**
     * Some user options have to be converted as parameters and added to the
     * general audit parameters.
     *
     * @param paramSet
     * @param referentialKey
     * @return
     */
private Set<Parameter> setUserParameters(Set<Parameter> paramSet, String referentialKey) {
    User user = getCurrentUser();
    Collection<OptionElement> optionElementSet = new HashSet();
    for (String optionFamily : userOptionDependingOnReferential) {
        optionElementSet.addAll(optionElementDataService.getOptionElementFromUserAndFamilyCode(user, referentialKey + "_" + optionFamily));
    }
    for (String optionFamily : userOption) {
        optionElementSet.addAll(optionElementDataService.getOptionElementFromUserAndFamilyCode(user, optionFamily));
    }
    paramSet.addAll(getParameterDataService().getParameterSetFromOptionElementSet(optionElementSet));
    return paramSet;
}
Also used : User(org.asqatasun.webapp.entity.user.User) OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 5 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.

the class AuditLauncherController method getUserParamSet.

/**
     * This method gets the default parameters for an audit and eventually
     * override some of them in case of contract restriction.
     *
     * @param auditSetUpCommand
     * @param contractId
     * @param nbOfPages
     * @param url
     * @return
     */
private Set<Parameter> getUserParamSet(AuditSetUpCommand auditSetUpCommand, Long contractId, int nbOfPages, String url) {
    Set<Parameter> paramSet;
    Set<Parameter> userParamSet = new HashSet();
    if (auditSetUpCommand != null) {
        // parameter set 
        if (auditSetUpCommand.getScope().equals(ScopeEnum.SCENARIO)) {
            paramSet = getAuditScenarioParameterSet();
        } else if (!auditSetUpCommand.getScope().equals(ScopeEnum.DOMAIN)) {
            paramSet = getAuditPageParameterSet(nbOfPages);
        } else {
            paramSet = getDefaultParamSet();
        }
        for (Map.Entry<String, String> entry : auditSetUpCommand.getAuditParameter().entrySet()) {
            Parameter param = getParameterDataService().getParameter(parameterElementMap.get(entry.getKey()), entry.getValue());
            userParamSet.add(param);
        }
        paramSet = getParameterDataService().updateParameterSet(paramSet, userParamSet);
        paramSet = setLevelParameter(paramSet, auditSetUpCommand.getLevel());
    } else {
        paramSet = getDefaultParamSet();
        Collection<OptionElement> optionElementSet = getContractDataService().read(contractId).getOptionElementSet();
        for (Parameter param : paramSet) {
            for (OptionElement optionElement : optionElementSet) {
                if (optionElement.getOption().getCode().equalsIgnoreCase(param.getParameterElement().getParameterElementCode())) {
                    param = getParameterDataService().getParameter(param.getParameterElement(), optionElement.getValue());
                    break;
                }
            }
            userParamSet.add(param);
        }
        paramSet = getParameterDataService().updateParameterSet(paramSet, userParamSet);
    }
    return (auditSetUpCommand.getLevel() != null) ? setUserParameters(paramSet, auditSetUpCommand.getLevel().split(";")[0]) : paramSet;
}
Also used : OptionElement(org.asqatasun.webapp.entity.option.OptionElement) Parameter(org.asqatasun.entity.parameterization.Parameter)

Aggregations

OptionElement (org.asqatasun.webapp.entity.option.OptionElement)13 HashSet (java.util.HashSet)2 Parameter (org.asqatasun.entity.parameterization.Parameter)2 User (org.asqatasun.webapp.entity.user.User)2 NumberFormat (java.text.NumberFormat)1 Date (java.util.Date)1 Set (java.util.Set)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1 Query (javax.persistence.Query)1 ParameterElement (org.asqatasun.entity.parameterization.ParameterElement)1 Test (org.asqatasun.entity.reference.Test)1 ChangeTestWeightCommand (org.asqatasun.webapp.command.ChangeTestWeightCommand)1 Contract (org.asqatasun.webapp.entity.contract.Contract)1 Functionality (org.asqatasun.webapp.entity.functionality.Functionality)1 Option (org.asqatasun.webapp.entity.option.Option)1 OptionElementImpl (org.asqatasun.webapp.entity.option.OptionElementImpl)1 Referential (org.asqatasun.webapp.entity.referential.Referential)1 Scenario (org.asqatasun.webapp.entity.scenario.Scenario)1 NumericalFormField (org.asqatasun.webapp.form.NumericalFormField)1