Search in sources :

Example 6 with OptionElementImpl

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;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 7 with OptionElementImpl

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);
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) OptionImpl(org.asqatasun.entity.option.OptionImpl)

Example 8 with OptionElementImpl

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());
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) User(org.asqatasun.entity.user.User) Test(org.junit.Test)

Example 9 with OptionElementImpl

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;
}
Also used : OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Set(java.util.Set)

Example 10 with OptionElementImpl

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());
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.ui.form.SelectElement) OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl)

Aggregations

OptionElementImpl (org.asqatasun.entity.option.OptionElementImpl)11 NumberFormat (java.text.NumberFormat)1 Set (java.util.Set)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1 Query (javax.persistence.Query)1 Option (org.asqatasun.entity.option.Option)1 OptionImpl (org.asqatasun.entity.option.OptionImpl)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 Test (org.asqatasun.entity.reference.Test)1 User (org.asqatasun.entity.user.User)1 ChangeTestWeightCommand (org.asqatasun.webapp.command.ChangeTestWeightCommand)1 NumericalFormField (org.asqatasun.webapp.ui.form.NumericalFormField)1 SelectElement (org.asqatasun.webapp.ui.form.SelectElement)1 SelectFormField (org.asqatasun.webapp.ui.form.SelectFormField)1 TextualFormField (org.asqatasun.webapp.ui.form.TextualFormField)1 Test (org.junit.Test)1