use of org.asqatasun.webapp.form.parameterization.AuditSetUpFormField in project Asqatasun by Asqatasun.
the class AuditSetUpCommandFactory method setUpAuditSetUpCommand.
/**
* Return a initialised auditCommand object for the given contract. This
* object contains a map that associates a Parameter and a value (handled by
* the AuditSetUpFormField). Each value is preset regarding the
*
* @param contract
* @param auditSetUpFormFieldList
* @param auditSite
* @return
*/
private synchronized void setUpAuditSetUpCommand(AuditSetUpCommand auditSetUpCommand, Contract contract, List<SelectFormField> levelFormFieldList, Map<String, List<AuditSetUpFormField>> optionalFormFieldMap, ScopeEnum scope) {
// the auditSetCommand instance handles the id of the current contract
auditSetUpCommand.setContractId(contract.getId());
boolean isDefaultSet = true;
if (scope == ScopeEnum.FILE || scope == ScopeEnum.PAGE) {
// the default parameter corresponds by default to the site audit
// parameter set. If the audit is a page audit by definition,
// the parameter set is not set as default
isDefaultSet = false;
}
// Set-up the audit level value to the auditSetUpCommand instance
isDefaultSet = isDefaultSet && extractAndSetLevelValueFromAuditSetUpFormFieldList(contract, levelFormFieldList, auditSetUpCommand);
// a different value as the default one, we override it
for (List<AuditSetUpFormField> apl : optionalFormFieldMap.values()) {
for (AuditSetUpFormField ap : apl) {
// We retrieve the default value of the Parameter associated
// with the AuditSetUpFormField
String defaultValue = getDefaultParameterValue(ap);
String paramValue = getValueOfParamOfAuditSetUpFormField(contract, defaultValue, ap, auditSetUpCommand);
Logger.getLogger(this.getClass()).debug("paramValue " + paramValue);
// The auditSetUpCommand instance handles a map to bind each field
// This map has to be set-up with the value of the Parameter and
// each parameter is identified throug the key with the
// ParameterElement code.
auditSetUpCommand.addAuditParameterEntry(ap.getParameterElement().getParameterElementCode(), paramValue);
// if from the set of options, one is different from the default
// a flag is set.
isDefaultSet = isDefaultSet && StringUtils.equals(defaultValue, paramValue);
Logger.getLogger(this.getClass()).debug("isDefaultSet " + isDefaultSet);
}
}
auditSetUpCommand.setDefaultParamSet(isDefaultSet);
}
use of org.asqatasun.webapp.form.parameterization.AuditSetUpFormField in project Asqatasun by Asqatasun.
the class AuditSetUpFormValidator method validate.
/**
* The AuditSetUpFormValidator checks whether the options values are
* acceptable regarding the FormField internal checker
*
* @param target
* @param errors
*/
@Override
public void validate(Object target, Errors errors) {
AuditSetUpCommand auditSetUpCommand = (AuditSetUpCommand) target;
AuditSetUpFormField asuff;
for (Map.Entry<String, String> entry : auditSetUpCommand.getAuditParameter().entrySet()) {
asuff = auditSetUpFormFieldMap.get(entry.getKey());
try {
if (!asuff.getFormField().checkParameters(entry.getValue())) {
// the auditParameter[] key is due to object mapping of the form
// management of Spring mvc. Each field is mapped with a method
// of the mapped object. In this case, the returned object of the method
// is a map.
errors.rejectValue("auditParameter[" + entry.getKey() + "]", asuff.getFormField().getErrorI18nKey());
}
} catch (NumberFormatException nfe) {
errors.rejectValue("auditParameter[" + entry.getKey() + "]", asuff.getFormField().getErrorI18nKey());
}
}
}
Aggregations