Search in sources :

Example 11 with SubscriptionEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteAPISubscription.

/**
 * {@inheritDoc}
 */
@Override
public void deleteAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
    SubscriptionEvent subscriptionDeleteEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_DELETE);
    subscriptionDeleteEvent.setSubscriptionsList(subscriptionValidationDataList);
    publishToStoreTopic(subscriptionDeleteEvent);
    if (log.isDebugEnabled()) {
        log.debug("Subscription deleted event has been successfully published to broker");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Example 12 with SubscriptionEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent in project carbon-apimgt by wso2.

the class SolaceSubscriptionsNotifier method updateSubscription.

/**
 * Update subscriptions related to Solace APIs
 *
 * @param event SubscriptionEvent to update Solace API subscriptions
 * @throws NotifierException if error occurs when updating subscription for Solace APIs
 */
private void updateSubscription(SubscriptionEvent event) throws NotifierException {
    String apiUUID = event.getApiUUID();
    String applicationUUID = event.getApplicationUUID();
    try {
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiUUID, apiMgtDAO.getOrganizationByAPIUUID(apiUUID));
        APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(CarbonContext.getThreadLocalCarbonContext().getUsername());
        Application application = apiMgtDAO.getApplicationByUUID(applicationUUID);
        Set<APIKey> consumerKeys = apiConsumer.getApplicationKeysOfApplication(application.getId());
        for (APIKey apiKey : consumerKeys) {
            application.addKey(apiKey);
        }
        // Check whether the subscription is belongs to an API deployed in Solace
        if (SolaceConstants.SOLACE_ENVIRONMENT.equals(api.getGatewayVendor())) {
            ArrayList<String> solaceApiProducts = new ArrayList<>();
            List<Environment> deployedSolaceEnvironments = SolaceNotifierUtils.getDeployedSolaceEnvironmentsFromRevisionDeployments(api);
            String applicationOrganizationName = SolaceNotifierUtils.getSolaceOrganizationName(deployedSolaceEnvironments);
            if (applicationOrganizationName != null) {
                try {
                    boolean apiProductDeployedIntoSolace = SolaceNotifierUtils.checkApiProductAlreadyDeployedIntoSolaceEnvironments(api, deployedSolaceEnvironments);
                    if (apiProductDeployedIntoSolace) {
                        for (Environment environment : deployedSolaceEnvironments) {
                            solaceApiProducts.add(SolaceNotifierUtils.generateApiProductNameForSolaceBroker(api, environment.getName()));
                        }
                        SolaceNotifierUtils.deployApplicationToSolaceBroker(application, solaceApiProducts, applicationOrganizationName);
                    }
                } catch (IOException e) {
                    log.error(e.getMessage());
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.error("Cannot create solace application " + application.getName() + "with API product " + "deployed in different organizations...");
                }
                throw new APIManagementException("Cannot create solace application " + application.getName() + "with API product deployed in different organizations...");
            }
        }
    } catch (APIManagementException e) {
        throw new NotifierException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException) APIKey(org.wso2.carbon.apimgt.api.model.APIKey) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Environment(org.wso2.carbon.apimgt.api.model.Environment) API(org.wso2.carbon.apimgt.api.model.API) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 13 with SubscriptionEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent in project carbon-apimgt by wso2.

the class SolaceSubscriptionsNotifier method removeSubscription.

/**
 * Remove subscriptions from Solace APIs
 *
 * @param event SubscriptionEvent to remove Solace API subscriptions
 * @throws NotifierException if error occurs when deleting subscriptions from Solace APIs
 */
private void removeSubscription(SubscriptionEvent event) throws NotifierException {
    String apiUUID = event.getApiUUID();
    String applicationUUID = event.getApplicationUUID();
    try {
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiUUID, apiMgtDAO.getOrganizationByAPIUUID(apiUUID));
        Application application = apiProvider.getApplicationByUUID(applicationUUID);
        // Check whether the subscription is belongs to an API deployed in Solace
        if (SolaceConstants.SOLACE_ENVIRONMENT.equals(api.getGatewayVendor())) {
            SolaceNotifierUtils.unsubscribeAPIProductFromSolaceApplication(api, application);
        }
    } catch (APIManagementException e) {
        throw new NotifierException(e.getMessage());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) API(org.wso2.carbon.apimgt.api.model.API) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Application(org.wso2.carbon.apimgt.api.model.Application) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 14 with SubscriptionEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent in project carbon-apimgt by wso2.

the class SolaceSubscriptionsNotifier method process.

/**
 * Process gateway notifier events related to Solace API subscriptions
 *
 * @param event related to subscription handling
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    SubscriptionEvent subscriptionEvent;
    subscriptionEvent = (SubscriptionEvent) event;
    if (APIConstants.EventType.SUBSCRIPTIONS_CREATE.name().equals(event.getType())) {
        crateSubscription(subscriptionEvent);
    } else if (APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name().equals(event.getType())) {
        updateSubscription(subscriptionEvent);
    } else if (APIConstants.EventType.SUBSCRIPTIONS_DELETE.name().equals(event.getType())) {
        removeSubscription(subscriptionEvent);
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent)

Example 15 with SubscriptionEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent in project carbon-apimgt by wso2.

the class APIProviderImpl method updateSubscription.

/**
 * This method is used to update the subscription
 *
 * @param subscribedAPI subscribedAPI object that represents the new subscription detals
 * @throws APIManagementException if failed to update subscription
 */
public void updateSubscription(SubscribedAPI subscribedAPI) throws APIManagementException {
    apiMgtDAO.updateSubscription(subscribedAPI);
    subscribedAPI = apiMgtDAO.getSubscriptionByUUID(subscribedAPI.getUUID());
    Identifier identifier = subscribedAPI.getApiId() != null ? subscribedAPI.getApiId() : subscribedAPI.getProductId();
    String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
    SubscriptionEvent subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name(), tenantId, tenantDomain, subscribedAPI.getSubscriptionId(), subscribedAPI.getUUID(), identifier.getId(), identifier.getUUID(), subscribedAPI.getApplication().getId(), subscribedAPI.getApplication().getUUID(), subscribedAPI.getTier().getName(), subscribedAPI.getSubStatus());
    APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)9 SubscriptionEvent (org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent)8 API (org.wso2.carbon.apimgt.api.model.API)5 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)5 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)5 Application (org.wso2.carbon.apimgt.api.model.Application)5 Identifier (org.wso2.carbon.apimgt.api.model.Identifier)5 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)4 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)4 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)3 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)3 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)3 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2