Search in sources :

Example 6 with UserBean

use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.

the class UserServiceImpl method getMinApiRequestIntervalForKey.

@Cacheable
@Transactional
@Override
public Long getMinApiRequestIntervalForKey(String key, @CacheableArgument(cacheRefreshIndicator = true) boolean forceRefresh) {
    UserIndexKey indexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
    UserIndex userIndex = getUserIndexForId(indexKey);
    if (userIndex == null) {
        return null;
    }
    User user = userIndex.getUser();
    UserBean bean = getUserAsBean(user);
    return bean.getMinApiRequestInterval();
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean) Cacheable(org.onebusaway.container.cache.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with UserBean

use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.

the class DefaultSearchLocationServiceImpl method getDefaultSearchLocationForCurrentUser.

@Override
public DefaultSearchLocation getDefaultSearchLocationForCurrentUser() {
    UserBean user = _currentUserService.getCurrentUser();
    if (user != null && user.hasDefaultLocation()) {
        return new DefaultSearchLocation(user.getDefaultLocationName(), user.getDefaultLocationLat(), user.getDefaultLocationLon(), false);
    }
    RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
    DefaultSearchLocation location = (DefaultSearchLocation) attributes.getAttribute(KEY_DEFAULT_SEARCH_LOCATION_FOR_SESSSION, RequestAttributes.SCOPE_SESSION);
    return location;
}
Also used : UserBean(org.onebusaway.users.client.model.UserBean) DefaultSearchLocation(org.onebusaway.presentation.model.DefaultSearchLocation) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 8 with UserBean

use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.

the class KeysResource method updateKeyContactInfo.

private void updateKeyContactInfo(String apiKey, String contactName, String contactCompany, String contactEmail, String contactDetails, Long minApiReqIntervalLong) throws Exception {
    UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
    UserIndex userIndex = _userService.getUserIndexForId(key);
    if (userIndex == null)
        throw new Exception("API key " + apiKey + " not found (userIndex null).");
    User user = userIndex.getUser();
    UserBean bean = _userService.getUserAsBean(user);
    String keyContactName = bean.getContactName();
    String keyContactCompany = bean.getContactCompany();
    String keyContactEmail = bean.getContactEmail();
    String keyContactDetails = bean.getContactDetails();
    if (contactName != null) {
        keyContactName = contactName;
    }
    if (contactCompany != null) {
        keyContactCompany = contactCompany;
    }
    if (contactEmail != null) {
        keyContactEmail = contactEmail;
    }
    if (contactDetails != null) {
        keyContactDetails = contactDetails;
    }
    _userPropertiesService.authorizeApi(userIndex.getUser(), minApiReqIntervalLong);
    _userPropertiesService.updateApiKeyContactInfo(user, keyContactName, keyContactCompany, keyContactEmail, keyContactDetails);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 9 with UserBean

use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.

the class KeysResource method listKeyDetails.

@Path("/list/{apiKey}")
@GET
@Produces("application/json")
public Response listKeyDetails(@PathParam("apiKey") String apiKey) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting listKeyDetails");
    try {
        validateSecurity();
        UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
        UserIndex userIndex = _userService.getUserIndexForId(key);
        if (userIndex == null)
            throw new Exception("API key " + apiKey + " not found (userIndex null).");
        User user = userIndex.getUser();
        UserBean bean = _userService.getUserAsBean(user);
        Map<String, String> result = new HashMap<String, String>();
        result.put("keyValue", apiKey);
        result.put("contactName", bean.getContactName());
        result.put("contactCompany", bean.getContactCompany());
        result.put("contactEmail", bean.getContactEmail());
        result.put("contactDetails", bean.getContactDetails());
        result.put("minApiRequestInterval", bean.getMinApiRequestInterval().toString());
        Response response = constructResponse(result);
        log.info("Returning response from listKeyDetails");
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new WebApplicationException(e, Response.serverError().build());
    }
}
Also used : Response(javax.ws.rs.core.Response) UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with UserBean

use of org.onebusaway.users.client.model.UserBean in project onebusaway-application-modules by camsys.

the class CommandBookmarksAction method execute.

@Override
public String execute() throws ServiceException, BookmarkException {
    UserBean currentUser = _currentUserService.getCurrentUser();
    if (_arg != null && _arg.length() > 0) {
        if (_arg.startsWith("add")) {
            if (currentUser == null)
                return "noUser";
            List<String> lastSelectedStopIds = currentUser.getLastSelectedStopIds();
            if (!lastSelectedStopIds.isEmpty()) {
                String name = _bookmarkPresentationService.getNameForStopIds(lastSelectedStopIds);
                _currentUserService.addStopBookmark(name, lastSelectedStopIds, new RouteFilter());
            }
            return "added";
        }
        if (_arg.startsWith("delete")) {
            int index = _arg.indexOf(' ');
            if (index == -1)
                return INPUT;
            int bookmarkIndex = Integer.parseInt(_arg.substring(index + 1).trim()) - 1;
            _currentUserService.deleteStopBookmarks(bookmarkIndex);
            return "deleted";
        }
        if (_arg.matches("\\d+")) {
            int index = Integer.parseInt(_arg) - 1;
            List<BookmarkBean> bookmarks = currentUser.getBookmarks();
            if (index < 0 || index >= bookmarks.size())
                return INPUT;
            BookmarkBean bookmark = bookmarks.get(index);
            _stopIds = bookmark.getStopIds();
            _routeFilter = bookmark.getRouteFilter().getRouteIds();
            return "arrivals-and-departures";
        }
    }
    _bookmarks = _bookmarkPresentationService.getBookmarksWithStops(currentUser.getBookmarks());
    return SUCCESS;
}
Also used : UserBean(org.onebusaway.users.client.model.UserBean) BookmarkBean(org.onebusaway.users.client.model.BookmarkBean) RouteFilter(org.onebusaway.users.model.properties.RouteFilter)

Aggregations

UserBean (org.onebusaway.users.client.model.UserBean)16 User (org.onebusaway.users.model.User)8 UserIndex (org.onebusaway.users.model.UserIndex)8 UserIndexKey (org.onebusaway.users.model.UserIndexKey)6 ArrayList (java.util.ArrayList)3 UserDetail (org.onebusaway.admin.model.ui.UserDetail)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 Criteria (org.hibernate.Criteria)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 UserRole (org.onebusaway.users.model.UserRole)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1