use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ConsistencyTest method test800Reconciliation.
// This should run last. It starts a task that may interfere with other tests
@Test
public void test800Reconciliation() throws Exception {
final String TEST_NAME = "test800Reconciliation";
TestUtil.displayTestTile(this, TEST_NAME);
openDJController.assumeRunning();
final OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
// TODO: remove this if the previous test is enabled
// openDJController.start();
// rename eobject dirrectly on resource before the recon start ..it tests the rename + recon situation (MID-1594)
// precondition
assertTrue(EmbeddedUtils.isRunning());
UserType userJack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result).asObjectable();
display("Jack before", userJack);
LOGGER.info("start running task");
// WHEN
repoAddObjectFromFile(TASK_OPENDJ_RECONCILIATION_FILENAME, result);
verbose = true;
long started = System.currentTimeMillis();
waitForTaskNextRunAssertSuccess(TASK_OPENDJ_RECONCILIATION_OID, false, 120000);
LOGGER.info("Reconciliation task run took {} seconds", (System.currentTimeMillis() - started) / 1000L);
// THEN
// STOP the task. We don't need it any more. Even if it's non-recurrent its safer to delete it
taskManager.deleteTask(TASK_OPENDJ_RECONCILIATION_OID, result);
// check if the account was added after reconciliation
UserType userE = repositoryService.getObject(UserType.class, USER_E_OID, null, result).asObjectable();
String accountOid = assertUserOneAccountRef(USER_E_OID);
ShadowType eAccount = checkNormalizedShadowWithAttributes(accountOid, "e", "Jackkk", "e", "e", true, null, result);
assertAttribute(eAccount, "employeeNumber", "emp4321");
ResourceAttributeContainer attributeContainer = ShadowUtil.getAttributesContainer(eAccount);
Collection<ResourceAttribute<?>> identifiers = attributeContainer.getPrimaryIdentifiers();
assertNotNull(identifiers);
assertFalse(identifiers.isEmpty());
assertEquals(1, identifiers.size());
// check if the account was modified during reconciliation process
String jackAccountOid = assertUserOneAccountRef(USER_JACK_OID);
ShadowType modifiedAccount = checkNormalizedShadowBasic(jackAccountOid, "jack", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
assertAttribute(modifiedAccount, "givenName", "Jackkk");
assertAttribute(modifiedAccount, "employeeNumber", "emp4321");
// check if the account was deleted during the reconciliation process
try {
modelService.getObject(ShadowType.class, ACCOUNT_DENIELS_OID, null, null, result);
fail("Expected ObjectNotFoundException but haven't got one.");
} catch (Exception ex) {
if (!(ex instanceof ObjectNotFoundException)) {
fail("Expected ObjectNotFoundException but got " + ex);
}
}
String elaineAccountOid = assertUserOneAccountRef(USER_ELAINE_OID);
modifiedAccount = checkNormalizedShadowBasic(elaineAccountOid, "elaine", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
assertAttribute(modifiedAccount, getOpenDjSecondaryIdentifierQName(), "uid=elaine,ou=people,dc=example,dc=com");
accountOid = assertUserOneAccountRef(USER_JACK2_OID);
ShadowType jack2Shadow = checkNormalizedShadowBasic(accountOid, "jack2", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
assertAttribute(jack2Shadow, "givenName", "jackNew2a");
assertAttribute(jack2Shadow, "cn", "jackNew2a");
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ConsistencyTest method test801TestReconciliationRename.
@Test
public void test801TestReconciliationRename() throws Exception {
final String TEST_NAME = "test801TestReconciliationRename";
TestUtil.displayTestTile(this, TEST_NAME);
openDJController.assumeRunning();
Task task = createTask(TEST_NAME);
final OperationResult result = task.getResult();
LOGGER.info("starting rename");
openDJController.executeRenameChange(LDIF_MODIFY_RENAME_FILENAME);
LOGGER.info("rename ended");
// Entry res = openDJController.searchByUid("e");
// LOGGER.info("E OBJECT AFTER RENAME " + res.toString());
LOGGER.info("start running task");
// WHEN
long started = System.currentTimeMillis();
repoAddObjectFromFile(TASK_OPENDJ_RECONCILIATION_FILENAME, result);
waitForTaskFinish(TASK_OPENDJ_RECONCILIATION_OID, false, 120000);
LOGGER.info("Reconciliation task run took {} seconds", (System.currentTimeMillis() - started) / 1000L);
// THEN
// STOP the task. We don't need it any more. Even if it's non-recurrent its safer to delete it
taskManager.deleteTask(TASK_OPENDJ_RECONCILIATION_OID, result);
// check if the account was added after reconciliation
UserType userE = repositoryService.getObject(UserType.class, USER_E_OID, null, result).asObjectable();
String accountOid = assertUserOneAccountRef(USER_E_OID);
ShadowType eAccount = checkNormalizedShadowWithAttributes(accountOid, "e123", "Jackkk", "e", "e", true, null, result);
assertAttribute(eAccount, "employeeNumber", "emp4321");
ResourceAttributeContainer attributeContainer = ShadowUtil.getAttributesContainer(eAccount);
Collection<ResourceAttribute<?>> identifiers = attributeContainer.getPrimaryIdentifiers();
assertNotNull(identifiers);
assertFalse(identifiers.isEmpty());
assertEquals(1, identifiers.size());
ResourceAttribute icfNameAttr = attributeContainer.findAttribute(getOpenDjSecondaryIdentifierQName());
assertEquals("Wrong secondary indetifier.", "uid=e123,ou=people,dc=example,dc=com", icfNameAttr.getRealValue());
assertEquals("Wrong shadow name. ", "uid=e123,ou=people,dc=example,dc=com", eAccount.getName().getOrig());
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
provisioningService.applyDefinition(repoShadow, task, result);
ResourceAttributeContainer repoAttributeContainer = ShadowUtil.getAttributesContainer(repoShadow);
ResourceAttribute repoIcfNameAttr = repoAttributeContainer.findAttribute(getOpenDjSecondaryIdentifierQName());
assertEquals("Wrong secondary indetifier.", "uid=e123,ou=people,dc=example,dc=com", repoIcfNameAttr.getRealValue());
assertEquals("Wrong shadow name. ", "uid=e123,ou=people,dc=example,dc=com", repoShadow.asObjectable().getName().getOrig());
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createAccount.
protected PrismObject<ShadowType> createAccount(PrismObject<ResourceType> resource, String name, boolean enabled) throws SchemaException {
PrismObject<ShadowType> shadow = getShadowDefinition().instantiate();
ShadowType shadowType = shadow.asObjectable();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(resource.getOid());
shadowType.setResourceRef(resourceRef);
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
shadowType.setObjectClass(objectClassDefinition.getTypeName());
shadowType.setKind(ShadowKindType.ACCOUNT);
ResourceAttributeContainer attrCont = ShadowUtil.getOrCreateAttributesContainer(shadow, objectClassDefinition);
RefinedAttributeDefinition idSecondaryDef = objectClassDefinition.getSecondaryIdentifiers().iterator().next();
ResourceAttribute icfsNameAttr = idSecondaryDef.instantiate();
icfsNameAttr.setRealValue(name);
attrCont.add(icfsNameAttr);
ActivationType activation = new ActivationType();
shadowType.setActivation(activation);
if (enabled) {
activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
} else {
activation.setAdministrativeStatus(ActivationStatusType.DISABLED);
}
return shadow;
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ShadowManager method searchShadowByIdenifiers.
private List<PrismObject<ShadowType>> searchShadowByIdenifiers(ProvisioningContext ctx, Change change, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
Collection<ResourceAttribute<?>> identifiers = change.getIdentifiers();
ObjectQuery query = createSearchShadowQuery(ctx, identifiers, true, prismContext, parentResult);
List<PrismObject<ShadowType>> accountList = null;
try {
accountList = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
} catch (SchemaException ex) {
parentResult.recordFatalError("Failed to search shadow according to the identifiers: " + identifiers + ". Reason: " + ex.getMessage(), ex);
throw new SchemaException("Failed to search shadow according to the identifiers: " + identifiers + ". Reason: " + ex.getMessage(), ex);
}
MiscSchemaUtil.reduceSearchResult(accountList);
return accountList;
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolvePrimaryIdentifiers.
/**
* Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
*/
private ResourceObjectIdentification resolvePrimaryIdentifiers(ProvisioningContext ctx, ResourceObjectIdentification identification, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (identification == null) {
return identification;
}
if (identification.hasPrimaryIdentifiers()) {
return identification;
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = (Collection<ResourceAttribute<?>>) identification.getSecondaryIdentifiers();
PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
if (repoShadow == null) {
// TODO: we should attempt resource search here
throw new ObjectNotFoundException("No repository shadow for " + secondaryIdentifiers + ", cannot resolve identifiers");
}
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
throw new SchemaException("No attributes in " + repoShadow + ", cannot resolve identifiers " + secondaryIdentifiers);
}
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 {} to primary identifiers {} (object class {})", identification, primaryIdentifiers, ocDef);
return new ResourceObjectIdentification(identification.getObjectClassDefinition(), primaryIdentifiers, identification.getSecondaryIdentifiers());
}
Aggregations