use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class JPANotificationDAO method delete.
@Override
public void delete(final String key) {
Notification notification = find(key);
if (notification == null) {
return;
}
taskDAO.findAll(TaskType.NOTIFICATION, null, notification, null, null, -1, -1, Collections.<OrderByClause>emptyList()).stream().map(Entity::getKey).forEach(task -> delete(task));
entityManager().remove(notification);
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class NotificationManagerImpl method getNotificationTask.
/**
* Create a notification task.
*
* @param notification notification to take as model
* @param any the any object this task is about
* @param jexlVars JEXL variables
* @return notification task, fully populated
*/
private NotificationTask getNotificationTask(final Notification notification, final Any<?> any, final Map<String, Object> jexlVars) {
if (any != null) {
virAttrHander.getValues(any);
}
List<User> recipients = new ArrayList<>();
if (notification.getRecipientsFIQL() != null) {
recipients.addAll(searchDAO.<User>search(SearchCondConverter.convert(notification.getRecipientsFIQL()), Collections.<OrderByClause>emptyList(), AnyTypeKind.USER));
}
if (notification.isSelfAsRecipient() && any instanceof User) {
recipients.add((User) any);
}
Set<String> recipientEmails = new HashSet<>();
List<UserTO> recipientTOs = new ArrayList<>(recipients.size());
recipients.forEach(recipient -> {
virAttrHander.getValues(recipient);
String email = getRecipientEmail(notification.getRecipientAttrName(), recipient);
if (email == null) {
LOG.warn("{} cannot be notified: {} not found", recipient, notification.getRecipientAttrName());
} else {
recipientEmails.add(email);
recipientTOs.add(userDataBinder.getUserTO(recipient, true));
}
});
if (notification.getStaticRecipients() != null) {
recipientEmails.addAll(notification.getStaticRecipients());
}
if (notification.getRecipientsProvider() != null) {
try {
RecipientsProvider recipientsProvider = ImplementationManager.build(notification.getRecipientsProvider());
recipientEmails.addAll(recipientsProvider.provideRecipients(notification));
} catch (Exception e) {
LOG.error("While building {}", notification.getRecipientsProvider(), e);
}
}
jexlVars.put("recipients", recipientTOs);
jexlVars.put("syncopeConf", this.findAllSyncopeConfs());
jexlVars.put("events", notification.getEvents());
NotificationTask task = entityFactory.newEntity(NotificationTask.class);
task.setNotification(notification);
if (any != null) {
task.setEntityKey(any.getKey());
task.setAnyTypeKind(any.getType().getKind());
}
task.setTraceLevel(notification.getTraceLevel());
task.getRecipients().addAll(recipientEmails);
task.setSender(notification.getSender());
task.setSubject(notification.getSubject());
if (StringUtils.isNotBlank(notification.getTemplate().getTextTemplate())) {
task.setTextBody(evaluate(notification.getTemplate().getTextTemplate(), jexlVars));
}
if (StringUtils.isNotBlank(notification.getTemplate().getHTMLTemplate())) {
task.setHtmlBody(evaluate(notification.getTemplate().getHTMLTemplate(), jexlVars));
}
return task;
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class ResourceLogic method listConnObjects.
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_LIST_CONNOBJECT + "')")
@Transactional(readOnly = true)
public Pair<SearchResult, List<ConnObjectTO>> listConnObjects(final String key, final String anyTypeKey, final int size, final String pagedResultsCookie, final List<OrderByClause> orderBy) {
ExternalResource resource;
ObjectClass objectClass;
OperationOptions options;
if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
resource = resourceDAO.authFind(key);
if (resource == null) {
throw new NotFoundException("Resource '" + key + "'");
}
if (resource.getOrgUnit() == null) {
throw new NotFoundException("Realm provisioning for resource '" + key + "'");
}
objectClass = resource.getOrgUnit().getObjectClass();
options = MappingUtils.buildOperationOptions(MappingUtils.getPropagationItems(resource.getOrgUnit().getItems()).iterator());
} else {
Triple<ExternalResource, AnyType, Provision> init = connObjectInit(key, anyTypeKey);
resource = init.getLeft();
objectClass = init.getRight().getObjectClass();
init.getRight().getMapping().getItems();
Set<MappingItem> linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream().map(virSchema -> virSchema.asLinkingMappingItem()).collect(Collectors.toSet());
Iterator<MappingItem> mapItems = new IteratorChain<>(init.getRight().getMapping().getItems().iterator(), linkinMappingItems.iterator());
options = MappingUtils.buildOperationOptions(mapItems);
}
final List<ConnObjectTO> connObjects = new ArrayList<>();
SearchResult searchResult = connFactory.getConnector(resource).search(objectClass, null, new ResultsHandler() {
private int count;
@Override
public boolean handle(final ConnectorObject connectorObject) {
connObjects.add(ConnObjectUtils.getConnObjectTO(connectorObject));
// safety protection against uncontrolled result size
count++;
return count < size;
}
}, size, pagedResultsCookie, orderBy, options);
return ImmutablePair.of(searchResult, connObjects);
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class SyncopeLogic method searchAssignableGroups.
@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
AssignableCond assignableCond = new AssignableCond();
assignableCond.setRealmFullPath(realm);
SearchCond searchCond;
if (StringUtils.isNotBlank(term)) {
AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
termCond.setSchema("name");
String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
termCond.setExpression(termSearchableValue);
searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
} else {
searchCond = SearchCond.getLeafCond(assignableCond);
}
int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("name");
orderByClause.setDirection(OrderByClause.Direction.ASC);
List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
return Pair.of(count, result);
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class TaskLogic method listExecutions.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@Override
public Pair<Integer, List<ExecTO>> listExecutions(final String key, final int page, final int size, final List<OrderByClause> orderByClauses) {
Task task = taskDAO.find(key);
if (task == null) {
throw new NotFoundException("Task " + key);
}
Integer count = taskExecDAO.count(key);
List<ExecTO> result = taskExecDAO.findAll(task, page, size, orderByClauses).stream().map(taskExec -> binder.getExecTO(taskExec)).collect(Collectors.toList());
return Pair.of(count, result);
}
Aggregations