GetUserProfileRS.java :  » UnTagged » ot-sims » fr » insa » lyon » ot » sims » centralserver » ws » Android Open Source

Android Open Source » UnTagged » ot sims 
ot sims » fr » insa » lyon » ot » sims » centralserver » ws » GetUserProfileRS.java
package fr.insa.lyon.ot.sims.centralserver.ws;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import fr.insa.lyon.ot.sims.centralserver.model.Profile;
import fr.insa.lyon.ot.sims.centralserver.model.User;
import fr.insa.lyon.ot.sims.centralserver.service.user.UserDoesNotExistException;
import fr.insa.lyon.ot.sims.centralserver.service.user.UserService;
import fr.insa.lyon.ot.sims.centralserver.ws.response.UserProfileResponse;

@Path("/profile/get/")
@Stateless
public class GetUserProfileRS {

    @EJB
    private UserService userService;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public UserProfileResponse getUserProfile(@QueryParam("login") String login) {
        try {
            User user = userService.findByLogin(login);
            Profile profile = user.getProfile();
            return UserProfileResponse.userProfileResponse(login, profile);
        } catch (UserDoesNotExistException ex) {
            return UserProfileResponse.userDoesNotExistResponse(login);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.