Search in sources :

Example 46 with ObjectClassComplexTypeDefinition

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

the class TestRefinedSchema method test114DetermineObjectClassKindIntentObjectClass.

@Test
public void test114DetermineObjectClassKindIntentObjectClass() throws Exception {
    final String TEST_NAME = "test114DetermineObjectClassKindIntentObjectClass";
    TestUtil.displayTestTile(this, TEST_NAME);
    OperationResult result = new OperationResult(TestRefinedSchema.class.getName() + "." + TEST_NAME);
    importObjectFromFile(TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_FILE);
    Task task = taskManager.getTask(TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_OID, result);
    display("Task", task);
    // WHEN
    ObjectClassComplexTypeDefinition objectClass = Utils.determineObjectClass(refinedSchema, task);
    // THEN
    display("Object class", objectClass);
    deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_OID);
    assertRefinedObjectClass(objectClass, RESOURCE_DUMMY_PRIVILEGE_OBJECTCLASS_QNAME, ShadowKindType.ENTITLEMENT, "privilege");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Test(org.testng.annotations.Test)

Example 47 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition 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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SynchronizeAccountResultHandler(com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 48 with ObjectClassComplexTypeDefinition

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

the class TestEntitlements method getGroupShadow.

private PrismObject<ShadowType> getGroupShadow(DummyResourceContoller dummyResourceCtl, QName objectClass, String name, Task task, OperationResult result) throws Exception {
    PrismObject<ResourceType> resource = dummyResourceCtl.getResource();
    ObjectClassComplexTypeDefinition groupDef = RefinedResourceSchema.getRefinedSchema(resource).findObjectClassDefinition(dummyResourceCtl.getGroupObjectClass());
    ResourceAttributeDefinition<Object> nameDef = groupDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
    assertNotNull("No icfs:name definition", nameDef);
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassFilterPrefix(resource.getOid(), objectClass, prismContext).and().item(new ItemPath(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME), nameDef).eq(name).build();
    SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);
    assertEquals("Wrong # of results for " + name + " of " + objectClass + " at " + resource, 1, shadows.size());
    return shadows.get(0);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 49 with ObjectClassComplexTypeDefinition

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

the class TestDummy method createOnOffQuery.

private ObjectQuery createOnOffQuery() throws SchemaException {
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME);
    ResourceAttributeDefinition<String> attrDef = objectClassDef.findAttributeDefinition(dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME));
    ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).item(ShadowType.F_RESOURCE_REF).ref(RESOURCE_DUMMY_OID).and().item(ShadowType.F_OBJECT_CLASS).eq(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME)).and().itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq("Sea Monkey").and().item(ShadowType.F_DEAD).eq(true).build();
    display("Query", query);
    return query;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 50 with ObjectClassComplexTypeDefinition

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

the class TestDummy method test502ModifyProtectedAccountShadowAttributes.

/**
	 * Attribute modification should fail.
	 */
@Test
public void test502ModifyProtectedAccountShadowAttributes() throws Exception {
    final String TEST_NAME = "test502ModifyProtectedAccountShadowAttributes";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    syncServiceMock.reset();
    Collection<? extends ItemDelta> modifications = new ArrayList<ItemDelta>(1);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    ResourceAttributeDefinition fullnameAttrDef = defaultAccountDefinition.findAttributeDefinition("fullname");
    ResourceAttribute fullnameAttr = fullnameAttrDef.instantiate();
    PropertyDelta fullnameDelta = fullnameAttr.createDelta(new ItemPath(ShadowType.F_ATTRIBUTES, fullnameAttrDef.getName()));
    fullnameDelta.setValueToReplace(new PrismPropertyValue<String>("Good Daemon"));
    ((Collection) modifications).add(fullnameDelta);
    // WHEN
    try {
        provisioningService.modifyObject(ShadowType.class, ACCOUNT_DAEMON_OID, modifications, null, null, task, result);
        AssertJUnit.fail("Expected security exception while modifying 'daemon' account");
    } catch (SecurityViolationException e) {
        // This is expected
        display("Expected exception", e);
    }
    result.computeStatus();
    display("modifyObject result (expected failure)", result);
    TestUtil.assertFailure(result);
    syncServiceMock.assertNotifyFailureOnly();
    //		checkConsistency();
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)53 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)18 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)17 Test (org.testng.annotations.Test)17 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)5 Containerable (com.evolveum.midpoint.prism.Containerable)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 ResultHandler (com.evolveum.midpoint.provisioning.ucf.api.ResultHandler)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3