+ /** Build repository request */
+ private NodeIterator listFilteredElements(Session session, String filter)
+ throws RepositoryException {
+ QueryManager queryManager = session.getWorkspace().getQueryManager();
+ QueryObjectModelFactory factory = queryManager.getQOMFactory();
+
+ final String bundleArtifactsSelector = "userProfiles";
+ Selector source = factory.selector(ArgeoTypes.ARGEO_USER_PROFILE,
+ bundleArtifactsSelector);
+
+ // Create a dynamic operand for each property on which we want to filter
+ DynamicOperand userIdDO = factory.propertyValue(
+ source.getSelectorName(), ARGEO_USER_ID);
+ DynamicOperand fullNameDO = factory.propertyValue(
+ source.getSelectorName(), Property.JCR_TITLE);
+ DynamicOperand mailDO = factory.propertyValue(source.getSelectorName(),
+ ARGEO_PRIMARY_EMAIL);
+
+ // Default Constraint: no source artifacts
+ Constraint defaultC = null;
+
+ // Build constraints based the textArea content
+ if (filter != null && !"".equals(filter.trim())) {
+ // Parse the String
+ String[] strs = filter.trim().split(" ");
+ for (String token : strs) {
+ token = token.replace('*', '%');
+ StaticOperand so = factory.literal(session.getValueFactory()
+ .createValue("%" + token + "%"));
+
+ Constraint currC = factory.comparison(userIdDO,
+ QueryObjectModelFactory.JCR_OPERATOR_LIKE, so);
+ currC = factory.or(currC, factory.comparison(fullNameDO,
+ QueryObjectModelFactory.JCR_OPERATOR_LIKE, so));
+ currC = factory.or(currC, factory.comparison(mailDO,
+ QueryObjectModelFactory.JCR_OPERATOR_LIKE, so));
+
+ if (defaultC == null)
+ defaultC = currC;
+ else
+ defaultC = factory.and(defaultC, currC);
+ }
+ }
+
+ Ordering order = factory.descending(factory.propertyValue(
+ bundleArtifactsSelector, ARGEO_USER_ID));
+ // Ordering order2 = factory.ascending(factory.propertyValue(
+ // bundleArtifactsSelector, ARGEO_PRIMARY_EMAIL));
+ // Ordering[] orderings = { order, order2 };
+ Ordering[] orderings = { order };
+
+ QueryObjectModel query = factory.createQuery(source, defaultC,
+ orderings, null);
+
+ QueryResult result = query.execute();
+ return result.getNodes();
+ }
+}
\ No newline at end of file