Search in sources :

Example 51 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class SqaleRepoBaseTest method addExtensionValue.

// region extension support
@SafeVarargs
protected final <V> void addExtensionValue(Containerable extContainer, String itemName, V... values) throws SchemaException {
    PrismContainerValue<?> pcv = extContainer.asPrismContainerValue();
    ItemDefinition<?> itemDefinition = pcv.getDefinition().findItemDefinition(new ItemName(itemName));
    assertThat(itemDefinition).withFailMessage("No definition found for item name '%s' in %s", itemName, pcv).isNotNull();
    if (itemDefinition instanceof PrismReferenceDefinition) {
        PrismReference ref = (PrismReference) itemDefinition.instantiate();
        for (V value : values) {
            ref.add(value instanceof PrismReferenceValue ? (PrismReferenceValue) value : ((Referencable) value).asReferenceValue());
        }
        pcv.add(ref);
    } else {
        // noinspection unchecked
        PrismProperty<V> property = (PrismProperty<V>) itemDefinition.instantiate();
        property.setRealValues(values);
        pcv.add(property);
    }
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 52 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class SchemaProcessorTest method testRoundTripResource.

@Test
public void testRoundTripResource() throws SchemaException {
    // GIVEN
    ResourceSchemaImpl schema = new ResourceSchemaImpl();
    // Property container
    ResourceObjectClassDefinitionImpl objectClassDef = (ResourceObjectClassDefinitionImpl) schema.createObjectClassDefinition(new QName(MidPointConstants.NS_RI, "AccountObjectClass"));
    objectClassDef.setDefaultAccountDefinition(true);
    objectClassDef.setNativeObjectClass("ACCOUNT");
    // ... in it ordinary attribute - an identifier
    ResourceAttributeDefinition<?> xLoginDef = objectClassDef.createAttributeDefinition("login", DOMUtil.XSD_STRING, def -> def.setNativeAttributeName("LOGIN"));
    objectClassDef.addPrimaryIdentifierName(xLoginDef.getItemName());
    objectClassDef.setDisplayNameAttributeName(xLoginDef.getItemName());
    // ... and local property with a type from another schema
    objectClassDef.createAttributeDefinition("password", ProtectedStringType.COMPLEX_TYPE, def -> def.setNativeAttributeName("PASSWORD"));
    // ... ignored attribute
    objectClassDef.createAttributeDefinition("sep", DOMUtil.XSD_STRING, def -> def.setProcessing(ItemProcessing.IGNORE));
    System.out.println("Resource schema before serializing to XSD: ");
    System.out.println(schema.debugDump());
    System.out.println();
    // WHEN
    Document xsd = schema.serializeToXsd();
    String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
    System.out.println("Resource schema after serializing to XSD: ");
    System.out.println(stringXmlSchema);
    System.out.println();
    Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
    ResourceSchema newSchema = ResourceSchemaParser.parse(DOMUtil.getFirstChildElement(parsedXsd), "serialized schema");
    System.out.println("Resource schema after parsing from XSD: ");
    System.out.println(newSchema.debugDump());
    System.out.println();
    // THEN
    ResourceObjectClassDefinition newObjectClassDef = newSchema.findObjectClassDefinitionRequired(new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"));
    assertThat(newObjectClassDef.getTypeName()).isEqualTo(new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"));
    assertThat(newObjectClassDef.isDefaultAccountDefinition()).isTrue();
    assertThat(newObjectClassDef.getNativeObjectClass()).isEqualTo("ACCOUNT");
    assertThat(newObjectClassDef.getPrimaryIdentifiersNames()).containsExactly(xLoginDef.getItemName());
    assertThat(newObjectClassDef.getDisplayNameAttributeName()).isEqualTo(xLoginDef.getItemName());
    PrismPropertyDefinition<?> loginDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
    assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
    assertFalse(loginDef.isIgnored());
    PrismPropertyDefinition<?> passwdDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
    assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
    assertFalse(passwdDef.isIgnored());
    PrismPropertyDefinition<?> sepDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "sep"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "sep"), sepDef.getItemName());
    assertEquals(DOMUtil.XSD_STRING, sepDef.getTypeName());
    assertTrue(sepDef.isIgnored());
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test) AbstractSchemaTest(com.evolveum.midpoint.schema.AbstractSchemaTest)

Example 53 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class SchemaProcessorTest method testRoundTripGeneric.

@Test
public void testRoundTripGeneric() throws SchemaException {
    // GIVEN
    PrismSchemaImpl schema = new PrismSchemaImpl(MidPointConstants.NS_RI);
    // Ordinary property
    schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
    // Property container
    MutablePrismContainerDefinition<?> containerDefinition = schema.createContainerDefinition("ContainerType");
    // ... in it ordinary property
    containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
    // ... and local property with a type from another schema
    containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
    // ... property reference
    containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
    // ... read-only int property
    PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
    counterProperty.toMutable().toMutable().setReadOnly();
    System.out.println("Generic schema before serializing to XSD: ");
    System.out.println(schema.debugDump());
    System.out.println();
    // WHEN
    Document xsd = schema.serializeToXsd();
    String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
    System.out.println("Generic schema after serializing to XSD: ");
    System.out.println(stringXmlSchema);
    System.out.println();
    Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
    PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
    System.out.println("Generic schema after parsing from XSD: ");
    System.out.println(newSchema.debugDump());
    System.out.println();
    // THEN
    PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new ItemName(MidPointConstants.NS_RI, "number1"), PrismPropertyDefinition.class);
    assertEquals(new ItemName(MidPointConstants.NS_RI, "number1"), number1def.getItemName());
    assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
    PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new ItemName(MidPointConstants.NS_RI, "ContainerType"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "ContainerType"), newContainerDef.getTypeName());
    PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
    assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
    assertTrue("Read flag is wrong", loginDef.canRead());
    assertTrue("Create flag is wrong", loginDef.canAdd());
    assertTrue("Update flag is wrong", loginDef.canModify());
    PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
    assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
    PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new ItemName(SchemaConstants.NS_C, "credentials"));
    assertEquals(new ItemName(SchemaConstants.NS_C, "credentials"), credDef.getItemName());
    assertEquals(new ItemName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
    PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "counter"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "counter"), countDef.getItemName());
    assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
    assertTrue("Read flag is wrong", countDef.canRead());
    assertFalse("Create flag is wrong", countDef.canAdd());
    assertFalse("Update flag is wrong", countDef.canModify());
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) PrismSchemaImpl(com.evolveum.midpoint.prism.impl.schema.PrismSchemaImpl) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) MutablePrismContainerDefinition(com.evolveum.midpoint.prism.MutablePrismContainerDefinition) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test) AbstractSchemaTest(com.evolveum.midpoint.schema.AbstractSchemaTest)

Example 54 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class RAnyConverterStaticTest method testAttributesDouble.

@Test
public void testAttributesDouble() throws Exception {
    Session session = getFactory().openSession();
    ItemName valueName = new ItemName(NS_FOO_RESOURCE, "uid");
    ItemDefinition def = getDefinition(GenericObjectType.class, valueName);
    AssertJUnit.assertNull(def);
    Element value = createAttributeValue(valueName, "xsd:double", "123.1");
    Object realValue = RAnyConverter.getRealRepoValue(def, value, prismContext);
    AssertJUnit.assertEquals("123.1", realValue);
    session.close();
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 55 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class RAnyConverterStaticTest method testAttributesString.

@Test
public void testAttributesString() throws Exception {
    Session session = getFactory().openSession();
    ItemName valueName = new ItemName(NS_FOO_RESOURCE, "uid");
    ItemDefinition def = getDefinition(GenericObjectType.class, valueName);
    AssertJUnit.assertNull(def);
    Element value = createAttributeValue(valueName, "xsd:string", "some uid");
    Object realValue = RAnyConverter.getRealRepoValue(def, value, prismContext);
    AssertJUnit.assertEquals("some uid", realValue);
    session.close();
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3