Search in sources :

Example 26 with LocalizableMessage

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;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject.asPrismObject(com.evolveum.midpoint.prism.PrismObject.asPrismObject) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction)

Example 27 with LocalizableMessage

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);
}
Also used : Locale(java.util.Locale) Task(com.evolveum.midpoint.task.api.Task) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 28 with LocalizableMessage

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);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) EvaluationOrder(com.evolveum.midpoint.model.api.context.EvaluationOrder) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Map(java.util.Map) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) ExclusionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType) EvaluatedAssignmentTargetImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType) PolicyRuleTypeUtil(com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil) JAXBElement(javax.xml.bind.JAXBElement) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath) AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) PolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) List(java.util.List) Component(org.springframework.stereotype.Component) DebugUtil.lazy(com.evolveum.midpoint.util.DebugUtil.lazy) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) QName(javax.xml.namespace.QName) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 29 with LocalizableMessage

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);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath)

Example 30 with LocalizableMessage

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();
    }
}
Also used : EvaluatedModificationTrigger(com.evolveum.midpoint.model.api.context.EvaluatedModificationTrigger) ObjectPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectPolicyRuleEvaluationContext) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)33 LocalizableMessageBuilder (com.evolveum.midpoint.util.LocalizableMessageBuilder)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)8 NotNull (org.jetbrains.annotations.NotNull)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)5 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 QName (javax.xml.namespace.QName)4 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)3 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)3 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)3 PolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext)3 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3