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();
}
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());
}
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());
}
}
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));
}
}
}
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());
}
}
Aggregations