Package org.sakaiproject.entitybus.exception

Examples of org.sakaiproject.entitybus.exception.EntityException


            // Check authorisation
//            AuthorizeManager.authorizeAction(context, item, Constants.READ);

            this.id = res.getID();
        } catch (SQLException ex) {
            throw new EntityException("Internal server error", "SQL error", 500);
//        } catch (AuthorizeException ex) {
//            throw new EntityException("Forbidden", "Forbidden", 403);
        } catch (NumberFormatException ex) {
            throw new EntityException("Bad request", "Could not parse input", 400);
        }
    }
View Full Code Here


            AuthorizeManager.authorizeAction(context, res, Constants.READ);

            this.id = res.getID();
            //context.complete();
        } catch (SQLException ex) {
            throw new EntityException("Internal server error", "SQL error", 500);
        } catch (AuthorizeException ex) {
            throw new EntityException("Forbidden", "Forbidden", 403);
        } catch (NumberFormatException ex) {
            throw new EntityException("Bad request", "Could not parse input", 400);
        }
    }
View Full Code Here

            EPerson eUser = EPerson.findByEmail(context, user);
            if ((eUser.canLogIn()) && (eUser.checkPassword(pass))) {
                context.setCurrentUser(eUser);
                loggedUser = eUser.getName();
            } else {
                throw new EntityException("Bad username or password", user, 403);
            }
        } catch (SQLException sql) {
//            System.out.println(sql.toString());
            sql.printStackTrace();
        } catch (AuthorizeException auth) {
            throw new EntityException("Unauthorised", user, 401);
        } catch (NullPointerException ne) {
            if (!(user.equals("") && pass.equals(""))) {
                throw new EntityException("Bad username or password", user, 403);
            }
        }

        this.collections = "true".equals(reqStor.getStoredValue("collections"));
        uparam.setCollections(this.collections);
        this.trim = "true".equals(reqStor.getStoredValue("trim"));
        uparam.setTrim(this.trim);
        this.parents = "true".equals(reqStor.getStoredValue("parents"));
        uparam.setParents(this.parents);
        this.children = "true".equals(reqStor.getStoredValue("children"));
        uparam.setChildren(this.children);
        this.groups = "true".equals(reqStor.getStoredValue("groups"));
        uparam.setGroups(this.groups);
        this.replies = "true".equals(reqStor.getStoredValue("replies"));
        uparam.setReplies(this.replies);

