Package com.streamreduce.rest.dto.response

Examples of com.streamreduce.rest.dto.response.UserResponseDTO


        }
        return allUsers;
    }

    protected UserResponseDTO toFullDTO(User user) {
        UserResponseDTO dto = new UserResponseDTO();

        toBaseDTO(user, dto);

        dto.setAccountOriginator(user.isAccountOriginator());
        dto.setFullname(user.getFullname());
        Set<RoleResponseDTO> rolesDTOs = new HashSet<>();
        for (Role role : user.getRoles()) {
            rolesDTOs.add(toDTO(role));
        }
        dto.setRoles(rolesDTOs);
        dto.setStatus(user.getUserStatus());
        dto.setUserConfig(user.getConfig());
        dto.setUsername(user.getUsername());
        return dto;
    }
View Full Code Here


        json.put("fullname", newName);
        json.put("alias", newAlias);

        makeRequest(getUrl() + "/profile", "PUT", json, authToken);

        UserResponseDTO userDTO = jsonToObject(makeRequest(getUrl(), "GET", null, authToken),
                TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertEquals(newName, userDTO.getFullname());
        assertEquals(newAlias, userDTO.getAlias());
    }
View Full Code Here

        String authn2Token = login(testUser2Username, testUser2Username);

        // Make sure a user can can get their own information
        String req = makeRequest(getUrl() + "/" + testUser.getId(), "GET", null,
                authToken);
        UserResponseDTO responseDTO = jsonToObject(req, TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertEquals(testUser.getAlias(), responseDTO.getAlias());
        assertEquals(testUser.getUsername(), responseDTO.getUsername());

        // Make sure a user in the same account can get another user in the same account
        responseDTO = jsonToObject(makeRequest(getUrl() + "/" + testUser3.getId(), "GET", null, authToken),
                TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertEquals(testUser3.getAlias(), responseDTO.getAlias());
        assertEquals(testUser3.getUsername(), responseDTO.getUsername());

        // Make sure a user in one account cannot get a user in another account
        jsonToObject(makeRequest(getUrl() + "/" + testUser3.getId(), "GET", null, authn2Token),
                TypeFactory.defaultInstance().constructType(ErrorMessage.class));
    }
View Full Code Here

* Methods in this class should not be publically available. They are for internal and super-user use only!
*/
public abstract class AbstractAdminResource extends AbstractResource {

    protected UserResponseDTO toDTO(User user) {
        UserResponseDTO dto = new UserResponseDTO();

        // do not use the toBaseDTO() since accountId could be null.
        if (user.getAccount() != null) {
            dto.setAccountId(user.getAccount().getId());
        }
        dto.setAlias(user.getAlias());
//        dto.setDescription(user.getDescription());
        dto.setHashtags(user.getHashtags());
        dto.setUserId(user.getUser().getId());
        dto.setCreated(user.getCreated());
        dto.setId(user.getId());
        dto.setModified(user.getModified());
        dto.setVisibility(user.getVisibility());

        dto.setAccountOriginator(user.isAccountOriginator());
        dto.setFullname(user.getFullname());
        Set<RoleResponseDTO> rolesDTOs = new HashSet<>();
        for (Role role : user.getRoles()) {
            rolesDTOs.add(toDTO(role));
        }
        dto.setRoles(rolesDTOs);
        dto.setStatus(user.getUserStatus());
        dto.setUserConfig(user.getConfig());
        dto.setUsername(user.getUsername());
        return dto;
    }
View Full Code Here

     * @return The requested item.
     */
    @GET
    public Response getCurrentUser() {
        User currentUser = securityService.getCurrentUser();
        UserResponseDTO userResponseDTO = toFullDTO(currentUser);

        return Response.ok(userResponseDTO).build();
    }
View Full Code Here

            }
        } catch (UserNotFoundException unfe) {
            return error("No user found with the following id: " + idOrUsername, Response.status(Response.Status.NOT_FOUND));
        }

        UserResponseDTO userResponseDTO = toFullDTO(requestedUser);
        return Response.ok(userResponseDTO).build();
    }
View Full Code Here

        json.put("visibility", "SELF");

        makeRequest(getUrl() + "/profile", "PUT", json, authToken);

        String req = makeRequest(getUrl(), "GET", null, authToken);
        UserResponseDTO userDTO = jsonToObject(req, TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertEquals("SELF", String.valueOf(userDTO.getVisibility()));

        // set it back...
        User user = userService.getUserById(testUser.getId());
        user.setVisibility(SobaObject.Visibility.ACCOUNT);
        userService.updateUser(user);
View Full Code Here

    @Ignore
    public void testAddRoleToUser() throws Exception {

        String url = getUrl() + "/" + testUser.getUsername();
        String req = makeRequest(url, "GET", null, authToken);
        UserResponseDTO user = jsonToObject(req, TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        int baseline = user.getRoles().size();

        assertNotNull(user);
        assertEquals(testUser.getId(), user.getId());
        assertTrue(baseline > 0);

        Set<Role> roles = userService.getAccountRoles(user.getAccountId());
        Role devRole = null;
        for (Role role : roles) {
            if (role.getName().equals(Roles.DEVELOPER_ROLE)) {
                devRole = role;
                break;
            }
        }
        assertNotNull(devRole);

        // make user admin
        makeRequest(getUrl() + "/" + user.getId() + "/roles/" + devRole.getId(), "POST", null, authToken);

        // get user again
        url = getUrl() + "/" + testUser.getUsername();
        user = jsonToObject(makeRequest(url, "GET", null, authToken), TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertEquals(baseline + 1, user.getRoles().size());
    }
View Full Code Here

    @Ignore
    public void testRemoveRoleFromUser() throws Exception {

        String url = getUrl() + "/" + testUser.getUsername();
        String req = makeRequest(url, "GET", null, authToken);
        UserResponseDTO user = jsonToObject(req, TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        int baseline = user.getRoles().size();

        assertNotNull(user);
        assertEquals(testUser.getId(), user.getId());
        assertTrue(baseline > 0);


        Set<RoleResponseDTO> roles = user.getRoles();
        RoleResponseDTO userRole = null;
        for (RoleResponseDTO role : roles) {
            if (role.getName().equals(Roles.USER_ROLE)) {
                userRole = role;
                break;
            }
        }
        assertNotNull(userRole);

        // remove user role
        makeRequest(getUrl() + "/" + user.getId() + "/roles/" + userRole.getId(), "DELETE", null, authToken);

        // get user again
        url = getUrl() + "/" + testUser.getUsername();
        user = jsonToObject(makeRequest(url, "GET", null, authToken), TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertTrue(user.getRoles().size() > 0);

        assertEquals(baseline - 1, user.getRoles().size());

    }
View Full Code Here

    @Test
    @Ignore
    public void testGetUserById() throws Exception {
        String url = usersBaseUrl + "/" + testUser.getId();
        UserResponseDTO user = jsonToObject(makeRequest(url, "GET", null, authToken), TypeFactory.defaultInstance().constructType(UserResponseDTO.class));

        assertNotNull(user);
        assertEquals(testUser.getUsername(), user.getUsername());

    }
View Full Code Here

TOP

Related Classes of com.streamreduce.rest.dto.response.UserResponseDTO

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.