use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class MidpointAbstractHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(@NotNull T object, @NotNull HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
// TODO implement in the standard serializer; also change root name
QName fakeQName = new QName(PrismConstants.NS_TYPES, "object");
String serializedForm;
PrismSerializer<String> serializer = getSerializer().options(SerializationOptions.createSerializeReferenceNames());
try {
if (object instanceof ObjectType) {
ObjectType ot = (ObjectType) object;
serializedForm = serializer.serialize(ot.asPrismObject());
} else if (object instanceof PrismObject) {
serializedForm = serializer.serialize((PrismObject<?>) object);
} else if (object instanceof OperationResult) {
Function<LocalizableMessage, String> resolveKeys = msg -> localizationService.translate(msg, Locale.US);
OperationResultType operationResultType = ((OperationResult) object).createOperationResultType(resolveKeys);
serializedForm = serializer.serializeAnyData(operationResultType, fakeQName);
} else {
serializedForm = serializer.serializeAnyData(object, fakeQName);
}
outputMessage.getBody().write(serializedForm.getBytes(StandardCharsets.UTF_8));
} catch (SchemaException | RuntimeException e) {
LoggingUtils.logException(LOGGER, "Couldn't marshal element to string: {}", e, object);
}
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ObjectPolicyAspectPart method prepareObjectRelatedTaskInstructions.
private <T extends ObjectType> void prepareObjectRelatedTaskInstructions(List<PcpStartInstruction> instructions, ApprovalSchemaBuilder.Result builderResult, List<ObjectDelta<T>> deltasToApprove, PrismObject<? extends FocusType> requester, ModelInvocationContext<T> ctx, OperationResult result) throws SchemaException {
ModelContext<T> modelContext = ctx.modelContext;
for (ObjectDelta<T> deltaToApprove : deltasToApprove) {
LocalizableMessage processName = main.createProcessName(builderResult, null, ctx, result);
if (main.useDefaultProcessName(processName)) {
processName = createDefaultProcessName(ctx, deltaToApprove);
}
String processNameInDefaultLocale = localizationService.translate(processName, Locale.getDefault(), "(unnamed)");
PcpStartInstruction instruction = PcpStartInstruction.createItemApprovalInstruction(main.getChangeProcessor(), builderResult.schemaType, builderResult.attachedRules);
instruction.prepareCommonAttributes(main, modelContext, requester);
instruction.setDeltasToApprove(deltaToApprove);
instruction.setObjectRef(ctx);
instruction.setName(processNameInDefaultLocale, processName);
instructions.add(instruction);
}
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ObjectModificationConstraintEvaluator method createMessage.
private <AH extends AssignmentHolderType> LocalizableMessage createMessage(JAXBElement<ModificationPolicyConstraintType> constraint, PolicyRuleEvaluationContext<AH> rctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
String keyPostfix = createStateKey(rctx) + createOperationKey(rctx);
LocalizableMessage builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix).args(ObjectTypeUtil.createDisplayInformation(rctx.focusContext.getObjectAny(), true)).build();
return evaluatorHelper.createLocalizableMessage(constraint, rctx, builtInMessage, result);
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ObjectModificationConstraintEvaluator method createShortMessage.
private <AH extends AssignmentHolderType> LocalizableMessage createShortMessage(JAXBElement<ModificationPolicyConstraintType> constraint, PolicyRuleEvaluationContext<AH> rctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
String keyPostfix = createStateKey(rctx) + createOperationKey(rctx);
LocalizableMessage builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix).args(ObjectTypeUtil.createDisplayInformation(rctx.focusContext.getObjectAny(), false)).build();
return evaluatorHelper.createLocalizableShortMessage(constraint, rctx, builtInMessage, result);
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class StateConstraintEvaluator method evaluateForObject.
private <AH extends AssignmentHolderType> EvaluatedStateTrigger evaluateForObject(JAXBElement<StatePolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
StatePolicyConstraintType constraint = constraintElement.getValue();
int count = (constraint.getFilter() != null ? 1 : 0) + (constraint.getExpression() != null ? 1 : 0) + (constraint.getMessageExpression() != null ? 1 : 0) + (constraint.getExecuteScript() != null ? 1 : 0);
if (count != 1) {
throw new SchemaException("Exactly one of filter, expression, messageExpression, executeScript element must be present.");
}
PrismObject<AH> object = ctx.getObject();
if (object == null) {
return null;
}
if (constraint.getFilter() != null) {
ObjectFilter filter = prismContext.getQueryConverter().parseFilter(constraint.getFilter(), object.asObjectable().getClass());
if (!filter.match(object.getValue(), matchingRuleRegistry)) {
return null;
}
}
if (constraint.getExecuteScript() != null) {
VariablesMap variables = new VariablesMap();
variables.put(VAR_OBJECT, object, object.getDefinition());
variables.put(VAR_RULE_EVALUATION_CONTEXT, ctx, PolicyRuleEvaluationContext.class);
ExecutionContext resultingContext;
try {
resultingContext = scriptingExpressionEvaluator.evaluateExpressionPrivileged(constraint.getExecuteScript(), variables, ctx.task, result);
} catch (ScriptExecutionException e) {
// TODO
throw new SystemException(e);
}
PipelineData output = resultingContext.getFinalOutput();
LOGGER.trace("Scripting expression returned {} item(s); console output is:\n{}", output != null ? output.getData().size() : null, resultingContext.getConsoleOutput());
List<PipelineItem> items = output != null ? output.getData() : emptyList();
if (items.isEmpty()) {
return null;
}
// TODO retrieve localization messages from output
}
if (constraint.getMessageExpression() != null) {
LocalizableMessageType messageBean = evaluatorHelper.evaluateLocalizableMessageType(constraint.getMessageExpression(), evaluatorHelper.createVariablesMap(ctx, constraintElement), "message expression in object state constraint " + constraint.getName() + " (" + ctx.state + ")", ctx.task, result);
if (messageBean == null) {
return null;
} else {
LocalizableMessage message = LocalizationUtil.toLocalizableMessage(messageBean);
return new EvaluatedStateTrigger(OBJECT_STATE, constraint, message, message);
}
}
if (constraint.getExpression() != null) {
if (!evaluatorHelper.evaluateBoolean(constraint.getExpression(), evaluatorHelper.createVariablesMap(ctx, constraintElement), "expression in object state constraint " + constraint.getName() + " (" + ctx.state + ")", ctx.task, result)) {
return null;
}
}
return new EvaluatedStateTrigger(OBJECT_STATE, constraint, createMessage(OBJECT_CONSTRAINT_KEY_PREFIX, constraintElement, ctx, false, result), createShortMessage(OBJECT_CONSTRAINT_KEY_PREFIX, constraintElement, ctx, false, result));
}
Aggregations