Package com.baasbox.commands.exceptions

Examples of com.baasbox.commands.exceptions.CommandParsingException


                        .build();



    public static JsonNode execute(JsonNode request, JsonCallback callback) throws CommandException {
        if (request == null) throw new CommandParsingException(NullNode.getInstance(),"command is null");
        JsonNode resourceNode = request.get(ScriptCommand.RESOURCE);
        if (resourceNode != null && resourceNode.isTextual()) {
            String name = resourceNode.textValue();
            if (name == null|| name.length()==0){
                throw new CommandParsingException(request,"Resource name cannot be empty");
            }
            Resource resource = RESOURCES.get(name);

            if (resource == null){
                throw new ResourceNotFoundException(request,"Resource not found");
            }
            JsonNode response = resource.execute(request,callback);

            return response;
        } else {
            throw new CommandParsingException(request,"Missing resource name");
        }
    }
View Full Code Here


    }

    private ScriptCommand getFriends(boolean following){
        return (command,unused) ->{
            JsonNode params = command.get(ScriptCommand.PARAMS);
            if (params == null) throw new CommandParsingException(command,"missing required parameters");
            JsonNode user = params.path("user");
            JsonNode query = params.get("query");
            if (!user.isTextual()) throw new CommandParsingException(command,"missing required paramter user as string");
            if (query!=null && !query.isObject()) throw new CommandParsingException(command,"query must be a json object");
            QueryParams qparams = QueryParams.getParamsFromJson(query);
            try {

                List<ODocument> res = following ?
                        FriendShipService.getFollowing(user.asText(), qparams) :
View Full Code Here

//        }
//    }

    protected JsonNode friendshipUpdate(JsonNode command,JsonCallback unused) throws CommandException {
        JsonNode params = command.get(ScriptCommand.PARAMS);
        if (params == null) throw new CommandParsingException(command,"missing required parameters");
        JsonNode from = params.get("from");
        JsonNode to = params.get("to");
        JsonNode remove = params.get("remove");
        if (from==null||!from.isTextual()||
            to == null||!to.isTextual())
            throw new CommandParsingException(command,"missing required user");
        boolean unfollow;
        if (remove == null){
            unfollow = false;
        } else if (remove.isBoolean()){
            unfollow =remove.asBoolean();
        } else {
            throw new CommandParsingException(command,"wrong parameter remove");
        }
        if (unfollow){
            return  doUnfollow(command, from.asText(), to.asText());
        } else {
            return doFollow(command, from.asText(), to.asText());
View Full Code Here

    private String getUsername(JsonNode command) throws CommandException {
        JsonNode params = command.get(ScriptCommand.PARAMS);
        JsonNode id = params.get("username");
        if (id==null||!id.isTextual()){
            throw new CommandParsingException(command,"missing user username");
        }

        String username = id.asText();
        boolean internalUsername = UserService.isInternalUsername(username);
        if (internalUsername){
View Full Code Here

    @Override
    protected JsonNode post(JsonNode command) throws CommandException {
        try {
            JsonNode params = command.get(ScriptCommand.PARAMS);
            if (params==null||!params.isObject()) throw new CommandParsingException(command,"missing parameters");
            String username = getUsername(command);
            JsonNode password = params.get("password");
            if (password==null||!password.isTextual()) throw new CommandParsingException(command,"missing required password");
            JsonNode roleNode = params.get("role");
            String role;
            if (roleNode == null){
                role = DefaultRoles.REGISTERED_USER.getORole().getName();
            } else if (roleNode.isTextual()){
                role = roleNode.asText();
            } else {
                throw new CommandParsingException(command,"role parameter is not valid");
            }
            if (!RoleService.exists(role)){
                throw new CommandExecutionException(command,"required role does not exists: "+role);
            }
            JsonNode userVisible = params.get(UserDao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER);
View Full Code Here


    private JsonNode sendMessage(JsonNode command,JsonCallback callback) throws CommandException{
        JsonNode params = command.get(ScriptCommand.PARAMS);
        if (params == null||!params.isObject()){
            throw new CommandParsingException(command,"missing parameters");
        }

        JsonNode body = params.get("body");
        if (body == null||!body.isObject()){
            throw new CommandParsingException(command,"missing body object parameter");
        }
        JsonNode messageNode = body.get("message");
        if (messageNode==null||!messageNode.isTextual()){
            throw new CommandParsingException(command,"missing message text parameter");
        }
        String message = messageNode.asText();

        List<String> users = new ArrayList<>();
        JsonNode usersNode = params.get("to");
        if (usersNode==null|| !usersNode.isArray()){
            throw new CommandParsingException(command,"missing required to parameter");
        }
        ArrayNode usrAry = (ArrayNode)usersNode;
        usrAry.forEach(j->{
            if (j==null||!j.isTextual()) return;
            users.add(j.asText());
        });

        JsonNode profilesNode = params.get("profiles");
        List<Integer> profiles;
        if (profilesNode == null){
            profiles = Collections.singletonList(1);
        } else if (profilesNode.isArray()) {
            ArrayNode pAry = (ArrayNode)profilesNode;
            profiles = new ArrayList<>();
            pAry.forEach((j)->{
                if(j==null||!j.isIntegralNumber()) return;
                profiles.add(j.asInt());
            });
        } else {
            throw new CommandParsingException(command,"wrong profiles parameter");
        }

        boolean[] errors = new boolean[users.size()];
        PushService ps = new PushService();
View Full Code Here

TOP

Related Classes of com.baasbox.commands.exceptions.CommandParsingException

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.