use of io.apiman.manager.api.beans.events.ApimanEventHeaders in project apiman by apiman.
the class ClientAppService method fireClientStatusChangeEvent.
// TODO: make private at some point
public void fireClientStatusChangeEvent(ClientVersionBean cvb, ClientStatus oldStatus) {
if (oldStatus == cvb.getStatus()) {
LOGGER.debug("Old status and new status same {0} => {1}", cvb.getId(), cvb.getStatus());
return;
}
ClientBean cb = cvb.getClient();
ApimanEventHeaders headers = ApimanEventHeaders.builder().setId(UUID.randomUUID().toString().substring(8)).setSource(URI.create("/apiman/events/clients")).setSubject("status.change").build();
var event = ClientVersionStatusEvent.builder().setHeaders(headers).setClientOrgId(cb.getOrganization().getId()).setClientId(cvb.getClient().getId()).setClientVersion(cvb.getVersion()).setPreviousStatus(oldStatus).setNewStatus(cvb.getStatus()).build();
eventService.fireEvent(event);
LOGGER.debug("Sending client status change event: {0}");
}
use of io.apiman.manager.api.beans.events.ApimanEventHeaders in project apiman by apiman.
the class ContractService method fireContractApprovalRequest.
private void fireContractApprovalRequest(String requesterId, ContractBean contract) {
LOGGER.debug("Firing contract approval request from requester {0} on contract {1}", requesterId, contract);
UserDto requester = UserMapper.INSTANCE.toDto(tryAction(() -> storage.getUser(requesterId)));
ApimanEventHeaders headers = ApimanEventHeaders.builder().setId(UUID.randomUUID().toString()).setSource(URI.create("/apiman/events/contracts/approvals")).setSubject("request").build();
PlanVersionBean plan = contract.getPlan();
ClientVersionBean cvb = contract.getClient();
ApiVersionBean avb = contract.getApi();
OrganizationBean orgA = avb.getApi().getOrganization();
OrganizationBean orgC = cvb.getClient().getOrganization();
var approvalRequestEvent = ContractCreatedEvent.builder().setHeaders(headers).setUser(requester).setClientOrgId(orgC.getId()).setClientId(cvb.getClient().getId()).setClientVersion(cvb.getVersion()).setApiOrgId(orgA.getId()).setApiId(avb.getApi().getId()).setApiVersion(avb.getVersion()).setContractId(String.valueOf(contract.getId())).setPlanId(plan.getPlan().getId()).setPlanVersion(plan.getVersion()).setApprovalRequired(true).build();
LOGGER.debug("Sending approval request event {0}", approvalRequestEvent);
eventService.fireEvent(approvalRequestEvent);
}
use of io.apiman.manager.api.beans.events.ApimanEventHeaders in project apiman by apiman.
the class SsoEventService method newAccountCreated.
public void newAccountCreated(NewAccountCreatedDto newAccountCreatedDto) {
ApimanEventHeaders headers = ApimanEventHeaders.builder().setId(key(newAccountCreatedDto.getUserId(), newAccountCreatedDto.getTime())).setSource(URI.create("http://replaceme.local/foo")).setSubject("new.account").build();
AccountSignupEvent accountSignup = AccountSignupEvent.builder().setHeaders(headers).setUserId(newAccountCreatedDto.getUserId()).setUsername(newAccountCreatedDto.getUsername()).setEmailAddress(newAccountCreatedDto.getEmailAddress()).setFirstName(newAccountCreatedDto.getFirstName()).setSurname(newAccountCreatedDto.getSurname()).build();
LOGGER.debug("Received an account creation event (externally): {0} => translated into: {1}", newAccountCreatedDto, accountSignup);
eventService.fireEvent(accountSignup);
}
use of io.apiman.manager.api.beans.events.ApimanEventHeaders in project apiman by apiman.
the class TransactionalOutboxService method onEvent.
/**
* Anything event fired that uses the {@link IVersionedApimanEvent} interface will be stored in the outbox.
* Fire events using the CDI observable system; generally, they should be enrolled in a transaction to ensure
* transactional properties.
*
* <p>This is then packed into an {@link OutboxEventEntity} and stored.
*
* <p>If the version number has not been set explicitly in the header segment by the implementor, it will be taken
* from the {@link ApimanEvent} annotation, which can be placed on any {@link IVersionedApimanEvent} impl.
* This allows multiple versions of an event to be detected/supported if that is necessary at some future point.
*
* <p>If the type of the event has not been set, the FQCN will be used (i.e. full class name).
*
* @param apimanEvent any {@link IVersionedApimanEvent} (usually fired by CDI observable subsystem).
*/
public void onEvent(@Observes IVersionedApimanEvent apimanEvent) {
if (!outboxActive) {
LOGGER.trace("Outbox has been set as inactive, skipping event: {0}", apimanEvent);
return;
}
ApimanEventHeaders headers = apimanEvent.getHeaders();
String eventType = getType(apimanEvent);
OutboxEventEntity outboxEvent = new OutboxEventEntity().setEventVersion(headers.getEventVersion()).setType(eventType).setSource(headers.getSource().toString()).setSubject(headers.getSubject()).setTime(headers.getTime()).setPayload(serializeWithoutHeaders(apimanEvent));
EntityManager em = getActiveEntityManager();
em.persist(outboxEvent);
em.remove(outboxEvent);
LOGGER.debug("Persisted event to transactional outbox & immediately deleted {0}", outboxEvent);
}
use of io.apiman.manager.api.beans.events.ApimanEventHeaders in project apiman by apiman.
the class ActionService method fireContractApprovedEvent.
private void fireContractApprovedEvent(UserBean approver, ContractBean contract, OrganizationBean orgC, ClientVersionBean cvb, OrganizationBean orgA, ApiVersionBean avb, PlanVersionBean plan) {
ApimanEventHeaders headers = ApimanEventHeaders.builder().setId(UUID.randomUUID().toString().substring(8)).setSource(URI.create("/apiman/events/contracts/approvals")).setSubject("approval").build();
var event = ContractApprovalEvent.builder().setApprover(userMapper.toDto(approver)).setApproved(true).setHeaders(headers).setClientOrgId(orgC.getId()).setClientId(cvb.getClient().getId()).setClientVersion(cvb.getVersion()).setApiOrgId(orgA.getId()).setApiId(avb.getApi().getId()).setApiVersion(avb.getVersion()).setContractId(String.valueOf(contract.getId())).setPlanId(plan.getPlan().getId()).setPlanVersion(plan.getVersion()).build();
LOGGER.debug("Sending contract approval response event: {0}", event);
eventService.fireEvent(event);
}
Aggregations