Search in sources :

Example 76 with PrismPropertyDefinition

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

the class ConsistencyTest method test000Integrity.

/**
	 * Test integrity of the test setup.
	 */
@Test
public void test000Integrity() throws Exception {
    final String TEST_NAME = "test000Integrity";
    TestUtil.displayTestTile(this, TEST_NAME);
    assertNotNull(modelWeb);
    assertNotNull(modelService);
    assertNotNull(repositoryService);
    assertTrue(isSystemInitialized());
    assertNotNull(taskManager);
    assertNotNull(prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull(schemaRegistry);
    // This is defined in extra schema. So this effectively checks whether
    // the extra schema was loaded
    PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
    assertNotNull("No my:shipState definition", shipStateDefinition);
    assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
    assertNoRepoCache();
    OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
    // Check if OpenDJ resource was imported correctly
    PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
    display("Imported OpenDJ resource (repository)", openDjResource);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
    assertNoRepoCache();
    String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
    PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
    display("LDAP Connector: ", ldapConnector);
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 77 with PrismPropertyDefinition

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

the class BasicValidatorTest method resource1Valid.

@Test
public void resource1Valid() throws Exception {
    System.out.println("\n===[ resource1Valid ]=====");
    OperationResult result = new OperationResult(this.getClass().getName() + ".resource1Valid");
    EventHandler handler = new EventHandler() {

        @Override
        public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
            return EventResult.cont();
        }

        @Override
        public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
            System.out.println("Validating resorce:");
            System.out.println(object.debugDump());
            object.checkConsistence();
            PrismContainer<?> extensionContainer = object.getExtension();
            PrismProperty<Integer> menProp = extensionContainer.findProperty(new QName("http://myself.me/schemas/whatever", "menOnChest"));
            assertNotNull("No men on a dead man chest!", menProp);
            assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
            PrismPropertyDefinition menPropDef = menProp.getDefinition();
            assertNotNull("Men on a dead man chest NOT defined", menPropDef);
            assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
            assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
            return EventResult.cont();
        }

        @Override
        public void handleGlobalError(OperationResult currentResult) {
        /* nothing */
        }
    };
    validateFile("resource-1-valid.xml", handler, result);
    AssertJUnit.assertTrue(result.isSuccess());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Objectable(com.evolveum.midpoint.prism.Objectable) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 78 with PrismPropertyDefinition

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

the class RawTypeUtil method getParsedItem.

public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
    Item<IV, ID> subItem = null;
    List<IV> parsedValues = new ArrayList<IV>();
    for (RawType rawValue : values) {
        if (itemDefinition == null && containerDef != null) {
            itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
        }
        IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
        if (parsed != null) {
            parsedValues.add(parsed);
        }
    }
    PrismContext prismContext = null;
    if (containerDef != null) {
        prismContext = containerDef.getPrismContext();
    }
    if (prismContext == null && itemDefinition != null) {
        prismContext = itemDefinition.getPrismContext();
    }
    if (itemDefinition == null) {
        PrismProperty property = new PrismProperty(elementQName, prismContext);
        property.addAll(PrismValue.cloneCollection(parsedValues));
        return property;
    }
    if (itemDefinition instanceof PrismPropertyDefinition<?>) {
        // property
        PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            property.add((PrismPropertyValue) val.clone());
        }
        subItem = (Item<IV, ID>) property;
    } else if (itemDefinition instanceof PrismContainerDefinition<?>) {
        PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            container.add((PrismContainerValue) val.clone());
        }
        subItem = (Item<IV, ID>) container;
    } else if (itemDefinition instanceof PrismReferenceDefinition) {
        // TODO
        PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            PrismReferenceValue ref;
            if (val instanceof PrismReferenceValue) {
                ref = (PrismReferenceValue) val.clone();
            } else if (val instanceof PrismContainerValue) {
                // this is embedded (full) object
                Containerable c = ((PrismContainerValue) val).asContainerable();
                if (!(c instanceof Objectable)) {
                    throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
                }
                Objectable o = (Objectable) c;
                ref = new PrismReferenceValue();
                ref.setObject(o.asPrismObject());
            } else {
                throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
            }
            reference.merge(ref);
        }
        subItem = (Item<IV, ID>) reference;
    } else {
        throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
    }
    return subItem;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 79 with PrismPropertyDefinition

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

the class PrismAsserts method assertPropertyDefinition.

public static void assertPropertyDefinition(PrismProperty property, QName type, int minOccurs, int maxOccurs, Boolean indexed) {
    assertDefinition(property, type, minOccurs, maxOccurs);
    PrismPropertyDefinition definition = property.getDefinition();
    assert equals(indexed, definition.isIndexed()) : "Property should have indexed=" + indexed + ", but it has indexed=" + definition.isIndexed();
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition)

Example 80 with PrismPropertyDefinition

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

the class PrismAsserts method assertPropertyDefinition.

public static void assertPropertyDefinition(PrismContainerDefinition<?> containerDef, QName propertyName, QName type, int minOccurs, int maxOccurs) {
    PrismPropertyDefinition definition = containerDef.findPropertyDefinition(propertyName);
    assertDefinition(definition, propertyName, type, minOccurs, maxOccurs);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition)

Aggregations

PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)134 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)93 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)82 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)62 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 Test (org.testng.annotations.Test)60 PrismObject (com.evolveum.midpoint.prism.PrismObject)24 QName (javax.xml.namespace.QName)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)19 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 Task (com.evolveum.midpoint.task.api.Task)12 ArrayList (java.util.ArrayList)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)8 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)7 File (java.io.File)7