use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class OptionElementDAO method findOptionElementFromValueAndOption.
/**
* @param value
* @param option
* @return
*/
public OptionElementImpl 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 (OptionElementImpl) query.getSingleResult();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class AuditSetUpControllerTest method getOptionElementSet.
private Set<OptionElementImpl> getOptionElementSet() {
OptionElementImpl oe = new OptionElementImpl();
OptionImpl option = new OptionImpl();
option.setCode("");
oe.setOption(option);
return Collections.singleton(oe);
}
use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class OptionImplElementDAOTest method testFindOptionElementFromUserAndFamilyCode.
/**
* Test of findOptionElementFromUserAndFamilyCode method, of class OptionElementDAOImpl.
*/
@Test
public void testFindOptionElementFromUserAndFamilyCode() {
User user1 = userDAO.findUserFromEmail("test1@test.com");
User user2 = userDAO.findUserFromEmail("test2@test.com");
User user3 = userDAO.findUserFromEmail("test3@test.com");
Collection<OptionElementImpl> oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "USER_OPTION");
assertEquals(2, oec.size());
oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "ANOTHER_OPTION");
assertTrue(oec.isEmpty());
oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "USER_OPTION");
assertEquals(1, oec.size());
oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "ANOTHER_OPTION");
assertTrue(oec.isEmpty());
oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "USER_OPTION");
assertTrue(oec.isEmpty());
oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "ANOTHER_OPTION");
assertTrue(oec.isEmpty());
}
use of org.asqatasun.entity.option.OptionElementImpl in project Asqatasun by Asqatasun.
the class RestrictionHandler method checkRestriction.
public synchronized String checkRestriction(Contract contract, String clientIp, ScopeEnum scope) {
String decision = TgolKeyStore.ACT_ALLOWED;
Set<OptionElementImpl> optionElementSet = (Set<OptionElementImpl>) contract.getOptionElementSet();
if (optionElementSet.isEmpty()) {
return decision;
}
for (OptionElementImpl 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.entity.option.OptionElementImpl 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 void activateSelectFormField(SelectFormField selectFormField, Collection<OptionElementImpl> optionElementSet) {
boolean enableElements = true;
OptionElementImpl 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());
}
}
}
Aggregations