use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class AuditLauncherController method getUserParamSet.
/**
* This method gets the default parameters for an audit and eventually
* override some of them in case of contract restriction.
*
* @param auditSetUpCommand
* @param contractId
* @param nbOfPages
* @param url
* @return
*/
private Set<Parameter> getUserParamSet(AuditSetUpCommand auditSetUpCommand, Long contractId, int nbOfPages, String url) {
Set<Parameter> paramSet;
Set<Parameter> userParamSet = new HashSet<>();
if (auditSetUpCommand != null) {
// parameter set
if (auditSetUpCommand.getScope().equals(ScopeEnum.SCENARIO)) {
paramSet = getAuditScenarioParameterSet();
} else if (!auditSetUpCommand.getScope().equals(ScopeEnum.DOMAIN)) {
paramSet = getAuditPageParameterSet(nbOfPages);
} else {
paramSet = getDefaultParamSet();
}
for (Map.Entry<String, String> entry : auditSetUpCommand.getAuditParameter().entrySet()) {
Parameter param = parameterDataService.getParameter(parameterElementMap.get(entry.getKey()), entry.getValue());
userParamSet.add(param);
}
paramSet = parameterDataService.updateParameterSet(paramSet, userParamSet);
paramSet = setLevelParameter(paramSet, auditSetUpCommand.getLevel());
} else {
paramSet = getDefaultParamSet();
Collection<OptionElementImpl> optionElementSet = contractDataService.read(contractId).getOptionElementSet();
for (Parameter param : paramSet) {
for (OptionElementImpl optionElement : optionElementSet) {
if (optionElement.getOption().getCode().equalsIgnoreCase(param.getParameterElement().getParameterElementCode())) {
param = parameterDataService.getParameter(param.getParameterElement(), optionElement.getValue());
break;
}
}
userParamSet.add(param);
}
paramSet = parameterDataService.updateParameterSet(paramSet, userParamSet);
}
return (auditSetUpCommand.getLevel() != null) ? setUserParameters(paramSet, auditSetUpCommand.getLevel().split(";")[0]) : paramSet;
}
use of org.asqatasun.entity.option.OptionElementImpl 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);
}
use of org.asqatasun.entity.option.OptionElementImpl 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 (OptionElementImpl 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.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class CreateContractCommandFactory method createOptionElement.
/**
* @param value
* @param option
* @return
*/
private OptionElementImpl createOptionElement(Option option, String value) {
OptionElementImpl 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.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class OptionElementFactory method createOptionElement.
public OptionElementImpl createOptionElement(Option option, String value) {
OptionElementImpl optionElement = new OptionElementImpl();
optionElement.setOption(option);
optionElement.setValue(value);
return optionElement;
}
Aggregations