use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolve.
PrismObject<ShadowType> resolve(ProvisioningContext ctx, ResourceObjectReferenceType resourceObjectReference, QName objectClass, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (resourceObjectReference == null) {
return null;
}
ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
if (shadowRef != null && shadowRef.getOid() != null) {
if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
return shadow;
}
} else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
}
if (resourceObjectReference.getObjectClass() != null) {
objectClass = resourceObjectReference.getObjectClass();
if (objectClass.getNamespaceURI() == null) {
objectClass = new QName(ResourceTypeUtil.getResourceNamespace(ctx.getResource()), objectClass.getLocalPart());
}
}
ProvisioningContext subctx = ctx.spawn(objectClass);
// Use "raw" definitions from the original schema to avoid endless loops
subctx.setUseRefinedDefinition(false);
subctx.assertDefinition();
ObjectQuery refQuery = QueryJaxbConvertor.createObjectQuery(ShadowType.class, resourceObjectReference.getFilter(), prismContext);
ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClass, prismContext);
ObjectFilter filter = AndFilter.createAnd(baseFilter, refQuery.getFilter());
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
// TODO: implement "repo" search strategies
Collection<SelectorOptions<GetOperationOptions>> options = null;
final Holder<ShadowType> shadowHolder = new Holder<>();
ShadowHandler<ShadowType> handler = new ShadowHandler<ShadowType>() {
@Override
public boolean handle(ShadowType shadow) {
if (shadowHolder.getValue() != null) {
throw new IllegalStateException("More than one search results for " + desc);
}
shadowHolder.setValue(shadow);
return true;
}
};
shadowCache.searchObjectsIterative(subctx, query, options, handler, true, result);
// TODO: implement storage of OID (ONCE search frequency)
ShadowType shadowType = shadowHolder.getValue();
return shadowType == null ? null : shadowType.asPrismObject();
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test103GetAccountNoFetch.
@Test
public void test103GetAccountNoFetch() throws Exception {
final String TEST_NAME = "test103GetAccountNoFetch";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
rememberShadowFetchOperationCount();
GetOperationOptions rootOptions = new GetOperationOptions();
rootOptions.setNoFetch(true);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result);
// THEN
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
assertShadowFetchOperationCountIncrement(0);
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
checkAccountShadow(shadow, result, false, startTs, endTs);
// This is noFetch. Therefore the read should NOT update the caching timestamp
checkRepoAccountShadowWill(shadow, null, startTs);
checkConsistency(shadow);
assertSteadyResource();
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test015ListResourcesNoFetch.
/**
* List resources with noFetch option. This is what GUI does. This operation
* should be harmless and should not change resource state.
*/
@Test
public void test015ListResourcesNoFetch() throws Exception {
final String TEST_NAME = "test015ListResourcesNoFetch";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
// WHEN
SearchResultList<PrismObject<ResourceType>> resources = provisioningService.searchObjects(ResourceType.class, null, options, task, result);
// THEN
result.computeStatus();
display("searchObjects result", result);
TestUtil.assertSuccess(result);
assertFalse("No resources found", resources.isEmpty());
for (PrismObject<ResourceType> resource : resources) {
ResourceType resourceType = resource.asObjectable();
display("Found resource " + resourceType, resourceType);
display("XML " + resourceType, PrismTestUtil.serializeObjectToString(resource, PrismContext.LANG_XML));
XmlSchemaType xmlSchemaType = resourceType.getSchema();
if (xmlSchemaType != null) {
Element xsdSchemaElement = ResourceTypeUtil.getResourceXsdSchema(resourceType);
assertNull("Found schema in " + resource, xsdSchemaElement);
}
}
assertConnectorSchemaParseIncrement(1);
assertConnectorCapabilitiesFetchIncrement(0);
assertConnectorInitializationCountIncrement(0);
assertResourceSchemaFetchIncrement(0);
assertResourceSchemaParseCountIncrement(0);
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class TestBrokenResources method test101GetAccountMurrayNoFetch.
@Test
public void test101GetAccountMurrayNoFetch() throws Exception {
final String TEST_NAME = "test101GetAccountMurrayNoFetch";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
// WHEN
PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, ACCOUNT_SHADOW_MURRAY_CSVFILE_OID, options, task, result);
display("getObject account", account);
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess("getObject result", result);
// TODO: better asserts
assertNotNull("Null resource", account);
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class TestBrokenResources method test221GetResourceNotFoundResolveConnector.
@Test
public void test221GetResourceNotFoundResolveConnector() throws Exception {
final String TEST_NAME = "test221GetResourceNotFoundResolveConnector";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestBrokenResources.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ResourceType.F_CONNECTOR_REF, GetOperationOptions.createResolve());
// WHEN
PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_CSVFILE_NOTFOUND_OID, options, task, result);
// THEN
display("getObject resource", resource);
result.computeStatus();
display("getObject result", result);
assertEquals("Expected partial errror in result", OperationResultStatus.PARTIAL_ERROR, result.getStatus());
OperationResultType fetchResult = resource.asObjectable().getFetchResult();
display("resource.fetchResult", fetchResult);
assertEquals("Expected partial errror in fetchResult", OperationResultStatusType.PARTIAL_ERROR, fetchResult.getStatus());
// TODO: better asserts
assertNotNull("Null resource", resource);
assertNotNull("Connector was not resolved", resource.asObjectable().getConnector());
}
Aggregations