use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.
the class RestrictionHandlerImpl method checkRestriction.
@Override
public synchronized String checkRestriction(Contract contract, String clientIp, ScopeEnum scope) {
String decision = TgolKeyStore.ACT_ALLOWED;
Set<OptionElement> optionElementSet = (Set<OptionElement>) contract.getOptionElementSet();
if (optionElementSet.isEmpty()) {
return decision;
}
for (OptionElement optionElement : optionElementSet) {
RestrictionVoter restrictionVoter = chooseRestrictionVoter(optionElement);
if (restrictionVoter != null) {
decision = restrictionVoter.checkRestriction(contract, optionElement, clientIp, scope);
}
if (!decision.equalsIgnoreCase(TgolKeyStore.ACT_ALLOWED)) {
break;
}
}
return decision;
}
use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.
the class AuditSetUpFormFieldHelper method activateSelectFormField.
/**
* This method enables/disables a select form field element regarding the
* activation / restriction strategy. If a SelectFormField is set as enabled
* by default and has a set restrictionCode, it can be disabled. If a
* SelectFormField is set as disabled by default and has a set
* activationCode, it can be enabled.
*
* @param selectFormField
* @param optionElementSet
*/
private static void activateSelectFormField(SelectFormField selectFormField, Collection<OptionElement> optionElementSet) {
boolean enableElements = true;
OptionElement optionElement = null;
if (StringUtils.isNotEmpty(selectFormField.getRestrictionCode())) {
optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getRestrictionCode());
enableElements = false;
} else if (StringUtils.isNotEmpty(selectFormField.getActivationCode())) {
optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getActivationCode());
}
if (optionElement != null) {
String[] optionValues = optionElement.getValue().split(";");
boolean isSelectFormFieldHasDefault = false;
for (String optionValue : optionValues) {
List<SelectElement> sel = selectFormField.getSelectElementMap().get(optionValue);
for (SelectElement se : sel) {
se.setEnabled(enableElements);
// By option mechanism, we can set an SelectElement as default.
if (!isSelectFormFieldHasDefault) {
isSelectFormFieldHasDefault = setSelectElementAsDefault(se, optionElementSet);
}
}
}
// is set as default
if (!isSelectFormFieldHasDefault) {
setFirstSelectElementAsDefault(selectFormField.getSelectElementMap());
}
}
}
use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.
the class AuditSetUpFormFieldHelper method applyRestrictionToAuditSetUpFormField.
/**
* A restriction can be applied to an AuditSetUpFormField when an option
* matches with a parameter (by its code). In this case, regarding the type
* of the FormField, the value of the option override the default
*
* @param ap
* @param optionElementSet
*/
public static void applyRestrictionToAuditSetUpFormField(AuditSetUpFormField ap, Collection<OptionElement> optionElementSet) {
if (ap.getFormField() instanceof NumericalFormField) {
OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
if (optionElement != null) {
((NumericalFormField) ap.getFormField()).setMaxValue(optionElement.getValue());
((NumericalFormField) ap.getFormField()).setValue(optionElement.getValue());
}
} else if (ap.getFormField() instanceof SelectFormField) {
activateSelectFormField((SelectFormField) ap.getFormField(), optionElementSet);
} else if (ap.getFormField() instanceof TextualFormField) {
OptionElement optionElement = getOptionFromOptionSet(optionElementSet, ap.getParameterElement().getParameterElementCode());
if (optionElement != null) {
((TextualFormField) ap.getFormField()).setValue(optionElement.getValue());
}
}
}
use of org.asqatasun.webapp.entity.option.OptionElement in project Asqatasun by Asqatasun.
the class AuditLauncherController method setUserParameters.
/**
* Some user options have to be converted as parameters and added to the
* general audit parameters.
*
* @param paramSet
* @param referentialKey
* @return
*/
private Set<Parameter> setUserParameters(Set<Parameter> paramSet, String referentialKey) {
User user = getCurrentUser();
Collection<OptionElement> optionElementSet = new HashSet();
for (String optionFamily : userOptionDependingOnReferential) {
optionElementSet.addAll(optionElementDataService.getOptionElementFromUserAndFamilyCode(user, referentialKey + "_" + optionFamily));
}
for (String optionFamily : userOption) {
optionElementSet.addAll(optionElementDataService.getOptionElementFromUserAndFamilyCode(user, optionFamily));
}
paramSet.addAll(getParameterDataService().getParameterSetFromOptionElementSet(optionElementSet));
return paramSet;
}
use of org.asqatasun.webapp.entity.option.OptionElement 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 = getParameterDataService().getParameter(parameterElementMap.get(entry.getKey()), entry.getValue());
userParamSet.add(param);
}
paramSet = getParameterDataService().updateParameterSet(paramSet, userParamSet);
paramSet = setLevelParameter(paramSet, auditSetUpCommand.getLevel());
} else {
paramSet = getDefaultParamSet();
Collection<OptionElement> optionElementSet = getContractDataService().read(contractId).getOptionElementSet();
for (Parameter param : paramSet) {
for (OptionElement optionElement : optionElementSet) {
if (optionElement.getOption().getCode().equalsIgnoreCase(param.getParameterElement().getParameterElementCode())) {
param = getParameterDataService().getParameter(param.getParameterElement(), optionElement.getValue());
break;
}
}
userParamSet.add(param);
}
paramSet = getParameterDataService().updateParameterSet(paramSet, userParamSet);
}
return (auditSetUpCommand.getLevel() != null) ? setUserParameters(paramSet, auditSetUpCommand.getLevel().split(";")[0]) : paramSet;
}
Aggregations