Search in sources :

Example 31 with RawType

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

the class TestParseTaskBulkAction2 method testParseTaskRoundtrip.

@Test
public void testParseTaskRoundtrip() throws Exception {
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);
    System.out.println("Parsed task:");
    System.out.println(task.debugDump());
    task.checkConsistence();
    // SERIALIZE
    String serializedTask = prismContext.xmlSerializer().serialize(task);
    System.out.println("serialized task:");
    System.out.println(serializedTask);
    // RE-PARSE
    RootXNode reparsedToXNode = prismContext.parserFor(serializedTask).xml().parseToXNode();
    System.out.println("Re-parsed task (to XNode):");
    System.out.println(reparsedToXNode.debugDump());
    // real reparse
    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);
    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());
    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    reparsedTask.checkConsistence();
    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());
    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
    Item executeScriptItem = reparsedTask.findExtensionItem(new QName("executeScript"));
    ExecuteScriptType executeScript = (ExecuteScriptType) executeScriptItem.getRealValue();
    Object o = executeScript.getInput().getValue().get(0);
    System.out.println(o);
    assertTrue("Raw value is not parsed", o instanceof RawType && ((RawType) o).getAlreadyParsedValue() != null);
}
Also used : Item(com.evolveum.midpoint.prism.Item) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismObject(com.evolveum.midpoint.prism.PrismObject) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Test(org.testng.annotations.Test)

Example 32 with RawType

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

the class ValueDisplayUtil method toStringValue.

private static String toStringValue(Object value) {
    // todo i18n
    String defaultStr = "(a value of type " + value.getClass().getSimpleName() + ")";
    if (value instanceof String) {
        return (String) value;
    } else if (value instanceof PolyString) {
        return ((PolyString) value).getOrig();
    } else if (value instanceof ProtectedStringType) {
        // todo i18n
        return "(protected string)";
    } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) {
        return value.toString();
    } else if (value instanceof XMLGregorianCalendar) {
        // todo fix
        return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString();
    } else if (value instanceof Date) {
        // todo fix
        return ((Date) value).toLocaleString();
    } else if (value instanceof LoginEventType) {
        LoginEventType loginEventType = (LoginEventType) value;
        if (loginEventType.getTimestamp() != null) {
            // todo fix
            return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString();
        } else {
            return "";
        }
    } else if (value instanceof ScheduleType) {
        return SchemaDebugUtil.prettyPrint((ScheduleType) value);
    } else if (value instanceof ApprovalSchemaType) {
        ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value;
        return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)";
    } else if (value instanceof ConstructionType) {
        ConstructionType ct = (ConstructionType) value;
        Object resource = (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null);
        return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : "");
    } else if (value instanceof Enum) {
        return value.toString();
    } else if (value instanceof ResourceAttributeDefinitionType) {
        ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value;
        ItemPathType ref = radt.getRef();
        String path;
        if (ref != null) {
            path = ref.getItemPath().toString();
        } else {
            path = "(null)";
        }
        StringBuilder sb = new StringBuilder();
        MappingType mappingType = radt.getOutbound();
        if (mappingType != null) {
            if (mappingType.getExpression() == null) {
                sb.append("Empty mapping for ").append(path);
            } else {
                sb.append(path).append(" = ");
                boolean first = true;
                for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                    if (first) {
                        first = false;
                    } else {
                        sb.append(", ");
                    }
                    if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
                        RawType raw = (RawType) evaluator.getValue();
                        try {
                            sb.append(raw.extractString("(a complex value)"));
                        } catch (RuntimeException e) {
                            sb.append("(an invalid value)");
                        }
                    } else {
                        sb.append("(a complex expression)");
                    }
                }
            }
            if (mappingType.getStrength() != null) {
                sb.append(" (").append(mappingType.getStrength().value()).append(")");
            }
        } else {
            sb.append("Empty mapping for ").append(path);
        }
        return sb.toString();
    } else if (value instanceof QName) {
        QName qname = (QName) value;
        return qname.getLocalPart();
    // if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
    // return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")";
    // } else {
    // return qname.getLocalPart();
    // }
    } else if (value instanceof Number) {
        return String.valueOf(value);
    } else if (value instanceof byte[]) {
        return "(binary data)";
    } else if (value instanceof RawType) {
        try {
            Object parsedValue = ((RawType) value).getValue();
            return toStringValue(parsedValue);
        } catch (SchemaException e) {
            return PrettyPrinter.prettyPrint(value);
        }
    } else if (value instanceof ItemPathType) {
        ItemPath itemPath = ((ItemPathType) value).getItemPath();
        StringBuilder sb = new StringBuilder();
        itemPath.getSegments().forEach(segment -> {
            if (ItemPath.isName(segment)) {
                sb.append(PrettyPrinter.prettyPrint(ItemPath.toName(segment)));
            } else if (ItemPath.isVariable(segment)) {
                sb.append(PrettyPrinter.prettyPrint(ItemPath.toVariableName(segment)));
            } else {
                sb.append(segment.toString());
            }
            sb.append("; ");
        });
        return sb.toString();
    } else if (value instanceof ExpressionType) {
        StringBuilder expressionString = new StringBuilder();
        if (((ExpressionType) value).getExpressionEvaluator() != null && ((ExpressionType) value).getExpressionEvaluator().size() > 0) {
            ((ExpressionType) value).getExpressionEvaluator().forEach(evaluator -> {
                if (evaluator.getValue() instanceof RawType) {
                    expressionString.append(PrettyPrinter.prettyPrint(evaluator.getValue()));
                    expressionString.append("; ");
                } else if (evaluator.getValue() instanceof SearchObjectExpressionEvaluatorType) {
                    SearchObjectExpressionEvaluatorType evaluatorValue = (SearchObjectExpressionEvaluatorType) evaluator.getValue();
                    if (evaluatorValue.getFilter() != null) {
                        DebugUtil.debugDumpMapMultiLine(expressionString, evaluatorValue.getFilter().getFilterClauseXNode().toMap(), 0, false, null);
                        // TODO temporary hack: removing namespace part of the QName
                        while (expressionString.indexOf("}") >= 0 && expressionString.indexOf("{") >= 0 && expressionString.indexOf("}") - expressionString.indexOf("{") > 0) {
                            expressionString.replace(expressionString.indexOf("{"), expressionString.indexOf("}") + 1, "");
                        }
                    }
                } else {
                    expressionString.append(defaultStr);
                }
            });
        }
        return expressionString.toString();
    } else {
        return defaultStr;
    }
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Date(java.util.Date) JAXBElement(javax.xml.bind.JAXBElement) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) DebugUtil(com.evolveum.midpoint.util.DebugUtil) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) QNameUtil(com.evolveum.midpoint.util.QNameUtil) QName(javax.xml.namespace.QName) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Date(java.util.Date) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 33 with RawType

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

