Search in sources :

Example 1 with UserPropertiesV2

use of org.onebusaway.users.model.properties.UserPropertiesV2 in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceV2Impl method markServiceAlertAsRead.

@Override
public void markServiceAlertAsRead(User user, String situationId, long time, boolean isRead) {
    UserPropertiesV2 properties = getProperties(user);
    Map<String, Long> readSituationIdsWithReadTime = properties.getReadSituationIdsWithReadTime();
    if (isRead) {
        if (readSituationIdsWithReadTime == null) {
            readSituationIdsWithReadTime = new HashMap<String, Long>();
            properties.setReadSituationIdsWithReadTime(readSituationIdsWithReadTime);
        }
        readSituationIdsWithReadTime.put(situationId, time);
        _userDao.saveOrUpdateUser(user);
    } else {
        if (readSituationIdsWithReadTime == null)
            return;
        if (readSituationIdsWithReadTime.remove(situationId) != null)
            _userDao.saveOrUpdateUser(user);
    }
}
Also used : UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 2 with UserPropertiesV2

use of org.onebusaway.users.model.properties.UserPropertiesV2 in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceV2Impl method setDefaultLocation.

@Override
public void setDefaultLocation(User user, String locationName, double lat, double lon) {
    UserPropertiesV2 properties = getProperties(user);
    if (!properties.isRememberPreferencesEnabled())
        return;
    properties.setDefaultLocationName(locationName);
    properties.setDefaultLocationLat(lat);
    properties.setDefaultLocationLon(lon);
    _userDao.saveOrUpdateUser(user);
}
Also used : UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 3 with UserPropertiesV2

use of org.onebusaway.users.model.properties.UserPropertiesV2 in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceV2Impl method addStopBookmark.

@Override
public int addStopBookmark(User user, String name, List<String> stopIds, RouteFilter filter) {
    UserPropertiesV2 properties = getProperties(user);
    if (!properties.isRememberPreferencesEnabled())
        return -1;
    int maxId = 0;
    for (Bookmark bookmark : properties.getBookmarks()) maxId = Math.max(maxId, bookmark.getId() + 1);
    Bookmark bookmark = new Bookmark(maxId, name, stopIds, filter);
    properties.getBookmarks().add(bookmark);
    _userDao.saveOrUpdateUser(user);
    return bookmark.getId();
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 4 with UserPropertiesV2

use of org.onebusaway.users.model.properties.UserPropertiesV2 in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceV2Impl method getUserAsBean.

@Override
public UserBean getUserAsBean(User user, UserBean bean) {
    UserPropertiesV2 properties = getProperties(user);
    bean.setRememberPreferencesEnabled(properties.isRememberPreferencesEnabled());
    bean.setHasDefaultLocation(properties.hasDefaultLocationLat() && properties.hasDefaultLocationLon());
    bean.setDefaultLocationName(properties.getDefaultLocationName());
    bean.setDefaultLocationLat(properties.getDefaultLocationLat());
    bean.setDefaultLocationLon(properties.getDefaultLocationLon());
    List<String> stopIds = _lastSelectedStopService.getLastSelectedStopsForUser(user.getId());
    bean.setLastSelectedStopIds(stopIds);
    for (Bookmark bookmark : properties.getBookmarks()) {
        BookmarkBean bookmarkBean = new BookmarkBean();
        bookmarkBean.setId(bookmark.getId());
        bookmarkBean.setName(bookmark.getName());
        bookmarkBean.setStopIds(bookmark.getStopIds());
        bookmarkBean.setRouteFilter(getRouteFilterAsBean(bookmark.getRouteFilter()));
        bean.addBookmark(bookmarkBean);
    }
    bean.setMinApiRequestInterval(properties.getMinApiRequestInterval());
    Map<String, Long> readServiceAlerts = properties.getReadSituationIdsWithReadTime();
    if (readServiceAlerts == null)
        readServiceAlerts = Collections.emptyMap();
    bean.setReadServiceAlerts(readServiceAlerts);
    return bean;
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) BookmarkBean(org.onebusaway.users.client.model.BookmarkBean) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2)

Example 5 with UserPropertiesV2

use of org.onebusaway.users.model.properties.UserPropertiesV2 in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceVersionedInvocationHandler method getPropertiesVersion.

private int getPropertiesVersion(User user) {
    UserProperties props = user.getProperties();
    if (props instanceof UserPropertiesV1)
        return 1;
    if (props instanceof UserPropertiesV2)
        return 2;
    if (props instanceof UserPropertiesV3)
        return 3;
    if (props instanceof UserPropertiesV4)
        return 4;
    _log.warn("unknown user properties version: " + props.getClass());
    return 0;
}
Also used : UserProperties(org.onebusaway.users.model.UserProperties) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) UserPropertiesV4(org.onebusaway.users.model.properties.UserPropertiesV4)

Aggregations

UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)21 Bookmark (org.onebusaway.users.model.properties.Bookmark)9 Test (org.junit.Test)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 Date (java.util.Date)3 User (org.onebusaway.users.model.User)3 UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)3 UserIndex (org.onebusaway.users.model.UserIndex)2 UserIndexKey (org.onebusaway.users.model.UserIndexKey)2 UserProperties (org.onebusaway.users.model.UserProperties)2 Calendar (java.util.Calendar)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserRole (org.onebusaway.users.model.UserRole)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1