Search in sources :

Example 1 with IVersionedApimanEvent

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

the class DefaultTemplatesTest method contract_approval_response_txt.

@Test
public void contract_approval_response_txt() throws IOException {
    var appDeveloper = new UserDto().setFullName("John Smith Appdev").setUsername("JohnSmith123").setEmail("foo@apiman.io").setLocale(Locale.ENGLISH);
    ContractApprovalEvent approvalEvent = ContractApprovalEvent.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").setApprover(appDeveloper).setApproved(true).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(approvalEvent);
    QuteTemplateEngine engine = new QuteTemplateEngine(CONFIG);
    engine.applyTemplate(Files.readString(CONFIG.getConfigDirectory().resolve("notifications/email/tpl/en/apiman.client.contract.approval.granted.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) UserDto(io.apiman.manager.api.beans.idm.UserDto) ContractApprovalEvent(io.apiman.manager.api.beans.events.ContractApprovalEvent) Test(org.junit.Test)

Example 2 with IVersionedApimanEvent

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

the class EventFactory method findEvents.

private void findEvents() {
    Reflections reflections = new Reflections("io.apiman.manager.api");
    Set<Class<? extends IVersionedApimanEvent>> eventKlazzes = reflections.getSubTypesOf(IVersionedApimanEvent.class);
    for (Class<? extends IVersionedApimanEvent> klazz : eventKlazzes) {
        String name = calculateName(klazz);
        ApimanEvent metadata = getAnnotation(klazz);
        klazzez.put(name, new ClazzAndMetadata(metadata, klazz));
        LOGGER.debug("Calculated name for {0} as {1}", klazz, name);
    }
}
Also used : IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) ApimanEvent(io.apiman.manager.api.beans.events.ApimanEvent) Reflections(org.reflections.Reflections)

Example 3 with IVersionedApimanEvent

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

the class EventFactory method calculateName.

private String calculateName(Class<? extends IVersionedApimanEvent> klazz) {
    if (klazz.isAnnotationPresent(ApimanEvent.class)) {
        ApimanEvent anno = klazz.getAnnotation(ApimanEvent.class);
        LOGGER.debug("Found annotation {0} for {1}", anno, klazz.getCanonicalName());
        if (!"".equals(anno.name())) {
            return anno.name();
        } else {
            return klazz.getCanonicalName();
        }
    } else {
        return klazz.getCanonicalName();
    }
}
Also used : IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) ApimanEvent(io.apiman.manager.api.beans.events.ApimanEvent)

Example 4 with IVersionedApimanEvent

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

the class EventService method getType.

private String getType(IVersionedApimanEvent event) {
    String currentValue = event.getHeaders().getType();
    if (StringUtils.isEmpty(currentValue)) {
        if (event.getClass().isAnnotationPresent(ApimanEvent.class)) {
            ApimanEvent ev = event.getClass().getAnnotation(ApimanEvent.class);
            currentValue = ev.name();
        }
    }
    return Optional.ofNullable(currentValue).filter(s -> !s.isBlank()).orElse(event.getClass().getCanonicalName());
}
Also used : Event(javax.enterprise.event.Event) Inject(javax.inject.Inject) IApimanLogger(io.apiman.common.logging.IApimanLogger) OffsetDateTime(java.time.OffsetDateTime) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ApimanEvent(io.apiman.manager.api.beans.events.ApimanEvent) IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StringUtils(org.apache.commons.lang3.StringUtils) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) ApimanEventHeaders(io.apiman.manager.api.beans.events.ApimanEventHeaders) ApimanEvent(io.apiman.manager.api.beans.events.ApimanEvent) IVersionedApimanEvent(io.apiman.manager.api.beans.events.IVersionedApimanEvent)

Example 5 with IVersionedApimanEvent

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

the class DefaultTemplatesTest method contract_approval_response_html.

@Test
public void contract_approval_response_html() throws IOException {
    var appDeveloper = new UserDto().setFullName("John Smith Appdev").setUsername("JohnSmith123").setEmail("foo@apiman.io").setLocale(Locale.ENGLISH);
    ContractApprovalEvent approvalEvent = ContractApprovalEvent.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").setApprover(appDeveloper).setApproved(true).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(approvalEvent);
    QuteTemplateEngine engine = new QuteTemplateEngine(CONFIG);
    engine.applyTemplate(Files.readString(CONFIG.getConfigDirectory().resolve("notifications/email/tpl/en/apiman.client.contract.approval.granted.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) UserDto(io.apiman.manager.api.beans.idm.UserDto) ContractApprovalEvent(io.apiman.manager.api.beans.events.ContractApprovalEvent) Test(org.junit.Test)

Aggregations

IVersionedApimanEvent (io.apiman.manager.api.beans.events.IVersionedApimanEvent)7 UserDto (io.apiman.manager.api.beans.idm.UserDto)4 NotificationDto (io.apiman.manager.api.beans.notifications.dto.NotificationDto)4 QuteTemplateEngine (io.apiman.manager.api.notifications.email.QuteTemplateEngine)4 Test (org.junit.Test)4 ApimanEvent (io.apiman.manager.api.beans.events.ApimanEvent)3 ContractApprovalEvent (io.apiman.manager.api.beans.events.ContractApprovalEvent)2 ContractCreatedEvent (io.apiman.manager.api.beans.events.ContractCreatedEvent)2 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)1 IApimanLogger (io.apiman.common.logging.IApimanLogger)1 ApimanEventHeaders (io.apiman.manager.api.beans.events.ApimanEventHeaders)1 OffsetDateTime (java.time.OffsetDateTime)1 Optional (java.util.Optional)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Reflections (org.reflections.Reflections)1