use of org.wso2.carbon.event.publisher.core.EventPublisherService in project identity-api-server by wso2.
the class NotificationSenderManagementService method validateEmailSenderUpdateRequestAndGetPublisherInSuperTenant.
/**
* Validate the email Sender put request and get the corresponding super tenant's event publisher configuration.
*
* @param senderName Email sender's name.
* @param tenantId Tenant id.
* @return Corresponding super tenant's event publisher's configuration.
*/
private EventPublisherConfiguration validateEmailSenderUpdateRequestAndGetPublisherInSuperTenant(String senderName, int tenantId) {
EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
EventPublisherConfiguration publisherInSuperTenant = null;
try {
// Check whether a publisher exists to replace.
NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, senderName);
startSuperTenantFlow();
List<EventPublisherConfiguration> activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
if (activeEventPublisherConfigurations == null) {
throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
}
startTenantFlow(tenantId);
// Check whether the super tenant has a publisher with the defined name.
publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(senderName)).findAny().orElse(null);
if (publisherInSuperTenant == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, senderName);
}
} catch (EventPublisherConfigurationException e) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
} catch (ConfigurationManagementException e) {
// If resource not found by id.
if (RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
throw handleConfigurationMgtException(e, ERROR_CODE_NO_RESOURCE_EXISTS, senderName);
}
throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
}
return publisherInSuperTenant;
}
use of org.wso2.carbon.event.publisher.core.EventPublisherService in project identity-api-server by wso2.
the class NotificationSenderManagementService method validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant.
/**
* Validate the SMS Sender put request and get the corresponding super tenant's event publisher configuration.
*
* @param senderName SMS sender's name.
* @param smsSenderUpdateRequest SMS Sender put request.
* @param tenantId Tenant id.
* @return Corresponding super tenant's event publisher's configuration.
*/
private EventPublisherConfiguration validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest, int tenantId) {
EventPublisherConfiguration publisherInSuperTenant = null;
EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
SMSProviderPayloadTemplateManager smsProviderPayloadTemplateManager = NotificationSenderServiceHolder.getSmsProviderPayloadTemplateManager();
Map<String, String> properties = new HashMap<>();
if (smsSenderUpdateRequest.getProperties() != null) {
smsSenderUpdateRequest.getProperties().stream().map(property -> properties.put(property.getKey(), property.getValue())).collect(Collectors.toList());
}
try {
// Check whether a publisher exists to replace.
NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, senderName);
if (StringUtils.isEmpty(smsSenderUpdateRequest.getProvider())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_REQUIRED, null);
}
if (StringUtils.isEmpty(properties.get(INLINE_BODY_PROPERTY))) {
SMSProviderTemplate sendSmsAPIPayload = smsProviderPayloadTemplateManager.getSMSProviderPayloadTemplateByProvider(smsSenderUpdateRequest.getProvider());
if (sendSmsAPIPayload == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PAYLOAD_NOT_FOUND, smsSenderUpdateRequest.getProvider());
}
}
if (StringUtils.isEmpty(smsSenderUpdateRequest.getProviderURL())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_URL_REQUIRED, null);
}
startSuperTenantFlow();
List<EventPublisherConfiguration> activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
if (activeEventPublisherConfigurations == null) {
throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
}
startTenantFlow(tenantId);
// Check whether the super tenant has a publisher with the defined name.
publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(senderName)).findAny().orElse(null);
if (publisherInSuperTenant == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, senderName);
}
} catch (ConfigurationManagementException e) {
// If resource not found by id.
if (RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
throw handleConfigurationMgtException(e, ERROR_CODE_NO_RESOURCE_EXISTS, senderName);
}
throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
} catch (EventPublisherConfigurationException e) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
}
return publisherInSuperTenant;
}
use of org.wso2.carbon.event.publisher.core.EventPublisherService in project identity-api-server by wso2.
the class NotificationSenderManagementService method validateEmailSenderAddAndGetPublisherInSuperTenant.
/**
* Validate the email Sender post request and get the corresponding super tenant's event publisher configuration.
*
* @param emailSenderAdd Email sender post request.
* @param tenantId Tenant id.
* @return Corresponding super tenant's event publisher's configuration.
*/
private EventPublisherConfiguration validateEmailSenderAddAndGetPublisherInSuperTenant(EmailSenderAdd emailSenderAdd, int tenantId) {
String emailSenderAddName = emailSenderAdd.getName();
EventPublisherConfiguration publisherInSuperTenant = null;
EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
List<EventPublisherConfiguration> activeEventPublisherConfigurations = null;
try {
startSuperTenantFlow();
activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
if (activeEventPublisherConfigurations == null) {
throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
}
startTenantFlow(tenantId);
// Set the default publisher name if name is not defined.
if (StringUtils.isEmpty(emailSenderAdd.getName())) {
emailSenderAddName = DEFAULT_EMAIL_PUBLISHER;
}
// Check whether the super tenant has a publisher with the defined name.
String finalEmailSenderAddName = emailSenderAddName;
publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(finalEmailSenderAddName)).findAny().orElse(null);
if (publisherInSuperTenant == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, emailSenderAddName);
}
// Check whether a publisher already exists with the same name in the particular tenant to be added.
Resource resource = NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, emailSenderAddName);
if (resource != null) {
throw handleException(Response.Status.CONFLICT, ERROR_CODE_CONFLICT_PUBLISHER, emailSenderAddName);
}
} catch (EventPublisherConfigurationException e) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
} catch (ConfigurationManagementException e) {
if (!RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER, emailSenderAddName);
}
}
return publisherInSuperTenant;
}
use of org.wso2.carbon.event.publisher.core.EventPublisherService in project identity-api-server by wso2.
the class NotificationSenderManagementService method validateSMSSenderAddAndGetPublisherInSuperTenant.
/**
* Validate the SMS Sender post request and get the corresponding super tenant's event publisher configuration.
*
* @param smsSenderAdd SMS sender post request.
* @param tenantId Tenant id.
* @return Corresponding super tenant's event publisher's configuration.
*/
private EventPublisherConfiguration validateSMSSenderAddAndGetPublisherInSuperTenant(SMSSenderAdd smsSenderAdd, int tenantId) {
String smsSenderAddName = smsSenderAdd.getName();
EventPublisherConfiguration publisherInSuperTenant = null;
EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
SMSProviderPayloadTemplateManager smsProviderPayloadTemplateManager = NotificationSenderServiceHolder.getSmsProviderPayloadTemplateManager();
List<EventPublisherConfiguration> activeEventPublisherConfigurations = null;
Map<String, String> properties = new HashMap<>();
if (smsSenderAdd.getProperties() != null) {
smsSenderAdd.getProperties().stream().map(property -> properties.put(property.getKey(), property.getValue())).collect(Collectors.toList());
}
try {
if (StringUtils.isEmpty(smsSenderAdd.getProvider())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_REQUIRED, null);
}
if (StringUtils.isEmpty(properties.get(INLINE_BODY_PROPERTY))) {
SMSProviderTemplate sendSmsAPIPayload = smsProviderPayloadTemplateManager.getSMSProviderPayloadTemplateByProvider(smsSenderAdd.getProvider());
if (sendSmsAPIPayload == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PAYLOAD_NOT_FOUND, smsSenderAdd.getProvider());
}
}
if (StringUtils.isEmpty(smsSenderAdd.getProviderURL())) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_URL_REQUIRED, null);
}
startSuperTenantFlow();
activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
if (activeEventPublisherConfigurations == null) {
throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
}
startTenantFlow(tenantId);
// Set the default publisher name if name is not defined.
if (StringUtils.isEmpty(smsSenderAdd.getName())) {
smsSenderAddName = DEFAULT_SMS_PUBLISHER;
} else {
smsSenderAddName = smsSenderAdd.getName();
}
// Check whether the super tenant has a publisher with the defined name.
String finalSmsSenderAddName = smsSenderAddName;
publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(finalSmsSenderAddName)).findAny().orElse(null);
if (publisherInSuperTenant == null) {
throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, smsSenderAddName);
}
// Check whether a publisher already exists with the same name in the particular tenant to be added.
Resource resource = NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, smsSenderAddName);
if (resource != null) {
throw handleException(Response.Status.CONFLICT, ERROR_CODE_CONFLICT_PUBLISHER, smsSenderAddName);
}
} catch (EventPublisherConfigurationException e) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
} catch (ConfigurationManagementException e) {
if (!RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER, smsSenderAddName);
}
}
return publisherInSuperTenant;
}
use of org.wso2.carbon.event.publisher.core.EventPublisherService in project identity-governance by wso2-extensions.
the class ResourceManagerImpl method deployEventPublisherConfiguration.
/**
* This is used to deploy an event publisher configuration using.
*
* @param publisherConfig Event Publisher Configuration as input stream.
* @throws EventPublisherConfigurationException Event Publisher Configuration Exception.
*/
private void deployEventPublisherConfiguration(InputStream publisherConfig) throws EventPublisherConfigurationException {
EventPublisherService carbonEventPublisherService = TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService();
EventPublisherConfiguration eventPublisherConfiguration;
eventPublisherConfiguration = carbonEventPublisherService.getEventPublisherConfiguration(publisherConfig);
if (TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService().getActiveEventPublisherConfiguration(eventPublisherConfiguration.getEventPublisherName()) != null) {
destroyEventPublisherConfiguration(eventPublisherConfiguration);
}
carbonEventPublisherService.addEventPublisherConfiguration(eventPublisherConfiguration);
}
Aggregations