Exemplo n.º 1
0
 private ObjectQuery getAssociationsSearchQuery(
     PrismContext prismContext,
     PrismObject resource,
     QName objectClass,
     ShadowKindType kind,
     String intent) {
   try {
     ObjectFilter andFilter =
         AndFilter.createAnd(
             EqualFilter.createEqual(
                 ShadowType.F_OBJECT_CLASS, ShadowType.class, prismContext, objectClass),
             EqualFilter.createEqual(ShadowType.F_KIND, ShadowType.class, prismContext, kind),
             //                    EqualFilter.createEqual(ShadowType.F_INTENT, ShadowType.class,
             // prismContext, intent),
             RefFilter.createReferenceEqual(
                 new ItemPath(ShadowType.F_RESOURCE_REF),
                 ShadowType.class,
                 prismContext,
                 resource.getOid()));
     ObjectQuery query = ObjectQuery.createObjectQuery(andFilter);
     return query;
   } catch (SchemaException ex) {
     LoggingUtils.logUnexpectedException(LOGGER, "Unable to create associations search query", ex);
     return null;
   }
 }
Exemplo 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;
    }
  }
Exemplo n.º 3
0
 <O extends Containerable> RefFilter createReferenceEqualFilter(
     ItemPath propertyPath, Class<O> type, String... oids) throws SchemaException {
   return RefFilter.createReferenceEqual(propertyPath, type, prismContext, oids);
 }
Exemplo n.º 4
0
 <O extends Containerable> RefFilter createReferenceEqualFilter(
     QName propertyName, Class<O> type, String... oids) {
   return RefFilter.createReferenceEqual(propertyName, type, prismContext, oids);
 }
Exemplo n.º 5
0
  private <T extends ObjectFilter> Restriction findAndCreateRestrictionInternal(
      T filter,
      InterpretationContext context,
      Restriction parent,
      ItemPathResolver resolver,
      JpaEntityDefinition baseEntityDefinition)
      throws QueryException {

    // the order of processing restrictions can be important, so we do the selection via handwritten
    // code

    if (filter instanceof AndFilter) {
      return new AndRestriction(context, (AndFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof OrFilter) {
      return new OrRestriction(context, (OrFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof NotFilter) {
      return new NotRestriction(context, (NotFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof InOidFilter) {
      return new InOidRestriction(context, (InOidFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof OrgFilter) {
      return new OrgRestriction(context, (OrgFilter) filter, baseEntityDefinition, parent);
    } else if (filter instanceof TypeFilter) {
      TypeFilter typeFilter = (TypeFilter) filter;
      JpaEntityDefinition refinedEntityDefinition =
          resolver.findRestrictedEntityDefinition(baseEntityDefinition, typeFilter.getType());
      return new TypeRestriction(context, typeFilter, refinedEntityDefinition, parent);
    } else if (filter instanceof ExistsFilter) {
      ExistsFilter existsFilter = (ExistsFilter) filter;
      ItemPath path = existsFilter.getFullPath();
      ItemDefinition definition = existsFilter.getDefinition();
      ProperDataSearchResult<JpaEntityDefinition> searchResult =
          resolver.findProperDataDefinition(
              baseEntityDefinition, path, definition, JpaEntityDefinition.class);
      if (searchResult == null) {
        throw new QueryException(
            "Path for ExistsFilter ("
                + path
                + ") doesn't point to a hibernate entity within "
                + baseEntityDefinition);
      }
      return new ExistsRestriction(
          context, existsFilter, searchResult.getEntityDefinition(), parent);
    } else if (filter instanceof RefFilter) {
      RefFilter refFilter = (RefFilter) filter;
      ItemPath path = refFilter.getFullPath();
      ItemDefinition definition = refFilter.getDefinition();
      ProperDataSearchResult<JpaReferenceDefinition> searchResult =
          resolver.findProperDataDefinition(
              baseEntityDefinition, path, definition, JpaReferenceDefinition.class);
      if (searchResult == null) {
        throw new QueryException(
            "Path for RefFilter ("
                + path
                + ") doesn't point to a reference item within "
                + baseEntityDefinition);
      }
      return new ReferenceRestriction(
          context,
          refFilter,
          searchResult.getEntityDefinition(),
          parent,
          searchResult.getLinkDefinition());
    } else if (filter instanceof PropertyValueFilter) {
      PropertyValueFilter valFilter = (PropertyValueFilter) filter;
      ItemPath path = valFilter.getFullPath();
      ItemDefinition definition = valFilter.getDefinition();

      ProperDataSearchResult<JpaPropertyDefinition> propDefRes =
          resolver.findProperDataDefinition(
              baseEntityDefinition, path, definition, JpaPropertyDefinition.class);
      if (propDefRes == null) {
        throw new QueryException(
            "Couldn't find a proper restriction for a ValueFilter: " + valFilter.debugDump());
      }
      // TODO can't be unified?
      if (propDefRes.getTargetDefinition() instanceof JpaAnyPropertyDefinition) {
        return new AnyPropertyRestriction(
            context,
            valFilter,
            propDefRes.getEntityDefinition(),
            parent,
            propDefRes.getLinkDefinition());
      } else {
        return new PropertyRestriction(
            context,
            valFilter,
            propDefRes.getEntityDefinition(),
            parent,
            propDefRes.getLinkDefinition());
      }
    } else if (filter instanceof NoneFilter
        || filter instanceof AllFilter
        || filter instanceof UndefinedFilter) {
      // these should be filtered out by the client
      throw new IllegalStateException(
          "Trivial filters are not supported by QueryInterpreter: " + filter.debugDump());
    } else {
      throw new IllegalStateException("Unknown filter: " + filter.debugDump());
    }
  }
Exemplo n.º 6
0
 public static ObjectFilter createResourceFilter(String resourceOid, PrismContext prismContext)
     throws SchemaException {
   return RefFilter.createReferenceEqual(
       ShadowType.F_RESOURCE_REF, ShadowType.class, prismContext, resourceOid);
 }