Search in sources :

Example 1 with APIEvent

use of org.wso2.carbon.apimgt.core.models.events.APIEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addCompositeAPI.

/**
 * @see APIGateway#addCompositeAPI(CompositeAPI api)
 */
@Override
public void addCompositeAPI(CompositeAPI api) throws GatewayException {
    // build the message to send
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
    gatewayDTO.setLabels(api.getLabels());
    APISummary apiSummary = new APISummary();
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    gatewayDTO.setApiSummary(apiSummary);
    publishToPublisherTopic(gatewayDTO);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 2 with APIEvent

use of org.wso2.carbon.apimgt.core.models.events.APIEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addAPI.

@Override
public void addAPI(API api) throws GatewayException {
    // build the message to send
    APIEvent apiCreateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
    apiCreateEvent.setLabels(api.getLabels());
    apiCreateEvent.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(apiCreateEvent);
    if (log.isDebugEnabled()) {
        log.debug("API : " + api.getName() + " created event has been successfully published to broker");
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 3 with APIEvent

use of org.wso2.carbon.apimgt.core.models.events.APIEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteCompositeAPI.

@Override
public void deleteCompositeAPI(CompositeAPI api) throws GatewayException {
    // build the message to send
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
    gatewayDTO.setLabels(api.getLabels());
    APISummary apiSummary = new APISummary();
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    gatewayDTO.setApiSummary(apiSummary);
    publishToPublisherTopic(gatewayDTO);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 4 with APIEvent

use of org.wso2.carbon.apimgt.core.models.events.APIEvent in project carbon-apimgt by wso2.

the class WorkflowUtils method sendNotificationAfterWFComplete.

public static void sendNotificationAfterWFComplete(WorkflowDTO workflowDTO, String wfType) throws APIManagementException {
    if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equalsIgnoreCase(wfType)) {
        String applicationId = workflowDTO.getWorkflowReference();
        int appId = Integer.parseInt(applicationId);
        ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
        Application application = apiMgtDAO.getApplicationById(appId);
        ApplicationWorkflowDTO appWFDto = (ApplicationWorkflowDTO) workflowDTO;
        appWFDto.setApplication(application);
        ApplicationEvent applicationEvent = new ApplicationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_CREATE.name(), appWFDto.getTenantId(), appWFDto.getTenantDomain(), appWFDto.getApplication().getId(), appWFDto.getApplication().getUUID(), appWFDto.getApplication().getName(), appWFDto.getApplication().getTokenType(), appWFDto.getApplication().getTier(), appWFDto.getApplication().getGroupId(), appWFDto.getApplication().getApplicationAttributes(), application.getSubscriber().getName());
        APIUtil.sendNotification(applicationEvent, APIConstants.NotifierType.APPLICATION.name());
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equalsIgnoreCase(wfType)) {
        ApplicationWorkflowDTO appWFDto = (ApplicationWorkflowDTO) workflowDTO;
        ApplicationEvent applicationEvent = new ApplicationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_DELETE.name(), appWFDto.getTenantId(), appWFDto.getTenantDomain(), appWFDto.getApplication().getId(), appWFDto.getApplication().getUUID(), appWFDto.getApplication().getName(), appWFDto.getApplication().getTokenType(), appWFDto.getApplication().getTier(), appWFDto.getApplication().getGroupId(), appWFDto.getApplication().getApplicationAttributes(), "");
        APIUtil.sendNotification(applicationEvent, APIConstants.NotifierType.APPLICATION.name());
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equalsIgnoreCase(wfType)) {
        SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
        SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
        SubscriptionEvent subscriptionEvent;
        if (sub.getApiId() != null) {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_CREATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        } else {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_CREATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        }
        APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_UPDATE.equalsIgnoreCase(wfType)) {
        SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
        SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
        SubscriptionEvent subscriptionEvent;
        if (sub.getApiId() != null) {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        } else {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        }
        APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equalsIgnoreCase(wfType)) {
        SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
        SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
        SubscriptionEvent subscriptionEvent;
        if (sub.getApiId() != null) {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        } else {
            subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
        }
        APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
    } else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equalsIgnoreCase(wfType) || WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE.equalsIgnoreCase(wfType)) {
        APIStateWorkflowDTO apiStateWFDto = (APIStateWorkflowDTO) workflowDTO;
        APIEvent apiEvent = new APIEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.API_LIFECYCLE_CHANGE.name(), apiStateWFDto.getTenantId(), apiStateWFDto.getTenantDomain(), apiStateWFDto.getApiName(), Integer.parseInt(apiStateWFDto.getWorkflowReference()), apiStateWFDto.getApiUUID(), apiStateWFDto.getApiVersion(), apiStateWFDto.getApiType(), apiStateWFDto.getApiContext(), apiStateWFDto.getApiProvider(), apiStateWFDto.getApiLCAction());
        APIUtil.sendNotification(apiEvent, APIConstants.NotifierType.API.name());
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION.equalsIgnoreCase(wfType)) {
        ApplicationRegistrationWorkflowDTO appRegWFDto = (ApplicationRegistrationWorkflowDTO) workflowDTO;
        ApplicationRegistrationEvent applicationRegistrationEvent = new ApplicationRegistrationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name(), appRegWFDto.getTenantId(), appRegWFDto.getTenantDomain(), appRegWFDto.getApplication().getId(), appRegWFDto.getApplication().getUUID(), appRegWFDto.getApplicationInfo().getClientId(), appRegWFDto.getApplication().getTokenType(), appRegWFDto.getKeyManager());
        APIUtil.sendNotification(applicationRegistrationEvent, APIConstants.NotifierType.APPLICATION_REGISTRATION.name());
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_SANDBOX.equalsIgnoreCase(wfType)) {
        ApplicationRegistrationWorkflowDTO appRegWFDto = (ApplicationRegistrationWorkflowDTO) workflowDTO;
        ApplicationRegistrationEvent applicationRegistrationEvent = new ApplicationRegistrationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name(), appRegWFDto.getTenantId(), appRegWFDto.getTenantDomain(), appRegWFDto.getApplication().getId(), appRegWFDto.getApplication().getUUID(), appRegWFDto.getApplicationInfo().getClientId(), appRegWFDto.getApplication().getTokenType(), appRegWFDto.getKeyManager());
        APIUtil.sendNotification(applicationRegistrationEvent, APIConstants.NotifierType.APPLICATION_REGISTRATION.name());
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationEvent) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) ApplicationRegistrationEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationRegistrationEvent) APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 5 with APIEvent

use of org.wso2.carbon.apimgt.core.models.events.APIEvent in project carbon-apimgt by wso2.

the class APIGatewayManager method transformAPIToAPIEvent.

private Set<APIEvent> transformAPIToAPIEvent(Set<API> apiSet) {
    Set<APIEvent> apiEvents = new HashSet<>();
    for (API api : apiSet) {
        APIIdentifier id = api.getId();
        APIEvent apiEvent = new APIEvent(id.getUUID(), id.getApiName(), id.getVersion(), id.getProviderName(), api.getType(), api.getStatus());
        apiEvents.add(apiEvent);
    }
    return apiEvents;
}
Also used : APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) HashSet(java.util.HashSet)

Aggregations

APIEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIEvent)15 API (org.wso2.carbon.apimgt.api.model.API)8 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6 APIEvent (org.wso2.carbon.apimgt.core.models.events.APIEvent)6 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)5 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)5 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 JSONObject (org.json.simple.JSONObject)4 Gson (com.google.gson.Gson)3 JSONParser (org.json.simple.parser.JSONParser)3 ParseException (org.json.simple.parser.ParseException)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 HashSet (java.util.HashSet)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)2 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)2