Search in sources :

Example 71 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestUuid method assertUser.

private void assertUser(PrismObject<UserType> user, String firstName, String lastName) {
    display("User", user);
    String oid = user.getOid();
    PolyStringType name = user.asObjectable().getName();
    assertEquals("User name-OID mismatch", oid, name.getOrig());
// TODO
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Example 72 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class JavaTypeConverter method convert.

public static Object convert(Class<?> expectedType, Object rawValue, boolean failIfImpossible) {
    if (rawValue == null || expectedType.isInstance(rawValue)) {
        return rawValue;
    }
    if (rawValue instanceof PrismPropertyValue<?>) {
        rawValue = ((PrismPropertyValue<?>) rawValue).getValue();
    }
    // This really needs to be checked twice
    if (rawValue == null || expectedType.isInstance(rawValue)) {
        return rawValue;
    }
    // boolean
    if (expectedType == boolean.class && rawValue instanceof Boolean) {
        return ((Boolean) rawValue);
    }
    if (expectedType == Boolean.class && rawValue instanceof String) {
        return (Boolean) Boolean.parseBoolean((((String) rawValue)).trim());
    }
    if (expectedType == Boolean.class && rawValue instanceof PolyString) {
        return (Boolean) Boolean.parseBoolean((rawValue.toString().trim()));
    }
    if (expectedType == boolean.class && rawValue instanceof String) {
        return (Boolean) Boolean.parseBoolean(((String) rawValue).trim());
    }
    if (expectedType == boolean.class && rawValue instanceof PolyString) {
        return (Boolean) Boolean.parseBoolean((rawValue).toString().trim());
    }
    if (expectedType == String.class && rawValue instanceof Boolean) {
        return rawValue.toString();
    }
    // int
    if (expectedType == int.class && rawValue instanceof Integer) {
        return ((Integer) rawValue);
    }
    if (expectedType == Integer.class && rawValue instanceof String) {
        return (Integer) Integer.parseInt(((String) rawValue).trim());
    }
    if (expectedType == int.class && rawValue instanceof String) {
        return (Integer) Integer.parseInt(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof Integer) {
        return rawValue.toString();
    }
    if (expectedType == int.class && rawValue instanceof Long) {
        return (Integer) ((Long) rawValue).intValue();
    }
    if (expectedType == long.class && rawValue instanceof Long) {
        return (rawValue);
    }
    if (expectedType == Long.class && rawValue instanceof String) {
        return (Long) Long.parseLong(((String) rawValue).trim());
    }
    if (expectedType == long.class && rawValue instanceof String) {
        return (Long) Long.parseLong(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof Long) {
        return rawValue.toString();
    }
    if (expectedType == float.class && rawValue instanceof Float) {
        return ((Float) rawValue);
    }
    if (expectedType == Float.class && rawValue instanceof String) {
        return (Float) Float.parseFloat(((String) rawValue).trim());
    }
    if (expectedType == float.class && rawValue instanceof String) {
        return (Float) Float.parseFloat(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof Float) {
        return rawValue.toString();
    }
    if (expectedType == double.class && rawValue instanceof Double) {
        return ((Double) rawValue);
    }
    if (expectedType == Double.class && rawValue instanceof String) {
        return (Double) Double.parseDouble(((String) rawValue).trim());
    }
    if (expectedType == double.class && rawValue instanceof String) {
        return (Double) Double.parseDouble(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof Float) {
        return rawValue.toString();
    }
    if (expectedType == byte.class && rawValue instanceof Byte) {
        return ((Byte) rawValue);
    }
    if (expectedType == Byte.class && rawValue instanceof String) {
        return (Byte) Byte.parseByte(((String) rawValue));
    }
    if (expectedType == byte.class && rawValue instanceof String) {
        return (Byte) Byte.parseByte(((String) rawValue));
    }
    if (expectedType == String.class && rawValue instanceof Byte) {
        return rawValue.toString();
    }
    if (expectedType == BigInteger.class && rawValue instanceof String) {
        return new BigInteger(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof BigInteger) {
        return rawValue.toString().trim();
    }
    if (expectedType == BigDecimal.class && rawValue instanceof String) {
        return new BigDecimal(((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue instanceof BigDecimal) {
        return ((BigDecimal) rawValue).toString().trim();
    }
    if (expectedType == PolyString.class && rawValue instanceof String) {
        return new PolyString((String) rawValue);
    }
    if (expectedType == PolyStringType.class && rawValue instanceof String) {
        PolyStringType polyStringType = new PolyStringType();
        polyStringType.setOrig((String) rawValue);
        return polyStringType;
    }
    if (expectedType == String.class && rawValue instanceof PolyString) {
        return ((PolyString) rawValue).getOrig();
    }
    if (expectedType == String.class && rawValue instanceof PolyStringType) {
        return ((PolyStringType) rawValue).getOrig();
    }
    if (expectedType == PolyString.class && rawValue instanceof PolyStringType) {
        return ((PolyStringType) rawValue).toPolyString();
    }
    if (expectedType == PolyString.class && rawValue instanceof Integer) {
        return new PolyString(((Integer) rawValue).toString());
    }
    if (expectedType == PolyStringType.class && rawValue instanceof PolyString) {
        PolyStringType polyStringType = new PolyStringType((PolyString) rawValue);
        return polyStringType;
    }
    if (expectedType == PolyStringType.class && rawValue instanceof Integer) {
        PolyStringType polyStringType = new PolyStringType(((Integer) rawValue).toString());
        return polyStringType;
    }
    // Date and time
    if (expectedType == XMLGregorianCalendar.class && rawValue instanceof Long) {
        XMLGregorianCalendar xmlCalType = XmlTypeConverter.createXMLGregorianCalendar((Long) rawValue);
        return xmlCalType;
    }
    if (expectedType == XMLGregorianCalendar.class && rawValue instanceof String) {
        XMLGregorianCalendar xmlCalType = magicDateTimeParse((String) rawValue);
        return xmlCalType;
    }
    if (expectedType == String.class && rawValue instanceof XMLGregorianCalendar) {
        return ((XMLGregorianCalendar) rawValue).toXMLFormat();
    }
    if (expectedType == Long.class && rawValue instanceof XMLGregorianCalendar) {
        return (Long) XmlTypeConverter.toMillis((XMLGregorianCalendar) rawValue);
    }
    // XML Enums (JAXB)
    if (expectedType.isEnum() && expectedType.getAnnotation(XmlEnum.class) != null && rawValue instanceof String) {
        return XmlTypeConverter.toXmlEnum(expectedType, ((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue.getClass().isEnum() && rawValue.getClass().getAnnotation(XmlEnum.class) != null) {
        return XmlTypeConverter.fromXmlEnum(rawValue);
    }
    // Java Enums
    if (expectedType.isEnum() && rawValue instanceof String) {
        return Enum.valueOf((Class<Enum>) expectedType, ((String) rawValue).trim());
    }
    if (expectedType == String.class && rawValue.getClass().isEnum()) {
        return rawValue.toString();
    }
    //QName
    if (expectedType == QName.class && rawValue instanceof QName) {
        return rawValue;
    }
    if (expectedType == QName.class && rawValue instanceof String) {
        return QNameUtil.uriToQName(((String) rawValue).trim());
    }
    if (failIfImpossible) {
        throw new IllegalArgumentException("Expected " + expectedType + " type, but got " + rawValue.getClass());
    } else {
        return rawValue;
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) XmlEnum(javax.xml.bind.annotation.XmlEnum) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) BigDecimal(java.math.BigDecimal) XmlEnum(javax.xml.bind.annotation.XmlEnum) BigInteger(java.math.BigInteger) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) BigInteger(java.math.BigInteger) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 73 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestJaxbConstruction method testResourceConstruction.

@Test
public void testResourceConstruction() throws Exception {
    System.out.println("\n\n ===[ testResourceConstruction ]===\n");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    ResourceType resourceType = new ResourceType();
    prismContext.adopt(resourceType);
    PrismObject<ResourceType> resource = resourceType.asPrismObject();
    assertNotNull("No object definition after adopt", resource.getDefinition());
    // name: PolyString
    resourceType.setName(new PolyStringType("Môj risórs"));
    PrismProperty<PolyString> fullNameProperty = resource.findProperty(ResourceType.F_NAME);
    PolyString fullName = fullNameProperty.getRealValue();
    assertEquals("Wrong name orig", "Môj risórs", fullName.getOrig());
    assertEquals("Wrong name norm", "moj risors", fullName.getNorm());
    // description: setting null value
    resourceType.setDescription(null);
    PrismProperty<String> descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
    // description: setting null value
    resourceType.setDescription("blah blah");
    descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
    // description: resetting null value
    resourceType.setDescription(null);
    descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
    // Extension
    ExtensionType extension = new ExtensionType();
    resourceType.setExtension(extension);
    resource.checkConsistence();
    PrismContainer<Containerable> extensionContainer = resource.findContainer(GenericObjectType.F_EXTENSION);
    checkExtension(extensionContainer, "resource extension after setExtension");
    checkExtension(extension, "resource extension after setExtension");
    // Schema
    XmlSchemaType xmlSchemaType = new XmlSchemaType();
    CachingMetadataType cachingMetadata = new CachingMetadataType();
    cachingMetadata.setSerialNumber("serial123");
    xmlSchemaType.setCachingMetadata(cachingMetadata);
    resourceType.setSchema(xmlSchemaType);
    SchemaDefinitionType schemaDefinition = new SchemaDefinitionType();
    Element xsdSchemaElement = DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT);
    schemaDefinition.getAny().add(xsdSchemaElement);
    xmlSchemaType.setDefinition(schemaDefinition);
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    assertNotNull("No schema container", schemaContainer);
    // TODO
    // Schema: null
    resourceType.setSchema(null);
    schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    assertNull("Unexpected schema container", schemaContainer);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExtensionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) Test(org.testng.annotations.Test)

Example 74 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestJaxbConstruction method testUserConstruction.

@Test
public void testUserConstruction() throws JAXBException, SchemaException {
    System.out.println("\n\n ===[ testUserConstruction ]===\n");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    UserType userType = new UserType();
    prismContext.adopt(userType);
    PrismObject<UserType> user = userType.asPrismObject();
    assertNotNull("No object definition after adopt", user.getDefinition());
    SchemaTestUtil.assertUserDefinition(user.getDefinition());
    // fullName: PolyString
    userType.setFullName(new PolyStringType("Čučoriedka"));
    PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
    PolyString fullName = fullNameProperty.getRealValue();
    assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
    assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
    // description: setting null value
    userType.setDescription(null);
    PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
    // description: setting null value
    userType.setDescription("blah blah");
    descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
    assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
    // description: resetting null value
    userType.setDescription(null);
    descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
    // Extension
    ExtensionType extension = new ExtensionType();
    userType.setExtension(extension);
    user.checkConsistence();
    PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
    checkExtension(extensionContainer, "user extension after setExtension");
    checkExtension(extension, "user extension after setExtension");
    AssignmentType assignmentType = new AssignmentType();
    userType.getAssignment().add(assignmentType);
    user.checkConsistence();
    user.assertDefinitions();
    // Assignment
    ExtensionType assignmentExtension = new ExtensionType();
    assignmentType.setExtension(assignmentExtension);
    user.assertDefinitions();
    user.checkConsistence();
    checkExtension(assignmentExtension, "assignment extension after setExtension");
    user.checkConsistence();
    user.assertDefinitions();
    // accountRef/account
    ObjectReferenceType accountRefType = new ObjectReferenceType();
    accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
    MapXNode filterElement = createFilter();
    SearchFilterType filter = new SearchFilterType();
    filter.setFilterClauseXNode(filterElement);
    accountRefType.setFilter(filter);
    userType.getLinkRef().add(accountRefType);
    assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID);
    user.checkConsistence();
    user.assertDefinitions();
    PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
    assertEquals("1/ Wrong accountRef values", 1, accountRef.getValues().size());
    PrismReferenceValue accountRefVal0 = accountRef.getValue(0);
    SearchFilterType prismFilter = accountRefVal0.getFilter();
    assertNotNull("Filter have not passed", prismFilter);
    //assertTrue("Bad filter in reference", prismFilter instanceof EqualsFilter);
    //        assertEquals("Difference filter", filterElement, prismFilter);
    ShadowType accountShadowType = new ShadowType();
    prismContext.adopt(accountShadowType);
    accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
    userType.getLink().add(accountShadowType);
    //value still should be only one... (reference was only resolved)
    assertEquals("2/ Wrong accountRef values", 1, user.findReference(UserType.F_LINK_REF).getValues().size());
    accountShadowType = new ShadowType();
    prismContext.adopt(accountShadowType);
    accountShadowType.setOid(USER_ACCOUNT_REF_2_OID);
    userType.getLink().add(accountShadowType);
    assertEquals("3/ Wrong accountRef values", 2, user.findReference(UserType.F_LINK_REF).getValues().size());
    assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
    user.checkConsistence();
    user.assertDefinitions();
    assertEquals("4/ Wrong accountRef values", 2, accountRef.getValues().size());
    PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExtensionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 75 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class TestJaxbConstruction method testUserConstructionBeforeAdopt.

@Test
public void testUserConstructionBeforeAdopt() throws Exception {
    System.out.println("\n\n ===[ testUserConstructionBeforeAdopt ]===\n");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    UserType userType = new UserType();
    userType.setFullName(new PolyStringType("Čučoriedka"));
    userType.setDescription("blah blah");
    ExtensionType extension = new ExtensionType();
    userType.setExtension(extension);
    AssignmentType assignmentType = new AssignmentType();
    userType.getAssignment().add(assignmentType);
    // Assignment
    ExtensionType assignmentExtension = new ExtensionType();
    assignmentType.setExtension(assignmentExtension);
    // accountRef/account
    ObjectReferenceType accountRefType = new ObjectReferenceType();
    accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
    MapXNode filterElement = createFilter();
    SearchFilterType filter = new SearchFilterType();
    filter.setFilterClauseXNode(filterElement);
    accountRefType.setFilter(filter);
    userType.getLinkRef().add(accountRefType);
    ShadowType accountShadowType = new ShadowType();
    accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
    userType.getLink().add(accountShadowType);
    accountShadowType = new ShadowType();
    accountShadowType.setOid(USER_ACCOUNT_REF_2_OID);
    userType.getLink().add(accountShadowType);
    // WHEN
    prismContext.adopt(userType);
    // THEN
    PrismObject<UserType> user = userType.asPrismObject();
    assertNotNull("No object definition after adopt", user.getDefinition());
    SchemaTestUtil.assertUserDefinition(user.getDefinition());
    // fullName: PolyString
    PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
    user.checkConsistence();
    user.assertDefinitions();
    PolyString fullName = fullNameProperty.getRealValue();
    assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
    assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
    PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
    assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
    PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
    checkExtension(extensionContainer, "user extension");
    checkExtension(extension, "user extension");
    PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
    assertEquals("Wrong accountRef values", 2, accountRef.getValues().size());
    PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
    PrismReferenceValue accountRefVal0 = accountRef.getValue(0);
    SearchFilterType prismFilter = accountRefVal0.getFilter();
    assertNotNull("Filter have not passed", prismFilter);
    // assertTrue("Wrong filter in reference " , prismFilter instanceof EqualsFilter);
    //        assertEquals("Difference filter", filterElement, prismFilter);
    assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
    user.assertDefinitions();
    user.checkConsistence();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ExtensionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4