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