Search in sources :

Example 1 with Option

use of org.asqatasun.webapp.entity.option.Option 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 2 with Option

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

the class OptionFactoryImpl method createOption.

@Override
public Option createOption(OptionFamily optionFamily, String code, String label, String description, boolean isRestriction) {
    Option option = new OptionImpl();
    option.setCode(code);
    option.setDescription(description);
    option.setLabel(label);
    option.setOptionFamily(optionFamily);
    option.setIsRestriction(isRestriction);
    return option;
}
Also used : Option(org.asqatasun.webapp.entity.option.Option) OptionImpl(org.asqatasun.webapp.entity.option.OptionImpl)

Example 3 with Option

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

the class CreateContractCommandFactory method addNewOptionsToCommand.

/**
     * 
     * @param ccc
     * @param contract 
     */
private void addNewOptionsToCommand(CreateContractCommand ccc) {
    Map<String, String> optionMap = new LinkedHashMap<String, String>();
    for (Option option : optionList) {
        if (!option.getCode().equals(DOMAIN_OPTION_CODE)) {
            optionMap.put(option.getCode(), "");
        }
    }
    ccc.setOptionMap(optionMap);
}
Also used : Option(org.asqatasun.webapp.entity.option.Option)

Example 4 with Option

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

the class CreateContractCommandFactory method addOptionToCommand.

/**
     * 
     * @param ccc
     * @param contract 
     */
private void addOptionToCommand(CreateContractCommand ccc, Contract contract) {
    Map<String, String> optionMap = new LinkedHashMap<String, String>();
    for (Option option : optionList) {
        optionMap.put(option.getCode(), getValueFromOptionElementCollection(contract.getOptionElementSet(), option));
    }
    ccc.setOptionMap(optionMap);
}
Also used : Option(org.asqatasun.webapp.entity.option.Option)

Example 5 with Option

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

the class OptionDAOImpl method findOptionFromCode.

@Override
public Option findOptionFromCode(String optionCode) {
    Query query = entityManager.createQuery("SELECT o FROM " + getEntityClass().getName() + " o" + " WHERE o.code = :optionCode");
    query.setParameter("optionCode", optionCode);
    try {
        return (Option) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    } catch (NonUniqueResultException nure) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Option(org.asqatasun.webapp.entity.option.Option) NoResultException(javax.persistence.NoResultException)

Aggregations

Option (org.asqatasun.webapp.entity.option.Option)5 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1 Query (javax.persistence.Query)1 OptionElement (org.asqatasun.webapp.entity.option.OptionElement)1 OptionImpl (org.asqatasun.webapp.entity.option.OptionImpl)1