Search in sources :

Example 1 with MessageTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType in project midpoint by Evolveum.

the class NotificationsTest method test120NotifierWithMessageTemplateReferenceAndOverridingContentParts.

@Test
public void test120NotifierWithMessageTemplateReferenceAndOverridingContentParts() throws Exception {
    OperationResult result = getTestOperationResult();
    given("message template");
    String objectName = "messageTemplate" + getTestNumber();
    String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).subjectExpression(velocityExpression("template-subject")).bodyExpression(velocityExpression("template-body")).contentType("text/plain").attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("attachment1"))).asPrismObject(), null, result);
    and("configuration with transport and notifier using the template");
    Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("test").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().messageTemplateRef(createObjectReference(templateOid, MessageTemplateType.COMPLEX_TYPE, null)).subjectExpression(velocityExpression("notifier-subject")).bodyExpression(velocityExpression("notifier-body")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("attachment2")).transport("test")))).asItemDeltas();
    repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
    assertThat(((TestMessageTransport) transportService.getTransport("test")).getMessages()).isEmpty();
    when("event is sent to notification manager");
    CustomEventImpl event = createCustomEvent();
    // This is used as default recipient, no recipient results in no message.
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user@example.com")));
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with content from notifier overriding the declared template parts");
    Message message = getSingleMessage(((TestMessageTransport) transportService.getTransport("test")));
    assertThat(message).isNotNull();
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@example.com");
    assertThat(message.getBody()).isEqualTo("notifier-body");
    assertThat(message.getSubject()).isEqualTo("notifier-subject");
    assertThat(message.getAttachments()).hasSize(2).anyMatch(a -> getRawValue(a.getContent()).equals("attachment1")).anyMatch(a -> getRawValue(a.getContent()).equals("attachment2"));
}
Also used : CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) SimpleExpressionUtil(com.evolveum.midpoint.schema.util.SimpleExpressionUtil) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) CustomMessageTransport(com.evolveum.midpoint.transport.impl.CustomMessageTransport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MailMessageTransport(com.evolveum.midpoint.transport.impl.MailMessageTransport) FileMessageTransport(com.evolveum.midpoint.transport.impl.FileMessageTransport) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) TransportService(com.evolveum.midpoint.notifications.api.transports.TransportService) LightweightIdentifierGenerator(com.evolveum.midpoint.task.api.LightweightIdentifierGenerator) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) Message(com.evolveum.midpoint.notifications.api.transports.Message) SmsMessageTransport(com.evolveum.midpoint.transport.impl.SmsMessageTransport) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Message(com.evolveum.midpoint.notifications.api.transports.Message) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with MessageTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType in project midpoint by Evolveum.

the class NotificationsTest method test160LocalizedMessageTemplateAttachmentInheritance.

@Test
public void test160LocalizedMessageTemplateAttachmentInheritance() throws Exception {
    OperationResult result = getTestOperationResult();
    given("localized message template with attachment");
    String objectName = "messageTemplate" + getTestNumber();
    String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).bodyExpression(velocityExpression("template-body-default")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"default-content1\");\n" + "return a;")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("default-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk").bodyExpression(velocityExpression("template-body-sk")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("sk-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("cz").bodyExpression(velocityExpression("template-body-cz")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"cz-content1\");\n" + "return a;"))).asPrismObject(), null, result);
    and("configuration with transport and notifier using the template");
    Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("test").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().messageTemplateRef(createObjectReference(templateOid, MessageTemplateType.COMPLEX_TYPE, null)).transport("test")))).asItemDeltas();
    repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
    TestMessageTransport testTransport = (TestMessageTransport) transportService.getTransport("test");
    assertThat(testTransport.getMessages()).isEmpty();
    when("event is sent to notification manager, recipient has no language set");
    CustomEventImpl event = createCustomEvent();
    // This is used as default recipient, no recipient results in no message.
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user@example.com")));
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content");
    Message message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
    // now when-then for sk language (attachment expression inherited)
    when("recipient has 'sk' language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user2@example.com").preferredLanguage("sk")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("message uses attachment expression from default content");
    message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("sk-content2"));
    // now when-then for cz language (attachment inherited)
    when("event is sent to notification manager, recipient has 'cz' language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user3@example.com").preferredLanguage("cz")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content, because no localized content for specified language is found");
    message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("cz-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
}
Also used : CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) SimpleExpressionUtil(com.evolveum.midpoint.schema.util.SimpleExpressionUtil) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) CustomMessageTransport(com.evolveum.midpoint.transport.impl.CustomMessageTransport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MailMessageTransport(com.evolveum.midpoint.transport.impl.MailMessageTransport) FileMessageTransport(com.evolveum.midpoint.transport.impl.FileMessageTransport) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) TransportService(com.evolveum.midpoint.notifications.api.transports.TransportService) LightweightIdentifierGenerator(com.evolveum.midpoint.task.api.LightweightIdentifierGenerator) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) Message(com.evolveum.midpoint.notifications.api.transports.Message) SmsMessageTransport(com.evolveum.midpoint.transport.impl.SmsMessageTransport) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Message(com.evolveum.midpoint.notifications.api.transports.Message) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 3 with MessageTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType in project midpoint by Evolveum.

