use of com.evolveum.midpoint.prism.query.ObjectFilter 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);
if (!isSimple) {
assertPropertyValue(resource, "namespace", TestConstants.RESOURCE_NAMESPACE);
assertPropertyDefinition(resource, "namespace", DOMUtil.XSD_ANYURI, 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 = QueryConvertor.parseFilter(filter, ConnectorType.class, prismContext);
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 ? new ItemPath(new QName("extension"), new QName("http://x/", "extConnType")) : new ItemPath(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();
List<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());
List<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) {
PrismProperty<SynchronizationType> synchronizationProp = resource.findProperty(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 = QueryConvertor.parseFilter(correlationFilterType.serializeToXNode(), prismContext);
PrismAsserts.assertAssignableFrom(EqualFilter.class, objectFilter);
EqualFilter equalsFilter = (EqualFilter) objectFilter;
equalsFilter.getFullPath();
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();
// $account/c:attributes/my:yyy
PrismAsserts.assertPathEqualsExceptForPrefixes("path in correlation expression", namespaces ? new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName(SchemaConstantsGenerated.NS_COMMON, "attributes")), new NameItemPathSegment(new QName("http://myself.me/schemas/whatever", "yyy"))) : new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName("attributes")), new NameItemPathSegment(new QName("yyy"))), itemPathType.getItemPath());
//PrismAsserts.assertAllParsedNodes(expression);
// TODO
}
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class AccCertUpdateHelper method createAdHocCampaignObject.
<O extends ObjectType> AccessCertificationCampaignType createAdHocCampaignObject(AccessCertificationDefinitionType definition, PrismObject<O> focus, Task task, OperationResult result) throws SecurityViolationException, ObjectNotFoundException, SchemaException {
definition.setName(PolyStringType.fromOrig(PolyString.getOrig(definition.getName()) + " " + PolyString.getOrig(focus.getName())));
definition.setLastCampaignIdUsed(null);
AccessCertificationCampaignType campaign = createCampaignObject(definition, task, result);
AccessCertificationObjectBasedScopeType scope;
if ((campaign.getScopeDefinition() instanceof AccessCertificationObjectBasedScopeType)) {
scope = (AccessCertificationObjectBasedScopeType) campaign.getScopeDefinition();
} else {
// TODO!
scope = new AccessCertificationAssignmentReviewScopeType(prismContext);
campaign.setScopeDefinition(scope);
}
Class<? extends ObjectType> focusClass = focus.asObjectable().getClass();
scope.setObjectType(ObjectTypes.getObjectType(focusClass).getTypeQName());
ObjectFilter objectFilter = QueryBuilder.queryFor(focusClass, prismContext).id(focus.getOid()).buildFilter();
scope.setSearchFilter(QueryConvertor.createSearchFilterType(objectFilter, prismContext));
return campaign;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method getDeltasToCreateCases.
<F extends FocusType> List<ItemDelta<?, ?>> getDeltasToCreateCases(final AccessCertificationCampaignType campaign, AccessCertificationStageType stage, final CertificationHandler handler, final Task task, final OperationResult result) throws SchemaException, ObjectNotFoundException {
final List<ItemDelta<?, ?>> rv = new ArrayList<>();
final String campaignShortName = toShortString(campaign);
final AccessCertificationScopeType scope = campaign.getScopeDefinition();
LOGGER.trace("Creating cases for scope {} in campaign {}", scope, campaignShortName);
if (scope != null && !(scope instanceof AccessCertificationObjectBasedScopeType)) {
throw new IllegalStateException("Unsupported access certification scope type: " + scope.getClass() + " for campaign " + campaignShortName);
}
final AccessCertificationObjectBasedScopeType objectBasedScope = (AccessCertificationObjectBasedScopeType) scope;
final List<AccessCertificationCaseType> existingCases = queryHelper.searchCases(campaign.getOid(), null, null, result);
if (!existingCases.isEmpty()) {
throw new IllegalStateException("Unexpected " + existingCases.size() + " certification case(s) in campaign object " + campaignShortName + ". At this time there should be none.");
}
// create a query to find target objects from which certification cases will be created
final ObjectQuery query = new ObjectQuery();
final QName scopeDeclaredObjectType;
if (objectBasedScope != null) {
scopeDeclaredObjectType = objectBasedScope.getObjectType();
} else {
scopeDeclaredObjectType = null;
}
final QName objectType;
if (scopeDeclaredObjectType != null) {
objectType = scopeDeclaredObjectType;
} else {
objectType = handler.getDefaultObjectType();
}
if (objectType == null) {
throw new IllegalStateException("Unspecified object type (and no default one provided) for campaign " + campaignShortName);
}
@SuppressWarnings({ "unchecked", "raw" }) final Class<F> objectClass = (Class<F>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
if (objectClass == null) {
throw new IllegalStateException("Object class not found for object type " + objectType + " in campaign " + campaignShortName);
}
final SearchFilterType searchFilter = objectBasedScope != null ? objectBasedScope.getSearchFilter() : null;
if (searchFilter != null) {
ObjectFilter filter = QueryConvertor.parseFilter(searchFilter, objectClass, prismContext);
query.setFilter(filter);
}
final List<AccessCertificationCaseType> caseList = new ArrayList<>();
// create certification cases by executing the query and caseExpression on its results
// here the subclasses of this class come into play
ResultHandler<F> resultHandler = (object, parentResult) -> {
try {
caseList.addAll(handler.createCasesForObject(object, campaign, task, parentResult));
} catch (ExpressionEvaluationException | ObjectNotFoundException | SchemaException e) {
// TODO process the exception more intelligently
throw new SystemException("Cannot create certification case for object " + toShortString(object.asObjectable()) + ": " + e.getMessage(), e);
}
return true;
};
repositoryService.searchObjectsIterative(objectClass, query, resultHandler, null, false, result);
AccessCertificationReviewerSpecificationType reviewerSpec = reviewersHelper.findReviewersSpecification(campaign, 1, task, result);
ContainerDelta<AccessCertificationCaseType> caseDelta = ContainerDelta.createDelta(F_CASE, AccessCertificationCampaignType.class, prismContext);
for (AccessCertificationCaseType _case : caseList) {
_case.setStageNumber(1);
_case.setCurrentStageCreateTimestamp(stage.getStartTimestamp());
_case.setCurrentStageDeadline(stage.getDeadline());
List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(_case, campaign, reviewerSpec, task, result);
_case.getWorkItem().addAll(createWorkItems(reviewers, 1));
String currentStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, 1));
_case.setCurrentStageOutcome(currentStageOutcome);
_case.setOutcome(OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, currentStageOutcome)));
@SuppressWarnings({ "raw", "unchecked" }) PrismContainerValue<AccessCertificationCaseType> caseCVal = _case.asPrismContainerValue();
caseDelta.addValueToAdd(caseCVal);
LOGGER.trace("Adding certification case:\n{}", caseCVal.debugDumpLazily());
}
rv.add(caseDelta);
LOGGER.trace("Created {} deltas to create {} cases for campaign {}", rv.size(), caseList.size(), campaignShortName);
return rv;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class ShadowRefreshTaskHandler method createQuery.
@Override
protected ObjectQuery createQuery(AbstractScannerResultHandler<ShadowType> handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException {
ObjectQuery query = new ObjectQuery();
ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext).exists(ShadowType.F_PENDING_OPERATION).buildFilter();
query.setFilter(filter);
return query;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class TestFilterExpression method test152EvaluateExpressionEmployeeTypeDefaultsCaptain.
@Test
public void test152EvaluateExpressionEmployeeTypeDefaultsCaptain() throws Exception {
final String TEST_NAME = "test152EvaluateExpressionEmployeeTypeDefaultsCaptain";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestFilterExpression.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectFilter filter = evaluateExpressionAssertFilter("expression-employeeType-filter-defaults.xml", "CAPTAIN", EqualFilter.class, task, result);
EqualFilter equalFilter = (EqualFilter) filter;
PrismAsserts.assertValues("Wrong values in filter", equalFilter.getValues(), "CAPTAIN");
executeFilter(filter, 1, task, result);
}
Aggregations