Search in sources :

Example 6 with ObjectTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.

the class Migrator method migrateObjectTemplate.

private PrismObject<ObjectTemplateType> migrateObjectTemplate(PrismObject<ObjectTemplateType> orig) {
    QName elementName = orig.getElementName();
    if (elementName.equals(SchemaConstants.C_OBJECT_TEMPLATE)) {
        return orig;
    }
    PrismObject<ObjectTemplateType> migrated = orig.clone();
    migrated.setElementName(SchemaConstants.C_OBJECT_TEMPLATE);
    return migrated;
}
Also used : QName(javax.xml.namespace.QName) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)

Example 7 with ObjectTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.

the class TestParseLookupTable method testParseTableFileRoundTrip.

@Test
public void testParseTableFileRoundTrip() throws Exception {
    System.out.println("===[ testParseTableFileRoundTrip ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    PrismObject<LookupTableType> table = prismContext.parserFor(LOOKUP_TABLE_FILE).xml().parse();
    // THEN
    System.out.println("Parsed table:");
    System.out.println(table.debugDump());
    assertTable(table);
    // WHEN
    String xml = prismContext.serializeObjectToString(table, PrismContext.LANG_XML);
    // THEN
    System.out.println("Serialized object:");
    System.out.println(xml);
    // WHEN
    PrismObject<ObjectTemplateType> reparsedObject = prismContext.parseObject(xml);
    // THEN
    System.out.println("Re-parsed object:");
    System.out.println(reparsedObject.debugDump());
    assertTable(table);
    PrismAsserts.assertEquals(table.asObjectable(), reparsedObject.asObjectable());
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Example 8 with ObjectTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType 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)

Example 9 with ObjectTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.

the class TestParseObjectTemplate method testParseWrongTemplateFile.

@Test
public void testParseWrongTemplateFile() throws Exception {
    final String TEST_NAME = "testParseWrongTemplateFile";
    File file = WRONG_TEMPLATE_FILE;
    System.out.println("===[ " + TEST_NAME + " ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    try {
        PrismObject<ObjectTemplateType> object = prismContext.parseObject(file);
        System.out.println("Parsed object - SHOULD NOT OCCUR:");
        System.out.println(object.debugDump());
        fail("Object was successfully parsed while it should not!");
    }// THEN
     catch (SchemaException e) {
    // ok
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) File(java.io.File) Test(org.testng.annotations.Test)

Example 10 with ObjectTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType in project midpoint by Evolveum.

the class SchemaTransformer method applyObjectTemplateToDefinition.

public <O extends ObjectType> void applyObjectTemplateToDefinition(PrismObjectDefinition<O> objectDefinition, ObjectTemplateType objectTemplateType, OperationResult result) throws ObjectNotFoundException, SchemaException {
    if (objectTemplateType == null) {
        return;
    }
    for (ObjectReferenceType includeRef : objectTemplateType.getIncludeRef()) {
        PrismObject<ObjectTemplateType> subTemplate = cacheRepositoryService.getObject(ObjectTemplateType.class, includeRef.getOid(), null, result);
        applyObjectTemplateToDefinition(objectDefinition, subTemplate.asObjectable(), result);
    }
    for (ObjectTemplateItemDefinitionType templateItemDefType : objectTemplateType.getItem()) {
        ItemPathType ref = templateItemDefType.getRef();
        if (ref == null) {
            throw new SchemaException("No 'ref' in item definition in " + objectTemplateType);
        }
        ItemPath itemPath = ref.getItemPath();
        ItemDefinition itemDef = objectDefinition.findItemDefinition(itemPath);
        if (itemDef != null) {
            applyObjectTemplateItem(itemDef, templateItemDefType, "item " + itemPath + " in object type " + objectDefinition.getTypeName() + " as specified in item definition in " + objectTemplateType);
        } else {
            OperationResult subResult = result.createMinorSubresult(SchemaTransformer.class.getName() + ".applyObjectTemplateToDefinition");
            subResult.recordPartialError("No definition for item " + itemPath + " in object type " + objectDefinition.getTypeName() + " as specified in item definition in " + objectTemplateType);
            continue;
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ObjectTemplateType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)19 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 ObjectTemplateItemDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ObjectTemplateMappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ObjectPolicyConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType)3 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 DeltaSetTriple (com.evolveum.midpoint.prism.delta.DeltaSetTriple)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 Task (com.evolveum.midpoint.task.api.Task)2 PersonaConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2