Search in sources :

Example 6 with UserPropertiesV3

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

the class UserPropertiesServiceV3Impl method getUserAsBean.

@Override
public UserBean getUserAsBean(User user, UserBean bean) {
    UserPropertiesV3 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());
    bean.setContactName(properties.getContactName());
    bean.setContactCompany(properties.getContactCompany());
    bean.setContactEmail(properties.getContactEmail());
    bean.setContactDetails(properties.getContactDetails());
    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) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Example 7 with UserPropertiesV3

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

the class UserPropertiesServiceV3Impl method addStopBookmark.

@Override
public int addStopBookmark(User user, String name, List<String> stopIds, RouteFilter filter) {
    UserPropertiesV3 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) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Example 8 with UserPropertiesV3

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

the class UserPropertiesServiceV3Impl method markServiceAlertAsRead.

@Override
public void markServiceAlertAsRead(User user, String situationId, long time, boolean isRead) {
    UserPropertiesV3 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 : UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3)

Example 9 with UserPropertiesV3

use of org.onebusaway.users.model.properties.UserPropertiesV3 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)

Example 10 with UserPropertiesV3

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

the class UserPropertiesMigrationImplTest method testV2ToV3Migration.

@Test
public void testV2ToV3Migration() {
    UserPropertiesV2 v2 = new UserPropertiesV2();
    v2.setDefaultLocationLat(47.0);
    v2.setDefaultLocationLon(-122.0);
    v2.setDefaultLocationName("Seattle");
    v2.setRememberPreferencesEnabled(true);
    Bookmark b1 = new Bookmark(0, null, Arrays.asList("1_29214"), new RouteFilter());
    Bookmark b2 = new Bookmark(1, null, Arrays.asList("1_75403", "1_75414"), new RouteFilter());
    v2.setBookmarks(Arrays.asList(b1, b2));
    UserPropertiesV2 result = _service.migrate(v2, UserPropertiesV2.class);
    assertTrue(v2 == result);
    UserPropertiesV3 v3 = _service.migrate(v2, UserPropertiesV3.class);
    assertTrue(v3.isRememberPreferencesEnabled());
    assertEquals(47.0, v3.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, v3.getDefaultLocationLon(), 0.0);
    assertEquals("Seattle", v3.getDefaultLocationName());
    List<Bookmark> bookmarks = v3.getBookmarks();
    assertEquals(2, bookmarks.size());
    Bookmark bookmark = bookmarks.get(0);
    assertEquals(0, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_29214"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
    bookmark = bookmarks.get(1);
    assertEquals(1, bookmark.getId());
    assertNull(bookmark.getName());
    assertEquals(Arrays.asList("1_75403", "1_75414"), bookmark.getStopIds());
    assertTrue(bookmark.getRouteFilter().getRouteIds().isEmpty());
}
Also used : Bookmark(org.onebusaway.users.model.properties.Bookmark) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) Test(org.junit.Test)

Aggregations

UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)17 Bookmark (org.onebusaway.users.model.properties.Bookmark)6 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)3 Test (org.junit.Test)2 UserProperties (org.onebusaway.users.model.UserProperties)2 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserIndex (org.onebusaway.users.model.UserIndex)1 UserIndexKey (org.onebusaway.users.model.UserIndexKey)1 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1