Search in sources :

Example 11 with EqualFilter

use of com.evolveum.midpoint.prism.query.EqualFilter in project midpoint by Evolveum.

the class TestAdHocCertification method test010HireUserOutOfScope.

@Test
public void test010HireUserOutOfScope() throws Exception {
    // GIVEN
    Task task = getTestTask();
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    when();
    assignOrg(USER_INDIGO_OID, ORG_LABORATORY_OID, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    SearchResultList<PrismObject<AccessCertificationCampaignType>> campaigns = getAllCampaigns(result);
    assertEquals("Wrong # of campaigns", 1, campaigns.size());
    AccessCertificationObjectBasedScopeType scope = (AccessCertificationObjectBasedScopeType) campaigns.get(0).asObjectable().getScopeDefinition();
    Class<? extends ObjectType> objectClass = ObjectTypes.getObjectTypeClass(scope.getObjectType());
    ObjectFilter parsedFilter = prismContext.getQueryConverter().parseFilter(scope.getSearchFilter(), objectClass);
    assertTrue("Unexpected type of scope filter, expected AndFilter", parsedFilter instanceof AndFilter);
    for (ObjectFilter subFilter : ((AndFilter) parsedFilter).getConditions()) {
        assertTrue("Unexpected type of subfilter in scope filter, expected EqualFilter or InOidFilter", (subFilter instanceof EqualFilter || subFilter instanceof InOidFilter));
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Test(org.testng.annotations.Test)

Example 12 with EqualFilter

use of com.evolveum.midpoint.prism.query.EqualFilter in project midpoint by Evolveum.

the class PropertyRestriction method createPropertyVsPropertyCondition.

Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
    HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
    String rightHqlPath = rightItem.getHqlPath();
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    if (filter instanceof EqualFilter) {
        // left = right OR (left IS NULL AND right IS NULL)
        Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
        return hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
    } else if (filter instanceof ComparativeFilter) {
        ItemRestrictionOperation operation = findOperationForFilter(filter);
        return hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
    } else {
        throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
    }
}
Also used : ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) ComparativeFilter(com.evolveum.midpoint.prism.query.ComparativeFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 13 with EqualFilter

use of com.evolveum.midpoint.prism.query.EqualFilter in project midpoint by Evolveum.

the class JsonbPolysPathItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<T> filter) throws RepositoryException {
    String matchingRule = filter.getMatchingRule() != null ? filter.getMatchingRule().getLocalPart() : null;
    if (!(filter instanceof EqualFilter) || STRICT_IGNORE_CASE.equals(matchingRule) || ORIG_IGNORE_CASE.equals(matchingRule) || NORM_IGNORE_CASE.equals(matchingRule)) {
        throw new QueryException("Can't translate filter '" + filter + "' to operation." + " JSONB stored poly strings support only equals with no IC matching rule.");
    }
    List<?> filterValues = filter.getValues();
    if (filterValues == null || filterValues.isEmpty()) {
        return path.isNull();
    }
    ValueFilterValues<?, ?> values = ValueFilterValues.from(filter);
    if (Strings.isNullOrEmpty(matchingRule) || DEFAULT.equals(matchingRule) || STRICT.equals(matchingRule)) {
        // The value here should be poly-string, otherwise it never matches both orig and norm.
        return processPolyStringBoth(values);
    } else if (ORIG.equals(matchingRule)) {
        return processPolyStringComponent(convertPolyValuesToString(values, filter, p -> p.getOrig()), JSONB_POLY_ORIG_KEY);
    } else if (NORM.equals(matchingRule)) {
        return processPolyStringComponent(convertPolyValuesToString(values, filter, p -> p.getNorm()), JSONB_POLY_NORM_KEY);
    } else {
        throw new QueryException("Unknown matching rule '" + matchingRule + "'.");
    }
}
Also used : Expressions.booleanTemplate(com.querydsl.core.types.dsl.Expressions.booleanTemplate) FlexibleRelationalPathBase(com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase) JSONB_POLY_ORIG_KEY(com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_ORIG_KEY) SqlQueryContext(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext) JSONB_POLY_NORM_KEY(com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_NORM_KEY) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) JsonbPath(com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath) Function(java.util.function.Function) PolyStringItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.PolyStringItemFilterProcessor) Strings(com.google.common.base.Strings) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) List(java.util.List) ValueFilterValues(com.evolveum.midpoint.repo.sqlbase.filtering.ValueFilterValues) SinglePathItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor) Predicate(com.querydsl.core.types.Predicate) NotNull(org.jetbrains.annotations.NotNull) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 14 with EqualFilter

use of com.evolveum.midpoint.prism.query.EqualFilter in project midpoint by Evolveum.

the class TestParseResource method assertResourcePrism.

