use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class TestUtil method setAttribute.
public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException {
PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES);
ResourceAttributeDefinition attrDef = new ResourceAttributeDefinitionImpl(attrName, typeName, prismContext);
ResourceAttribute attribute = attrDef.instantiate();
attribute.setRealValue(value);
attributesContainer.add(attribute);
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class TestRefinedSchema method testApplyAttributeDefinition.
@Test
public void testApplyAttributeDefinition() throws JAXBException, SchemaException, SAXException, IOException {
System.out.println("\n===[ testApplyAttributeDefinition ]===\n");
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resource, prismContext);
RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
assertNotNull("No refined default account definition in " + rSchema, defaultAccountDefinition);
System.out.println("Refined account definition:");
System.out.println(defaultAccountDefinition.debugDump());
PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml"));
PrismContainer<Containerable> attributesContainer = accObject.findContainer(ShadowType.F_ATTRIBUTES);
System.out.println("Attributes container:");
System.out.println(attributesContainer.debugDump());
// WHEN
attributesContainer.applyDefinition((PrismContainerDefinition) defaultAccountDefinition.toResourceAttributeContainerDefinition(), true);
// THEN
System.out.println("Parsed account:");
System.out.println(accObject.debugDump());
assertAccountShadow(accObject, resource, prismContext);
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.
/**
* Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
*/
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (identifiers == null) {
return null;
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, ctx.getObjectClassDefinition());
PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
if (repoShadow == null) {
return null;
}
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
return null;
}
RefinedObjectClassDefinition ocDef = ctx.getObjectClassDefinition();
Collection primaryIdentifiers = new ArrayList<>();
for (PrismProperty<?> property : attributesContainer.getValue().getProperties()) {
if (ocDef.isPrimaryIdentifier(property.getElementName())) {
RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName());
ResourceAttribute<?> primaryIdentifier = new ResourceAttribute<>(property.getElementName(), attrDef, prismContext);
primaryIdentifier.setRealValue(property.getRealValue());
primaryIdentifiers.add(primaryIdentifier);
}
}
LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, ocDef);
return primaryIdentifiers;
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test030ResourceAndConnectorCaching.
@Test
public void test030ResourceAndConnectorCaching() throws Exception {
TestUtil.displayTestTile("test030ResourceAndConnectorCaching");
// GIVEN
OperationResult result = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching");
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
assertNotNull("No resource schema", resourceSchema);
// WHEN
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
// Check resource schema caching
ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
// Check capabilities caching
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
assertNotNull("No capabilities fetched from provisioning", capabilitiesType);
CachingMetadataType capCachingMetadataType = capabilitiesType.getCachingMetadata();
assertNotNull("No capabilities caching metadata fetched from provisioning", capCachingMetadataType);
CachingMetadataType capCachingMetadataTypeAgain = resourceTypeAgain.getCapabilities().getCachingMetadata();
assertEquals("Capabilities caching metadata serial number has changed", capCachingMetadataType.getSerialNumber(), capCachingMetadataTypeAgain.getSerialNumber());
assertEquals("Capabilities caching metadata timestamp has changed", capCachingMetadataType.getRetrievalTimestamp(), capCachingMetadataTypeAgain.getRetrievalTimestamp());
// Rough test if everything is fine
resource.asObjectable().setFetchResult(null);
resourceAgain.asObjectable().setFetchResult(null);
ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resource, resourceAgain);
display("Dummy resource diff", dummyResourceDiff);
assertTrue("The resource read again is not the same as the original. diff:" + dummyResourceDiff, dummyResourceDiff.isEmpty());
// Now we stick our nose deep inside the provisioning impl. But we need
// to make sure that the
// configured connector is properly cached
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
// Check if the connector still works.
OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching.test");
configuredConnectorInstanceAgain.test(testResult);
testResult.computeStatus();
TestUtil.assertSuccess("Connector test failed", testResult);
// Test connection should also refresh the connector by itself. So check if it has been refreshed
ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest);
assertTrue("Connector instance was not cached", configuredConnectorInstanceAgain == configuredConnectorInstanceAfterTest);
assertSteadyResource();
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test031ResourceAndConnectorCachingForceFresh.
@Test
public void test031ResourceAndConnectorCachingForceFresh() throws Exception {
TestUtil.displayTestTile("test031ResourceAndConnectorCachingForceFresh");
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + ".test011ResourceAndConnectorCachingForceFresh");
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
assertNotNull("No resource schema", resourceSchema);
// WHEN
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
// Now we stick our nose deep inside the provisioning impl. But we need
// to make sure that the configured connector is properly refreshed
// forceFresh = true
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, true, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
assertFalse("Connector instance was not refreshed", configuredConnectorInstance == configuredConnectorInstanceAgain);
// Check if the connector still works
OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test011ResourceAndConnectorCachingForceFresh.test");
configuredConnectorInstanceAgain.test(testResult);
testResult.computeStatus();
TestUtil.assertSuccess("Connector test failed", testResult);
assertConnectorInitializationCountIncrement(1);
rememberConnectorInstance(configuredConnectorInstanceAgain);
assertSteadyResource();
}
Aggregations