Search in sources :

Example 1 with Notifier

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

the class NotificationExecutor method sendAsyncNotifications.

/**
 * Executes the notifer classes in separtate threads.
 *
 * @param notificationDTO
 * @throws org.wso2.carbon.apimgt.core.exception.NotificationException
 */
public void sendAsyncNotifications(NotificationDTO notificationDTO) throws NotificationException {
    List<NotifierConfigurations> notifierConfigurations = new APIMConfigurations().getNotificationConfigurations().getNewVersionNotifierConfiguration().getNotifierConfigurations();
    if (notificationDTO.getType().equalsIgnoreCase(NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION)) {
        for (NotifierConfigurations listItem : notifierConfigurations) {
            String executorClass = listItem.getExecutorClass();
            Map property = listItem.getPropertyList();
            Properties prop = notificationDTO.getProperties();
            prop.putAll(property);
            notificationDTO.setProperties(prop);
            // starting Notifier threads
            if (executorClass != null && !executorClass.isEmpty()) {
                Notifier notifier;
                try {
                    notifier = (Notifier) APIUtils.getClassForName(executorClass).newInstance();
                } catch (InstantiationException e) {
                    throw new NotificationException("Instantiation Error while Initializing the notifier class", e);
                } catch (IllegalAccessException e) {
                    throw new NotificationException("IllegalAccess Error while Initializing the notifier class", e);
                } catch (ClassNotFoundException e) {
                    throw new NotificationException("ClassNotFound Error while Initializing the notifier class", e);
                }
                notifier.setNotificationDTO(notificationDTO);
                executor.execute(notifier);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Class " + executorClass + " Empty Or Null");
                }
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Notification Type Does Not match with " + NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
        }
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }
}
Also used : APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) NotificationException(org.wso2.carbon.apimgt.core.exception.NotificationException) NotifierConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations) Properties(java.util.Properties) Map(java.util.Map) Notifier(org.wso2.carbon.apimgt.core.impl.Notifier)

Example 2 with Notifier

use of org.wso2.carbon.apimgt.impl.notifier.Notifier in project ballerina by ballerina-lang.

the class CompilerPluginRunner method notifyProcessors.

private void notifyProcessors(List<BLangAnnotationAttachment> attachments, BiConsumer<CompilerPlugin, List<AnnotationAttachmentNode>> notifier) {
    Map<CompilerPlugin, List<AnnotationAttachmentNode>> attachmentMap = new HashMap<>();
    for (BLangAnnotationAttachment attachment : attachments) {
        DefinitionID aID = new DefinitionID(attachment.annotationSymbol.pkgID.getName().value, attachment.annotationName.value);
        if (!processorMap.containsKey(aID)) {
            continue;
        }
        List<CompilerPlugin> procList = processorMap.get(aID);
        procList.forEach(proc -> {
            List<AnnotationAttachmentNode> attachmentNodes = attachmentMap.computeIfAbsent(proc, k -> new ArrayList<>());
            attachmentNodes.add(attachment);
        });
    }
    for (CompilerPlugin processor : attachmentMap.keySet()) {
        notifier.accept(processor, Collections.unmodifiableList(attachmentMap.get(processor)));
    }
}
Also used : HashMap(java.util.HashMap) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) CompilerPlugin(org.ballerinalang.compiler.plugins.CompilerPlugin) ArrayList(java.util.ArrayList) List(java.util.List) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 3 with Notifier

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

the class APIUtilTierTest method mockPolicyRetrieval.