the class TestSanity method test502NotifyChangeModifyAccountPassword.

@Test
public void test502NotifyChangeModifyAccountPassword() throws Exception {
    final String TEST_NAME = "test502NotifyChangeModifyAccountPassword";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    String newPassword = "newPassword";
    openDJController.modifyReplace("uid=" + ANGELIKA_NAME + "," + openDJController.getSuffixPeople(), "userPassword", newPassword);
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.MODIFY);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    RawType passwordValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(ModelClientUtil.createProtectedString(newPassword)), prismContext);
    passwordDelta.getValue().add(passwordValue);
    delta.getItemDelta().add(passwordDelta);
    delta.setOid(oid);
    LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(passwordDelta));
    LOGGER.info("delta: {}", DebugUtil.dump(passwordDelta));
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    //    	changeDescription.setCurrentShadow(angelicaShadowType);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    // WHEN
    TaskType task = modelWeb.notifyChange(changeDescription);
    // THEN
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    assertUserLdapPassword(userAngelikaAfterSync, newPassword);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 34 with RawType

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

the class TestSanity method test501NotifyChangeModifyAccount.

@Test
public void test501NotifyChangeModifyAccount() throws Exception {
    final String TEST_NAME = "test501NotifyChangeModifyAccount";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.MODIFY);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType path = new ItemPathType(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(resourceTypeOpenDjrepo.getNamespace(), "givenName")));
    mod1.setPath(path);
    RawType value = new RawType(new PrimitiveXNode<String>("newAngelika"), prismContext);
    mod1.getValue().add(value);
    delta.getItemDelta().add(mod1);
    delta.setOid(oid);
    LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(mod1));
    LOGGER.info("delta: {}", DebugUtil.dump(mod1));
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    // WHEN
    TaskType task = modelWeb.notifyChange(changeDescription);
    // THEN
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    UserType userAfterSync = userAngelikaAfterSync.asObjectable();
    PrismAsserts.assertEqualsPolyString("wrong given name in user angelika", PrismTestUtil.createPolyStringType("newAngelika"), userAfterSync.getGivenName());
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 35 with RawType

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

the class TestSanity method test023ChangeUserPasswordJAXB.

/**
     * Similar to previous test just the request is constructed a bit differently.
     */
@Test
public void test023ChangeUserPasswordJAXB() throws Exception {
    final String TEST_NAME = "test023ChangeUserPasswordJAXB";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final String NEW_PASSWORD = "abandonSHIP";
    Document doc = ModelClientUtil.getDocumnent();
    ObjectDeltaType userDelta = new ObjectDeltaType();
    userDelta.setOid(USER_JACK_OID);
    userDelta.setChangeType(ChangeTypeType.MODIFY);
    userDelta.setObjectType(UserType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    ProtectedStringType pass = new ProtectedStringType();
    pass.setClearValue(NEW_PASSWORD);
    XNode passValue = ((PrismContextImpl) prismContext).getBeanMarshaller().marshall(pass);
    System.out.println("PASSWORD VALUE: " + passValue.debugDump());
    RawType passwordValue = new RawType(passValue, prismContext);
    passwordDelta.getValue().add(passwordValue);
    userDelta.getItemDelta().add(passwordDelta);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(userDelta);
    // THEN
    assertUserPasswordChange(NEW_PASSWORD, result);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Document(org.w3c.dom.Document) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

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