Package com.baasbox.commands.exceptions

Examples of com.baasbox.commands.exceptions.CommandParsingException


    }

    private static String extractCollectionName(JsonNode command) throws CommandParsingException {
        JsonNode node = command.get(ScriptCommand.PARAMS);
        if (!node.isTextual()){
            throw new CommandParsingException(command,"expeceted params to be the name of a collection");
        }
        return node.asText();
    }
View Full Code Here


    public abstract Map<String,ScriptCommand> commands();


    public final JsonNode execute(JsonNode request, JsonCallback callback) throws CommandException {
        if (request == null) throw new CommandParsingException(NullNode.getInstance(),"Invalid request: null");
        JsonNode nameNode = request.get(ScriptCommand.NAME);

        if (nameNode != null && nameNode.isTextual()) {
            String name = nameNode.textValue();
            if (name==null || name.length()==0){
                throw new CommandParsingException(request,"Command name cannot be empty");
            }

            ScriptCommand command = commands().get(name);
            if (command == null){
                throw new CommandNotFoundException(request,"command not defined: "+name);
            }
            return command.execute(request,callback);
        } else {
            throw new CommandParsingException(request,"Missing command name");
        }
    }
View Full Code Here

    }


    private void validateHasParams(JsonNode commnand) throws CommandParsingException{
        if (!commnand.has(ScriptCommand.PARAMS)) {
            throw new CommandParsingException(commnand,"missing parameters");
        }
    }
View Full Code Here

    private String getCollectionName(JsonNode command) throws CommandParsingException {
        JsonNode params = command.get(ScriptCommand.PARAMS);
        JsonNode collNode = params.get(COLLECTION);
        if (collNode == null|| !collNode.isTextual()){
            throw new CommandParsingException(command,"invalid collection param: "+(collNode==null?"null":collNode.toString()));
        }
        return collNode.asText();
    }
View Full Code Here

    }

    private String getAuthorOverride(JsonNode command) throws CommandParsingException{
        JsonNode node = command.get(ScriptCommand.PARAMS).get(AUTHOR);
        if (node != null && !node.isTextual()){
            throw new CommandParsingException(command,"author must be a string");

        } else if (node != null){
            return node.asText();
        }
        return null;
View Full Code Here

    }

    private JsonNode getData(JsonNode command) throws CommandParsingException {
        JsonNode node = command.get(ScriptCommand.PARAMS).get(DATA);
        if (node == null||(!node.isObject())){
            throw new CommandParsingException(command,"missing required data parameter");
        }
        return node;
    }
View Full Code Here

        }
    }

    private void alterGrantsTo(JsonNode command, JsonNode to, String collection, String docId, boolean isGrant,boolean users, Permissions permission) throws CommandParsingException, UserNotFoundException, DocumentNotFoundException, InvalidCollectionException, InvalidModelException, RoleNotFoundException {
        if (!to.isArray()) throw new CommandParsingException(command,"targets of permissions must be an array");
        if (isGrant){
           if (users){
               for (JsonNode u: to){
                   if (!u.isTextual()) throw new CommandParsingException(command,"invalid user name specified: "+u);
                   DocumentService.grantPermissionToUser(collection,docId,permission,u.asText());
               }
           } else {
               for (JsonNode r:to){
                    if (!r.isTextual()) throw new CommandParsingException(command,"invalid role name specified: "+r);
                    DocumentService.grantPermissionToRole(collection,docId,permission,r.asText());
               }
           }
        } else {
            if (users){
                for (JsonNode u: to){
                    if (!u.isTextual()) throw new CommandParsingException(command,"invalid user name specified: "+u);
                    DocumentService.revokePermissionToUser(collection, docId, permission, u.asText());
                }
            } else {
                for (JsonNode r:to){
                    if (!r.isTextual()) throw new CommandParsingException(command,"invalid role name specified: "+r);
                    DocumentService.revokePermissionToRole(collection, docId, permission, r.asText());
                }
            }
        }
    }
View Full Code Here

    private String getDocumentId(JsonNode command) throws CommandException{
        JsonNode params = command.get(ScriptCommand.PARAMS);
        JsonNode id = params.get("id");
        if (id==null||!id.isTextual()){
            throw new CommandParsingException(command,"missing document id");
        }
        String idString = id.asText();
        try{
            UUID.fromString(idString);
        } catch (IllegalArgumentException e){
            throw new CommandParsingException(command,"document id: "+id+" must be a valid uuid");
        }
        return idString;
    }
View Full Code Here

    public static final String ID = "mod";
    public static final String MAIN="main";

    public default void validate(JsonNode command,boolean hasParams) throws CommandParsingException {
        boolean isObj = command.isObject();
        if (!isObj)throw new CommandParsingException(command,"command is not an object");
        JsonNode res = command.get(RESOURCE);
        if (res==null||!res.isTextual())throw new CommandParsingException(command,"missing required resource");
        JsonNode name = command.get(NAME);
        if (name == null||!name.isTextual())throw new CommandParsingException(command,"missing required name");

        if (hasParams){
            JsonNode p = command.get(PARAMS);
            if (p==null||!(p.isObject())){
                throw new CommandParsingException(command,"missing required parameters");
            }
        }
    }
View Full Code Here

    private static JsonNode storageCommand(JsonNode command, JsonCallback callback) throws CommandException {
        JsonNode moduleId = command.get(ScriptCommand.ID);

        if (moduleId==null||!moduleId.isTextual()){
            throw new CommandParsingException(command,"error parsing module id");
        }
        String id = moduleId.asText();
        JsonNode params = command.get(ScriptCommand.PARAMS);
        if (params == null||!params.isObject()){
            throw new CommandParsingException(command,"error parsing params");
        }
        JsonNode actionNode = params.get("action");
        if (actionNode==null||!actionNode.isTextual()){
            throw new CommandParsingException(command,"error parsing action");
        }
        String action=actionNode.asText();
        ODocument result;
        if ("get".equals(action)){
            try {
                result = ScriptingService.getStore(id);
             } catch (ScriptException e) {
                //should never happen
                throw new CommandExecutionException(command,"script does not exists");
            }
        } else if ("set".equals(action)){
            JsonNode args = params.get("args");
            if (args==null){
                args = NullNode.getInstance();
            }
            if (!args.isObject()||!args.isNull()){
                throw new CommandExecutionException(command,"Stored values should be objects or null");
            }
            try {
                result = ScriptingService.resetStore(id,args);
            } catch (ScriptException e) {
                throw new CommandExecutionException(command,"script does not exists");
            }
        } else if ("swap".equals(action)){
            if (callback==null) throw new CommandExecutionException(command,"missing function callback");
            try {
                result = ScriptingService.swap(id,callback);
            } catch (ScriptException e) {
                throw new CommandExecutionException(command,e.getMessage(),e);
            }
        } else if ("trade".equals(action)){
            if (callback==null) throw new CommandExecutionException(command,"missing function callback");
            try {
                result = ScriptingService.trade(id,callback);
            } catch (ScriptException e) {
                throw new CommandExecutionException(command,e.getMessage(),e);
            }
        } else {
            throw new CommandParsingException(command,"unknown action: "+action);
        }
        if (result == null){
            return NullNode.getInstance();
        } else {
            String s = result.toJSON();
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.