use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.
the class ShadowManager method createSearchShadowQuery.
private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, PrismContext prismContext, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceShadow);
PrismProperty identifier = attributesContainer.getPrimaryIdentifier();
Collection<PrismPropertyValue<Object>> idValues = identifier.getValues();
// Only one value is supported for an identifier
if (idValues.size() > 1) {
// TODO: This should probably be switched to checked exception later
throw new IllegalArgumentException("More than one identifier value is not supported");
}
if (idValues.size() < 1) {
// TODO: This should probably be switched to checked exception later
throw new IllegalArgumentException("The identifier has no value");
}
// We have all the data, we can construct the filter now
try {
// TODO TODO TODO TODO: set matching rule instead of null
PrismPropertyDefinition def = identifier.getDefinition();
return QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getName()).eq(getNormalizedValue(identifier, ctx.getObjectClassDefinition())).and().item(ShadowType.F_OBJECT_CLASS).eq(resourceShadow.getPropertyRealValue(ShadowType.F_OBJECT_CLASS, QName.class)).and().item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
} catch (SchemaException e) {
throw new SchemaException("Schema error while creating search filter: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method addAttributeToShadow.
protected <T> void addAttributeToShadow(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, String attrName, T attrValue) throws SchemaException {
ResourceAttributeContainer attrs = ShadowUtil.getAttributesContainer(shadow);
ResourceAttributeDefinition attrSnDef = attrs.getDefinition().findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resource), attrName));
ResourceAttribute<T> attr = attrSnDef.instantiate();
attr.setRealValue(attrValue);
attrs.add(attr);
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.
the class TestDummy method testLiveSyncDeleteCorsairs.
public void testLiveSyncDeleteCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
syncServiceMock.reset();
dummyResource.setSyncStyle(syncStyle);
if (isNameUnique()) {
dummyResource.deleteGroupByName(GROUP_CORSAIRS_NAME);
} else {
dummyResource.deleteGroupById(corsairsIcfUid);
}
display("Resource before sync", dummyResource.debugDump());
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.synchronize(coords, syncTokenTask, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("Synchronization result", result);
TestUtil.assertSuccess("Synchronization result is not OK", result);
if (expectReaction) {
syncServiceMock.assertNotifyChange();
ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
display("The change", lastChange);
PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
assertNotNull("Old shadow missing", oldShadow);
assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
ShadowType oldShadowType = oldShadow.asObjectable();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
assertNotNull("No attributes container in old shadow", attributesContainer);
Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
assertFalse("Attributes container is empty", attributes.isEmpty());
assertEquals("Unexpected number of attributes", 2, attributes.size());
ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
assertNotNull("No ICF name attribute in old shadow", icfsNameAttribute);
assertEquals("Wrong value of ICF name attribute in old shadow", GROUP_CORSAIRS_NAME, icfsNameAttribute.getRealValue());
ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
assertNotNull("Delta missing", objectDelta);
assertEquals("Wrong delta changetype", ChangeType.DELETE, objectDelta.getChangeType());
PrismAsserts.assertClass("delta", ShadowType.class, objectDelta);
assertNotNull("No OID in delta", objectDelta.getOid());
assertNull("Unexpected current shadow", lastChange.getCurrentShadow());
try {
// The shadow should be gone
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
} catch (ObjectNotFoundException e) {
// This is expected
}
} else {
syncServiceMock.assertNoNotifyChange();
}
checkAllShadows();
assertSteadyResource();
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.
the class TestDummy method testLiveSyncAddCorsairs.
public void testLiveSyncAddCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
syncServiceMock.reset();
dummyResource.setSyncStyle(syncStyle);
DummyGroup newGroup = new DummyGroup(GROUP_CORSAIRS_NAME);
newGroup.setEnabled(true);
dummyResource.addGroup(newGroup);
corsairsIcfUid = newGroup.getId();
display("Resource before sync", dummyResource.debugDump());
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.synchronize(coords, syncTokenTask, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("Synchronization result", result);
TestUtil.assertSuccess("Synchronization result is not OK", result);
if (expectReaction) {
syncServiceMock.assertNotifyChange();
ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
display("The change", lastChange);
PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
assertNotNull("Old shadow missing", oldShadow);
assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
if (syncStyle == DummySyncStyle.DUMB) {
assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
} else {
ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
assertNotNull("Delta present when not expecting it", objectDelta);
assertTrue("Delta is not add: " + objectDelta, objectDelta.isAdd());
}
ShadowType currentShadowType = lastChange.getCurrentShadow().asObjectable();
assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
PrismAsserts.assertClass("current shadow", ShadowType.class, currentShadowType);
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadowType);
assertNotNull("No attributes container in current shadow", attributesContainer);
Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
assertFalse("Attributes container is empty", attributes.isEmpty());
assertEquals("Unexpected number of attributes", 2, attributes.size());
corsairsShadowOid = currentShadowType.getOid();
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
display("Corsairs repo shadow", repoShadow);
PrismObject<ShadowType> accountRepo = findShadowByName(new QName(RESOURCE_DUMMY_NS, SchemaConstants.GROUP_OBJECT_CLASS_LOCAL_NAME), GROUP_CORSAIRS_NAME, resource, result);
assertNotNull("Shadow was not created in the repository", accountRepo);
display("Repository shadow", accountRepo);
ProvisioningTestUtil.checkRepoShadow(repoShadow, ShadowKindType.ENTITLEMENT);
} else {
syncServiceMock.assertNoNotifyChange();
}
checkAllShadows();
assertSteadyResource();
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.
the class TestDummy method assertSyncOldShadow.
protected void assertSyncOldShadow(PrismObject<? extends ShadowType> oldShadow, String repoName, Integer expectedNumberOfAttributes) {
assertNotNull("Old shadow missing", oldShadow);
assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
ShadowType oldShadowType = oldShadow.asObjectable();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
assertNotNull("No attributes container in old shadow", attributesContainer);
Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
assertFalse("Attributes container is empty", attributes.isEmpty());
if (expectedNumberOfAttributes != null) {
assertEquals("Unexpected number of attributes", (int) expectedNumberOfAttributes, attributes.size());
}
ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
assertNotNull("No ICF name attribute in old shadow", icfsNameAttribute);
assertEquals("Wrong value of ICF name attribute in old shadow", repoName, icfsNameAttribute.getRealValue());
}
Aggregations