Search in sources :

Example 1 with Option

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

the class OptionDAO method findOptionFromCode.

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 | NonUniqueResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Option(org.asqatasun.entity.option.Option) NoResultException(javax.persistence.NoResultException)

Example 2 with Option

use of org.asqatasun.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<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 Option

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

the class CreateContractCommandFactory method init.

@PostConstruct
private void init() {
    referentialList = referentialDataService.findAll();
    LoggerFactory.getLogger(this.getClass()).debug("All referentials" + referentialList.size());
    referentialList.forEach((referential) -> LoggerFactory.getLogger(this.getClass()).debug(referential.getCode()));
    functionalityList = functionalityDataService.findAll();
    for (Option option : optionDataService.findAll()) {
        if (option.getCode().equals(DOMAIN_OPTION_CODE)) {
            contractUrlOption = option;
        } else {
            optionList.add(option);
        }
    }
}
Also used : Option(org.asqatasun.entity.option.Option) PostConstruct(javax.annotation.PostConstruct)

Example 4 with Option

use of org.asqatasun.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<>();
    for (Option option : optionList) {
        optionMap.put(option.getCode(), getValueFromOptionElementCollection(contract.getOptionElementSet(), option));
    }
    ccc.setOptionMap(optionMap);
}
Also used : Option(org.asqatasun.entity.option.Option)

Example 5 with Option

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

the class CreateContractCommandFactory method addNewOptionsToCommand.

/**
 * @param ccc
 */
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.entity.option.Option)

Aggregations

Option (org.asqatasun.entity.option.Option)5 PostConstruct (javax.annotation.PostConstruct)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1 Query (javax.persistence.Query)1 OptionElementImpl (org.asqatasun.entity.option.OptionElementImpl)1