use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class ReportLogic method listExecutions.
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
@Override
public Pair<Integer, List<ExecTO>> listExecutions(final String key, final int page, final int size, final List<OrderByClause> orderByClauses) {
Report report = reportDAO.find(key);
if (report == null) {
throw new NotFoundException("Report " + key);
}
Integer count = reportExecDAO.count(key);
List<ExecTO> result = reportExecDAO.findAll(report, page, size, orderByClauses).stream().map(reportExec -> binder.getExecTO(reportExec)).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 AnySearchTest method groupOrderBy.
@Test
public void groupOrderBy() {
AnyCond idLeafCond = new AnyCond(AnyCond.Type.LIKE);
idLeafCond.setSchema("name");
idLeafCond.setExpression("%r");
SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
assertTrue(searchCondition.isValid());
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("name");
List<Group> groups = searchDAO.search(searchCondition, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.GROUP), groups.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class AnySearchTest method issueSYNCOPE983.
@Test
public void issueSYNCOPE983() {
AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
fullnameLeafCond.setSchema("surname");
fullnameLeafCond.setExpression("%o%");
List<OrderByClause> orderByClauses = new ArrayList<>();
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("surname");
orderByClause.setDirection(OrderByClause.Direction.ASC);
orderByClauses.add(orderByClause);
orderByClause = new OrderByClause();
orderByClause.setField("username");
orderByClause.setDirection(OrderByClause.Direction.DESC);
orderByClauses.add(orderByClause);
List<User> users = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, SearchCond.getLeafCond(fullnameLeafCond), -1, -1, orderByClauses, AnyTypeKind.USER);
assertFalse(users.isEmpty());
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class AbstractService method doSearch.
@SuppressWarnings("unchecked")
protected ListResponse<R> doSearch(final Resource type, final SCIMSearchRequest request) {
if (type == null) {
throw new UnsupportedOperationException();
}
if (request.getCount() > confManager().get().getFilterMaxResults()) {
throw new BadRequestException(ErrorType.tooMany, "Too many results requested");
}
SearchCondVisitor visitor = new SearchCondVisitor(type, confManager().get());
int startIndex = request.getStartIndex() <= 1 ? 1 : (request.getStartIndex() / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
int itemsPerPage = request.getCount() <= 1 ? AnyDAO.DEFAULT_PAGE_SIZE : request.getCount();
List<OrderByClause> sort;
if (request.getSortBy() == null) {
sort = Collections.<OrderByClause>emptyList();
} else {
OrderByClause clause = new OrderByClause();
clause.setField(visitor.createAttributeCond(request.getSortBy()).getSchema());
clause.setDirection(request.getSortOrder() == null || request.getSortOrder() == SortOrder.ascending ? OrderByClause.Direction.ASC : OrderByClause.Direction.DESC);
sort = Collections.singletonList(clause);
}
Pair<Integer, ? extends List<? extends AnyTO>> result = anyLogic(type).search(StringUtils.isBlank(request.getFilter()) ? null : SearchCondConverter.convert(visitor, request.getFilter()), startIndex, itemsPerPage, sort, SyncopeConstants.ROOT_REALM, false);
if (result.getLeft() > confManager().get().getFilterMaxResults()) {
throw new BadRequestException(ErrorType.tooMany, "Too many results found");
}
ListResponse<R> response = new ListResponse<>(result.getLeft(), startIndex == 1 ? 1 : startIndex - 1, itemsPerPage);
result.getRight().forEach(anyTO -> {
SCIMResource resource = null;
if (anyTO instanceof UserTO) {
resource = binder().toSCIMUser((UserTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
} else if (anyTO instanceof GroupTO) {
resource = binder().toSCIMGroup((GroupTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
}
if (resource != null) {
response.getResources().add((R) resource);
}
});
return response;
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class ResourceTest method delete.
@Test
public void delete() {
ExternalResource resource = resourceDAO.find("resource-testdb");
assertNotNull(resource);
// -------------------------------------
// Get originally associated connector
// -------------------------------------
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
// -------------------------------------
// -------------------------------------
// Get originally associated users
// -------------------------------------
List<User> users = userDAO.findByResource(resource);
assertNotNull(users);
Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
// -------------------------------------
// Get tasks
List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
assertFalse(propagationTasks.isEmpty());
// delete resource
resourceDAO.delete(resource.getKey());
// close the transaction
resourceDAO.flush();
// resource must be removed
ExternalResource actual = resourceDAO.find("resource-testdb");
assertNull(actual);
// resource must be not referenced any more from users
userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
assertNotNull(actualUser);
return actualUser;
}).forEachOrdered((actualUser) -> {
userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
});
// resource must be not referenced any more from the connector
ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
assertNotNull(actualConnector);
actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
// there must be no tasks
propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
Aggregations