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);
}
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;
}
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);
}
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);
}
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;
}
}
Aggregations