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));
}
}
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);
}
}
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 + "'.");
}
}
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
}
}
Aggregations