use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class Construction method evaluateKindIntentObjectClass.
private void evaluateKindIntentObjectClass(Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
String resourceOid = null;
if (getConstructionType().getResourceRef() != null) {
resourceOid = getConstructionType().getResourceRef().getOid();
}
if (getConstructionType().getResource() != null) {
resourceOid = getConstructionType().getResource().getOid();
}
ResourceType resource = getResource(task, result);
if (resourceOid != null && !resource.getOid().equals(resourceOid)) {
throw new IllegalStateException("The specified resource and the resource in construction does not match");
}
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, getPrismContext());
if (refinedSchema == null) {
// Refined schema may be null in some error-related border cases
throw new SchemaException("No (refined) schema for " + resource);
}
ShadowKindType kind = getConstructionType().getKind();
if (kind == null) {
kind = ShadowKindType.ACCOUNT;
}
refinedObjectClassDefinition = refinedSchema.getRefinedDefinition(kind, getConstructionType().getIntent());
if (refinedObjectClassDefinition == null) {
if (getConstructionType().getIntent() != null) {
throw new SchemaException("No " + kind + " type '" + getConstructionType().getIntent() + "' found in " + getResource(task, result) + " as specified in construction in " + getSource());
} else {
throw new SchemaException("No default " + kind + " type found in " + resource + " as specified in construction in " + getSource());
}
}
auxiliaryObjectClassDefinitions = new ArrayList<>(getConstructionType().getAuxiliaryObjectClass().size());
for (QName auxiliaryObjectClassName : getConstructionType().getAuxiliaryObjectClass()) {
RefinedObjectClassDefinition auxOcDef = refinedSchema.getRefinedDefinition(auxiliaryObjectClassName);
if (auxOcDef == null) {
throw new SchemaException("No auxiliary object class " + auxiliaryObjectClassName + " found in " + getResource(task, result) + " as specified in construction in " + getSource());
}
auxiliaryObjectClassDefinitions.add(auxOcDef);
}
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class SynchronizeAccountResultHandler method handleObjectInternal.
protected boolean handleObjectInternal(PrismObject<ShadowType> accountShadow, Task workerTask, OperationResult result) {
ShadowType newShadowType = accountShadow.asObjectable();
if (newShadowType.isProtectedObject() != null && newShadowType.isProtectedObject()) {
LOGGER.trace("{} skipping {} because it is protected", new Object[] { getProcessShortNameCapitalized(), accountShadow });
result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Skipped because it is protected");
return true;
}
if (objectClass != null && (objectClass instanceof RefinedObjectClassDefinition) && !((RefinedObjectClassDefinition) objectClass).matches(newShadowType)) {
LOGGER.trace("{} skipping {} because it does not match objectClass/kind/intent", new Object[] { getProcessShortNameCapitalized(), accountShadow });
result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Skipped because it does not match objectClass/kind/intent");
return true;
}
if (objectChangeListener == null) {
LOGGER.warn("No object change listener set for {} task, ending the task", getProcessShortName());
result.recordFatalError("No object change listener set for " + getProcessShortName() + " task, ending the task");
return false;
}
// We are going to pretend that all of the objects were just created.
// That will efficiently import them to the IDM repository
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setSourceChannel(QNameUtil.qNameToUri(sourceChannel));
change.setResource(getResourceWorkingCopy().asPrismObject());
if (forceAdd) {
// We should provide shadow in the state before the change. But we are
// pretending that it has
// not existed before, so we will not provide it.
ObjectDelta<ShadowType> shadowDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.ADD, accountShadow.getPrismContext());
//PrismObject<AccountShadowType> shadowToAdd = refinedAccountDefinition.getObjectDefinition().parseObjectType(newShadowType);
PrismObject<ShadowType> shadowToAdd = newShadowType.asPrismObject();
shadowDelta.setObjectToAdd(shadowToAdd);
shadowDelta.setOid(newShadowType.getOid());
change.setObjectDelta(shadowDelta);
// Need to also set current shadow. This will get reflected in "old" object in lens context
change.setCurrentShadow(accountShadow);
} else {
// No change, therefore the delta stays null. But we will set the current
change.setCurrentShadow(accountShadow);
}
try {
change.checkConsistence();
} catch (RuntimeException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Check consistence failed: {}\nChange:\n{}", ex, change.debugDump());
}
throw ex;
}
// Invoke the change notification
Utils.clearRequestee(workerTask);
objectChangeListener.notifyChange(change, workerTask, result);
return workerTask.canRun();
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ReconciliationTaskHandler method performShadowReconciliation.
// returns false in case of execution interruption
private boolean performShadowReconciliation(final PrismObject<ResourceType> resource, final ObjectClassComplexTypeDefinition objectclassDef, long startTimestamp, long endTimestamp, ReconciliationTaskResult reconResult, final Task task, OperationResult result) throws SchemaException {
boolean interrupted;
// find accounts
LOGGER.trace("Shadow reconciliation starting for {}, {} -> {}", new Object[] { resource, startTimestamp, endTimestamp });
OperationResult opResult = result.createSubresult(OperationConstants.RECONCILIATION + ".shadowReconciliation");
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).block().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).le(XmlTypeConverter.createXMLGregorianCalendar(startTimestamp)).or().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).isNull().endBlock().and().item(ShadowType.F_RESOURCE_REF).ref(ObjectTypeUtil.createObjectRef(resource).asReferenceValue()).and().item(ShadowType.F_OBJECT_CLASS).eq(objectclassDef.getTypeName()).build();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Shadow recon query:\n{}", query.debugDump());
}
long started = System.currentTimeMillis();
final Holder<Long> countHolder = new Holder<Long>(0L);
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
if ((objectclassDef instanceof RefinedObjectClassDefinition) && !((RefinedObjectClassDefinition) objectclassDef).matches(shadow.asObjectable())) {
return true;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Shadow reconciliation of {}, fullSynchronizationTimestamp={}", shadow, shadow.asObjectable().getFullSynchronizationTimestamp());
}
long started = System.currentTimeMillis();
PrismObject<ShadowType> resourceShadow = null;
try {
task.recordIterativeOperationStart(shadow.asObjectable());
resourceShadow = reconcileShadow(shadow, resource, task);
task.recordIterativeOperationEnd(shadow.asObjectable(), started, null);
} catch (Throwable t) {
task.recordIterativeOperationEnd(shadow.asObjectable(), started, t);
throw t;
}
if (ShadowUtil.isProtected(resourceShadow)) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Skipping recording counter for {} because it is protected", shadow);
}
return task.canRun();
}
countHolder.setValue(countHolder.getValue() + 1);
// reconcileShadow writes to its own dummy OperationResult, so we do the same here
incrementAndRecordProgress(task, new OperationResult("dummy"));
return task.canRun();
}
};
repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, true, opResult);
interrupted = !task.canRun();
// for each try the operation again
opResult.computeStatus();
LOGGER.trace("Shadow reconciliation finished, processed {} shadows for {}, result: {}", new Object[] { countHolder.getValue(), resource, opResult.getStatus() });
reconResult.setShadowReconCount(countHolder.getValue());
result.createSubresult(OperationConstants.RECONCILIATION + ".shadowReconciliation.statistics").recordStatus(OperationResultStatus.SUCCESS, "Processed " + countHolder.getValue() + " shadow(s) in " + (System.currentTimeMillis() - started) + " ms." + (interrupted ? " Was interrupted during processing." : ""));
return !interrupted;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class Utils method determineObjectClassInternal.
private static ObjectClassComplexTypeDefinition determineObjectClassInternal(RefinedResourceSchema refinedSchema, QName objectclass, ShadowKindType kind, String intent, Object source) throws SchemaException {
if (kind == null && intent == null && objectclass != null) {
// Return generic object class definition from resource schema. No kind/intent means that we want
// to process all kinds and intents in the object class.
ObjectClassComplexTypeDefinition objectClassDefinition = refinedSchema.findObjectClassDefinition(objectclass);
if (objectClassDefinition == null) {
throw new SchemaException("No object class " + objectclass + " in the schema for " + source);
}
return objectClassDefinition;
}
RefinedObjectClassDefinition refinedObjectClassDefinition;
if (kind != null) {
refinedObjectClassDefinition = refinedSchema.getRefinedDefinition(kind, intent);
LOGGER.trace("Determined refined object class {} by using kind={}, intent={}", new Object[] { refinedObjectClassDefinition, kind, intent });
} else if (objectclass != null) {
refinedObjectClassDefinition = refinedSchema.getRefinedDefinition(objectclass);
LOGGER.trace("Determined refined object class {} by using objectClass={}", new Object[] { refinedObjectClassDefinition, objectclass });
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.debug("No kind or objectclass specified in {}, assuming null object class", source);
}
refinedObjectClassDefinition = null;
}
return refinedObjectClassDefinition;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.
/**
* We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
*
*/
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
final String TEST_NAME = "test191ModifyUserJackModifyAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
//PrismPropertyDefinition definition = getAssignmentDefinition().findPropertyDefinition(new QName(SchemaConstantsGenerated.NS_COMMON, "accountConstruction"));
PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(dummyResource, prismContext);
// This explicitly parses the schema, therefore ...
assertResourceSchemaParseCountIncrement(1);
RefinedObjectClassDefinition accountDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
assertNotNull("gossip attribute definition not found", gossipDefinition);
ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
radt.setRef(new ItemPathType(new ItemPath(gossipDefinition.getName())));
MappingType outbound = new MappingType();
radt.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
MappingType value = new MappingType();
PrismProperty<String> property = gossipDefinition.instantiate();
property.add(new PrismPropertyValue<String>("q"));
List evaluators = expression.getExpressionEvaluator();
Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property, null);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> obj : collection) {
evaluators.add(of.createValue(obj.getValue()));
}
value.setExpression(expression);
radt.setOutbound(value);
accountConstruction.getAttribute().add(radt);
PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
deltas.add(accountAssignmentUserDelta);
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
display("User before change execution", userJackOld);
display("Deltas to execute execution", deltas);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
// First fetch: initial account read
// Second fetch: fetchback after modification to correctly process inbound
assertShadowFetchOperationCountIncrement(2);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
accountJackOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
display(dummyAccount.debugDump());
assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
//assertEquals("Missing or incorrect attribute value", "soda", dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, String.class));
assertDummyScriptsModify(userJack, true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
assertScriptCompileIncrement(0);
assertSteadyResources();
}
Aggregations