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