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);
}
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;
}
}
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);
}
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());
}
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);
}
Aggregations