diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services')
4 files changed, 50 insertions, 74 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationPropagationManagerImpl.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationPropagationManagerImpl.java index 9795c7bd1a..d817f1798c 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationPropagationManagerImpl.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationPropagationManagerImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.notification.services.impl; import org.openecomp.sdc.destinationprovider.impl.MulticastDestination; @@ -36,16 +35,14 @@ public class NotificationPropagationManagerImpl implements NotificationPropagati private PropagationService propagationService; private SubscriptionService subscriptionService; - public NotificationPropagationManagerImpl(PropagationService propagationService, - SubscriptionService subscriptionService) { + public NotificationPropagationManagerImpl(PropagationService propagationService, SubscriptionService subscriptionService) { this.propagationService = propagationService; this.subscriptionService = subscriptionService; } @Override - public void notifySubscribers(Event event, String ... excludedSubscribers) { - propagationService.notify(event, new MulticastDestination(event.getEntityId(), - subscriptionService, excludedSubscribers)); + public void notifySubscribers(Event event, String... excludedSubscribers) { + propagationService.notify(event, new MulticastDestination(event.getEntityId(), subscriptionService, excludedSubscribers)); } @Override diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationsServiceImpl.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationsServiceImpl.java index d3558d1904..0b5161ff63 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationsServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/NotificationsServiceImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.notification.services.impl; +import java.util.List; +import java.util.Objects; +import java.util.UUID; import org.openecomp.sdc.notification.dao.LastNotificationDao; import org.openecomp.sdc.notification.dao.NotificationsDao; import org.openecomp.sdc.notification.dao.types.LastSeenNotificationEntity; @@ -28,10 +30,6 @@ import org.openecomp.sdc.notification.dtos.NotificationsStatus; import org.openecomp.sdc.notification.exceptons.NotificationNotExistException; import org.openecomp.sdc.notification.services.NotificationsService; -import java.util.List; -import java.util.Objects; -import java.util.UUID; - /** * @author Avrahamg * @since June 26, 2017 @@ -41,54 +39,46 @@ public class NotificationsServiceImpl implements NotificationsService { private LastNotificationDao lastNotificationDao; private NotificationsDao notificationsDao; - public NotificationsServiceImpl(LastNotificationDao lastNotificationDao, - NotificationsDao notificationsDao) { + public NotificationsServiceImpl(LastNotificationDao lastNotificationDao, NotificationsDao notificationsDao) { this.lastNotificationDao = lastNotificationDao; this.notificationsDao = notificationsDao; } @Override public LastSeenNotificationEntity getLastNotification(String ownerId) { - return new LastSeenNotificationEntity(ownerId, - lastNotificationDao.getOwnerLastEventId(ownerId)); + return new LastSeenNotificationEntity(ownerId, lastNotificationDao.getOwnerLastEventId(ownerId)); } @Override - public void updateLastSeenNotification(String ownerId, UUID eventId) - { + public void updateLastSeenNotification(String ownerId, UUID eventId) { lastNotificationDao.persistOwnerLastEventId(ownerId, eventId); } @Override public NotificationsStatus getNotificationsStatus(String ownerId, UUID lastDelivered, int numOfRecordsToReturn, UUID endOfPage) { - if (Objects.isNull(lastDelivered)) { - LastSeenNotificationEntity entity = getLastNotification(ownerId); - if (Objects.nonNull(entity)) { - lastDelivered = entity.getLastEventId(); - } - if (Objects.isNull(lastDelivered)) { - lastDelivered = UUID.fromString("00000000-0000-1000-8080-808080808080"); // Lowest time UUID value - } - } - if (Objects.isNull(endOfPage)) { - // First page - return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn); - } - else { - // Next page + if (Objects.isNull(lastDelivered)) { + LastSeenNotificationEntity entity = getLastNotification(ownerId); + if (Objects.nonNull(entity)) { + lastDelivered = entity.getLastEventId(); + } + if (Objects.isNull(lastDelivered)) { + lastDelivered = UUID.fromString("00000000-0000-1000-8080-808080808080"); // Lowest time UUID value + } + } + if (Objects.isNull(endOfPage)) { + // First page + return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn); + } else { + // Next page return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn, endOfPage); - } + } } @Override - public void markAsRead(String ownerId, String notificationId) throws - NotificationNotExistException { - NotificationEntity notificationEntity = - notificationsDao.get(new NotificationEntity(ownerId, UUID.fromString(notificationId))); + public void markAsRead(String ownerId, String notificationId) throws NotificationNotExistException { + NotificationEntity notificationEntity = notificationsDao.get(new NotificationEntity(ownerId, UUID.fromString(notificationId))); if (Objects.isNull(notificationEntity)) { - throw new NotificationNotExistException( - "Notification '" + notificationId + "' is not related to ownerId" + - " '" + ownerId + "'"); + throw new NotificationNotExistException("Notification '" + notificationId + "' is not related to ownerId" + " '" + ownerId + "'"); } notificationEntity.setRead(true); notificationsDao.update(notificationEntity); @@ -96,17 +86,16 @@ public class NotificationsServiceImpl implements NotificationsService { @Override public List<NotificationEntity> getNotificationsByOwnerId(String ownerId, int limit) { - return notificationsDao.getNotificationsByOwnerId(ownerId, limit); + return notificationsDao.getNotificationsByOwnerId(ownerId, limit); } @Override public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId) { - return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId); + return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId); } @Override public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId, int limit) { - return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId, limit); + return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId, limit); } - } diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/PropagationServiceImpl.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/PropagationServiceImpl.java index 99d35b3726..de6880c46c 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/PropagationServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/PropagationServiceImpl.java @@ -17,10 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.notification.services.impl; +import static java.util.Objects.requireNonNull; + import com.datastax.driver.core.utils.UUIDs; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.sdc.destinationprovider.DestinationProvider; @@ -29,13 +34,6 @@ import org.openecomp.sdc.notification.dao.types.NotificationEntity; import org.openecomp.sdc.notification.dtos.Event; import org.openecomp.sdc.notification.services.PropagationService; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -import static java.util.Objects.requireNonNull; - public class PropagationServiceImpl implements PropagationService { private NotificationsDao notificationsDao; @@ -44,7 +42,6 @@ public class PropagationServiceImpl implements PropagationService { this.notificationsDao = notificationsDao; } - @Override public void notify(Event event, DestinationProvider destinationProvider) { requireNonNull(event.getEventType()); @@ -53,26 +50,21 @@ public class PropagationServiceImpl implements PropagationService { if (CollectionUtils.isEmpty(subscribers)) { return; } - List<NotificationEntity> notificationEntities = subscribers.stream().map( - subscriber -> { - UUID eventId = UUIDs.timeBased(); - return createNotificationEntity(event.getEventType(), subscriber, - event.getOriginatorId(), event.getAttributes(), eventId); - }).collect(Collectors.toList()); - if(CollectionUtils.isNotEmpty(notificationEntities)) { + List<NotificationEntity> notificationEntities = subscribers.stream().map(subscriber -> { + UUID eventId = UUIDs.timeBased(); + return createNotificationEntity(event.getEventType(), subscriber, event.getOriginatorId(), event.getAttributes(), eventId); + }).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(notificationEntities)) { notificationsDao.createBatch(notificationEntities); } } - private NotificationEntity createNotificationEntity(String eventType, String subscriber, - String originatorId, - Map<String, Object> attributes, + private NotificationEntity createNotificationEntity(String eventType, String subscriber, String originatorId, Map<String, Object> attributes, UUID eventId) { - NotificationEntity notificationEntity = - new NotificationEntity(subscriber, eventId, eventType, originatorId); + NotificationEntity notificationEntity = new NotificationEntity(subscriber, eventId, eventType, originatorId); if (attributes != null && !attributes.isEmpty()) { notificationEntity.setEventAttributes(JsonUtil.object2Json(attributes)); } return notificationEntity; } -}
\ No newline at end of file +} diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/SubscriptionServiceImpl.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/SubscriptionServiceImpl.java index 2a12463fae..dbbbf43177 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/SubscriptionServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/main/java/org/openecomp/sdc/notification/services/impl/SubscriptionServiceImpl.java @@ -17,14 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.notification.services.impl; +import java.util.Set; import org.openecomp.sdc.notification.dao.SubscribersDao; import org.openecomp.sdc.notification.services.SubscriptionService; -import java.util.Set; - public class SubscriptionServiceImpl implements SubscriptionService { private SubscribersDao subscribersDao; @@ -47,4 +45,4 @@ public class SubscriptionServiceImpl implements SubscriptionService { public Set<String> getSubscribers(String entityId) { return subscribersDao.getSubscribers(entityId); } -}
\ No newline at end of file +} |