use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
List<AccessMethod> methods = acMethodManager.getAvailableMethods();
assertNotNull(methods);
assertTrue(methods.size() >= 2);
Set<String> duplicateTypes = new HashSet<>();
boolean foundFree = false;
boolean foundToken = false;
for (AccessMethod method : methods) {
Assert.assertFalse(duplicateTypes.contains(method.getType()));
if (method instanceof FreeAccessMethod) {
foundFree = true;
} else if (method instanceof TokenAccessMethod) {
foundToken = true;
}
assertTrue(method.isEnabled());
assertTrue(method.isValid());
duplicateTypes.add(method.getType());
}
assertTrue(foundFree);
assertTrue(foundToken);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
the class ACFrontendManager method findOrderItems.
@Override
public List<OrderTableItem> findOrderItems(OLATResource resource, IdentityRef delivery, Long orderNr, Date from, Date to, OrderStatus[] status, int firstResult, int maxResults, List<UserPropertyHandler> userPropertyHandlers, SortKey... orderBy) {
List<AccessMethod> methods = methodManager.getAllMethods();
Map<String, AccessMethod> methodMap = new HashMap<>();
for (AccessMethod method : methods) {
methodMap.put(method.getKey().toString(), method);
}
List<RawOrderItem> rawOrders = orderManager.findNativeOrderItems(resource, delivery, orderNr, from, to, status, firstResult, maxResults, userPropertyHandlers, orderBy);
List<OrderTableItem> items = new ArrayList<>(rawOrders.size());
for (RawOrderItem rawOrder : rawOrders) {
String orderStatusStr = rawOrder.getOrderStatus();
OrderStatus orderStatus = OrderStatus.valueOf(orderStatusStr);
Status finalStatus = getStatus(orderStatusStr, rawOrder.getTrxStatus(), rawOrder.getPspTrxStatus());
String methodIds = rawOrder.getTrxMethodIds();
List<AccessMethod> orderMethods = new ArrayList<>(2);
if (StringHelper.containsNonWhitespace(methodIds)) {
String[] methodIdArr = methodIds.split(",");
for (String methodId : methodIdArr) {
if (methodMap.containsKey(methodId)) {
orderMethods.add(methodMap.get(methodId));
}
}
}
OrderTableItem item = new OrderTableItem(rawOrder.getOrderKey(), rawOrder.getOrderNr(), rawOrder.getTotal(), rawOrder.getCreationDate(), orderStatus, finalStatus, rawOrder.getDeliveryKey(), rawOrder.getUsername(), rawOrder.getUserProperties(), orderMethods);
item.setResourceDisplayname(rawOrder.getResourceName());
items.add(item);
}
return items;
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodDAO method isValidMethodAvailable.
public boolean isValidMethodAvailable(OLATResource resource, Date atDate) {
StringBuilder sb = new StringBuilder();
sb.append("select access.method from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=true").append(" and offer.valid=true").append(" and oResource.key=:resourceKey");
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<AccessMethod> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class);
query.setParameter("resourceKey", resource.getKey());
if (atDate != null) {
query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
}
List<AccessMethod> methods = query.getResultList();
List<AccessMethod> guiMethods = new ArrayList<>();
for (AccessMethod method : methods) {
if (method.isVisibleInGui()) {
guiMethods.add(method);
}
}
return !guiMethods.isEmpty();
}
Aggregations