use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class AssignmentPolicyAspectPart method prepareAssignmentRelatedStartInstruction.
private PcpStartInstruction prepareAssignmentRelatedStartInstruction(ApprovalSchemaBuilder.Result builderResult, EvaluatedAssignment<?> evaluatedAssignment, ObjectDelta<? extends ObjectType> deltaToApprove, PrismObject<? extends FocusType> requester, ModelInvocationContext<?> ctx, OperationResult result) throws SchemaException {
ModelContext<?> modelContext = ctx.modelContext;
@SuppressWarnings("unchecked") PrismObject<? extends ObjectType> target = (PrismObject<? extends ObjectType>) evaluatedAssignment.getTarget();
Validate.notNull(target, "assignment target is null");
LocalizableMessage processName = main.createProcessName(builderResult, evaluatedAssignment, ctx, result);
if (main.useDefaultProcessName(processName)) {
processName = createDefaultProcessName(ctx, evaluatedAssignment, target);
}
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.setTargetRef(createObjectRef(target, prismContext), result);
instruction.setName(processNameInDefaultLocale, processName);
return instruction;
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class TestPolicyRules method test400AssignRoleLocalized.
/**
* Tests policy rule messages for objects with localized names.
* See also MID-5916.
*/
@Test
public void test400AssignRoleLocalized() throws Exception {
Task task = getTestTask();
OperationResult result = getTestOperationResult();
// GIVEN
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_LOCALIZED.oid, result);
addModificationToContextAssignRole(context, USER_LOCALIZED.oid, ROLE_LOCALIZED.oid);
displayDumpable("Input context", context);
assertFocusModificationSanity(context);
// WHEN
when();
projector.project(context, "test", task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
dumpPolicyRules(context);
Locale SLOVAK = Locale.forLanguageTag("sk-SK");
assertNotNull("No Slovak locale", SLOVAK);
// sanity check
PrismObject<RoleType> roleLocalized = getRole(ROLE_LOCALIZED.oid);
String roleNameUs = localizationService.translate(roleLocalized.getName(), Locale.US, false);
String roleNameSk = localizationService.translate(roleLocalized.getName(), SLOVAK, false);
System.out.println("Role name translated (US): " + roleNameUs);
System.out.println("Role name translated (SK): " + roleNameSk);
assertEquals("Wrong US role name", roleNameUs, "Localized role");
assertEquals("Wrong SK role name", roleNameSk, "Lokalizovana rola");
// checking the rules
assertEvaluatedTargetPolicyRules(context, 1);
assertTargetTriggers(context, PolicyConstraintKindType.ASSIGNMENT_MODIFICATION, 1);
EvaluatedPolicyRuleTrigger<?> trigger = assertTriggeredTargetPolicyRule(context, ROLE_LOCALIZED.oid, PolicyConstraintKindType.ASSIGNMENT_MODIFICATION, 1, true);
LocalizableMessage message = trigger.getMessage();
System.out.println("Trigger message: " + message);
String messageUs = localizationService.translate(message, Locale.US);
String messageSk = localizationService.translate(message, SLOVAK);
System.out.println("Trigger message translated (US): " + messageUs);
System.out.println("Trigger message translated (SK): " + messageSk);
assertEquals("Wrong US message", messageUs, "Assignment of role \"Localized role\" (relation default) is to be added");
assertEquals("Wrong SK message", messageSk, "Priradenie pre rola \"Lokalizovana rola\" (vztah default) ma byt pridane");
assertSerializable(context);
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ExclusionConstraintEvaluator method createObjectInfo.
private LocalizableMessage createObjectInfo(AssignmentPath path, PrismObject<?> defaultObject, boolean startsWithUppercase) {
if (path == null) {
return ObjectTypeUtil.createDisplayInformation(defaultObject, startsWithUppercase);
}
List<ObjectType> objects = path.getFirstOrderChain();
if (objects.isEmpty()) {
// shouldn't occur
return ObjectTypeUtil.createDisplayInformation(defaultObject, startsWithUppercase);
}
PrismObject<?> last = objects.get(objects.size() - 1).asPrismObject();
if (objects.size() == 1) {
return ObjectTypeUtil.createDisplayInformation(last, startsWithUppercase);
}
String pathString = objects.stream().map(o -> PolyString.getOrig(o.getName())).collect(Collectors.joining(" -> "));
return ObjectTypeUtil.createDisplayInformationWithPath(last, startsWithUppercase, pathString);
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ExclusionConstraintEvaluator method createTrigger.
private <AH extends AssignmentHolderType> EvaluatedExclusionTrigger createTrigger(EvaluatedAssignmentImpl<AH> assignmentA, @NotNull EvaluatedAssignmentImpl<AH> assignmentB, EvaluatedAssignmentTargetImpl targetB, JAXBElement<ExclusionPolicyConstraintType> constraintElement, EvaluatedPolicyRule policyRule, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
AssignmentPath pathA = policyRule.getAssignmentPath();
AssignmentPath pathB = targetB.getAssignmentPath();
LocalizableMessage infoA = createObjectInfo(pathA, assignmentA.getTarget(), true);
LocalizableMessage infoB = createObjectInfo(pathB, targetB.getTarget(), false);
ObjectType objectA = getConflictingObject(pathA, assignmentA.getTarget());
ObjectType objectB = getConflictingObject(pathB, targetB.getTarget());
LocalizableMessage message = createMessage(infoA, infoB, constraintElement, ctx, result);
LocalizableMessage shortMessage = createShortMessage(infoA, infoB, constraintElement, ctx, result);
return new EvaluatedExclusionTrigger(constraintElement.getValue(), message, shortMessage, assignmentB, objectA, objectB, pathA, pathB);
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ObjectModificationConstraintEvaluator method evaluate.
@Override
public <AH extends AssignmentHolderType> EvaluatedModificationTrigger evaluate(@NotNull JAXBElement<ModificationPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
try {
if (!(rctx instanceof ObjectPolicyRuleEvaluationContext)) {
LOGGER.trace("Policy rule evaluation context is not of type ObjectPolicyRuleEvaluationContext. Skipping processing.");
return null;
}
ObjectPolicyRuleEvaluationContext<AH> ctx = (ObjectPolicyRuleEvaluationContext<AH>) rctx;
if (modificationConstraintMatches(constraint, ctx, result)) {
LocalizableMessage message = createMessage(constraint, rctx, result);
LocalizableMessage shortMessage = createShortMessage(constraint, rctx, result);
return new EvaluatedModificationTrigger(PolicyConstraintKindType.OBJECT_MODIFICATION, constraint.getValue(), null, message, shortMessage);
} else {
LOGGER.trace("No operation matches.");
return null;
}
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
Aggregations