Search in sources :

Example 1 with BookmarkWithStopsBean

use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.

the class AbstractBookmarkAction method populateBookmarks.

protected void populateBookmarks(List<BookmarkWithStopsBean> bookmarks, String messageKey) {
    int index = 1;
    for (BookmarkWithStopsBean bookmark : bookmarks) {
        _log.debug("found bookmark=" + bookmark);
        String toPress = Integer.toString(index);
        addMessage(messageKey);
        List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
        Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
        addBookmarkDescription(bookmark);
        addText(", ");
        addMessage(Messages.PLEASE_PRESS);
        addText(toPress);
        addText(". ");
        index++;
    }
    addMessage(Messages.HOW_TO_GO_BACK);
}
Also used : BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) HashSet(java.util.HashSet)

Example 2 with BookmarkWithStopsBean

use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.

the class AbstractBookmarkAction method setSelection.

protected void setSelection() {
    List<BookmarkWithStopsBean> bookmarks = _bookmarkPresentationService.getBookmarksWithStops(_currentUser.getBookmarks());
    int selection = 0;
    try {
        selection = Integer.parseInt(getInput()) - 1;
    } catch (NumberFormatException nfe) {
    // bury
    }
    if (selection >= bookmarks.size()) {
        _log.warn("resetting bookmark size to " + (bookmarks.size() - 1));
        selection = bookmarks.size() - 1;
    }
    _log.debug("bookmark selection=" + selection);
    if (selection < 0) {
        _isValidSelection = false;
        setStopIds(null);
        setRouteIds(null);
    } else {
        _isValidSelection = true;
        BookmarkWithStopsBean bookmark = bookmarks.get(selection);
        _log.debug("selected stop=" + bookmark.getStops());
        List<String> stopIds = MappingLibrary.map(bookmark.getStops(), "id");
        Set<String> routeIds = new HashSet<String>(MappingLibrary.map(bookmark.getRoutes(), "id", String.class));
        setStopIds(stopIds);
        setRouteIds(routeIds);
        setIndex(selection);
    }
}
Also used : BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) HashSet(java.util.HashSet)

Example 3 with BookmarkWithStopsBean

use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.

the class ManageTemplate method buildTemplate.

@SuppressWarnings("unchecked")
@Override
public void buildTemplate(ActionContext context) {
    ValueStack stack = context.getValueStack();
    List<BookmarkWithStopsBean> bookmarks = (List<BookmarkWithStopsBean>) stack.findValue("bookmarks");
    if (bookmarks.isEmpty()) {
        addMessage(Messages.BOOKMARKS_EMPTY);
    } else {
        int index = 1;
        for (BookmarkWithStopsBean bookmark : bookmarks) {
            addMessage(Messages.BOOKMARKS_TO_DELETE_THE_BOOKMARK_FOR);
            addBookmarkDescription(bookmark);
            addMessage(Messages.PLEASE_PRESS);
            String toPress = Integer.toString(index);
            addText(toPress);
            AgiActionName deleteAction = addAction(toPress, "/bookmarks/deleteByIndex");
            deleteAction.putParam("index", index - 1);
            index++;
        }
    }
    addAction("(#|0|.+\\*)", "/repeat");
    addMessage(Messages.HOW_TO_GO_BACK);
    addAction("\\*", "/back");
    addMessage(Messages.TO_REPEAT);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) List(java.util.List) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Example 4 with BookmarkWithStopsBean

use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.

the class BookmarkPresentationServiceImpl method getBookmarksWithStops.

@Override
public List<BookmarkWithStopsBean> getBookmarksWithStops(List<BookmarkBean> bookmarks) {
    List<BookmarkWithStopsBean> beans = new ArrayList<BookmarkWithStopsBean>(bookmarks.size());
    for (BookmarkBean bookmark : bookmarks) {
        BookmarkWithStopsBean bean = new BookmarkWithStopsBean();
        bean.setId(bookmark.getId());
        bean.setName(bookmark.getName());
        bean.setStops(getStopsForStopIds(bookmark.getStopIds()));
        bean.setRoutes(getRoutesForRouteFilter(bookmark.getRouteFilter()));
        beans.add(bean);
    }
    return beans;
}
Also used : BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) BookmarkBean(org.onebusaway.users.client.model.BookmarkBean) ArrayList(java.util.ArrayList)

Example 5 with BookmarkWithStopsBean

use of org.onebusaway.presentation.model.BookmarkWithStopsBean in project onebusaway-application-modules by camsys.

the class BookmarkStopAction method execute.

@Override
public String execute() throws Exception {
    _log.debug("in execute! with input=" + getInput() + " and stops=" + _stops + " and stopIds=" + _stopIds + " and user=" + _currentUser);
    if (PREVIOUS_MENU_ITEM.equals(getInput()) || "9".equals(getInput())) {
        clearNextAction();
        return "index";
    }
    if (_currentUser != null && !_currentUser.isRememberPreferencesEnabled())
        return "preferences_disabled";
    setNextAction("bookmarks/bookmark-stop");
    if (_currentUser == null) {
        // something went wrong, bail
        addMessage(Messages.BOOKMARKS_EMPTY);
        addMessage(Messages.HOW_TO_GO_BACK);
        addMessage(Messages.TO_REPEAT);
        return INPUT;
    }
    // from here we have a currentUser
    if (_stops.isEmpty()) {
        _log.debug("empty stops!");
        addMessage(Messages.BOOKMARKS_EMPTY);
        addMessage(Messages.HOW_TO_GO_BACK);
        addMessage(Messages.TO_REPEAT);
        return INPUT;
    }
    // to allow REPEAT/BACK choices to still work, we need to limit bookmarks to 7
    List<BookmarkWithStopsBean> bookmarks = _bookmarkPresentationService.getBookmarksWithStops(_currentUser.getBookmarks());
    if (bookmarks.size() > MAX_BOOKMARKS) {
        addMessage(Messages.BOOKMARKS_AT_CAPACITY);
        addMessage(Messages.HOW_TO_GO_BACK);
        return SUCCESS;
    }
    // make sure the bookmark isn't already there
    for (BookmarkWithStopsBean bookmark : bookmarks) {
        for (StopBean stopBean : _stops) {
            if (bookmark.getStops().contains(stopBean)) {
                addMessage(Messages.BOOKMARK_ALREADY_ADDED);
                addMessage(Messages.HOW_TO_GO_BACK);
                return SUCCESS;
            }
        }
    }
    // add the bookmark
    String name = _bookmarkPresentationService.getNameForStops(_stops);
    List<String> stopIds = MappingLibrary.map(_stops, "id");
    _currentUserService.addStopBookmark(name, stopIds, new RouteFilter());
    logUserInteraction("stopIds", stopIds);
    addMessage(Messages.BOOKMARK_ADDED);
    return SUCCESS;
}
Also used : BookmarkWithStopsBean(org.onebusaway.presentation.model.BookmarkWithStopsBean) StopBean(org.onebusaway.transit_data.model.StopBean) RouteFilter(org.onebusaway.users.model.properties.RouteFilter)

Aggregations

BookmarkWithStopsBean (org.onebusaway.presentation.model.BookmarkWithStopsBean)6 HashSet (java.util.HashSet)3 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 List (java.util.List)2 AgiActionName (org.onebusaway.probablecalls.AgiActionName)2 ArrayList (java.util.ArrayList)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)1