notificationTarget = parameterToNotificationTarget(parameter, notificationTarget);
notificationTargets.put(identifier, notificationTarget);
}
}
final MetadataNotificationRepository notificationRepository = context.getBean(MetadataNotificationRepository.class);
final MetadataNotifierRepository notifierRepository = context.getBean(MetadataNotifierRepository.class);
for(NotificationTarget notificationTarget : notificationTargets.values()) {
final MetadataNotifier metadataNotifier = new MetadataNotifier();
metadataNotifier.setName(notificationTarget.getName());
metadataNotifier.setUsername(notificationTarget.getUsername());
metadataNotifier.setPassword(notificationTarget.getPassword());
metadataNotifier.setUrl(notificationTarget.getUrl());
metadataNotifier.setEnabled(notificationTarget.isEnabled());
// insert
if (!notificationTarget.isPreExisting() && StringUtils.isNotBlank(notificationTarget.getName())
&& StringUtils.isNotBlank(notificationTarget.getUrl())) {
notifierRepository.save(metadataNotifier);
} else if(notificationTarget.isPreExisting()) {
// pre-existing
String id = notificationTarget.getId();
// delete
if(notificationTarget.getName() == null) {
int iid = Integer.parseInt(id);
notificationRepository.deleteAllWithNotifierId(iid);
notifierRepository.delete(iid);
} else {
// update
notifierRepository.save(metadataNotifier);
}