Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.User


    @PUT
    @Path("{userId}/disable")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response disableUser(@PathParam("userId") ObjectId userId) {

        User currentUser = securityService.getCurrentUser();

        // require admin role
        if (!securityService.hasRole(Roles.ADMIN_ROLE)) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.UNAUTHORIZED));
        }

        try {
            User user = userService.getUserById(userId, currentUser.getAccount());
            user.setUserStatus(User.UserStatus.DISABLED);
            user.setUserLocked(true);

            // can't disable yourself
            if (user.getId().equals(currentUser.getId())) {
                return error("You can't disable yourself", Response.status(Response.Status.BAD_REQUEST));
            }

            // TODO: need to lock this user somehow... this will do for now
            if (user.getUsername().equals(Constants.NODEABLE_SUPER_USERNAME)) {
                return error("Can't delete super user", Response.status(Response.Status.BAD_REQUEST));
            }

            userService.updateUser(user);
        } catch (UserNotFoundException e) {
View Full Code Here


    @PUT
    @Path("{userId}/enable")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response enableUser(@PathParam("userId") ObjectId userId) {

        User currentUser = securityService.getCurrentUser();

        // require admin role
        if (!securityService.hasRole(Roles.ADMIN_ROLE)) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.UNAUTHORIZED));
        }
        try {
            User user = userService.getUserById(userId, currentUser.getAccount());
            user.setUserStatus(User.UserStatus.ACTIVATED);
            user.setUserLocked(false);
            userService.updateUser(user);
        } catch (UserNotFoundException e) {
            return error("User not found.", Response.status(Response.Status.NOT_FOUND));
        }
        return Response.status(Response.Status.NO_CONTENT).build();
View Full Code Here

     */
    @GET
    @Path("config")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getConfig() {
        User currentUser = securityService.getCurrentUser();
        return Response.ok(currentUser.getConfig()).build();
    }
View Full Code Here

     */
    @POST
    @Path("config")
    @Produces(MediaType.APPLICATION_JSON)
    public Response setConfigValues(JSONObject jsonObject) {
        User currentUser = securityService.getCurrentUser();
        try {
            currentUser.appendToConfig(jsonObject);
            userService.updateUser(currentUser);
            return Response.ok(currentUser.getConfig()).build();
        } catch (Exception e) {
            return error(e.getMessage(), Response.status(Response.Status.BAD_REQUEST));
        }
    }
View Full Code Here

     */
    @DELETE
    @Path("config/{key}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response removeConfigKey(@PathParam("key") String key) {
        User currentUser = securityService.getCurrentUser();
        Map<String,Object> userConfig = currentUser.getConfig();
        if (!userConfig.containsKey(key)) {
            return error(key + " does not exist", Response.status(Response.Status.NOT_FOUND));
        }
        try {
            currentUser.removeConfigValue(key);
            userService.updateUser(currentUser);
            return Response.noContent().build();
        } catch (Exception e) {
            return error(e.getMessage(), Response.status(Response.Status.BAD_REQUEST));
        }
View Full Code Here

     */
    @GET
    @Path("config/{key}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getConfigValueByKey(@PathParam("key") String key) {
        User currentUser = securityService.getCurrentUser();
        Map<String,Object> userConfig = currentUser.getConfig();
        if (userConfig.containsKey(key)) {
            return Response.ok(
                    new JSONObjectBuilder().add(key, userConfig.get(key)).build()
            ).build();
        } else {
View Full Code Here

    @Override
    public Response addTag(@PathParam("userId") String userId, JSONObject json) {

        String hashtag = getJSON(json, HASHTAG);

        User currentUser = securityService.getCurrentUser();

        if (isEmpty(hashtag)) {
            return error("Hashtag payload is empty", Response.status(Response.Status.BAD_REQUEST));
        }

        try {
            User user = userService.getUserById(new ObjectId(userId), currentUser.getAccount());
            user.addHashtag(hashtag);
            userService.updateUser(user);

        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }
View Full Code Here

    @GET
    @Path("{userId}/hashtag")
    @Override
    public Response getTags(@PathParam("userId") String userId) {

        User currentUser = securityService.getCurrentUser();

        Set<String> tags;
        try {
            User user = userService.getUserById(new ObjectId(userId), currentUser.getAccount());
            tags = user.getHashtags();

        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }
View Full Code Here

    public Response removeTag(@PathParam("userId") String userId, @PathParam("tagname") String hashtag) {

        if (isEmpty(hashtag)) {
            return error("Hashtag payload is empty", Response.status(Response.Status.BAD_REQUEST));
        }
        User currentUser = securityService.getCurrentUser();

        try {
            User user = userService.getUserById(new ObjectId(userId), currentUser.getAccount());
            user.removeHashtag(hashtag);
            userService.updateUser(user);

        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }
View Full Code Here

        // require admin role
        if (!securityService.hasRole(Roles.ADMIN_ROLE)) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.UNAUTHORIZED));
        }

        User currentUser = securityService.getCurrentUser();

        try {

            User user = userService.getUserById(userId, currentUser.getAccount());
            userService.addRole(user, roleId);

        } catch (UserNotFoundException e) {
            return error("User not found.", Response.status(Response.Status.NOT_FOUND));
        }
View Full Code Here

TOP

Related Classes of com.streamreduce.core.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.