private void assertResourcePrism(PrismObject<ResourceType> resource, boolean isSimple) throws SchemaException {
    PrismContext prismContext = getPrismContext();
    AssertJUnit.assertEquals("Wrong oid (prism)", TestConstants.RESOURCE_OID, resource.getOid());
    // assertEquals("Wrong version", "42", resource.getVersion());
    PrismObjectDefinition<ResourceType> resourceDefinition = resource.getDefinition();
    assertNotNull("No resource definition", resourceDefinition);
    PrismAsserts.assertObjectDefinition(resourceDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "resource"), ResourceType.COMPLEX_TYPE, ResourceType.class);
    assertEquals("Wrong class in resource", ResourceType.class, resource.getCompileTimeClass());
    ResourceType resourceType = resource.asObjectable();
    assertNotNull("asObjectable resulted in null", resourceType);
    assertPropertyValue(resource, "name", PrismTestUtil.createPolyString("Embedded Test OpenDJ"));
    assertPropertyDefinition(resource, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    PrismReference connectorRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    assertNotNull("No connectorRef", connectorRef);
    PrismReferenceValue connectorRefVal = connectorRef.getValue();
    assertNotNull("No connectorRef value", connectorRefVal);
    assertEquals("Wrong type in connectorRef value", ConnectorType.COMPLEX_TYPE, connectorRefVal.getTargetType());
    SearchFilterType filter = connectorRefVal.getFilter();
    assertNotNull("No filter in connectorRef value", filter);
    if (!isSimple) {
        ObjectFilter objectFilter = prismContext.getQueryConverter().parseFilter(filter, ConnectorType.class);
        assertTrue("Wrong kind of filter: " + objectFilter, objectFilter instanceof EqualFilter);
        EqualFilter equalFilter = (EqualFilter) objectFilter;
        // should be extension/x:extConnType
        ItemPath path = equalFilter.getPath();
        PrismAsserts.assertPathEqualsExceptForPrefixes("Wrong filter path", namespaces ? ItemPath.create(new QName("extension"), new QName("http://x/", "extConnType")) : ItemPath.create(new QName("extension"), new QName("extConnType")), path);
        PrismPropertyValue filterValue = (PrismPropertyValue) equalFilter.getValues().get(0);
        assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((RawType) filterValue.getValue()).getParsedRealValue(String.class).trim());
    // assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((String) filterValue.getValue()).trim());
    }
    EvaluationTimeType resolutionTime = connectorRefVal.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.IMPORT, resolutionTime);
    }
    PrismContainer<?> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertContainerDefinition(configurationContainer, "configuration", ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
    PrismContainerValue<?> configContainerValue = configurationContainer.getValue();
    Collection<Item<?, ?>> configItems = configContainerValue.getItems();
    assertEquals("Wrong number of config items", isSimple ? 1 : 4, configItems.size());
    PrismContainer<?> ldapConfigPropertiesContainer = configurationContainer.findContainer(ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No icfcldap:configurationProperties container", ldapConfigPropertiesContainer);
    PrismContainerDefinition<?> ldapConfigPropertiesContainerDef = ldapConfigPropertiesContainer.getDefinition();
    assertNotNull("No icfcldap:configurationProperties container definition", ldapConfigPropertiesContainerDef);
    assertEquals("icfcldap:configurationProperties container definition maxOccurs", 1, ldapConfigPropertiesContainerDef.getMaxOccurs());
    Collection<Item<?, ?>> ldapConfigPropItems = ldapConfigPropertiesContainer.getValue().getItems();
    assertEquals("Wrong number of ldapConfigPropItems items", 7, ldapConfigPropItems.size());
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (isSimple) {
        assertNull("Schema sneaked in", schemaContainer);
    } else {
        assertNotNull("No schema container", schemaContainer);
    }
    PrismContainer<?> schemaHandlingContainer = resource.findContainer(ResourceType.F_SCHEMA_HANDLING);
    if (isSimple) {
        assertNull("SchemaHandling sneaked in", schemaHandlingContainer);
    } else {
        assertNotNull("No schemaHandling container", schemaHandlingContainer);
    }
    if (!isSimple) {
        PrismContainer<SynchronizationType> synchronizationProp = resource.findContainer(ResourceType.F_SYNCHRONIZATION);
        SynchronizationType synchronizationType = synchronizationProp.getRealValue();
        ObjectSynchronizationType objectSynchronizationType = synchronizationType.getObjectSynchronization().get(0);
        List<ConditionalSearchFilterType> correlations = objectSynchronizationType.getCorrelation();
        assertEquals("Wrong number of correlation expressions", 1, correlations.size());
        ConditionalSearchFilterType correlationFilterType = correlations.get(0);
        System.out.println("\nCorrelation filter");
        System.out.println(correlationFilterType.debugDump());
    // ObjectFilter objectFilter = prismContext.getQueryConverter().parseFilter(correlationFilterType.serializeToXNode());
    // PrismAsserts.assertAssignableFrom(EqualFilter.class, objectFilter);
    // EqualFilter equalsFilter = (EqualFilter)objectFilter;
    // assertNull("Unexpected values in correlation expression", equalsFilter.getValues());
    // ExpressionWrapper expression = equalsFilter.getExpression();
    // assertNotNull("No expressions in correlation expression", expression);
    // ExpressionType expressionType = (ExpressionType) expression.getExpression();
    // assertEquals("Wrong number of expression evaluators in correlation expression", 1, expressionType.getExpressionEvaluator().size());
    // ItemPathType itemPathType = (ItemPathType) expressionType.getExpressionEvaluator().get(0).getValue();
    // PrismAsserts.assertPathEqualsExceptForPrefixes("path in correlation expression",
    // namespaces ?
    // ItemPath.create(
    // new NameItemPathSegment(new QName("account"), true),
    // new NameItemPathSegment(new QName(SchemaConstantsGenerated.NS_COMMON, "attributes")),
    // new NameItemPathSegment(new QName("http://myself.me/schemas/whatever", "yyy"))
    // ) :
    // ItemPath.create(
    // new NameItemPathSegment(new QName("account"), true),
    // new NameItemPathSegment(new QName("attributes")),
    // new NameItemPathSegment(new QName("yyy"))
    // ), itemPathType.getItemPath());
    // PrismAsserts.assertAllParsedNodes(expression);
    // TODO
    }
}
Also used : EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)5 ArrayList (java.util.ArrayList)5 List (java.util.List)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 QName (javax.xml.namespace.QName)3 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 ComparativeFilter (com.evolveum.midpoint.prism.query.ComparativeFilter)2 QueryFactory (com.evolveum.midpoint.prism.query.QueryFactory)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)2 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)2 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 MatchingRule (com.evolveum.midpoint.prism.match.MatchingRule)1