//        try {
//            action = reqStor.getStoredValue("action").toString();
//            uparam.setAction(action);
//        } catch (NullPointerException ex) {
//            action = "";
//        }

        try {
            query = reqStor.getStoredValue("query").toString();
            uparam.setQuery(query);
        } catch (NullPointerException ex) {
            query = "";
        }

        try {
            Object o = reqStor.getStoredValue("fields");
            if (o instanceof String) {
                fields = new String[]{o.toString()};
            } else if (o instanceof String[]) {
                fields = (String[]) o;
            } else if (o == null) {
                fields = null;
            }
            uparam.setFields(fields);
        } catch (NullPointerException ex) {
            fields = null;
        }

        try {
            status = reqStor.getStoredValue("status").toString();
            uparam.setStatus(status);
        } catch (NullPointerException ex) {
            status = "";
        }

        try {
            submitter = reqStor.getStoredValue("submitter").toString();
            uparam.setSubmitter(submitter);
        } catch (NullPointerException ex) {
            submitter = "";
        }

        try {
            reviewer = reqStor.getStoredValue("reviewer").toString();
            uparam.setReviewer(reviewer);
        } catch (NullPointerException ex) {
            reviewer = "";
        }

        try {
            String bundleStr = reqStor.getStoredValue("type").toString();
            uparam.setType(bundleStr.split(","));
        } catch (NullPointerException ex) {
            type = null;
        }

        try {
            _order = reqStor.getStoredValue("order").toString();
            uparam.setOrder(_order);
        } catch (NullPointerException ex) {
            _order = "";
        }

        try {
            _sort = reqStor.getStoredValue("sort").toString();
            uparam.setSort(_sort);
        } catch (NullPointerException ex) {
            _sort = "";


        } // both parameters are used according to requirements
        if (_order.length() > 0 && _sort.equals("")) {
            _sort = _order;
        }

        try {
            _start = Integer.parseInt(reqStor.getStoredValue("start").toString());
            uparam.setStart(_start);
        } catch (NullPointerException ex) {
            _start = 0;
        }

        try {
            _limit = Integer.parseInt(reqStor.getStoredValue("limit").toString());
            uparam.setLimit(_limit);
        } catch (NullPointerException ex) {
            _limit = 0;
        } // some checking for invalid values

        if (_limit < 0) {
            _limit = 0;
        }


        try {
            _sdate = reqStor.getStoredValue("startdate").toString();
        } catch (NullPointerException ex) {
            _sdate = null;
        }

        try {
            _edate = reqStor.getStoredValue("enddate").toString();
        } catch (NullPointerException ex) {
            _edate = null;
        }

        try {
            withdrawn = reqStor.getStoredValue("withdrawn").toString().equalsIgnoreCase("true");
        } catch (NullPointerException ex) {
            withdrawn = false;
        }
        // defining sort fields and values
        _sort = _sort.toLowerCase();
        String[] sort_arr = _sort.split(",");

        for (String option : sort_arr) {
            if (option.startsWith("submitter")) {
                sortOptions.add(UtilHelper.SORT_SUBMITTER);
            } else if (option.startsWith("email")) {
                sortOptions.add(UtilHelper.SORT_EMAIL);
            } else if (option.startsWith("firstname")) {
                sortOptions.add(UtilHelper.SORT_FIRSTNAME);
            } else if (option.startsWith("lastname")) {
                sortOptions.add(UtilHelper.SORT_LASTNAME);
            } else if (option.startsWith("fullname")) {
                sortOptions.add(UtilHelper.SORT_FULL_NAME);
            } else if (option.startsWith("language")) {
                sortOptions.add(UtilHelper.SORT_LANGUAGE);
            } else if (option.startsWith("lastmodified")) {
                sortOptions.add(UtilHelper.SORT_LASTMODIFIED);
            } else if (option.startsWith("countitems")) {
                sortOptions.add(UtilHelper.SORT_COUNT_ITEMS);
            } else if (option.startsWith("name")) {
                sortOptions.add(UtilHelper.SORT_NAME);
            } else {
                sortOptions.add(UtilHelper.SORT_ID);
            }
            if ((option.endsWith("_desc") || option.endsWith("_reverse"))) {
                int i = sortOptions.get(sortOptions.size() - 1);
                sortOptions.remove(sortOptions.size() - 1);
                i += 100;
                sortOptions.add(i);
            }
        }

        int intcommunity = 0;
        int intcollection = 0;

        // integer values used in some parts
        try {
            intcommunity = Integer.parseInt(reqStor.getStoredValue("community").toString());
        } catch (NullPointerException nul) {
        }

        try {
            _community = Community.find(context, intcommunity);
        } catch (SQLException sql) {
        }

        try {
            intcollection = Integer.parseInt(reqStor.getStoredValue("collection").toString());
        } catch (NullPointerException nul) {
        }

        try {
            _collection = Collection.find(context, intcollection);
        } catch (SQLException sql) {
        }

        if ((intcommunity > 0) && (intcollection > 0)) {
            throw new EntityException("Bad request", "Community and collection selected", 400);
        }

        if ((intcommunity > 0) && (_community == null)) {
            throw new EntityException("Bad request", "Unknown community", 400);
        }

        if ((intcollection > 0) && (_collection == null)) {
            throw new EntityException("Bad request", "Unknown collection", 400);
        }

        return uparam;
    }
View Full Code Here

        if (func2actionMapGET_rev.containsKey(action)) {
            Object result;
            String function = getMethod(action, func2actionMapGET_rev);
            if (function == null) {
                throw new EntityException("Bad request", "Method not supported - not defined", 400);
            }

            Context context = null;
            try {
                context = new Context();
                UserRequestParams uparams = refreshParams(context);

                Object CE = entityConstructor.newInstance();
                Method method = CE.getClass().getMethod(function, funcParamsGET.get(action));
                result = method.invoke(CE, ref, uparams, context);
            } catch (NoSuchMethodException ex) {
                throw new EntityException("Not found", "Method not supported ", 404);
            } catch (SQLException ex) {
                throw new EntityException("Internal server error", "SQL error", 500);
            } catch (InvocationTargetException ex) {
                if (ex.getCause() != null) {
                    throw (RuntimeException) ex.getCause();
                } else {
                    throw new EntityException("Internal server error", "Unknown error", 500);
                }
            } catch (Exception ex) {
                throw new EntityException("Internal server error", "Unknown error", 500);
            } finally {
                removeConn(context);
            }
            return result;
        } else {
            throw new EntityException("Bad request", "Method not supported " + action, 400);
        }
    }
