Search in sources :

Example 6 with OptionElement

use of org.asqatasun.webapp.entity.option.OptionElement 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 (OptionElement 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 : Test(org.asqatasun.entity.reference.Test) OptionElement(org.asqatasun.webapp.entity.option.OptionElement) NumberFormat(java.text.NumberFormat) ChangeTestWeightCommand(org.asqatasun.webapp.command.ChangeTestWeightCommand)

Example 7 with OptionElement

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

the class ChangeTestWeightCommandFactory method updateUserTestWeight.

/**
     * 
     * @param user
     * @param changeTestWeightCommand
     */
public void updateUserTestWeight(User user, ChangeTestWeightCommand changeTestWeightCommand) {
    Collection<OptionElement> userOptionElementSet = optionElementDataService.getOptionElementFromUser(user);
    // first we need to remove the option elements associated with the user
    // that are going to be updated
    Iterator<OptionElement> iter = userOptionElementSet.iterator();
    // testWeightMap.
    while (iter.hasNext()) {
        OptionElement 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());
            OptionElement 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 : OptionElement(org.asqatasun.webapp.entity.option.OptionElement) Option(org.asqatasun.webapp.entity.option.Option)

Example 8 with OptionElement

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

the class CreateContractCommandFactory method createOptionElement.

/**
     * 
     * @param value
     * @param option
     * @return 
     */
private OptionElement createOptionElement(Option option, String value) {
    OptionElement 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 : OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 9 with OptionElement

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

the class OptionElementDAOImpl method findOptionElementFromValueAndOption.

/**
     * 
     * @param value
     * @param option
     * @return 
     */
@Override
public OptionElement findOptionElementFromValueAndOption(String value, Option option) {
    Query query = entityManager.createQuery("SELECT oe FROM " + getEntityClass().getName() + " oe" + " WHERE oe.value=:value" + " AND oe.option=:option");
    query.setParameter("value", value);
    query.setParameter("option", option);
    try {
        return (OptionElement) query.getSingleResult();
    } catch (NoResultException | NonUniqueResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) OptionElement(org.asqatasun.webapp.entity.option.OptionElement) NoResultException(javax.persistence.NoResultException)

Example 10 with OptionElement

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

the class ParameterDataServiceDecoratorImpl method getParameterSetFromOptionElementSet.

@Override
public Collection<Parameter> getParameterSetFromOptionElementSet(Collection<OptionElement> optionElementSet) {
    Set<Parameter> paramSet = new HashSet<>();
    for (OptionElement optionElement : optionElementSet) {
        ParameterElement pe = parameterElementDataService.getParameterElement(optionElement.getOption().getCode());
        if (pe != null) {
            Parameter p = decoratedParameterDataService.getParameter(pe, optionElement.getValue());
            p = saveOrUpdate(p);
            paramSet.add(p);
        }
    }
    return paramSet;
}
Also used : OptionElement(org.asqatasun.webapp.entity.option.OptionElement) Parameter(org.asqatasun.entity.parameterization.Parameter) ParameterElement(org.asqatasun.entity.parameterization.ParameterElement) HashSet(java.util.HashSet)

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