Search in sources :

Example 11 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.

the class ACMethodDAO method getAccessMethodForResources.

public List<OLATResourceAccess> getAccessMethodForResources(Collection<Long> resourceKeys, String resourceType, String excludedResourceType, boolean valid, Date atDate) {
    // quicker to filter in java, numerous keys in "in" are slow
    final int maxResourcesEntries = 250;
    StringBuilder sb = new StringBuilder();
    sb.append("select access.method, resource, offer.price from acofferaccess access, ").append(OLATResourceImpl.class.getName()).append(" resource").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=").append(valid).append(" and offer.valid=").append(valid).append(" and resource.key=oResource.key");
    if (resourceKeys != null && !resourceKeys.isEmpty()) {
        if (resourceKeys.size() < maxResourcesEntries) {
            sb.append(" and resource.key in (:resourceKeys) ");
        }
        sb.append(" and oResource.key=resource.key");
    }
    if (StringHelper.containsNonWhitespace(resourceType)) {
        sb.append(" and oResource.resName =:resourceType ");
    }
    if (StringHelper.containsNonWhitespace(excludedResourceType)) {
        sb.append(" and not(oResource.resName=:excludedResourceType)");
    }
    if (atDate != null) {
        sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)").append(" and (offer.validTo is null or offer.validTo>=:atDate)");
    }
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    if (atDate != null) {
        query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
    }
    Set<Long> resourceKeysSet = null;
    if (resourceKeys != null && !resourceKeys.isEmpty()) {
        if (resourceKeys.size() < maxResourcesEntries) {
            query.setParameter("resourceKeys", resourceKeys);
        } else {
            resourceKeysSet = new HashSet<Long>(resourceKeys);
        }
    }
    if (StringHelper.containsNonWhitespace(resourceType)) {
        query.setParameter("resourceType", resourceType);
    }
    if (StringHelper.containsNonWhitespace(excludedResourceType)) {
        query.setParameter("excludedResourceType", excludedResourceType);
    }
    List<Object[]> rawResults = query.getResultList();
    Map<Long, OLATResourceAccess> rawResultsMap = new HashMap<Long, OLATResourceAccess>();
    for (Object[] rawResult : rawResults) {
        AccessMethod method = (AccessMethod) rawResult[0];
        OLATResource resource = (OLATResource) rawResult[1];
        if (resourceKeysSet != null && !resourceKeysSet.contains(resource.getKey())) {
            continue;
        }
        if (!method.isVisibleInGui()) {
            continue;
        }
        Price price = (Price) rawResult[2];
        if (rawResultsMap.containsKey(resource.getKey())) {
            rawResultsMap.get(resource.getKey()).addBundle(price, method);
        } else {
            rawResultsMap.put(resource.getKey(), new OLATResourceAccess(resource, price, method));
        }
    }
    return new ArrayList<OLATResourceAccess>(rawResultsMap.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceImpl(org.olat.resource.OLATResourceImpl) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) Price(org.olat.resource.accesscontrol.Price)

Example 12 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.

the class ACMethodDAO method activateTokenMethod.

/**
 * Activate the token method if not already configured.
 */
protected void activateTokenMethod(boolean enable) {
    StringBuilder sb = new StringBuilder();
    sb.append("select method from actokenmethod method");
    List<AccessMethod> methods = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class).getResultList();
    if (methods.isEmpty() && enable) {
        TokenAccessMethod method = new TokenAccessMethod();
        method.setCreationDate(new Date());
        method.setLastModified(method.getCreationDate());
        dbInstance.getCurrentEntityManager().persist(method);
    } else {
        for (AccessMethod method : methods) {
            if (method.isEnabled() != enable) {
                ((AbstractAccessMethod) method).setEnabled(enable);
                ((AbstractAccessMethod) method).setLastModified(new Date());
                dbInstance.getCurrentEntityManager().merge(method);
            }
        }
    }
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) Date(java.util.Date)

Example 13 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.

the class AccessConfigurationController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (addMethods.contains(source)) {
        AccessMethod method = (AccessMethod) source.getUserObject();
        addMethod(ureq, method);
    } else if (source instanceof FormLink) {
        FormLink button = (FormLink) source;
        String cmd = button.getCmd();
        if ("delete".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            removeMethod(infos);
            fireEvent(ureq, Event.CHANGED_EVENT);
        } else if ("edit".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            editMethod(ureq, infos);
        }
    } else if (confirmationEmailEl == source) {
        setConfirmationEmail(confirmationEmailEl.isAtLeastSelected(1));
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 14 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.

the class AccessConfigurationController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // contextHelptexts for Label
    HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
    ((FormLayoutContainer) formLayout).put("acMethodsLabelHelp", acMethodsLabelHelp);
    if (editable) {
        List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
        for (AccessMethod method : methods) {
            AccessMethodHandler handler = acModule.getAccessMethodHandler(method.getType());
            if (handler.isPaymentMethod() && !allowPaymentMethod) {
                continue;
            }
            String title = handler.getMethodName(getLocale());
            FormLink add = uifactory.addFormLink("create." + handler.getType(), title, null, formLayout, Link.LINK | Link.NONTRANSLATED);
            add.setUserObject(method);
            add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
            addMethods.add(add);
            formLayout.add(add.getName(), add);
        }
        ((FormLayoutContainer) formLayout).contextPut("methods", addMethods);
    }
    String[] onValues = new String[] { "" };
    confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", formLayout, onKeys, onValues);
    confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
    confirmationEmailEl.setVisible(false);
    String confPage = velocity_root + "/configuration_list.html";
    confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
    confControllerContainer.setRootForm(mainForm);
    formLayout.add(confControllerContainer);
    loadConfigurations();
    confControllerContainer.contextPut("confControllers", confControllers);
    boolean confirmationEmail = false;
    for (AccessInfo info : confControllers) {
        Offer offer = info.getLink().getOffer();
        confirmationEmail |= offer.isConfirmationEmail();
    }
    if (confirmationEmail) {
        confirmationEmailEl.select(onKeys[0], true);
    }
    if (!embbed) {
        setFormTitle("accesscontrol.title");
        if (editable) {
            final FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
            buttonGroupLayout.setRootForm(mainForm);
            formLayout.add(buttonGroupLayout);
            formLayout.add("buttonLayout", buttonGroupLayout);
            uifactory.addFormSubmitButton("save", buttonGroupLayout);
        }
    }
    confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Offer(org.olat.resource.accesscontrol.Offer) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 15 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.

the class AutoAccessManagerImpl method createAndPersistAdvanceOrderIfNotExist.

private void createAndPersistAdvanceOrderIfNotExist(Identity identity, IdentifierKey key, String value, Class<? extends AutoAccessMethod> type) {
    List<AccessMethod> methods = acService.getAvailableMethodsByType(type);
    AccessMethod method = methods.get(0);
    if (doesNotExist(identity, key, value, method)) {
        AdvanceOrder advanceOrder = advanceOrderDAO.create(identity, key, value, method);
        advanceOrderDAO.save(advanceOrder);
    }
}
Also used : AutoAccessMethod(org.olat.resource.accesscontrol.provider.auto.model.AutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) AdvanceOrder(org.olat.resource.accesscontrol.provider.auto.AdvanceOrder)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6