the class PageMessageTemplates method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    MainObjectListPanel<MessageTemplateType> table = new MainObjectListPanel<>(ID_TABLE, MessageTemplateType.class) {

        @Override
        protected TableId getTableId() {
            return TableId.TABLE_MESSAGE_TEMPLATES;
        }

        @Override
        protected IColumn<SelectableBean<MessageTemplateType>, String> createCheckboxColumn() {
            return null;
        }
    };
    table.setOutputMarkupId(true);
    mainForm.add(table);
}
Also used : MainObjectListPanel(com.evolveum.midpoint.gui.api.component.MainObjectListPanel) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) MessageTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm)

Example 4 with MessageTemplateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType in project midpoint by Evolveum.

the class RepoCommonAddGetTest method test200MessageTemplate.

@Test
public void test200MessageTemplate() throws Exception {
    OperationResult result = createOperationResult();
    given("message template");
    String objectName = "messageTemplate" + getTestNumber();
    var messageTemplate = new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).subjectExpression(velocityExpression("subject-prefix"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk_SK").subjectExpression(velocityExpression("Oné")));
    when("adding it to the repository");
    String oid = repositoryService.addObject(messageTemplate.asPrismObject(), null, result);
    assertThatOperationResult(result).isSuccess();
    then("it can be obtained using getObject");
    MessageTemplateType objectFromRepo = repositoryService.getObject(MessageTemplateType.class, oid, null, result).asObjectable();
    // not null implied by the contract
    assertThat(objectFromRepo.getDefaultContent()).isNotNull();
    ExpressionType subjectExpression = objectFromRepo.getDefaultContent().getSubjectExpression();
    assertThat(subjectExpression).isNotNull();
    assertThatOperationResult(result).isSuccess();
    and("it can be deleted");
    repositoryService.deleteObject(MessageTemplateType.class, oid, result);
    assertThatOperationResult(result).isSuccess();
    assertThatThrownBy(() -> repositoryService.getObject(MessageTemplateType.class, oid, null, result)).isInstanceOf(ObjectNotFoundException.class);
}
Also used : LocalizedMessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType) MessageTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizedMessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType) MessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateContentType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Test (org.testng.annotations.Test)3 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)2 Message (com.evolveum.midpoint.notifications.api.transports.Message)2 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)2 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)2 SimpleExpressionUtil (com.evolveum.midpoint.schema.util.SimpleExpressionUtil)2 LightweightIdentifier (com.evolveum.midpoint.task.api.LightweightIdentifier)2 LightweightIdentifierGenerator (com.evolveum.midpoint.task.api.LightweightIdentifierGenerator)2 Task (com.evolveum.midpoint.task.api.Task)2 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)2 CustomMessageTransport (com.evolveum.midpoint.transport.impl.CustomMessageTransport)2 FileMessageTransport (com.evolveum.midpoint.transport.impl.FileMessageTransport)2 MailMessageTransport (com.evolveum.midpoint.transport.impl.MailMessageTransport)2 SmsMessageTransport (com.evolveum.midpoint.transport.impl.SmsMessageTransport)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)2