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()) {
}
}
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)));
}
}
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);
}
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);
}
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);
}
Aggregations