Search in sources :

Example 46 with AccessMethod

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

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 47 with AccessMethod

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

the class AccessMethodRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Object val, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (val instanceof AccessTransaction) {
        AccessTransaction transaction = (AccessTransaction) val;
        Set<String> uniqueType = new HashSet<String>(3);
        render(sb, transaction, uniqueType, translator.getLocale());
    } else if (val instanceof Collection) {
        Collection<?> transactions = (Collection<?>) val;
        Set<String> uniqueType = new HashSet<String>((transactions.size() * 2) + 1);
        for (Object transaction : transactions) {
            if (transaction instanceof AccessTransaction) {
                render(sb, (AccessTransaction) transaction, uniqueType, translator.getLocale());
            } else if (transaction instanceof AccessMethod) {
                render(sb, (AccessMethod) transaction, uniqueType, translator.getLocale());
            }
        }
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) Set(java.util.Set) HashSet(java.util.HashSet) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 48 with AccessMethod

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

the class AccessMethodRenderer method render.

@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    if (val instanceof AccessTransaction) {
        AccessTransaction transaction = (AccessTransaction) val;
        Set<String> uniqueType = new HashSet<String>(3);
        render(sb, transaction, uniqueType, locale);
    } else if (val instanceof Collection) {
        Collection<?> transactions = (Collection<?>) val;
        Set<String> uniqueType = new HashSet<String>((transactions.size() * 2) + 1);
        for (Object transaction : transactions) {
            if (transaction instanceof AccessTransaction) {
                render(sb, (AccessTransaction) transaction, uniqueType, locale);
            } else if (transaction instanceof AccessMethod) {
                render(sb, (AccessMethod) transaction, uniqueType, locale);
            }
        }
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) Set(java.util.Set) HashSet(java.util.HashSet) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 49 with AccessMethod

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

the class BusinessGroupDAO method loadOfferAccess.

public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
    if (resourceKeyToGroup.isEmpty())
        return;
    final int OFFERS_IN_LIMIT = 255;
    // offers
    StringBuilder so = new StringBuilder();
    so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        so.append(" where resource.key in (:resourceKeys)");
    } else {
        so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
    }
    TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
        for (Long resourceKey : resourceKeyToGroup.keySet()) {
            resourceKeys.add(resourceKey);
        }
        offersQuery.setParameter("resourceKeys", resourceKeys);
    }
    List<Object[]> offers = offersQuery.getResultList();
    for (Object[] offer : offers) {
        Long resourceKey = (Long) offer[1];
        BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
        if (row != null) {
            AccessMethod method = (AccessMethod) offer[0];
            Price price = (Price) offer[2];
            if (row.getBundles() == null) {
                row.setBundles(new ArrayList<>(3));
            }
            row.getBundles().add(new PriceMethodBundle(price, method));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Price(org.olat.resource.accesscontrol.Price) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 50 with AccessMethod

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

the class BusinessGroupDAOTest method findPublicGroupsLimitedDate.

@Test
public void findPublicGroupsLimitedDate() {
    // create a group with an access control limited by a valid date
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
    BusinessGroup groupVisible = businessGroupDao.createAndPersist(null, "access-grp-2", "access-grp-2-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer offer = acService.createOffer(groupVisible.getResource(), "TestBGWorkflow");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    offer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 2);
    offer.setValidTo(cal.getTime());
    assertNotNull(offer);
    offer = acService.save(offer);
    acMethodManager.enableMethod(TokenAccessMethod.class, true);
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    // create a group with an access control limited by dates in the past
    BusinessGroup oldGroup = businessGroupDao.createAndPersist(null, "access-grp-3", "access-grp-3-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer oldOffer = acService.createOffer(oldGroup.getResource(), "TestBGWorkflow");
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidTo(cal.getTime());
    assertNotNull(oldOffer);
    oldOffer = acService.save(oldOffer);
    OfferAccess oldAccess = acMethodManager.createOfferAccess(oldOffer, method);
    acMethodManager.save(oldAccess);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    BusinessGroupQueryParams paramsAll = new BusinessGroupQueryParams();
    paramsAll.setPublicGroups(Boolean.TRUE);
    List<BusinessGroupRow> accessGroups = businessGroupDao.searchBusinessGroupsWithMemberships(paramsAll, id);
    Assert.assertNotNull(accessGroups);
    Assert.assertTrue(accessGroups.size() >= 1);
    Assert.assertTrue(contains(accessGroups, groupVisible));
    Assert.assertFalse(contains(accessGroups, oldGroup));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) BusinessGroup(org.olat.group.BusinessGroup) Offer(org.olat.resource.accesscontrol.Offer) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

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