Search in sources :

Example 16 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class MidPointAbstractDataSource method getFieldValue.

@Override
public Object getFieldValue(JRField jrField) throws JRException {
    // TODO Auto-generated method stub
    String fieldName = jrField.getName();
    if (fieldName.equals("oid")) {
        return currentObject.getOid();
    }
    Item i = currentObject.findItem(new QName(fieldName));
    if (i == null) {
        return null;
    }
    if (i instanceof PrismProperty) {
        if (i.isSingleValue()) {
            return ((PrismProperty) i).getRealValue();
        }
        return ((PrismProperty) i).getRealValues();
    } else if (i instanceof PrismReference) {
        if (i.isSingleValue()) {
            return ((PrismReference) i).getValue().asReferencable();
        }
        List<Referencable> refs = new ArrayList<Referencable>();
        for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
            refs.add(refVal.asReferencable());
        }
        return refs;
    } else if (i instanceof PrismContainer) {
        if (i.isSingleValue()) {
            return ((PrismContainer) i).getValue().asContainerable();
        }
        List<Containerable> containers = new ArrayList<Containerable>();
        for (Object pcv : i.getValues()) {
            if (pcv instanceof PrismContainerValue) {
                containers.add(((PrismContainerValue) pcv).asContainerable());
            }
        }
        return containers;
    } else
        throw new JRException("Could not get value of the fileld: " + fieldName);
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) JRException(net.sf.jasperreports.engine.JRException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ArrayList(java.util.ArrayList) List(java.util.List) Containerable(com.evolveum.midpoint.prism.Containerable) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 17 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestOpenDjNegative method test004ResourceAndConnectorCaching.

@Test
public void test004ResourceAndConnectorCaching() throws Exception {
    TestUtil.displayTestTile("test004ResourceAndConnectorCaching");
    OperationResult result = new OperationResult(TestOpenDjNegative.class.getName() + ".test004ResourceAndConnectorCaching");
    Task task = taskManager.createTaskInstance();
    // WHEN
    // This should NOT throw an exception. It should just indicate the failure in results
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    ResourceType resourceType = resource.asObjectable();
    // THEN
    result.computeStatus();
    display("getObject(resource) result", result);
    TestUtil.assertFailure(result);
    TestUtil.assertFailure(resource.asObjectable().getFetchResult());
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNull("Resource schema found", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    // THEN
    result.computeStatus();
    display("getObject(resourceAgain) result", result);
    TestUtil.assertFailure(result);
    TestUtil.assertFailure(resourceAgain.asObjectable().getFetchResult());
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    assertTrue("Configurations not equals", configurationContainer.equals(configurationContainerAgain));
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNull("Resource schema (again)", resourceSchemaAgain);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 18 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractIntegrationTest method assertShadowRepo.

protected void assertShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username, ResourceType resourceType, QName objectClass, MatchingRule<String> nameMatchingRule) throws SchemaException {
    assertShadowCommon(accountShadow, oid, username, resourceType, objectClass, nameMatchingRule, true);
    PrismContainer<Containerable> attributesContainer = accountShadow.findContainer(ShadowType.F_ATTRIBUTES);
    List<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
    //		Collection secIdentifiers = ShadowUtil.getSecondaryIdentifiers(accountShadow);
    if (attributes == null) {
        AssertJUnit.fail("No attributes in repo shadow");
    }
    RefinedResourceSchema refinedSchema = null;
    try {
        refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    } catch (SchemaException e) {
        AssertJUnit.fail(e.getMessage());
    }
    ObjectClassComplexTypeDefinition objClassDef = refinedSchema.getRefinedDefinition(objectClass);
    Collection secIdentifiers = objClassDef.getSecondaryIdentifiers();
    if (secIdentifiers == null) {
        AssertJUnit.fail("No secondary identifiers in repo shadow");
    }
    // repo shadow should contains all secondary identifiers + ICF_UID
    assertRepoShadowAttributes(attributes, secIdentifiers.size() + 1);
}
Also used : Item(com.evolveum.midpoint.prism.Item) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 19 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractIntegrationTest method getIcfUid.

protected String getIcfUid(PrismObject<ShadowType> shadow) {
    PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    assertNotNull("Null attributes in " + shadow, attributesContainer);
    assertFalse("Empty attributes in " + shadow, attributesContainer.isEmpty());
    PrismProperty<String> icfUidProp = attributesContainer.findProperty(new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"));
    assertNotNull("No ICF name attribute in " + shadow, icfUidProp);
    return icfUidProp.getRealValue();
}
Also used : QName(javax.xml.namespace.QName) Containerable(com.evolveum.midpoint.prism.Containerable) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 20 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestDummyNegative method testGetResourceBrokenSchema.

public void testGetResourceBrokenSchema(BreakMode breakMode, String testName) throws Exception {
    TestUtil.displayTestTile(testName);
    // GIVEN
    OperationResult result = new OperationResult(TestDummyNegative.class.getName() + "." + testName);
    // precondition
    PrismObject<ResourceType> repoResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    display("Repo resource (before)", repoResource);
    PrismContainer<Containerable> schema = repoResource.findContainer(ResourceType.F_SCHEMA);
    assertTrue("Schema found in resource before the test (precondition)", schema == null || schema.isEmpty());
    dummyResource.setSchemaBreakMode(breakMode);
    try {
        // WHEN
        PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
        // THEN
        display("Resource with broken schema", resource);
        OperationResultType fetchResult = resource.asObjectable().getFetchResult();
        result.computeStatus();
        display("getObject result", result);
        assertEquals("Unexpected result of getObject operation", OperationResultStatus.PARTIAL_ERROR, result.getStatus());
        assertNotNull("No fetch result", fetchResult);
        display("fetchResult", fetchResult);
        assertEquals("Unexpected result of fetchResult", OperationResultStatusType.PARTIAL_ERROR, fetchResult.getStatus());
    } finally {
        dummyResource.setSchemaBreakMode(BreakMode.NONE);
    }
}
Also used : OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Test (org.testng.annotations.Test)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)9 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 QName (javax.xml.namespace.QName)7 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 Task (com.evolveum.midpoint.task.api.Task)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 Item (com.evolveum.midpoint.prism.Item)4 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 Collection (java.util.Collection)4