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