Search in sources :

Example 1 with RawType

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

the class PrismInternalTestUtil method assertUserJackContent.

public static void assertUserJackContent(PrismObject<UserType> user, boolean expectRawInConstructions) throws SchemaException {
    assertEquals("Wrong oid", USER_JACK_OID, user.getOid());
    assertEquals("Wrong version", "42", user.getVersion());
    PrismAsserts.assertObjectDefinition(user.getDefinition(), USER_QNAME, USER_TYPE_QNAME, UserType.class);
    PrismAsserts.assertParentConsistency(user);
    assertPropertyValue(user, "fullName", "cpt. Jack Sparrow");
    assertPropertyDefinition(user, "fullName", DOMUtil.XSD_STRING, 1, 1);
    assertPropertyValue(user, "givenName", "Jack");
    assertPropertyDefinition(user, "givenName", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "familyName", "Sparrow");
    assertPropertyDefinition(user, "familyName", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "name", new PolyString("jack", "jack"));
    assertPropertyDefinition(user, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    assertPropertyValue(user, "special", "got it!");
    assertPropertyDefinition(user, "special", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "polyName", new PolyString("Džek Sperou", "dzek sperou"));
    assertPropertyDefinition(user, "polyName", PolyStringType.COMPLEX_TYPE, 0, 1);
    ItemPath enabledPath = USER_ENABLED_PATH;
    PrismProperty<Boolean> enabledProperty1 = user.findProperty(enabledPath);
    assertNotNull("No enabled property", enabledProperty1);
    PrismAsserts.assertDefinition(enabledProperty1.getDefinition(), USER_ENABLED_QNAME, DOMUtil.XSD_BOOLEAN, 0, 1);
    assertNotNull("Property " + enabledPath + " not found", enabledProperty1);
    PrismAsserts.assertPropertyValue(enabledProperty1, true);
    PrismProperty<XMLGregorianCalendar> validFromProperty = user.findProperty(USER_VALID_FROM_PATH);
    assertNotNull("Property " + USER_VALID_FROM_PATH + " not found", validFromProperty);
    PrismAsserts.assertPropertyValue(validFromProperty, USER_JACK_VALID_FROM);
    QName actName = new QName(NS_FOO, "activation");
    // Use path
    ItemPath actPath = new ItemPath(actName);
    PrismContainer<ActivationType> actContainer1 = user.findContainer(actPath);
    assertContainerDefinition(actContainer1, "activation", ACTIVATION_TYPE_QNAME, 0, 1);
    assertNotNull("Property " + actPath + " not found", actContainer1);
    assertEquals("Wrong activation name", actName, actContainer1.getElementName());
    // Use name
    PrismContainer<ActivationType> actContainer2 = user.findContainer(actName);
    assertNotNull("Property " + actName + " not found", actContainer2);
    assertEquals("Wrong activation name", actName, actContainer2.getElementName());
    // Compare
    assertEquals("Eh?", actContainer1, actContainer2);
    PrismProperty<Boolean> enabledProperty2 = actContainer1.findProperty(new QName(NS_FOO, "enabled"));
    assertNotNull("Property enabled not found", enabledProperty2);
    PrismAsserts.assertPropertyValue(enabledProperty2, true);
    assertEquals("Eh?", enabledProperty1, enabledProperty2);
    QName assName = new QName(NS_FOO, "assignment");
    QName descriptionName = new QName(NS_FOO, "description");
    QName accountConstructionName = new QName(NS_FOO, "accountConstruction");
    PrismContainer<AssignmentType> assContainer = user.findContainer(assName);
    assertEquals("Wrong assignement values", 2, assContainer.getValues().size());
    PrismProperty<String> a2DescProperty = assContainer.getValue(USER_ASSIGNMENT_2_ID).findProperty(descriptionName);
    assertEquals("Wrong assigment 2 description", "Assignment 2", a2DescProperty.getValue().getValue());
    ItemPath a1Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_1_ID), new NameItemPathSegment(descriptionName));
    PrismProperty a1Property = user.findProperty(a1Path);
    assertNotNull("Property " + a1Path + " not found", a1Property);
    PrismAsserts.assertPropertyValue(a1Property, "Assignment 1");
    ItemPath a2Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(accountConstructionName));
    PrismProperty a2Property = user.findProperty(a2Path);
    assertNotNull("Property " + a2Path + " not found", a2Property);
    AccountConstructionType accountConstructionType = (AccountConstructionType) a2Property.getRealValue();
    assertEquals("Wrong number of values in accountConstruction", 2, accountConstructionType.getValue().size());
    RawType value1 = accountConstructionType.getValue().get(0).clone();
    if (expectRawInConstructions) {
        assertNotNull("Value #1 has no XNode present", value1.getXnode());
        PrismPropertyDefinition value1def = new PrismPropertyDefinitionImpl(// element name
        new QName(NS_FOO, "dummy"), // type name
        DOMUtil.XSD_STRING, user.getPrismContext());
        PrismPropertyValue<String> prismValue1 = value1.getParsedValue(value1def, value1def.getName());
        assertEquals("Wrong value #1", "ABC", prismValue1.getValue());
    } else {
        assertNull("Value #1 has XNode present", value1.getXnode());
        assertEquals("Wrong value #1", "ABC", value1.getParsedRealValue(String.class));
    }
    RawType value2 = accountConstructionType.getValue().get(1).clone();
    assertNotNull("Value #2 has no XNode present", value2.getXnode());
    PrismValue prismValue2 = value2.getParsedValue(user.getDefinition(), user.getDefinition().getName());
    PrismContainerValue<UserType> prismUserValue2 = (PrismContainerValue<UserType>) prismValue2;
    assertEquals("Wrong value #2", "Nobody", prismUserValue2.findProperty(new QName(NS_FOO, "fullName")).getRealValue());
    PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME);
    assertNotNull("Reference " + USER_ACCOUNTREF_QNAME + " not found", accountRef);
    assertEquals("Wrong number of accountRef values", 3, accountRef.getValues().size());
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1111");
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1113");
    PrismReferenceValue accountRefVal2 = accountRef.findValueByOid("c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
    assertEquals("Wrong oid for accountRef", "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112", accountRefVal2.getOid());
    assertEquals("Wrong accountRef description", "This is a reference with a filter", accountRefVal2.getDescription());
    assertNotNull("No filter in accountRef", accountRefVal2.getFilter());
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) AccountConstructionType(com.evolveum.midpoint.prism.foo.AccountConstructionType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) QName(javax.xml.namespace.QName) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with RawType

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