View Full Code Here

        }

        if (func2actionMapDELETE_rev.containsKey(action)) {
            String function = getMethod(action, func2actionMapDELETE_rev);
            if (function == null) {
                throw new EntityException("Bad request", "Method not supported - not defined", 400);
            }
            Context context = null;
            try {
                context = new Context();
                refreshParams(context);

                Object CE = entityConstructor.newInstance();
                Method method = CE.getClass().getMethod(function, funcParamsDELETE.get(action));
                method.invoke(CE, ref, inputVar, context);
            } catch (NoSuchMethodException ex) {
                throw new EntityException("Not found", "Meethod not supported " + segments[3], 404);
            } catch (SQLException ex) {
                throw new EntityException("Internal server error", "SQL error", 500);
            } catch (InvocationTargetException ex) {
                if (ex.getCause() != null) {
                    throw (RuntimeException) ex.getCause();
                } else {
                    throw new EntityException("Internal server error", "Unknown error", 500);
                }
            } catch (Exception ex) {
                throw new EntityException("Internal server error", "Unknown error", 500);
            } finally {
                removeConn(context);
            }
        } else {
            throw new EntityException("Bad request", "Method not supported " + action, 400);
        }
    }
View Full Code Here

        }

        if (func2actionMapPUT_rev.containsKey(action)) {
            String function = getMethod(action, func2actionMapPUT_rev);
            if (function == null) {
                throw new EntityException("Bad request", "Method not supported - not defined", 400);
            }

            Context context = null;
            try {
                context = new Context();
                refreshParams(context);

                Object CE = entityConstructor.newInstance();
                Method method = CE.getClass().getMethod(function, funcParamsPUT.get(action));
                method.invoke(CE, ref, inputVar, context);
            } catch (NoSuchMethodException ex) {
                throw new EntityException("Not found", "Meethod not supported " + segments[3], 404);
            } catch (SQLException ex) {
                throw new EntityException("Internal server error", "SQL error", 500);
            } catch (InvocationTargetException ex) {
                if (ex.getCause() != null) {
                    throw (RuntimeException) ex.getCause();
                } else {
                    throw new EntityException("Internal server error", "Unknown error", 500);
                }
            } catch (Exception ex) {
                throw new EntityException("Internal server error", "Unknown error", 500);
            } finally {
                removeConn(context);
            }
        } else {
            throw new EntityException("Bad request", "Maethod not supported " + action, 400);
        }
    }
View Full Code Here

        }

        if (func2actionMapPOST_rev.containsKey(action)) {
            function = func2actionMapPOST_rev.get(action);
            if (function == null) {
                throw new EntityException("Bad request", "Method not supported - not defined", 400);
            }
            mandatory_params = inputParamsPOST.get(function);
            if (mandatory_params != null) {
                for (String param : mandatory_params) {
                    if (inputVar.get(param) == null) {
                        throw new EntityException("Bad request", "Incomplete request [mandatory param]", 400);
                    }
                }
            }

            Context context = null;
            try {
                context = new Context();
                refreshParams(context);

                Object CE = entityConstructor.newInstance();
                Method method = CE.getClass().getMethod(function, funcParamsPOST.get(action));
                if(entity instanceof Map){
                    result = (String) method.invoke(CE, ref, inputVar, context);
                }else {
                    result = (String) method.invoke(CE, ref, entity, context);
                }
            } catch (NoSuchMethodException ex) {
                throw new EntityException("Not found", "Method not supported ", 404);
            } catch (SQLException ex) {
                throw new EntityException("Internal server error", "SQL error", 500);
            } catch (InvocationTargetException ex) {
                if (ex.getCause() != null) {
                    throw (RuntimeException) ex.getCause();
                } else {
                    throw new EntityException("Internal server error", "Unknown error", 500);
                }
            } catch (Exception ex) {
                throw new EntityException("Internal server error", "Unknown error", 500);
            } finally {
                removeConn(context);
            }
            return result;
        } else {
            throw new EntityException("Bad request", "Method not supported " + action, 400);
        }
    }
View Full Code Here

        try {
            Integer.parseInt(ref.getId());
        } catch (NumberFormatException ex) {
            return super.getEntity(ref, ref.getId());
        }
        throw new EntityException("Not Acceptable", "The data is not available", 406);
    }
View Full Code Here

                entities.add(new SubmissionEntity(workspaceItem, context));
            }

            return entities;
        } catch (SQLException ex) {
            throw new EntityException("Internal server error", "SQL error", 500);
        } finally {
            removeConn(context);
        }
    }
View Full Code Here

            refreshParams(context);

            WorkflowItem comm = WorkflowItem.find(context, Integer.parseInt(id));
            return comm != null ? true : false;
        } catch (SQLException ex) {
            throw new EntityException("Internal server error", "SQL error", 500);
        } finally {
            removeConn(context);
        }
    }
View Full Code Here

TOP

Related Classes of org.sakaiproject.entitybus.exception.EntityException

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.