Search in sources :

Example 21 with AccessMethod

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

the class ACOfferManagerTest method testDeleteOffer.

@Test
public void testDeleteOffer() {
    OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
    assertNotNull(testOres);
    dbInstance.commitAndCloseSession();
    // create an offer
    Offer offer = acOfferManager.createOffer(testOres, "TestDeleteOffer");
    assertNotNull(offer);
    assertEquals(OfferImpl.class, offer.getClass());
    // and save the offer
    acOfferManager.saveOffer(offer);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(offers);
    assertEquals(1, offers.size());
    assertEquals(offer, offers.get(0));
    dbInstance.commitAndCloseSession();
    // delete the offer
    acOfferManager.deleteOffer(offer);
    dbInstance.commitAndCloseSession();
    // try to retrieve the offer
    List<Offer> noOffers = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(noOffers);
    assertEquals(0, noOffers.size());
    dbInstance.commitAndCloseSession();
    // retrieve all offers, deleted too
    List<Offer> delOffers = acOfferManager.findOfferByResource(testOres, false, null);
    assertNotNull(delOffers);
    assertEquals(1, delOffers.size());
    assertEquals(offer, delOffers.get(0));
    assertEquals(false, delOffers.get(0).isValid());
    dbInstance.commitAndCloseSession();
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 22 with AccessMethod

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

the class ACOfferManagerTest method testSaveOffer.

@Test
public void testSaveOffer() {
    // create a resource
    OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
    assertNotNull(testOres);
    dbInstance.commitAndCloseSession();
    // create an offer
    Offer offer = acOfferManager.createOffer(testOres, "TestSaveOffer");
    assertNotNull(offer);
    assertEquals(OfferImpl.class, offer.getClass());
    if (offer instanceof OfferImpl) {
        OfferImpl offerImpl = (OfferImpl) offer;
        offerImpl.setToken("token1");
    }
    offer.setValidFrom(new Date());
    offer.setValidTo(new Date());
    // and save the offer
    acOfferManager.saveOffer(offer);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    dbInstance.commitAndCloseSession();
    // check if the offer is saved
    List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(offers);
    assertEquals(1, offers.size());
    Offer savedOffer = offers.get(0);
    assertNotNull(savedOffer);
    assertEquals(OfferImpl.class, savedOffer.getClass());
    if (savedOffer instanceof OfferImpl) {
        OfferImpl offerImpl = (OfferImpl) savedOffer;
        assertEquals("token1", offerImpl.getToken());
    }
    assertNotNull(offer.getValidFrom());
    assertNotNull(offer.getValidTo());
    assertEquals(testOres.getResourceableId(), savedOffer.getResourceId());
    assertEquals(testOres.getResourceableTypeName(), savedOffer.getResourceTypeName());
    assertEquals("TestSaveOffer", savedOffer.getResourceDisplayName());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) Test(org.junit.Test)

Example 23 with AccessMethod

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

the class TransactionDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = velocity_root + "/transaction_details.html";
    FormLayoutContainer detailsLayout = FormLayoutContainer.createCustomFormLayout("transaction-details-layout", getTranslator(), page);
    formLayout.add(detailsLayout);
    detailsLayout.setRootForm(mainForm);
    AccessTransaction transaction = wrapper.getTransaction();
    DetailsForm detailsForm = new DetailsForm(ureq, getWindowControl(), transaction, mainForm);
    detailsLayout.add("simple", detailsForm.getInitialFormItem());
    AccessMethod method = transaction.getMethod();
    AccessMethodHandler handler = acModule.getAccessMethodHandler(method.getType());
    FormController controller = handler.createTransactionDetailsController(ureq, getWindowControl(), order, wrapper.getPart(), method, mainForm);
    if (controller != null) {
        uifactory.addSpacerElement("details-spacer", detailsLayout, false);
        detailsLayout.add("custom", controller.getInitialFormItem());
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 24 with AccessMethod

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

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

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

the class BusinessGroupDAOTest method findPublicGroups.

@Test
public void findPublicGroups() {
    // create a group with an access control
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
    BusinessGroup group = businessGroupDao.createAndPersist(null, "access-grp-1", "access-grp-1-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer offer = acService.createOffer(group.getResource(), "TestBGWorkflow");
    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);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    // check the search with the views
    BusinessGroupQueryParams queryAllParams = new BusinessGroupQueryParams();
    queryAllParams.setPublicGroups(Boolean.TRUE);
    List<OpenBusinessGroupRow> accessGroupViews = businessGroupDao.searchPublishedBusinessGroups(queryAllParams, identity);
    Assert.assertNotNull(accessGroupViews);
    Assert.assertTrue(accessGroupViews.size() >= 1);
    Assert.assertTrue(contains(accessGroupViews, group));
    for (OpenBusinessGroupRow accessGroup : accessGroupViews) {
        OLATResource resource = resourceManager.findResourceById(accessGroup.getResourceKey());
        List<Offer> offers = acService.findOfferByResource(resource, true, new Date());
        Assert.assertNotNull(offers);
        Assert.assertFalse(offers.isEmpty());
    }
}
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) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Date(java.util.Date) 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