Skip to content

Commit

Permalink
Fix for MID-1950.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 16, 2014
1 parent 8e7aa64 commit f1bba38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Expand Up @@ -131,7 +131,10 @@ public void processEvent(Event event, Task task, OperationResult result) {
LOGGER.trace("NotificationManager processing event " + event);
}

SystemConfigurationType systemConfigurationType = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, result).asObjectable();
SystemConfigurationType systemConfigurationType = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, result);
if (systemConfigurationType == null) { // something really wrong happened (or we are doing initial import of objects)
return;
}
if (systemConfigurationType.getNotificationConfiguration() == null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("No notification configuration in repository, exiting the change listener.");
Expand Down
Expand Up @@ -51,22 +51,15 @@ public class NotificationsUtil {
@Qualifier("cacheRepositoryService")
private RepositoryService cacheRepositoryService;

public static PrismObject<SystemConfigurationType> getSystemConfiguration(RepositoryService repositoryService, OperationResult result) {
PrismObject<SystemConfigurationType> systemConfiguration;
// beware, may return null if there's any problem getting sysconfig (e.g. during initial import)
public static SystemConfigurationType getSystemConfiguration(RepositoryService repositoryService, OperationResult result) {
try {
systemConfiguration = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(),
null, result);
} catch (ObjectNotFoundException e) {
LoggingUtils.logException(LOGGER, "Couldn't get system configuration", e);
throw new SystemException("Couldn't get system configuration", e);
} catch (SchemaException e) {
LoggingUtils.logException(LOGGER, "Couldn't get system configuration", e);
throw new SystemException("Couldn't get system configuration", e);
}
if (systemConfiguration == null) {
throw new SystemException("Couldn't get system configuration");
return repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(),
null, result).asObjectable();
} catch (ObjectNotFoundException|SchemaException e) {
LoggingUtils.logException(LOGGER, "Notification(s) couldn't be processed, because the system configuration couldn't be retrieved", e);
return null;
}
return systemConfiguration;
}

public static String getResourceNameFromRepo(RepositoryService repositoryService, String oid, OperationResult result) {
Expand Down
Expand Up @@ -85,16 +85,16 @@ public void send(Message mailMessage, String transportName, Task task, Operation
result.addCollectionOfSerializablesAsParam("mailMessage recipient(s)", mailMessage.getTo());
result.addParam("mailMessage subject", mailMessage.getSubject());

PrismObject<SystemConfigurationType> systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.asObjectable().getNotificationConfiguration() == null
|| systemConfiguration.asObjectable().getNotificationConfiguration().getMail() == null) {
SystemConfigurationType systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null
|| systemConfiguration.getNotificationConfiguration().getMail() == null) {
String msg = "No notifications are configured. Mail notification to " + mailMessage.getTo() + " will not be sent.";
LOGGER.warn(msg) ;
result.recordWarning(msg);
return;
}

MailConfigurationType mailConfigurationType = systemConfiguration.asObjectable().getNotificationConfiguration().getMail();
MailConfigurationType mailConfigurationType = systemConfiguration.getNotificationConfiguration().getMail();
if (mailConfigurationType.getRedirectToFile() != null) {
try {
TransportUtil.appendToFile(mailConfigurationType.getRedirectToFile(), formatToFile(mailMessage));
Expand Down
Expand Up @@ -100,8 +100,8 @@ public void send(Message message, String transportName, Task task, OperationResu
result.addCollectionOfSerializablesAsParam("message recipient(s)", message.getTo());
result.addParam("message subject", message.getSubject());

PrismObject<SystemConfigurationType> systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.asObjectable().getNotificationConfiguration() == null) {
SystemConfigurationType systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null) {
String msg = "No notifications are configured. SMS notification to " + message.getTo() + " will not be sent.";
LOGGER.warn(msg) ;
result.recordWarning(msg);
Expand All @@ -110,7 +110,7 @@ public void send(Message message, String transportName, Task task, OperationResu

String smsConfigName = transportName.length() > NAME.length() ? transportName.substring(NAME.length() + 1) : null; // after "sms:"
SmsConfigurationType found = null;
for (SmsConfigurationType smsConfigurationType: systemConfiguration.asObjectable().getNotificationConfiguration().getSms()) {
for (SmsConfigurationType smsConfigurationType: systemConfiguration.getNotificationConfiguration().getSms()) {
if ((smsConfigName == null && smsConfigurationType.getName() == null) || (smsConfigName != null && smsConfigName.equals(smsConfigurationType.getName()))) {
found = smsConfigurationType;
break;
Expand Down

0 comments on commit f1bba38

Please sign in to comment.