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;
  }
Esempio n. 2
0
  private ObjectQuery createQuery() {
    ReportOutputSearchDto dto = searchModel.getObject();

    try {
      List<ObjectFilter> ands = new ArrayList<>();

      if (StringUtils.isNotEmpty(dto.getText())) {
        PolyStringNormalizer normalizer = getPrismContext().getDefaultPolyStringNormalizer();
        String normalizedString = normalizer.normalize(dto.getText());

        SubstringFilter substring =
            SubstringFilter.createSubstring(
                ReportOutputType.F_NAME,
                ReportOutputType.class,
                getPrismContext(),
                PolyStringNormMatchingRule.NAME,
                normalizedString);
        ands.add(substring);
      }

      String oid = dto.getReportTypeMap().get(dto.getReportType());
      if (StringUtils.isNotEmpty(oid)) {
        RefFilter ref =
            RefFilter.createReferenceEqual(
                ReportOutputType.F_REPORT_REF, ReportOutputType.class, getPrismContext(), oid);
        ands.add(ref);
      }

      switch (ands.size()) {
        case 0:
          return null;
        case 1:
          return ObjectQuery.createObjectQuery(ands.get(0));
        default:
          AndFilter and = AndFilter.createAnd(ands);
          return ObjectQuery.createObjectQuery(and);
      }
    } catch (Exception e) {
      error(getString("pageCreatedReports.message.queryError") + " " + e.getMessage());
      LoggingUtils.logException(LOGGER, "Couldn't create query filter.", e);
      return null;
    }
  }