Search in sources :

Example 1 with Notifications

use of com.webstart.model.Notifications in project FarmCloud by vratsasg.

the class UsersServiceImpl method makeNotificationRead.

public void makeNotificationRead(int notificationid) {
    try {
        Notifications notification = this.notificationsJpaRepository.getByNotificationid(notificationid);
        // 
        notification.setIsreaded(true);
        this.notificationsJpaRepository.save(notification);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Notifications(com.webstart.model.Notifications) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with Notifications

use of com.webstart.model.Notifications in project FarmCloud by vratsasg.

the class UsersServiceImpl method createNewNotification.

public void createNewNotification(int userid, String message, int notificationType) {
    try {
        Notifications notification = new Notifications(userid, message, false, notificationType);
        // 
        notificationsJpaRepository.save(notification);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Notifications(com.webstart.model.Notifications) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with Notifications

use of com.webstart.model.Notifications in project FarmCloud by vratsasg.

the class UserController method getCounterNotifications.

@RequestMapping(value = "notifications", method = RequestMethod.GET)
@ResponseBody
public List<Notifications> getCounterNotifications(HttpServletRequest request) {
    List<Notifications> notificationList = null;
    Users users = (Users) request.getSession().getAttribute("current_user");
    try {
        notificationList = usersService.getUserCounterNotifications(users.getUser_id());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return notificationList;
}
Also used : Users(com.webstart.model.Users) Notifications(com.webstart.model.Notifications)

Example 4 with Notifications

use of com.webstart.model.Notifications in project FarmCloud by vratsasg.

the class UsersServiceImpl method getUserCounterNotifications.

public List<Notifications> getUserCounterNotifications(Integer userId) {
    List<Notifications> notifications = null;
    try {
        notifications = this.notificationsJpaRepository.getAllByUseridAndIsreaded(userId, false);
        // 
        List<Featureofinterest> enddevices = this.featureofinterestJpaRepository.getAllByUseridAndFeatureofinteresttypeid(userId, 3L);
        int offset = DateTimeZone.getDefault().getOffset(new Instant());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter dtfInput = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        // Convert Datetime created to user timezone
        for (Notifications notification : notifications) {
            HelperCls.ConvertToDateTime convertable = new HelperCls.ConvertToDateTime();
            DateTime dt = convertable.GetUTCDateTime(sdf.format(notification.getDatecreated()), dtfInput, enddevices.get(0).getTimezone(), StatusTimeConverterEnum.TO_TIMEZONE);
            Timestamp ts = new Timestamp(dt.getMillis() - offset);
            notification.setDatecreated(ts);
            // 
            logger.debug("params: dt={}, ts={}", dt, ts);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return notifications;
    }
}
Also used : Featureofinterest(com.webstart.model.Featureofinterest) HelperCls(com.webstart.Helpers.HelperCls) Instant(org.joda.time.Instant) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Notifications(com.webstart.model.Notifications) SimpleDateFormat(java.text.SimpleDateFormat) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

Notifications (com.webstart.model.Notifications)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 HelperCls (com.webstart.Helpers.HelperCls)1 Featureofinterest (com.webstart.model.Featureofinterest)1 Users (com.webstart.model.Users)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DateTime (org.joda.time.DateTime)1 Instant (org.joda.time.Instant)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1