Search in sources :

Example 1 with OptionElementImpl

use of org.asqatasun.entity.option.OptionElementImpl 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 = parameterDataService.getParameter(parameterElementMap.get(entry.getKey()), entry.getValue());
            userParamSet.add(param);
        }
        paramSet = parameterDataService.updateParameterSet(paramSet, userParamSet);
        paramSet = setLevelParameter(paramSet, auditSetUpCommand.getLevel());
    } else {
        paramSet = getDefaultParamSet();
        Collection<OptionElementImpl> optionElementSet = contractDataService.read(contractId).getOptionElementSet();
        for (Parameter param : paramSet) {
            for (OptionElementImpl optionElement : optionElementSet) {
                if (optionElement.getOption().getCode().equalsIgnoreCase(param.getParameterElement().getParameterElementCode())) {
                    param = parameterDataService.getParameter(param.getParameterElement(), optionElement.getValue());
                    break;
                }
            }
            userParamSet.add(param);
        }
        paramSet = parameterDataService.updateParameterSet(paramSet, userParamSet);
    }
    return (auditSetUpCommand.getLevel() != null) ? setUserParameters(paramSet, auditSetUpCommand.getLevel().split(";")[0]) : paramSet;
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Parameter(org.asqatasun.entity.parameterization.Parameter)

Example 2 with OptionElementImpl

use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.

the class ChangeTestWeightCommandFactory method updateUserTestWeight.

/**
 * @param user
 * @param changeTestWeightCommand
 */
public void updateUserTestWeight(User user, ChangeTestWeightCommand changeTestWeightCommand) {
    Collection<OptionElementImpl> userOptionElementSet = optionElementDataService.getOptionElementFromUser(user);
    // first we need to remove the option elements associated with the user
    // that are going to be updated
    Iterator<OptionElementImpl> iter = userOptionElementSet.iterator();
    // testWeightMap.
    while (iter.hasNext()) {
        OptionElementImpl oe = iter.next();
        if (changeTestWeightCommand.getTestWeightMap().containsKey(oe.getOption().getCode()) && !StringUtils.isEmpty(changeTestWeightCommand.getTestWeightMap().get(oe.getOption().getCode()))) {
            iter.remove();
        }
    }
    for (Map.Entry<String, String> entry : changeTestWeightCommand.getTestWeightMap().entrySet()) {
        if (!StringUtils.isEmpty(entry.getValue())) {
            String value = entry.getValue().replaceAll(",", ".");
            Option option = optionDataService.getOption(entry.getKey());
            OptionElementImpl oe = optionElementDataService.getOptionElementFromValueAndOption(value, option);
            if (oe == null) {
                oe = optionElementDataService.create();
                oe.setOption(option);
                oe.setValue(value);
                optionElementDataService.saveOrUpdate(oe);
            }
            userOptionElementSet.add(oe);
        }
    }
    user.addAllOptionElement(userOptionElementSet);
    userDataService.saveOrUpdate(user);
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Option(org.asqatasun.entity.option.Option)

Example 3 with OptionElementImpl

use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.

the class ChangeTestWeightCommandFactory method getChangeTestWeightCommand.

/**
 * @param user
 * @param locale
 * @param testList
 * @param referentialKey
 * @return
 *      an initialised instance of ChangeTestWeightCommand
 */
public ChangeTestWeightCommand getChangeTestWeightCommand(User user, Locale locale, Collection<Test> testList, String referentialKey) {
    Map<String, String> userTestWeight = new HashMap<String, String>();
    NumberFormat nf = NumberFormat.getNumberInstance(locale);
    nf.setMinimumFractionDigits(1);
    nf.setMaximumFractionDigits(1);
    nf.setMaximumIntegerDigits(1);
    nf.setMinimumIntegerDigits(1);
    for (OptionElementImpl oe : optionElementDataService.getOptionElementFromUserAndFamilyCode(user, referentialKey + "_" + optionFamilyCodeStr)) {
        userTestWeight.put(oe.getOption().getCode(), nf.format(Double.valueOf(oe.getValue())));
    }
    for (Test test : testList) {
        if (!userTestWeight.containsKey(test.getCode())) {
            userTestWeight.put(test.getCode(), "");
        }
    }
    ChangeTestWeightCommand changeTestWeightCommand = new ChangeTestWeightCommand();
    changeTestWeightCommand.setTestWeightMap(userTestWeight);
    return changeTestWeightCommand;
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Test(org.asqatasun.entity.reference.Test) NumberFormat(java.text.NumberFormat) ChangeTestWeightCommand(org.asqatasun.webapp.command.ChangeTestWeightCommand)

Example 4 with OptionElementImpl

use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.

the class CreateContractCommandFactory method createOptionElement.

/**
 * @param value
 * @param option
 * @return
 */
private OptionElementImpl createOptionElement(Option option, String value) {
    OptionElementImpl optionElement = optionElementDataService.getOptionElementFromValueAndOption(value, option);
    if (optionElement != null) {
        return optionElement;
    }
    optionElement = optionElementDataService.create();
    optionElement.setValue(value);
    optionElement.setOption(option);
    optionElementDataService.saveOrUpdate(optionElement);
    return optionElement;
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl)

Example 5 with OptionElementImpl

use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.

the class OptionElementFactory method createOptionElement.

public OptionElementImpl createOptionElement(Option option, String value) {
    OptionElementImpl optionElement = new OptionElementImpl();
    optionElement.setOption(option);
    optionElement.setValue(value);
    return optionElement;
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl)

Aggregations

OptionElementImpl (org.asqatasun.entity.option.OptionElementImpl)11 NumberFormat (java.text.NumberFormat)1 Set (java.util.Set)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1 Query (javax.persistence.Query)1 Option (org.asqatasun.entity.option.Option)1 OptionImpl (org.asqatasun.entity.option.OptionImpl)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 Test (org.asqatasun.entity.reference.Test)1 User (org.asqatasun.entity.user.User)1 ChangeTestWeightCommand (org.asqatasun.webapp.command.ChangeTestWeightCommand)1 NumericalFormField (org.asqatasun.webapp.ui.form.NumericalFormField)1 SelectElement (org.asqatasun.webapp.ui.form.SelectElement)1 SelectFormField (org.asqatasun.webapp.ui.form.SelectFormField)1 TextualFormField (org.asqatasun.webapp.ui.form.TextualFormField)1 Test (org.junit.Test)1