the class PipelineData method parseFrom.

static PipelineData parseFrom(ValueListType input, PrismContext prismContext) {
    PipelineData rv = new PipelineData();
    if (input != null) {
        for (Object o : input.getValue()) {
            if (o instanceof RawType) {
                // a bit of hack: this should have been solved by the parser (we'll fix this later)
                RawType raw = (RawType) o;
                PrismValue prismValue = raw.getAlreadyParsedValue();
                if (prismValue != null) {
                    rv.addValue(prismValue);
                } else {
                    throw new IllegalArgumentException("Raw value in the input data: " + DebugUtil.debugDump(raw.getXnode()));
                // TODO attempt to parse it somehow (e.g. by passing to the pipeline and then parsing based on expected type)
                }
            } else {
                if (o instanceof Containerable) {
                    rv.addValue(((Containerable) o).asPrismContainerValue());
                } else if (o instanceof Referencable) {
                    rv.addValue(((Referencable) o).asReferenceValue());
                } else {
                    rv.addValue(new PrismPropertyValue<>(o, prismContext));
                }
            }
        }
    }
    return rv;
}
Also used : RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 3 with RawType

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

the class TestParseDiffPatch method getParsedShadowBefore.

protected PrismObject<ShadowType> getParsedShadowBefore(PrismContext prismContext) throws SchemaException, IOException {
    PrismObject<ShadowType> oldObject = getRawShadowBefore(prismContext);
    // resolve rawtypes
    ObjectDeltaType objectChange = oldObject.asObjectable().getObjectChange();
    for (ItemDeltaType itemDeltaType : objectChange.getItemDelta()) {
        for (RawType rawType : itemDeltaType.getValue()) {
            rawType.getParsedItem(new PrismPropertyDefinitionImpl(itemDeltaType.getPath().getItemPath().lastNamed().getName(), rawType.getXnode().getTypeQName(), prismContext));
        }
    }
    return oldObject;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 4 with RawType

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

the class TestJaxbSanity method testAssignmentEquals.

@Test
public void testAssignmentEquals() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testAssnignmentEquals]===\n");
    // GIVEN
    JAXBElement<UserType> userEl1 = JaxbTestUtil.getInstance().unmarshalElement(new File(USER_BARBOSSA_FILENAME), UserType.class);
    UserType user = userEl1.getValue();
    assertNotNull(user);
    AssignmentType userAssignmentType = user.getAssignment().get(0);
    assertNotNull(userAssignmentType);
    System.out.println("\n*** user assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(userAssignmentType));
    JAXBElement<ObjectModificationType> modEl = JaxbTestUtil.getInstance().unmarshalElement(new File(TEST_DIR, "user-barbossa-modify-delete-assignment-account-opendj-attr.xml"), ObjectModificationType.class);
    ObjectModificationType mod = modEl.getValue();
    assertNotNull(mod);
    //FIXME : modification value -> rawType...
    RawType rawType = mod.getItemDelta().get(0).getValue().get(0);
    ItemDefinition assignmentDefinition = PrismTestUtil.getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
    assertNotNull(assignmentDefinition);
    AssignmentType assignmentType = ((PrismContainerValue<AssignmentType>) rawType.getParsedValue(assignmentDefinition, null)).getValue();
    //                was: (JAXBElement<AssignmentType>) mod.getItemDelta().get(0).getValue().get(0).getContent().get(0);
    assertNotNull(assignmentType);
    System.out.println("\n*** assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(assignmentType));
    // WHEN, THEN
    assertTrue("Assignment not equals", userAssignmentType.equals(assignmentType));
    assertTrue("HashCode does not match", userAssignmentType.hashCode() == assignmentType.hashCode());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with RawType

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

the class TestParseObjectTemplate method assertObjectTemplateInternals.

// checks raw values of mappings
// should be called only on reparsed values in order to catch some raw-data-related serialization issues (MID-2196)
private void assertObjectTemplateInternals(PrismObject<ObjectTemplateType> object, QName elementName) throws SchemaException {
    int assignmentValuesFound = 0;
    for (ObjectTemplateMappingType mappingType : object.asObjectable().getMapping()) {
        if (mappingType.getExpression() != null) {
            if (mappingType.getTarget() != null && mappingType.getTarget().getPath() != null && new ItemPath(UserType.F_ASSIGNMENT).equivalent(mappingType.getTarget().getPath().getItemPath())) {
                ItemDefinition assignmentDef = PrismTestUtil.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findItemDefinition(UserType.F_ASSIGNMENT);
                for (JAXBElement evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                    if (evaluator.getValue() instanceof RawType) {
                        RawType rawType = (RawType) evaluator.getValue();
                        Item assignment = rawType.getParsedItem(assignmentDef);
                        System.out.println("assignment:\n" + assignment.debugDump());
                        assignmentValuesFound++;
                    }
                }
            }
        }
    }
    assertEquals("wrong # of assignment values found in mapping", 2, assignmentValuesFound);
}
Also used : ObjectTemplateMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)62 QName (javax.xml.namespace.QName)22 Test (org.testng.annotations.Test)19 JAXBElement (javax.xml.bind.JAXBElement)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)10 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)9 ArrayList (java.util.ArrayList)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 Task (com.evolveum.midpoint.task.api.Task)8 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)6 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5