use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest in project identity-api-server by wso2.
the class NotificationSenderManagementService method buildSMSSenderAddFromSMSSenderUpdateRequest.
/**
* Build SMS sender add object from SMS sender update request.
*
* @param senderName SMS sender's name.
* @param smsSenderUpdateRequest SMS sender's update request body.
* @return SMS sender add object.
*/
private SMSSenderAdd buildSMSSenderAddFromSMSSenderUpdateRequest(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) {
SMSSenderAdd smsSenderAdd = new SMSSenderAdd();
smsSenderAdd.setName(senderName);
smsSenderAdd.setProvider(smsSenderUpdateRequest.getProvider());
smsSenderAdd.setProviderURL(smsSenderUpdateRequest.getProviderURL());
smsSenderAdd.setKey(smsSenderUpdateRequest.getKey());
smsSenderAdd.setSecret(smsSenderUpdateRequest.getSecret());
smsSenderAdd.setSender(smsSenderUpdateRequest.getSender());
smsSenderAdd.setProperties(smsSenderUpdateRequest.getProperties());
return smsSenderAdd;
}
use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest in project identity-api-server by wso2.
the class NotificationSenderManagementService method updateSMSSender.
/**
* Update sms sender details by name.
*
* @param senderName SMS sender' name.
* @param smsSenderUpdateRequest SMS sender's updated configurations.
* @return Updated SMS sender.
*/
public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) {
Resource smsSenderResource = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
EventPublisherConfiguration publisherInSuperTenant = validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant(senderName, smsSenderUpdateRequest, tenantId);
SMSSenderAdd smsSenderAdd = buildSMSSenderAddFromSMSSenderUpdateRequest(senderName, smsSenderUpdateRequest);
addDefaultProperties(smsSenderAdd, publisherInSuperTenant);
try {
InputStream inputStream = generateSMSPublisher(smsSenderAdd);
smsSenderResource = buildResourceFromSmsSenderAdd(smsSenderAdd, inputStream);
NotificationSenderServiceHolder.getNotificationSenderConfigManager().replaceResource(PUBLISHER_RESOURCE_TYPE, smsSenderResource);
} 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 buildSmsSenderFromResource(smsSenderResource);
}
use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest 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;
}
Aggregations