Search in sources :

Example 1 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class ResourceAssociationEditor method loadObjectReferences.

private List<QName> loadObjectReferences(boolean restrictObjectClass) {
    List<QName> references = new ArrayList<>();
    ResourceSchema schema = loadResourceSchema();
    if (schema == null) {
        return references;
    }
    for (ObjectClassComplexTypeDefinition def : schema.getObjectClassDefinitions()) {
        if (restrictObjectClass) {
            if (objectType != null && def.getTypeName().equals(objectType.getObjectClass())) {
                for (ResourceAttributeDefinition attributeDefinition : def.getAttributeDefinitions()) {
                    references.add(attributeDefinition.getName());
                }
            }
        } else {
            for (ResourceAttributeDefinition attributeDefinition : def.getAttributeDefinitions()) {
                references.add(attributeDefinition.getName());
            }
        }
    }
    return references;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Example 2 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class ReconciliationTaskHandler method runInternal.

public TaskRunResult runInternal(Task coordinatorTask) {
    ReconciliationTaskResult reconResult = new ReconciliationTaskResult();
    boolean finishOperationsOnly = BooleanUtils.isTrue(coordinatorTask.getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_FINISH_OPERATIONS_ONLY));
    OperationResult opResult = new OperationResult(OperationConstants.RECONCILIATION);
    opResult.setStatus(OperationResultStatus.IN_PROGRESS);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    String resourceOid = coordinatorTask.getObjectOid();
    opResult.addContext("resourceOid", resourceOid);
    if (coordinatorTask.getChannel() == null) {
        coordinatorTask.setChannel(SchemaConstants.CHANGE_CHANNEL_RECON_URI);
    }
    if (resourceOid == null) {
        throw new IllegalArgumentException("Resource OID is missing in task extension");
    }
    recordProgress(coordinatorTask, 0, opResult);
    // todo consider setting expectedTotal to null here
    PrismObject<ResourceType> resource;
    ObjectClassComplexTypeDefinition objectclassDef;
    try {
        resource = provisioningService.getObject(ResourceType.class, resourceOid, null, coordinatorTask, opResult);
        RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
        objectclassDef = Utils.determineObjectClass(refinedSchema, coordinatorTask);
    } catch (ObjectNotFoundException ex) {
        // This is bad. The resource does not exist. Permanent problem.
        processErrorPartial(runResult, "Resource does not exist, OID: " + resourceOid, ex, TaskRunResultStatus.PERMANENT_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (CommunicationException ex) {
        // Error, but not critical. Just try later.
        processErrorPartial(runResult, "Communication error", ex, TaskRunResultStatus.TEMPORARY_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (SchemaException 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.
        processErrorPartial(runResult, "Error dealing with schema", ex, TaskRunResultStatus.TEMPORARY_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (RuntimeException 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.
        processErrorPartial(runResult, "Internal Error", ex, TaskRunResultStatus.PERMANENT_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (ConfigurationException 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.
        processErrorPartial(runResult, "Configuration error", ex, TaskRunResultStatus.TEMPORARY_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (SecurityViolationException ex) {
        processErrorPartial(runResult, "Security violation", ex, TaskRunResultStatus.PERMANENT_ERROR, null, coordinatorTask, opResult);
        return runResult;
    } catch (ExpressionEvaluationException ex) {
        processErrorPartial(runResult, "Expression error", ex, TaskRunResultStatus.PERMANENT_ERROR, null, coordinatorTask, opResult);
        return runResult;
    }
    if (objectclassDef == null) {
        processErrorPartial(runResult, "Reconciliation without an object class specification is not supported", null, TaskRunResultStatus.PERMANENT_ERROR, null, coordinatorTask, opResult);
        return runResult;
    }
    reconResult.setResource(resource);
    reconResult.setObjectclassDefinition(objectclassDef);
    LOGGER.info("Start executing reconciliation of resource {}, reconciling object class {}, finish operations only: {}", resource, objectclassDef, finishOperationsOnly);
    long reconStartTimestamp = clock.currentTimeMillis();
    AuditEventRecord requestRecord = new AuditEventRecord(AuditEventType.RECONCILIATION, AuditEventStage.REQUEST);
    requestRecord.setTarget(resource);
    auditService.audit(requestRecord, coordinatorTask);
    try {
        if (!scanForUnfinishedOperations(coordinatorTask, resourceOid, reconResult, opResult)) {
            // appends also "last N failures" (TODO refactor)
            processInterruption(runResult, resource, coordinatorTask, opResult);
            return runResult;
        }
    } catch (ObjectNotFoundException ex) {
        // This is bad. The resource does not exist. Permanent problem.
        processErrorPartial(runResult, "Resource does not exist, OID: " + resourceOid, ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
    } catch (ObjectAlreadyExistsException ex) {
        processErrorPartial(runResult, "Object already exist", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
    } catch (CommunicationException ex) {
        // Error, but not critical. Just try later.
        // appends also "last N failures" (TODO refactor)
        processErrorFinal(runResult, "Communication error", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (SchemaException 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.
        processErrorPartial(runResult, "Error dealing with schema", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
    } catch (RuntimeException 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.
        processErrorFinal(runResult, "Internal Error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (ConfigurationException 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.
        processErrorFinal(runResult, "Configuration error", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (SecurityViolationException ex) {
        processErrorPartial(runResult, "Security violation", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
    }
    long beforeResourceReconTimestamp = clock.currentTimeMillis();
    long afterResourceReconTimestamp;
    long afterShadowReconTimestamp;
    try {
        if (!finishOperationsOnly && !performResourceReconciliation(resource, objectclassDef, reconResult, coordinatorTask, opResult)) {
            processInterruption(runResult, resource, coordinatorTask, opResult);
            return runResult;
        }
        afterResourceReconTimestamp = clock.currentTimeMillis();
        if (!finishOperationsOnly && !performShadowReconciliation(resource, objectclassDef, reconStartTimestamp, afterResourceReconTimestamp, reconResult, coordinatorTask, opResult)) {
            processInterruption(runResult, resource, coordinatorTask, opResult);
            return runResult;
        }
        afterShadowReconTimestamp = clock.currentTimeMillis();
    } catch (ObjectNotFoundException ex) {
        // This is bad. The resource does not exist. Permanent problem.
        processErrorFinal(runResult, "Resource does not exist, OID: " + resourceOid, ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (CommunicationException ex) {
        // Error, but not critical. Just try later.
        processErrorFinal(runResult, "Communication error", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (SchemaException 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.
        processErrorFinal(runResult, "Error dealing with schema", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (RuntimeException 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.
        processErrorFinal(runResult, "Internal Error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (ConfigurationException 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.
        processErrorFinal(runResult, "Configuration error", ex, TaskRunResultStatus.TEMPORARY_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (SecurityViolationException ex) {
        processErrorFinal(runResult, "Security violation", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    } catch (ExpressionEvaluationException ex) {
        processErrorFinal(runResult, "Expression error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, coordinatorTask, opResult);
        return runResult;
    }
    opResult.computeStatus();
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(coordinatorTask.getProgress());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Reconciliation.run stopping, result: {}", opResult.getStatus());
    //			LOGGER.trace("Reconciliation.run stopping, result: {}", opResult.dump());
    }
    AuditEventRecord executionRecord = new AuditEventRecord(AuditEventType.RECONCILIATION, AuditEventStage.EXECUTION);
    executionRecord.setTarget(resource);
    executionRecord.setOutcome(OperationResultStatus.SUCCESS);
    auditService.audit(executionRecord, coordinatorTask);
    long reconEndTimestamp = clock.currentTimeMillis();
    long etime = reconEndTimestamp - reconStartTimestamp;
    long unOpsTime = beforeResourceReconTimestamp - reconStartTimestamp;
    long resourceReconTime = afterResourceReconTimestamp - beforeResourceReconTimestamp;
    long shadowReconTime = afterShadowReconTimestamp - afterResourceReconTimestamp;
    LOGGER.info("Done executing reconciliation of resource {}, object class {}, Etime: {} ms (un-ops: {}, resource: {}, shadow: {})", new Object[] { resource, objectclassDef, etime, unOpsTime, resourceReconTime, shadowReconTime });
    reconResult.setRunResult(runResult);
    if (reconciliationTaskResultListener != null) {
        reconciliationTaskResultListener.process(reconResult);
    }
    TaskHandlerUtil.appendLastFailuresInformation(OperationConstants.RECONCILIATION, coordinatorTask, opResult);
    return runResult;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 3 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
    if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
        String policyIntent = synchronizationPolicy.getIntent();
        ShadowKindType policyKind = synchronizationPolicy.getKind();
        ObjectClassComplexTypeDefinition policyObjectClass = null;
        RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (schema == null) {
            throw new SchemaException("No schema defined in resource. Possible configuration problem?");
        }
        if (policyKind == null && policyIntent == null) {
            policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
        }
        if (policyKind != null) {
            if (StringUtils.isEmpty(policyIntent)) {
                policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
            } else {
                policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
            }
        }
        if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
            return false;
        }
    }
    if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
        if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
            return false;
        }
    }
    // kind
    ShadowKindType policyKind = synchronizationPolicy.getKind();
    if (policyKind != null && kind != null && !policyKind.equals(kind)) {
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    String policyIntent = synchronizationPolicy.getIntent();
    if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
        return false;
    }
    return true;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 4 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class AbstractCsvTest method test005ParsedSchema.

@Test
public void test005ParsedSchema() throws Exception {
    final String TEST_NAME = "test005ParsedSchema";
    TestUtil.displayTestTile(TEST_NAME);
    // THEN
    // The returned type should have the schema pre-parsed
    assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType));
    // Also test if the utility method returns the same thing
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext);
    display("Parsed resource schema", resourceSchema);
    assertNotNull("No resource schema", resourceSchema);
    ObjectClassComplexTypeDefinition accountDef = resourceSchema.findObjectClassDefinition(RESOURCE_CSV_ACCOUNT_OBJECTCLASS);
    assertNotNull("Account definition is missing", accountDef);
    assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
    assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
    assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
    assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getNativeObjectClass()));
    assertAccountDefinition(accountDef);
    ResourceAttributeDefinition<String> icfsNameDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
    assertNull("ICFS NAME definition sneaked in", icfsNameDef);
    ResourceAttributeDefinition<String> icfsUidDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_UID);
    assertNull("ICFS UID definition sneaked in", icfsUidDef);
    // Check whether it is reusing the existing schema and not parsing it all over again
    // Not equals() but == ... we want to really know if exactly the same
    // object instance is returned
    assertTrue("Broken caching", resourceSchema == RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext));
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Example 5 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class AbstractIntegrationTest method assertShadowSecondaryIdentifier.

protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException {
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass());
    ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next();
    PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName());
    assertNotNull("No secondary identifier (" + idSecDef.getName() + ") attribute in shadow for " + expectedIdentifier, idProp);
    if (nameMatchingRule == null) {
        assertEquals("Unexpected secondary identifier in shadow for " + expectedIdentifier, expectedIdentifier, idProp.getRealValue());
    } else {
        PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for " + expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue());
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Containerable(com.evolveum.midpoint.prism.Containerable) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)27 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)13 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)11 QName (javax.xml.namespace.QName)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 Containerable (com.evolveum.midpoint.prism.Containerable)3 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)3 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 AbstractProvisioningIntegrationTest (com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)2 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)2 ResourceAttributeContainerDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeContainerDefinition)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2