Search in sources :

Example 1 with ContractCreatedEvent

use of io.apiman.manager.api.beans.events.ContractCreatedEvent in project apiman by apiman.

the class ContractApprovalRequestEmailNotification method handle.

@Override
public void handle(NotificationDto<ContractCreatedEvent> notification, Map<String, Object> defaultTemplateMap) {
    ContractCreatedEvent event = notification.getPayload();
    if (event.isApprovalRequired()) {
        UserDto recipient = notification.getRecipient();
        mailNotificationService.findTemplateFor(notification.getReason(), recipient.getLocale()).ifPresentOrElse(template -> send(recipient, template, defaultTemplateMap), () -> warnOnce(recipient, notification));
    }
}
Also used : ContractCreatedEvent(io.apiman.manager.api.beans.events.ContractCreatedEvent) UserDto(io.apiman.manager.api.beans.idm.UserDto)

Example 2 with ContractCreatedEvent

use of io.apiman.manager.api.beans.events.ContractCreatedEvent in project apiman by apiman.

the class DefaultTemplatesTest method contract_approval_request_html.

@Test
public void contract_approval_request_html() throws IOException {
    var appDeveloper = new UserDto().setFullName("John Smith Appdev").setUsername("JohnSmith123").setEmail("foo@apiman.io").setLocale(Locale.ENGLISH);
    ContractCreatedEvent contractCreated = ContractCreatedEvent.builder().setHeaders(ApimanEventHeaders.builder().setId("Event123").setSource(URI.create("https://example.org")).setSubject("Hello").setEventVersion(1L).setTime(OffsetDateTime.now()).setType("X").build()).setApiOrgId("ApiOrg").setApiId("CoolApi").setApiVersion("1.0").setClientOrgId("MobileKompany").setClientId("MobileApp").setClientVersion("2.0").setContractId("1234").setPlanId("Gold").setPlanVersion("1.3").setApprovalRequired(true).setUser(appDeveloper).build();
    UserDto recipient = new UserDto().setEmail("approver@apiman.io").setUsername("ApproverPerson").setFullName("David Approver").setLocale(Locale.ENGLISH);
    NotificationDto<IVersionedApimanEvent> notificationDto = new NotificationDto<>().setId(123L).setCategory(NotificationCategory.API_ADMINISTRATION).setReason("whatever").setReasonMessage("hi").setStatus(NotificationStatus.OPEN).setCreatedOn(OffsetDateTime.now()).setModifiedOn(OffsetDateTime.now()).setRecipient(recipient).setSource("adsadsaad").setPayload(contractCreated);
    QuteTemplateEngine engine = new QuteTemplateEngine(CONFIG);
    engine.applyTemplate(Files.readString(CONFIG.getConfigDirectory().resolve("notifications/email/tpl/en/apiman.client.contract.approval.request.html")), EmailNotificationDispatcher.createDefaultTemplateMap(notificationDto, CONFIG));
}
Also used : IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) NotificationDto(io.apiman.manager.api.beans.notifications.dto.NotificationDto) QuteTemplateEngine(io.apiman.manager.api.notifications.email.QuteTemplateEngine) ContractCreatedEvent(io.apiman.manager.api.beans.events.ContractCreatedEvent) UserDto(io.apiman.manager.api.beans.idm.UserDto) Test(org.junit.Test)

Example 3 with ContractCreatedEvent

use of io.apiman.manager.api.beans.events.ContractCreatedEvent in project apiman by apiman.

the class DefaultTemplatesTest method contract_approval_request_txt.

