use of com.evolveum.midpoint.common.refinery.RefinedResourceSchema in project midpoint by Evolveum.
the class TestUnix method test010Schema.
@Test
public void test010Schema() throws Exception {
final String TEST_NAME = "test010Schema";
TestUtil.displayTestTile(this, TEST_NAME);
resourceOpenDj = getObject(ResourceType.class, RESOURCE_OPENDJ_OID);
resourceOpenDjType = resourceOpenDj.asObjectable();
IntegrationTestTools.displayXml("Initialized resource", resourceOpenDj);
ResourceSchema resourceSchema = RefinedResourceSchema.getResourceSchema(resourceOpenDj, prismContext);
display("OpenDJ schema (resource)", resourceSchema);
ObjectClassComplexTypeDefinition ocDefPosixAccount = resourceSchema.findObjectClassDefinition(OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME);
assertNotNull("No objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", ocDefPosixAccount);
assertTrue("Objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", ocDefPosixAccount.isAuxiliary());
ObjectClassComplexTypeDefinition ocDefPosixGroup = resourceSchema.findObjectClassDefinition(OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME);
assertNotNull("No objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", ocDefPosixGroup);
assertTrue("Objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", ocDefPosixGroup.isAuxiliary());
RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resourceOpenDj);
display("OpenDJ schema (refined)", refinedSchema);
RefinedObjectClassDefinition rOcDefPosixAccount = refinedSchema.getRefinedDefinition(OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME);
assertNotNull("No refined objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", rOcDefPosixAccount);
assertTrue("Refined objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", rOcDefPosixAccount.isAuxiliary());
RefinedObjectClassDefinition rOcDefPosixGroup = refinedSchema.getRefinedDefinition(OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME);
assertNotNull("No refined objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", rOcDefPosixGroup);
assertTrue("Refined objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", rOcDefPosixGroup.isAuxiliary());
}
use of com.evolveum.midpoint.common.refinery.RefinedResourceSchema 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.RefinedResourceSchema in project midpoint by Evolveum.
the class LiveSyncTaskHandler method runInternal.
private TaskRunResult runInternal(Task task) {
LOGGER.trace("LiveSyncTaskHandler.run starting");
long progress = task.getProgress();
OperationResult opResult = new OperationResult(OperationConstants.LIVE_SYNC);
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
String resourceOid = task.getObjectOid();
if (resourceOid == null) {
LOGGER.error("Live Sync: No resource OID specified in the task");
opResult.recordFatalError("No resource OID specified in the task");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
ResourceType resource = null;
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, opResult).asObjectable();
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: Resource {} not found: {}", new Object[] { resourceOid, ex.getMessage(), ex });
// This is bad. The resource does not exist. Permanent problem.
opResult.recordFatalError("Resource not found " + resourceOid, ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema: {}", ex.getMessage(), ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error: {}", ex.getMessage(), ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (resource == null) {
LOGGER.error("Live Sync: No resource specified");
opResult.recordFatalError("No resource specified");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
RefinedResourceSchema refinedSchema;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
} catch (SchemaException e) {
LOGGER.error("Live Sync: Schema error during processing account definition: {}", e.getMessage());
opResult.recordFatalError("Schema error during processing account definition: " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (refinedSchema == null) {
opResult.recordFatalError("No refined schema defined. Probably some configuration problem.");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
LOGGER.error("Live Sync: No refined schema defined. Probably some configuration problem.");
return runResult;
}
ObjectClassComplexTypeDefinition objectClass;
try {
objectClass = Utils.determineObjectClass(refinedSchema, task);
} catch (SchemaException e) {
LOGGER.error("Live Sync: schema error: {}", e.getMessage());
opResult.recordFatalError(e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (objectClass == null) {
LOGGER.debug("Syncing all object classes");
}
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(resourceOid, objectClass == null ? null : objectClass.getTypeName());
int changesProcessed;
try {
// MAIN PART
// Calling synchronize(..) in provisioning.
// This will detect the changes and notify model about them.
// It will use extension of task to store synchronization state
Utils.clearRequestee(task);
changesProcessed = provisioningService.synchronize(coords, task, opResult);
progress += changesProcessed;
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: A required object does not exist, OID: {}", ex.getOid());
LOGGER.error("Exception stack trace", ex);
// This is bad. The resource or task or something like that does not exist. Permanent problem.
opResult.recordFatalError("A required object does not exist, OID: " + ex.getOid(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Communication error:", ex);
// Error, but not critical. Just try later.
opResult.recordPartialError("Communication error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error:", ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Configuration error:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Recompute: Security violation: {}", ex.getMessage(), ex);
opResult.recordFatalError("Security violation: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Recompute: Expression error: {}", ex.getMessage(), ex);
opResult.recordFatalError("Expression error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
}
opResult.computeStatus("Live sync run has failed");
opResult.createSubresult(OperationConstants.LIVE_SYNC_STATISTICS).recordStatus(OperationResultStatus.SUCCESS, "Changes processed: " + changesProcessed);
// This "run" is finished. But the task goes on ...
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
// Might collide with increasing progress in provisioning module, e.g. when an exception is thrown. But that's OK for now.
runResult.setProgress(progress);
LOGGER.trace("LiveSyncTaskHandler.run stopping (resource {})", resourceOid);
return runResult;
}
use of com.evolveum.midpoint.common.refinery.RefinedResourceSchema in project midpoint by Evolveum.
the class ImportAccountsFromResourceTaskHandler method createHandler.
// shadowToImport - it is used to derive objectClass/intent/kind when importing a single shadow
private SynchronizeAccountResultHandler createHandler(ResourceType resource, PrismObject<ShadowType> shadowToImport, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) {
RefinedResourceSchema refinedSchema;
ObjectClassComplexTypeDefinition objectClass;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined schema:\n{}", refinedSchema.debugDump());
}
if (shadowToImport != null) {
objectClass = Utils.determineObjectClass(refinedSchema, shadowToImport);
} else {
objectClass = Utils.determineObjectClass(refinedSchema, coordinatorTask);
}
if (objectClass == null) {
LOGGER.error("Import: No objectclass specified and no default can be determined.");
opResult.recordFatalError("No objectclass specified and no default can be determined");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return null;
}
} catch (SchemaException e) {
LOGGER.error("Import: Schema error during processing account definition: {}", e.getMessage());
opResult.recordFatalError("Schema error during processing account definition: " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return null;
}
LOGGER.info("Start executing import from resource {}, importing object class {}", resource, objectClass.getTypeName());
SynchronizeAccountResultHandler handler = new SynchronizeAccountResultHandler(resource, objectClass, "import", coordinatorTask, changeNotificationDispatcher, taskManager);
handler.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_IMPORT);
handler.setForceAdd(true);
handler.setStopOnError(false);
handler.setContextDesc("from " + resource);
handler.setLogObjectProgress(true);
return handler;
}
use of com.evolveum.midpoint.common.refinery.RefinedResourceSchema in project midpoint by Evolveum.
the class MidpointFunctionsImpl method countAccounts.
private <T> Integer countAccounts(ResourceType resourceType, QName attributeName, T attributeValue, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
RefinedObjectClassDefinition rAccountDef = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
RefinedAttributeDefinition attrDef = rAccountDef.findAttributeDefinition(attributeName);
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attributeValue).and().item(ShadowType.F_OBJECT_CLASS).eq(rAccountDef.getObjectClassDefinition().getTypeName()).and().item(ShadowType.F_RESOURCE_REF).ref(resourceType.getOid()).build();
return modelObjectResolver.countObjects(ShadowType.class, query, null, task, result);
}
Aggregations