Ana içeriğe geç

Polling Backend#

Polling olarak kullanıcıya ait ve kullanıcı bağımsız bildirim işlemlerinin yönetilmesini sağlayan altyapı bileşenidir.

Client:#

Gradle Dependencies

compile (
    [group: 'tr.com.havelsan.framework.support.notification.cloud', name: 'hvl-notification-polling-cloud-client']
)

Rest Servis Tanımı#

Feign client uçlarını kullanabilmek için konfigurasyon bean'ine @HvlEnabledPollingNotificationClient annotasyonu eklenmelidir.

@Autowired
private HvlPollingNotificationAnnouncementRestService notificationAnnouncementRestService;

@Autowired
private HvlPollingNotificationUserRestService notificationUserRestService;
@Autowired
private HvlPollingNotificationAnnouncementRestService notificationAnnouncementRestService;

@Autowired
private HvlPollingNotificationUserRestService notificationUserRestService;

HvlPollingNotificationAnnouncementRestService sağlanan servisler

@HvlPublicFeignRestService
@FeignClient(name = "notificationPollingRestService",
        path = "${hvl.notification.polling.service.announcement.path:/polling/announcement}",
        url = "${hvl.notification.polling.service.announcement.url:${hvl.notification.polling.service.url}}")
public interface HvlNotificationPollingAnnouncementRestService {

    /**
     * sendAnnouncement is a method which provides send announcement notification
     *
     * @param notificationPollingAnnouncementModel
     * @return
     */
    @PostMapping(path = "/send",
            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    HvlResponse<HvlNotificationPollingAnnouncementModel> sendAnnouncement(
            @Valid @RequestBody HvlNotificationPollingAnnouncementModel notificationPollingAnnouncementModel);

    /**
     * getUnreadNotifications is a method which provides notifications according to notificationPollingAnnouncementQueryModel
     *
     * @param notificationPollingAnnouncementQueryModel
     * @return
     */
    @PostMapping(path = "/notifications",
            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    HvlResponse<HvlPage<HvlNotificationPollingAnnouncementModel>> getNotificationPage(
            @Valid @RequestBody HvlNotificationPollingAnnouncementQueryModel notificationPollingAnnouncementQueryModel);
}
HvlNotificationPollingUserRestService üzerinden sağlanan servisler

/**
 * @author hcguler
 */
@HvlPublicFeignRestService
@FeignClient(name = "notificationPollingRestService",
        path = "${hvl.notification.polling.service.user.path:/polling/user}",
        url = "${hvl.notification.polling.service.user.url:${hvl.polling.notification.service.url}}")
public interface HvlNotificationPollingUserRestService {

    /**
     * getUnreadNotificationCount is a method which provides unread notification count according to token owner
     *
     * @return
     */
    @GetMapping(path = "/count/{assigneeUser}")
    HvlResponse<Number> getUnreadNotificationCount(@NotBlank @PathVariable("assigneeUser") String assigneeUser);

    /**
     * markReadNotification is a method which provides mark read notification
     *
     * @return
     */
    @GetMapping(path = "/markRead/{notificationId}")
    HvlResponse<Void> markReadNotification(@NotNull @PathVariable("notificationId") Long notificationId);

    /**
     * markAllRead is a method which provides all unread notification marked read
     *
     * @return
     */
    @GetMapping(path = "/markAllRead/{assigneeUser}")
    HvlResponse<Void> markAllRead(@NotBlank @PathVariable("assigneeUser") String assigneeUser);

    /**
     * sendAnnouncement is a method which provides send user specific notification
     *
     * @param pollingNotificationUserModel
     * @return
     */
    @PostMapping(path = "/send", produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    HvlResponse<HvlNotificationPollingUserModel> sendUserSpecific(
            @Valid @RequestBody HvlNotificationPollingUserModel pollingNotificationUserModel);

    /**
     * getUnreadNotifications is a method which provides notifications according to pollingNotificationQueryModel
     *
     * @param pollingNotificationQueryModel
     * @return
     */
    @PostMapping(path = "/notifications",
            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    HvlResponse<HvlPage<HvlNotificationPollingUserModel>> getNotificationPage(
            @Validated(value = {HvlNotificationPollingUserQueryModel.UserNotification.class})
            @RequestBody HvlNotificationPollingUserQueryModel pollingNotificationQueryModel);
}

Announcement için gönderilen payload HvlNotificationPollingAnnouncementModel

public class HvlNotificationPollingAnnouncementModel extends HvlNotificationPayload {

    @NotNull
    private OffsetDateTime expirationDate;

    public OffsetDateTime getExpirationDate() {
        return expirationDate;
    }

    public void setExpirationDate(OffsetDateTime expirationDate) {
        this.expirationDate = expirationDate;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        HvlNotificationPollingAnnouncementModel that = (HvlNotificationPollingAnnouncementModel) o;
        return Objects.equals(expirationDate, that.expirationDate);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), expirationDate);
    }

}

User notification için gönderilen payload HvlNotificationPollingUserModel

public class HvlNotificationPollingUserModel extends HvlNotificationPayload {

    @NotBlank
    private String assigneeUser;

    private boolean read;

    public String getAssigneeUser() {
        return assigneeUser;
    }

    public void setAssigneeUser(String assigneeUser) {
        this.assigneeUser = assigneeUser;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean isRead) {
        this.read = isRead;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        HvlNotificationPollingUserModel that = (HvlNotificationPollingUserModel) o;
        return read == that.read && Objects.equals(assigneeUser, that.assigneeUser);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), assigneeUser, read);
    }
}

Server Kullanımı#

Polling notification gönderilebilmesi için polling notification server'ın ayağa kaldırılması gerekmektedir. Server ayağa kaldırılırken aşağıdaki değerler ezilerek konfigüre edilebilir. Örnek docker-compose file'ı hvl-infra projesinde bulunmaktadır.

Swagger:http://{ip}:{port}/swagger-ui/index.html üzerinden servis bilgileri görüntülenmektedir.