use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class JPAAnySearchDAO method parseOrderBy.
private OrderBySupport parseOrderBy(final AnyTypeKind kind, final SearchSupport svs, final List<OrderByClause> orderBy) {
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
OrderBySupport obs = new OrderBySupport();
for (OrderByClause clause : filterOrderBy(orderBy)) {
OrderBySupport.Item item = new OrderBySupport.Item();
// Manage difference among external key attribute and internal JPA @Id
String fieldName = "key".equals(clause.getField()) ? "id" : clause.getField();
if (ReflectionUtils.findField(attrUtils.anyClass(), fieldName) == null) {
PlainSchema schema = schemaDAO.find(fieldName);
if (schema != null) {
// keep track of involvement of non-mandatory schemas in the order by clauses
obs.nonMandatorySchemas = !"true".equals(schema.getMandatoryCondition());
if (schema.isUniqueConstraint()) {
obs.views.add(svs.uniqueAttr());
item.select = new StringBuilder().append(svs.uniqueAttr().alias).append('.').append(svs.fieldName(schema.getType())).append(" AS ").append(fieldName).toString();
item.where = new StringBuilder().append(svs.uniqueAttr().alias).append(".schema_id='").append(fieldName).append("'").toString();
item.orderBy = fieldName + " " + clause.getDirection().name();
} else {
obs.views.add(svs.attr());
item.select = new StringBuilder().append(svs.attr().alias).append('.').append(svs.fieldName(schema.getType())).append(" AS ").append(fieldName).toString();
item.where = new StringBuilder().append(svs.attr().alias).append(".schema_id='").append(fieldName).append("'").toString();
item.orderBy = fieldName + " " + clause.getDirection().name();
}
}
} else {
// Adjust field name to column name
fieldName = "realm".equals(fieldName) ? "realm_id" : fieldName;
obs.views.add(svs.field());
item.select = svs.field().alias + "." + fieldName;
item.where = StringUtils.EMPTY;
item.orderBy = svs.field().alias + "." + fieldName + " " + clause.getDirection().name();
}
if (item.isEmpty()) {
LOG.warn("Cannot build any valid clause from {}", clause);
} else {
obs.items.add(item);
}
}
return obs;
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class AnySearchTest method searchByPageAndSize.
@Test
public void searchByPageAndSize() {
AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
fullnameLeafCond.setSchema("fullname");
fullnameLeafCond.setExpression("%o%");
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("root");
AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
loginDateCond.setSchema("loginDate");
loginDateCond.setExpression("2009-05-26");
SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(groupCond));
assertTrue(subCond.isValid());
SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
assertTrue(cond.isValid());
List<User> users = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, 1, 2, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER);
assertNotNull(users);
assertEquals(1, users.size());
users = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, 2, 2, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER);
assertNotNull(users);
assertTrue(users.isEmpty());
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class AnySearchTest method userOrderBy.
@Test
public void userOrderBy() {
AnyCond usernameLeafCond = new AnyCond(AnyCond.Type.EQ);
usernameLeafCond.setSchema("username");
usernameLeafCond.setExpression("rossini");
AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
idRightCond.setSchema("fullname");
idRightCond.setExpression("Giuseppe V%");
SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond), SearchCond.getLeafCond(idRightCond));
List<OrderByClause> orderByClauses = new ArrayList<>();
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("username");
orderByClause.setDirection(OrderByClause.Direction.DESC);
orderByClauses.add(orderByClause);
orderByClause = new OrderByClause();
orderByClause.setField("fullname");
orderByClause.setDirection(OrderByClause.Direction.ASC);
orderByClauses.add(orderByClause);
List<User> users = searchDAO.search(searchCondition, orderByClauses, AnyTypeKind.USER);
assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.USER), users.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.
the class TaskTest method findPaginated.
@Test
public void findPaginated() {
List<Task> tasks = taskDAO.findAll(TaskType.PROPAGATION, null, null, null, null, 1, 2, Collections.<OrderByClause>emptyList());
assertNotNull(tasks);
assertEquals(2, tasks.size());
for (Task task : tasks) {
assertNotNull(task);
}
tasks = taskDAO.findAll(TaskType.PROPAGATION, null, null, null, null, 2, 2, Collections.<OrderByClause>emptyList());
assertNotNull(tasks);
assertEquals(2, tasks.size());
for (Task task : tasks) {
assertNotNull(task);
}
tasks = taskDAO.findAll(TaskType.PROPAGATION, null, null, null, null, 1000, 2, Collections.<OrderByClause>emptyList());
assertNotNull(tasks);
assertTrue(tasks.isEmpty());
assertEquals(5, taskDAO.count(TaskType.PROPAGATION, null, null, null, null));
}
Aggregations