private void mockPolicyRetrieval(ApiMgtDAO apiMgtDAO) throws Exception {
    QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class);
    ApplicationPolicy applicationPolicy = Mockito.mock(ApplicationPolicy.class);
    SubscriptionPolicy subscriptionPolicy = Mockito.mock(SubscriptionPolicy.class);
    APIPolicy apiPolicy = Mockito.mock(APIPolicy.class);
    Mockito.when(applicationPolicy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy);
    Mockito.when(subscriptionPolicy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy);
    Mockito.when(apiPolicy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy);
    Mockito.when(apiMgtDAO.getApplicationPolicy(anyString(), anyInt())).thenReturn(applicationPolicy);
    Mockito.when(apiMgtDAO.getSubscriptionPolicy(anyString(), anyInt())).thenReturn(subscriptionPolicy);
    Mockito.when(apiMgtDAO.getAPIPolicy(anyString(), anyInt())).thenReturn(apiPolicy);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Map<String, List<Notifier>> notifierMap = Mockito.mock(Map.class);
    List<Notifier> notifierList = new ArrayList<>();
    Mockito.when(notifierMap.get(any())).thenReturn(notifierList);
    Mockito.when(serviceReferenceHolder.getNotifiersMap()).thenReturn(notifierMap);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    Map<String, Long> defaultLimits = new HashMap<>();
    Mockito.when(throttleProperties.getDefaultThrottleTierLimits()).thenReturn(defaultLimits);
    Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) List(java.util.List) ArrayList(java.util.ArrayList) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) Notifier(org.wso2.carbon.apimgt.impl.notifier.Notifier) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)

Example 4 with Notifier

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

the class APIMgtDAOTest method setUp.

@Before
public void setUp() throws Exception {
    String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
    APIManagerConfiguration config = new APIManagerConfiguration();
    initializeDatabase(dbConfigPath);
    config.load(dbConfigPath);
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl(config));
    List<Notifier> notifierList = new ArrayList<>();
    Notifier subscriptionsNotifier = Mockito.mock(Notifier.class);
    Mockito.when(subscriptionsNotifier.getType()).thenReturn(APIConstants.NotifierType.SUBSCRIPTIONS.name());
    notifierList.add(subscriptionsNotifier);
    ServiceReferenceHolder.getInstance().getNotifiersMap().put(subscriptionsNotifier.getType(), notifierList);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    keyManager = Mockito.mock(KeyManager.class);
    APIMgtDBUtil.initialize();
    apiMgtDAO = ApiMgtDAO.getInstance();
    IdentityTenantUtil.setRealmService(new TestRealmService());
    String identityConfigPath = System.getProperty("IdentityConfigurationPath");
    IdentityConfigParser.getInstance(identityConfigPath);
    OAuthServerConfiguration oAuthServerConfiguration = OAuthServerConfiguration.getInstance();
    ServiceReferenceHolder.getInstance().setOauthServerConfiguration(oAuthServerConfiguration);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) ArrayList(java.util.ArrayList) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) Notifier(org.wso2.carbon.apimgt.impl.notifier.Notifier) Before(org.junit.Before)

Example 5 with Notifier

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

the class NewAPIVersionEmailNotifierTest method setup.

@Before
public void setup() {
    notifier = new NewAPIVersionEmailNotifier();
    registry = Mockito.mock(Registry.class);
    claimsRetriever = Mockito.mock(ClaimsRetriever.class);
    Subscriber subscriber = new Subscriber(ADMIN);
    Set<Subscriber> subscribersOfAPI = new HashSet<Subscriber>();
    subscribersOfAPI.add(subscriber);
    Properties properties = new Properties();
    properties.put(NotifierConstants.API_KEY, new APIIdentifier(ADMIN, API_NAME, "1.0.0"));
    properties.put(NotifierConstants.NEW_API_KEY, new APIIdentifier(ADMIN, API_NAME, "2.0.0"));
    properties.put(NotifierConstants.TITLE_KEY, "New Version");
    properties.put(NotifierConstants.SUBSCRIBERS_PER_API, subscribersOfAPI);
    properties.put(NotifierConstants.CLAIMS_RETRIEVER_IMPL_CLASS, "org.wso2.carbon.apimgt.impl.token.DefaultClaimsRetriever");
    properties.put(NotifierConstants.TEMPLATE_KEY, "<html>$1</html>");
    notificationDTO = new NotificationDTO(properties, NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
    notificationDTO.setTenantID(TENANT_ID);
}
Also used : Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Registry(org.wso2.carbon.registry.core.Registry) ClaimsRetriever(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever) Before(org.junit.Before)

Aggregations

Properties (java.util.Properties)6 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 NotificationException (org.wso2.carbon.apimgt.impl.notification.exception.NotificationException)4 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 Before (org.junit.Before)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)2 Notifier (org.wso2.carbon.apimgt.impl.notifier.Notifier)2 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1