Package com.imaginea.mongodb.exceptions

Examples of com.imaginea.mongodb.exceptions.ApplicationException


            throw new DatabaseException(ErrorCodes.PASSWORD_IS_EMPTY, "Password is empty");
        }
        try {
            mongoInstance.getDB(dbName).addUser(username, password.toCharArray(), readOnly);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.USER_CREATION_EXCEPTION, e.getMessage());
        }
        return "User: " + username + " has been added to the DB: " + dbName;
    }
View Full Code Here


            throw new DatabaseException(ErrorCodes.USERNAME_IS_EMPTY, "Username is empty");
        }
        try {
            mongoInstance.getDB(dbName).removeUser(username);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.USER_DELETION_EXCEPTION, e.getMessage());
        }
        return "User: " + username + " deleted from the DB: " + dbName;
    }
View Full Code Here

        if (users.size() != 0) {
            for (DBObject user : users) {
                try {
                    mongoInstance.getDB(dbName).getCollection("system.users").remove(user);
                } catch (MongoException e) {
                    throw new ApplicationException(ErrorCodes.USER_DELETION_EXCEPTION, e.getMessage());
                }
            }
            return "All users are dropped from the DB: " + dbName;
        } else {
            return "The DB:" + dbName + "does not have any users";
View Full Code Here

            throw new DatabaseException(ErrorCodes.KEYS_EMPTY, "Index keys are Empty");
        }
        try {
            mongoInstance.getDB(dbName).getCollection(collectionName).ensureIndex(keys);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.INDEX_ADDITION_EXCEPTION, e.getMessage());
        }
        return "Index successfully added to the collection: " + dbName + ":" + collectionName;
    }
View Full Code Here

        Set<String> collectionNames = mongoInstance.getDB(dbName).getCollectionNames();
        for (String collection : collectionNames) {
            try {
                mongoInstance.getDB(dbName).getCollection(collection).dropIndexes();
            } catch (MongoException e) {
                throw new ApplicationException(ErrorCodes.INDEX_REMOVE_EXCEPTION, e.getMessage());
            }
        }
        return "All indexes are dropped from DB: " + dbName;
    }
View Full Code Here

            throw new DatabaseException(ErrorCodes.INDEX_EMPTY, "Index name is Empty");
        }
        try {
            mongoInstance.getDB(dbName).getCollection(collectionName).dropIndexes(indexName);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.INDEX_REMOVE_EXCEPTION, e.getMessage());
        }

        return "Index: " + indexName + " dropped from the collection: " + dbName + ":" + collectionName;
    }
View Full Code Here

        String response = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() {
            public Object execute() throws Exception {
                GridFSService gridFSService = new GridFSServiceImpl(connectionId);
                String result = null;
                if ("".equals(_id)) {
                    ApplicationException e = new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "File Data Missing in Request Body");
                    result = formErrorResponse(logger, e);
                } else {
                    result = gridFSService.deleteFile(dbName, bucketName, _id);
                }
                return result;
View Full Code Here

    private Mongo getMongoAndAuthenticate(ConnectionDetails connectionDetails) throws ApplicationException {
        Mongo mongo;
        try {
            mongo = new Mongo(connectionDetails.getHostIp(), connectionDetails.getHostPort());
        } catch (UnknownHostException e) {
            throw new ApplicationException(ErrorCodes.HOST_UNKNOWN, "Could not connect to mongo instance with the given host and port");
        }
        String dbNames = connectionDetails.getDbNames();
        String[] dbNamesList = dbNames.split(",");
        String username = connectionDetails.getUsername();
        String password = connectionDetails.getPassword();
        for (String dbName : dbNamesList) {
            dbName = dbName.trim();
            DB db = mongo.getDB(dbName);
            boolean loginStatus = false;
            try {
                // Hack. Checking server connectivity status by fetching collection names on selected db
                db.getCollectionNames();//this line will throw exception in two cases.1)On Invalid mongo host Address,2)Invalid authorization to fetch collection names
                loginStatus = true;
            } catch (MongoException me) {
                loginStatus = db.authenticate(username, password.toCharArray());//login using given username and password.This line will throw exception if invalid mongo host address
            }
            if (loginStatus) {
                connectionDetails.addToAuthenticatedDbNames(dbName);
            }
        }
        if (connectionDetails.getAuthenticatedDbNames().isEmpty()) {
            throw new ApplicationException(("".equals(username) && "".equals(password)) ?
                    ErrorCodes.NEED_AUTHORISATION : ErrorCodes.INVALID_USERNAME, "Invalid UserName or Password");
        }
        return mongo;
    }
View Full Code Here

    @Override
    public MongoConnectionDetails getMongoConnectionDetails(String connectionId) throws ApplicationException {
        String[] split = connectionId.split("_");
        if (split.length != 2) {
            throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
        }
        String connectionDetailsHashCode = String.valueOf(split[1]);
        Collection<MongoConnectionDetails> mongoConnectionDetailsList = allConnectionDetails.get(connectionDetailsHashCode);
        if (mongoConnectionDetailsList == null) {
            throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
        }
        for (MongoConnectionDetails mongoConnectionDetails : mongoConnectionDetailsList) {
            if (connectionId.equals(mongoConnectionDetails.getConnectionId())) {
                return mongoConnectionDetails;
            }
        }
        throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
    }
View Full Code Here

    @Override
    public Mongo getMongoInstance(String connectionId) throws ApplicationException {
        String[] split = connectionId.split("_");
        if (split.length != 2) {
            throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
        }
        String connectionDetailsHashCode = String.valueOf(split[1]);
        Collection<MongoConnectionDetails> mongoConnectionDetailsList = allConnectionDetails.get(connectionDetailsHashCode);
        if (mongoConnectionDetailsList == null) {
            throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
        }
        for (MongoConnectionDetails mongoConnectionDetails : mongoConnectionDetailsList) {
            if (connectionId.equals(mongoConnectionDetails.getConnectionId())) {
                return mongoConnectionDetails.getMongo();
            }
        }
        throw new ApplicationException(ErrorCodes.INVALID_CONNECTION, "Invalid Connection");
    }
View Full Code Here

TOP

Related Classes of com.imaginea.mongodb.exceptions.ApplicationException

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.