@Test
public void contract_approval_request_txt() throws IOException {
    var appDeveloper = new UserDto().setFullName("John Smith Appdev").setUsername("JohnSmith123").setEmail("foo@apiman.io").setLocale(Locale.ENGLISH);
    ContractCreatedEvent contractCreated = ContractCreatedEvent.builder().setHeaders(ApimanEventHeaders.builder().setId("Event123").setSource(URI.create("https://example.org")).setSubject("Hello").setEventVersion(1L).setTime(OffsetDateTime.now()).setType("X").build()).setApiOrgId("ApiOrg").setApiId("CoolApi").setApiVersion("1.0").setClientOrgId("MobileKompany").setClientId("MobileApp").setClientVersion("2.0").setContractId("1234").setPlanId("Gold").setPlanVersion("1.3").setApprovalRequired(true).setUser(appDeveloper).build();
    UserDto recipient = new UserDto().setEmail("approver@apiman.io").setUsername("ApproverPerson").setFullName("David Approver").setLocale(Locale.ENGLISH);
    NotificationDto<IVersionedApimanEvent> notificationDto = new NotificationDto<>().setId(123L).setCategory(NotificationCategory.API_ADMINISTRATION).setReason("whatever").setReasonMessage("hi").setStatus(NotificationStatus.OPEN).setCreatedOn(OffsetDateTime.now()).setModifiedOn(OffsetDateTime.now()).setRecipient(recipient).setSource("adsadsaad").setPayload(contractCreated);
    QuteTemplateEngine engine = new QuteTemplateEngine(CONFIG);
    engine.applyTemplate(Files.readString(CONFIG.getConfigDirectory().resolve("notifications/email/tpl/en/apiman.client.contract.approval.request.txt")), EmailNotificationDispatcher.createDefaultTemplateMap(notificationDto, CONFIG));
}
Also used : IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) NotificationDto(io.apiman.manager.api.beans.notifications.dto.NotificationDto) QuteTemplateEngine(io.apiman.manager.api.notifications.email.QuteTemplateEngine) ContractCreatedEvent(io.apiman.manager.api.beans.events.ContractCreatedEvent) UserDto(io.apiman.manager.api.beans.idm.UserDto) Test(org.junit.Test)

Example 4 with ContractCreatedEvent

use of io.apiman.manager.api.beans.events.ContractCreatedEvent in project apiman by apiman.

the class NotificationRulesServiceTest method setup.

@Before
public void setup() {
    var appDeveloper = new UserDto().setFullName("John Smith Appdev").setUsername("JohnSmith123").setEmail("foo@apiman.io").setLocale(Locale.ENGLISH);
    ContractCreatedEvent contractCreated = ContractCreatedEvent.builder().setHeaders(ApimanEventHeaders.builder().setId("Event123").setSource(URI.create("https://example.org")).setSubject("Hello").setEventVersion(1L).setTime(OffsetDateTime.now()).setType("X").build()).setApiOrgId("ApiOrg").setApiId("CoolApi").setApiVersion("1.0").setClientOrgId("MobileKompany").setClientId("MobileApp").setClientVersion("2.0").setContractId("1234").setPlanId("Gold").setPlanVersion("1.3").setApprovalRequired(true).setUser(appDeveloper).build();
    UserDto recipient = new UserDto().setEmail("approver@apiman.io").setUsername("ApproverPerson").setFullName("David Approver").setLocale(Locale.ENGLISH);
    this.notification = new NotificationDto<>().setId(123L).setCategory(NotificationCategory.API_ADMINISTRATION).setReason("whatever").setReasonMessage("hi").setStatus(NotificationStatus.OPEN).setCreatedOn(OffsetDateTime.now()).setModifiedOn(OffsetDateTime.now()).setRecipient(recipient).setSource("adsadsaad").setPayload(contractCreated);
}
Also used : ContractCreatedEvent(io.apiman.manager.api.beans.events.ContractCreatedEvent) UserDto(io.apiman.manager.api.beans.idm.UserDto) Before(org.junit.Before)

Aggregations

ContractCreatedEvent (io.apiman.manager.api.beans.events.ContractCreatedEvent)4 UserDto (io.apiman.manager.api.beans.idm.UserDto)4 IVersionedApimanEvent (io.apiman.manager.api.beans.events.IVersionedApimanEvent)2 NotificationDto (io.apiman.manager.api.beans.notifications.dto.NotificationDto)2 QuteTemplateEngine (io.apiman.manager.api.notifications.email.QuteTemplateEngine)2 Test (org.junit.Test)2 Before (org.junit.Before)1