Search in sources :

Example 1 with EmailSenderUpdateRequest

use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest in project identity-api-server by wso2.

the class NotificationSenderManagementService method updateEmailSender.

/**
 * Update email sender details by name.
 *
 * @param senderName               Email sender's name.
 * @param emailSenderUpdateRequest Email sender's updated configurations.
 * @return Updated email sender.
 */
public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) {
    Resource emailSenderResource = null;
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    EventPublisherConfiguration publisherInSuperTenant = validateEmailSenderUpdateRequestAndGetPublisherInSuperTenant(senderName, tenantId);
    EmailSenderAdd emailSenderAdd = buildEmailSenderAddFromEmailSenderUpdateRequest(senderName, emailSenderUpdateRequest);
    addDefaultProperties(emailSenderAdd, publisherInSuperTenant);
    try {
        InputStream inputStream = generateEmailPublisher(emailSenderAdd);
        emailSenderResource = buildResourceFromEmailSenderAdd(emailSenderAdd, inputStream);
        NotificationSenderServiceHolder.getNotificationSenderConfigManager().replaceResource(PUBLISHER_RESOURCE_TYPE, emailSenderResource);
        reDeployEmailSenderResource(emailSenderResource.getFiles().get(0));
    } catch (ConfigurationManagementException e) {
        throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
    } catch (ParserConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_PARSER_CONFIG_EXCEPTION, e.getMessage());
    } catch (TransformerException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_TRANSFORMER_EXCEPTION, e.getMessage());
    }
    return buildEmailSenderFromResource(emailSenderResource);
}
Also used : EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd) InputStream(java.io.InputStream) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) TransformerException(javax.xml.transform.TransformerException)

Example 2 with EmailSenderUpdateRequest

use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest in project identity-api-server by wso2.

the class NotificationSenderManagementService method buildEmailSenderAddFromEmailSenderUpdateRequest.

/**
 * Build email sender add object from email sender update request.
 *
 * @param senderName               Email sender's name.
 * @param emailSenderUpdateRequest Email sender's update request body.
 * @return Email sender add object
 */
private EmailSenderAdd buildEmailSenderAddFromEmailSenderUpdateRequest(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) {
    EmailSenderAdd emailSenderAdd = new EmailSenderAdd();
    emailSenderAdd.setName(senderName);
    emailSenderAdd.setSmtpServerHost(emailSenderUpdateRequest.getSmtpServerHost());
    emailSenderAdd.setSmtpPort(emailSenderUpdateRequest.getSmtpPort());
    emailSenderAdd.setFromAddress(emailSenderUpdateRequest.getFromAddress());
    emailSenderAdd.setUserName(emailSenderUpdateRequest.getUserName());
    emailSenderAdd.setPassword(emailSenderUpdateRequest.getPassword());
    emailSenderAdd.setProperties(emailSenderUpdateRequest.getProperties());
    return emailSenderAdd;
}
Also used : EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd)

Aggregations

EmailSenderAdd (org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd)2 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 EventPublisherConfiguration (org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration)1 ConfigurationManagementException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)1 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)1