Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.User$Builder


     */
    @GET
    @Path("users")
    public Response getAccountUsers() {

        User currentUser = applicationManager.getSecurityService().getCurrentUser();
        List<User> users;
        try {
            Account account = applicationManager.getUserService().getAccount(currentUser.getAccount().getId());
            users = applicationManager.getUserService().allEnabledUsersForAccount(account);
        } catch (AccountNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

View Full Code Here


        if (isEmpty(password) || isEmpty(alias) || isEmpty(fullname)) {
            return error(ErrorMessages.MISSING_REQUIRED_FIELD, Response.status(Response.Status.BAD_REQUEST));
        }

        User user;

        try {

            // validate password
            if (!SecurityUtil.isValidPassword(password)) {
                return error(ErrorMessages.INVALID_PASSWORD_ERROR, Response.status(Response.Status.BAD_REQUEST));
            }

            user = userService.getUserFromInvite(inviteKey, accountId);

            // this account is already active!
            // FIXME: this status code sucks here
            if (user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User is already activated", Response.status(Response.Status.NOT_ACCEPTABLE));
            }

            // verify alias is unique
            if (!userService.isAliasAvailable(user.getAccount(), alias)) {
                return error("Alias is not available", Response.status(Response.Status.NOT_ACCEPTABLE));
            }

            user.setPassword(password);
            user.setFullname(fullname);
            user.setAlias(alias);
            // we already know their company..so no need to set it

            // user can login
            user.setUserLocked(false);

            // we want to make this a one time thing, blow away the secret key
            user.setSecretKey(null);

            userService.createUser(user);

        } catch (UserNotFoundException e) {
            return error("Invalid Invite " + inviteKey + ":" + accountId, Response.status(Response.Status.NOT_FOUND));
        } catch (InvalidUserAliasException e) {
            ConstraintViolationExceptionResponseDTO dto = new ConstraintViolationExceptionResponseDTO();
            dto.setViolations(ImmutableMap.of("alias", e.getMessage()));
            return Response.status(Response.Status.BAD_REQUEST).entity(dto).build();
        }

        // user created, they can now login
        return Response
                .status(Response.Status.CREATED)
                .entity(user.getUsername())
                .build();
    }
View Full Code Here

     * @resource.representation.404.doc returned if the account to get users for is not found
     */
    @GET
    @Path("users/active")
    public Response getActiveLoggedInUsers() {
        User currentUser = applicationManager.getSecurityService().getCurrentUser();
        Set<User> theUsers;
        try {
            Account account = applicationManager.getUserService().getAccount(currentUser.getAccount().getId());
            theUsers = applicationManager.getSecurityService().getActiveUsers(account, (Constants.PERIOD_MINUTE * 3));
        } catch (AccountNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }
        List<User> users = new ArrayList<>(theUsers);
View Full Code Here

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

        User currentUser = applicationManager.getSecurityService().getCurrentUser();

        Set<Role> roles;
        try {
            roles = applicationManager.getUserService().getAccountRoles(currentUser.getAccount().getId());
        } catch (AccountNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        RolesResponseDTO dto = new RolesResponseDTO();
View Full Code Here

        // check for missing required values
        if (isEmpty(signupKey) || isEmpty(userId)) {
            return error("Required path params missing", Response.status(Response.Status.BAD_REQUEST));
        }

        User user;
        try {

            user = applicationManager.getUserService().getUserFromSignupKey(signupKey, userId);

            // this account is already active!
            if (user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User is already activated", Response.status(Response.Status.NOT_ACCEPTABLE));
            }

        } catch (UserNotFoundException e) {
            return error("Invalid Signup " + signupKey + ":" + userId, Response.status(Response.Status.NOT_FOUND));
        }

        return Response
                .ok()
                .entity(user.getUsername())
                .build();
    }
View Full Code Here

        if (isEmpty(password) || isEmpty(alias) || isEmpty(fullname) || isEmpty(accountName)) {
            return error(ErrorMessages.MISSING_REQUIRED_FIELD, Response.status(Response.Status.BAD_REQUEST));
        }

        User user;

        try {

            // validate password
            if (!SecurityUtil.isValidPassword(password)) {
                return error(ErrorMessages.INVALID_PASSWORD_ERROR, Response.status(Response.Status.BAD_REQUEST));
            }

            user = userService.getUserFromSignupKey(signupKey, userId);

            // this account is already active!
            if (user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User is already activated", Response.status(Response.Status.NOT_ACCEPTABLE));
            }

            user.setPassword(password);
            user.setFullname(fullname);
            user.setAlias(alias); // no need to check, you are the first user

            // user can now login, the account is "activated"
            user.setUserLocked(false);

            // we want to make this a one time thing, blow away the secret key
            user.setSecretKey(null);

            Account account = new Account.Builder()
                    .name(accountName)
                    .build();

            // create the account and fire events
            userService.createAccount(account);
            user.setAccount(account);

            // create the user and fire events
            userService.createUser(user);

        } catch (UserNotFoundException e) {
            return error("Invalid Signup " + signupKey + ":" + userId, Response.status(Response.Status.NOT_FOUND));
        } catch (InvalidUserAliasException e) {
            ConstraintViolationExceptionResponseDTO dto = new ConstraintViolationExceptionResponseDTO();
            dto.setViolations(ImmutableMap.of("alias", e.getMessage()));
            return Response.status(Response.Status.BAD_REQUEST).entity(dto).build();
        }

        return Response
                .status(Response.Status.CREATED)
                .entity(user.getUsername()) // This should probably be some sort of response DTO but due to time this is what you'll get.
                .build();
    }
View Full Code Here

        if (isEmpty(message)) {
            return error(ErrorMessages.MISSING_REQUIRED_FIELD + " message", Response.status(Response.Status.BAD_REQUEST));
        }

        try {
            User sender;
            if (isEmpty(username)) {
                sender = applicationManager.getUserService().getSuperUser();
            } else {
                sender = applicationManager.getUserService().getUser(username);
            }

            MessageUtils.ParsedMessage parsedMessage = MessageUtils.parseMessage(message);
            Set<String> hashtags = parsedMessage.getTags();

            for (Object rawHashtag : tags) {
                hashtags.add((String) rawHashtag);
            }

            Map<String, Object> eventMetadata = new HashMap<>();

            eventMetadata.put("message", parsedMessage);
            eventMetadata.put("messageHashtags", hashtags);
            eventMetadata.put("payload", json);
            eventMetadata.put("senderId", sender.getId());
            eventMetadata.put("senderAccountId", sender.getAccount().getId());

            Event event = applicationManager.getEventService().createEvent(EventId.CREATE_GLOBAL_MESSAGE,
                    null, eventMetadata);

            applicationManager.getMessageService().sendNodebellyGlobalMessage(event, sender, null, new Date().getTime(),
View Full Code Here

    public void setUp() throws Exception {
        super.setUp();

        // we know this user has inventory items right now...
        // just grab the first one we find.
        User user = userService.getUser(Constants.NODEABLE_SUPER_USERNAME);
        Connection cloud = connectionService.getConnections(CloudProvider.TYPE, user).get(0);
        List<InventoryItem> inventoryItems = inventoryService.getInventoryItems(cloud);
        int retry = 0;

        while (inventoryItems.size() == 0 && retry < 3) {
View Full Code Here

        try {
            Account account = userService.getAccount(id);

            // TODO: need a better way to lock this...
            User superUser = userService.getSuperUser();
            if (superUser.getAccount().getId().equals(id)) {
                return error("Cannot disable Nodeable account.", Response.status(Response.Status.BAD_REQUEST));
            }

            account.setConfigValue(Account.ConfigKey.ACCOUNT_LOCKED, true);
            userService.updateAccount(account);
View Full Code Here

        try {
            Account account = userService.getAccount(id);

            // TODO: need a better way to lock this...
            User superUser = userService.getSuperUser();
            if (superUser.getAccount().getId().equals(id)) {
                return error("Can not disable Nodeable account.", Response.status(Response.Status.BAD_REQUEST));
            }

            account.setConfigValue(Account.ConfigKey.DISABLE_INBOUND_API, true);
            userService.updateAccount(account);
View Full Code Here

TOP

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

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.