use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class AbstractModelImplementationIntegrationTest method fillContextWithAccount.
protected LensProjectionContext fillContextWithAccount(LensContext<UserType> context, PrismObject<ShadowType> account, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ShadowType accountType = account.asObjectable();
String resourceOid = accountType.getResourceRef().getOid();
ResourceType resourceType = provisioningService.getObject(ResourceType.class, resourceOid, null, task, result).asObjectable();
applyResourceSchema(accountType, resourceType);
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(resourceOid, ShadowKindType.ACCOUNT, ShadowUtil.getIntent(accountType));
LensProjectionContext accountSyncContext = context.findOrCreateProjectionContext(rat);
accountSyncContext.setOid(account.getOid());
accountSyncContext.setLoadedObject(account);
accountSyncContext.setResource(resourceType);
accountSyncContext.setExists(true);
context.rememberResource(resourceType);
return accountSyncContext;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class AssignmentProcessor method evaluateConstructions.
private <F extends FocusType> void evaluateConstructions(LensContext<F> context, Collection<EvaluatedAssignmentImpl<F>> evaluatedAssignments, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
if (evaluatedAssignments == null) {
return;
}
ObjectDeltaObject<F> focusOdo = null;
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
focusOdo = focusContext.getObjectDeltaObject();
}
Iterator<EvaluatedAssignmentImpl<F>> iterator = evaluatedAssignments.iterator();
while (iterator.hasNext()) {
EvaluatedAssignmentImpl<F> evaluatedAssignment = iterator.next();
try {
evaluatedAssignment.evaluateConstructions(focusOdo, context.getSystemConfiguration(), task, result);
} catch (ObjectNotFoundException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
iterator.remove();
if (!ModelExecuteOptions.isForce(context.getOptions())) {
ModelUtils.recordFatalError(result, ex);
}
} catch (SchemaException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
ModelUtils.recordFatalError(result, ex);
String resourceOid = FocusTypeUtil.determineConstructionResource(evaluatedAssignment.getAssignmentType());
if (resourceOid == null) {
// This is a role assignment or something like that. Just throw the original exception for now.
throw ex;
}
ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid, FocusTypeUtil.determineConstructionKind(evaluatedAssignment.getAssignmentType()), FocusTypeUtil.determineConstructionIntent(evaluatedAssignment.getAssignmentType()));
LensProjectionContext accCtx = context.findProjectionContext(rad);
if (accCtx != null) {
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
iterator.remove();
}
}
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class LensProjectionContext method fromLensProjectionContextType.
public static LensProjectionContext fromLensProjectionContextType(LensProjectionContextType projectionContextType, LensContext lensContext, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
String objectTypeClassString = projectionContextType.getObjectTypeClass();
if (StringUtils.isEmpty(objectTypeClassString)) {
throw new SystemException("Object type class is undefined in LensProjectionContextType");
}
ResourceShadowDiscriminator resourceShadowDiscriminator = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(projectionContextType.getResourceShadowDiscriminator());
LensProjectionContext projectionContext = new LensProjectionContext(lensContext, resourceShadowDiscriminator);
projectionContext.retrieveFromLensElementContextType(projectionContextType, task, result);
if (projectionContextType.getSyncDelta() != null) {
projectionContext.syncDelta = DeltaConvertor.createObjectDelta(projectionContextType.getSyncDelta(), lensContext.getPrismContext());
} else {
projectionContext.syncDelta = null;
}
ObjectDeltaType secondaryDeltaType = projectionContextType.getSecondaryDelta();
projectionContext.secondaryDelta = secondaryDeltaType != null ? (ObjectDelta) DeltaConvertor.createObjectDelta(secondaryDeltaType, lensContext.getPrismContext()) : null;
ObjectType object = projectionContextType.getObjectNew() != null ? projectionContextType.getObjectNew() : projectionContextType.getObjectOld();
projectionContext.fixProvisioningTypeInDelta(projectionContext.secondaryDelta, object, task, result);
projectionContext.wave = projectionContextType.getWave() != null ? projectionContextType.getWave() : 0;
projectionContext.fullShadow = projectionContextType.isFullShadow() != null ? projectionContextType.isFullShadow() : false;
projectionContext.isAssigned = projectionContextType.isIsAssigned() != null ? projectionContextType.isIsAssigned() : false;
projectionContext.isAssignedOld = projectionContextType.isIsAssignedOld() != null ? projectionContextType.isIsAssignedOld() : false;
projectionContext.isActive = projectionContextType.isIsActive() != null ? projectionContextType.isIsActive() : false;
projectionContext.isLegal = projectionContextType.isIsLegal();
projectionContext.isLegalOld = projectionContextType.isIsLegalOld();
projectionContext.isExists = projectionContextType.isIsExists() != null ? projectionContextType.isIsExists() : false;
projectionContext.synchronizationPolicyDecision = SynchronizationPolicyDecision.fromSynchronizationPolicyDecisionType(projectionContextType.getSynchronizationPolicyDecision());
projectionContext.doReconciliation = projectionContextType.isDoReconciliation() != null ? projectionContextType.isDoReconciliation() : false;
projectionContext.synchronizationSituationDetected = projectionContextType.getSynchronizationSituationDetected();
projectionContext.synchronizationSituationResolved = projectionContextType.getSynchronizationSituationResolved();
projectionContext.accountPasswordPolicy = projectionContextType.getAccountPasswordPolicy();
projectionContext.syncAbsoluteTrigger = projectionContextType.isSyncAbsoluteTrigger();
return projectionContext;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class LensUtil method findRelatedContexts.
/**
* Returns a list of context that have equivalent discriminator with the reference context. Ordered by "order" in the
* discriminator.
*/
public static <F extends ObjectType> List<LensProjectionContext> findRelatedContexts(LensContext<F> context, LensProjectionContext refProjCtx) {
List<LensProjectionContext> projCtxs = new ArrayList<LensProjectionContext>();
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
if (refDiscr == null) {
return projCtxs;
}
for (LensProjectionContext aProjCtx : context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr)) {
projCtxs.add(aProjCtx);
}
}
Comparator<? super LensProjectionContext> orderComparator = new Comparator<LensProjectionContext>() {
@Override
public int compare(LensProjectionContext ctx1, LensProjectionContext ctx2) {
int order1 = ctx1.getResourceShadowDiscriminator().getOrder();
int order2 = ctx2.getResourceShadowDiscriminator().getOrder();
return Integer.compare(order1, order2);
}
};
Collections.sort(projCtxs, orderComparator);
return projCtxs;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class TestSynchronizationService method test100AddedAccountJack.
@Test
public void test100AddedAccountJack() throws Exception {
final String TEST_NAME = "test100AddedAccountJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
assertLinks(userBefore, 0);
MockLensDebugListener mockListener = new MockLensDebugListener();
clockwork.setDebugListener(mockListener);
PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
accountShadowJackDummyOid = accountShadowJack.getOid();
provisioningService.applyDefinition(accountShadowJack, task, result);
assertNotNull("No oid in shadow", accountShadowJack.getOid());
DummyAccount dummyAccount = new DummyAccount();
dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
dummyAccount.setPassword("deadMenTellNoTales");
dummyAccount.setEnabled(true);
dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
getDummyResource().addAccount(dummyAccount);
display("Dummy resource before", getDummyResource());
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setCurrentShadow(accountShadowJack);
change.setResource(getDummyResourceObject());
// WHEN
synchronizationService.notifyChange(change, task, result);
// THEN
LensContext<UserType> context = mockListener.getLastSyncContext();
display("Resulting context (as seen by debug listener)", context);
assertNotNull("No resulting context (as seen by debug listener)", context);
assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
LensProjectionContext accCtx = context.findProjectionContext(rat);
assertNotNull("No account sync context for " + rat, accCtx);
assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
//it this really expected?? delta was already executed, should we expect it in the secondary delta?
// assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
// assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
assertIteration(shadow, 0, "");
assertSituation(shadow, SynchronizationSituationType.LINKED);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
assertLinks(userAfter, 1);
assertLinked(userAfter, shadow);
}
Aggregations