private ObjectQuery createQuery() { AccountContentSearchDto dto = searchModel.getObject(); if (StringUtils.isEmpty(dto.getSearchText())) { return null; } try { ObjectQuery query = null; List<ObjectFilter> conditions = new ArrayList<>(); ObjectClassComplexTypeDefinition def = getAccountDefinition(); if (dto.isIdentifiers()) { List<ResourceAttributeDefinition> identifiers = new ArrayList<>(); if (def.getIdentifiers() != null) { identifiers.addAll(def.getIdentifiers()); } // TODO set matching rule instead fo null for (ResourceAttributeDefinition attrDef : identifiers) { conditions.add( EqualFilter.createEqual( new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()), attrDef, dto.getSearchText())); } } if (dto.isName()) { List<ResourceAttributeDefinition> secondaryIdentifiers = new ArrayList<>(); if (def.getNamingAttribute() != null) { secondaryIdentifiers.add(def.getNamingAttribute()); } else if (def.getSecondaryIdentifiers() != null) { secondaryIdentifiers.addAll(def.getSecondaryIdentifiers()); } for (ResourceAttributeDefinition attrDef : secondaryIdentifiers) { conditions.add( SubstringFilter.createSubstring( new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()), attrDef, dto.getSearchText())); } } if (!conditions.isEmpty()) { if (conditions.size() > 1) { query = ObjectQuery.createObjectQuery(OrFilter.createOr(conditions)); } else { query = ObjectQuery.createObjectQuery(conditions.get(0)); } } return query; } catch (Exception ex) { error(getString("pageUsers.message.queryError") + " " + ex.getMessage()); LoggingUtils.logException(LOGGER, "Couldn't create query filter.", ex); } return null; }
private void clearSearchPerformed(AjaxRequestTarget target) { searchModel.setObject(new AccountContentSearchDto()); TablePanel panel = getTable(); DataTable table = panel.getDataTable(); AccountContentDataProvider provider = (AccountContentDataProvider) table.getDataProvider(); provider.setQuery(null); ResourcesStorage storage = getSessionStorage().getResources(); storage.setAccountContentSearch(searchModel.getObject()); storage.setAccountContentPaging(null); panel.setCurrentPage(null); target.add(get(ID_SEARCH_FORM)); target.add(panel); }