Example usage for org.springframework.http HttpStatus FORBIDDEN

List of usage examples for org.springframework.http HttpStatus FORBIDDEN

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus FORBIDDEN.

Prototype

HttpStatus FORBIDDEN

To view the source code for org.springframework.http HttpStatus FORBIDDEN.

Click Source Link

Document

403 Forbidden .

Usage

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}//from   ww w.ja v a  2 s .c  om
 */
@Override
@RequestMapping(value = "/getList", method = RequestMethod.POST)
public ResponseEntity<Response> getList(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        Map<String, String> queryParams = new HashMap<String, String>();

        if ("userid".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "userid");
        } else if ("school".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "school");
        } else if ("name".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "firstName");
        } else if ("lastName".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "lastName");
        } else {
            queryParams.put("order", request.getRequest_data().getOrder());
        }

        queryParams.put("offset", request.getRequest_data().getPage());
        queryParams.put("limit", request.getRequest_data().getLimit());

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_MENTOR_LIST, queryParams);

        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}//w  ww  .  j a  v a2s  .com
 */
@Override
@RequestMapping(value = "/search", method = RequestMethod.POST)
public ResponseEntity<Response> search(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        CommonUtil util = CommonUtil.getInstance();

        Map<String, String> map = util.getLimit(request.getRequest_data().getPageno(),
                request.getRequest_data().getLimit());

        Map<String, String> queryParams = new HashMap<String, String>();

        queryParams.put("searchKey", request.getRequest_data().getKeySearch());
        queryParams.put("from", map.get("from"));
        queryParams.put("to", map.get("to"));
        if ("userid".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "userid");
        } else if ("school".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "school");
        } else if ("name".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "firstName");
        } else if ("lastName".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            queryParams.put("order", "lastName");
        } else {
            queryParams.put("order", "points");
        }

        String[] fieldSearch = request.getRequest_data().getFieldSearch();
        if (fieldSearch.length == 0) {
            queryParams.put("filter", "");
        } else {
            StringBuffer strFilter = new StringBuffer("AND (");
            for (String str : fieldSearch) {
                if (strFilter.length() > 5) {
                    strFilter.append(" OR ");
                }
                strFilter.append(str + " LIKE '%" + queryParams.get("searchKey") + "%'");
            }
            strFilter.append(")");
            queryParams.put("filter", strFilter.toString());
        }
        String entityName = "";

        if ("online".equalsIgnoreCase(request.getRequest_data().getOrder())) {
            entityName = SibConstants.SqlMapper.SQL_MENTOR_LIST_FILTER_ONLINE;
        } else {
            entityName = SibConstants.SqlMapper.SQL_MENTOR_LIST_FILTER;
        }
        List<Object> readObject = dao.readObjects(entityName, queryParams);

        simpleResponse = new SimpleResponse("" + Boolean.TRUE, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}/* w w  w. j a v a 2s. c  o  m*/
 */
@Override
@RequestMapping(value = "/getInforTopMentor", method = RequestMethod.POST)
public ResponseEntity<Response> getInforTopMentor(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_USER_BY_ID,
                new Object[] { request.getRequest_data().getUid() });

        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    ResponseEntity<Response> entity = new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
    return entity;
}

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}//from ww w .  java 2 s .  c o  m
 */
@Override
@RequestMapping(value = "/getTopMentorsMostLike", method = RequestMethod.POST)
public ResponseEntity<Response> getTopMentorsMostLike(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }
        String limit = request.getRequest_data().getLimit();
        String offset = request.getRequest_data().getOffset();
        Object[] queryParams = {};
        List<Object> readObject = null;
        String whereClause = "";
        if (!StringUtil.isNull(limit)) {
            whereClause += " LIMIT " + limit;
        }
        if (!StringUtil.isNull(offset)) {
            whereClause += " OFFSET " + offset;
        }
        readObject = dao.readObjectsWhereClause(SibConstants.SqlMapper.SQL_GET_TOP_MENTORS_MOST_LIKE,
                whereClause, queryParams);

        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), readObject);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}//from   w  w w  . j  ava2s . co  m
 */
@Override
@RequestMapping(value = "/getStudentsSubcribe", method = RequestMethod.POST)
public ResponseEntity<Response> getStudentsSubcribe(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }
        String limit = request.getRequest_data().getLimit();
        String offset = request.getRequest_data().getOffset();
        String mentorId = request.getRequest_data().getMentorid();
        Object[] queryParams = { mentorId };

        String entityName = SibConstants.SqlMapper.SQL_GET_STUDENT_SUBCRIBE;

        List<Object> readObject = null;
        String whereClause = "";
        whereClause += " ORDER BY S.datetime DESC";
        if (!StringUtil.isNull(limit)) {
            whereClause += " LIMIT " + limit;
        }
        if (!StringUtil.isNull(offset)) {
            whereClause += " OFFSET " + offset;
        }

        readObject = dao.readObjectsWhereClause(entityName, whereClause, queryParams);

        new SimpleResponse("" + Boolean.TRUE, request.getRequest_data_type(), request.getRequest_data_method(),
                readObject);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.MentorServiceImpl.java

/**
 * {@inheritDoc}//from ww w  . j  ava 2 s. c o  m
 */
@Override
@RequestMapping(value = "/getTopMentorsByLikeRateSubcrible", method = RequestMethod.GET)
public ResponseEntity<Response> getTopMentorsByLikeRateSubcrible(@RequestParam final String subjectId,
        @RequestParam final String content, @RequestParam final String uid, @RequestParam final String type,
        @RequestParam final String limit, @RequestParam final String offset) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }
        List<Object> listParam = new ArrayList<Object>();
        String tempUserId = uid;
        String entityName = SibConstants.SqlMapper.SQL_GET_TOP_MENTORS_BY_LIKE_RATE_SUBS;
        if (StringUtil.isNull(tempUserId)) {
            tempUserId = "-1";
        }
        String whereClause = "";
        if (!"-1".equalsIgnoreCase(tempUserId)) {
            whereClause += ",(SELECT count(*) isSubs FROM Sib_Student_Subcribe where Subcribe ='Y' AND "
                    + " MentorId = U.userid AND StudentId =" + tempUserId + ") isSubs";
        } else {
            whereClause += ",('-1') as isSubs ";
        }
        whereClause += " FROM Sib_Users U LEFT JOIN Sib_School_College_Degree SCD ON U.school = SCD.sch_colle_degree_id LEFT JOIN Sib_Videos V ON U.userid = V.authorID "
                + "WHERE U.userType = 'M' GROUP BY U.userid, U.lastName, U.imageUrl, U.firstName)X ";
        if (!StringUtil.isNull(content)) {
            String keySearch = "%" + content + "%";
            listParam.add(keySearch);
            listParam.add(keySearch);
            whereClause += " WHERE ((firstName is null AND lastName is null AND SUBSTRING_INDEX(X.loginName,'@',1) LIKE (?)) OR concat(IFNULL(firstname,''),' ',IFNULL(lastName,'')) like (?))";

        }
        if (!StringUtil.isNull(subjectId)) {
            whereClause += " WHERE FIND_IN_SET(" + subjectId + ",X.defaultSubjectId)";
        }

        if (Parameters.LIKE.equalsIgnoreCase(type)) {
            whereClause += " ORDER BY X.numlike DESC";
        } else if (Parameters.RATE.equalsIgnoreCase(type)) {
            whereClause += " ORDER BY X.avgrate DESC";
        } else if (Parameters.SUBCRIBED.equalsIgnoreCase(type)) {
            whereClause += " WHERE X.isSubs > 0 ";
            whereClause += " ORDER BY X.numsub DESC";
        } else {
            whereClause += " ORDER BY X.numsub DESC";

        }

        if (!StringUtil.isNull(limit)) {
            listParam.add(Integer.parseInt(limit));
            whereClause += " LIMIT ?";
        }

        if (!StringUtil.isNull(offset)) {
            listParam.add(Integer.parseInt(offset));
            whereClause += " OFFSET ?";
        }

        List<Object> readObject = dao.readObjectsWhereClause(entityName, whereClause, listParam.toArray());

        // dao.readObjects(SibConstants.SqlMapper.SQL_GET_ALL_CATEGORY, new
        // Object[] {});
        String count = "0";

        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "mentor", "getTopMentorsByLikeRateSubcrible",
                readObject, count);
    } catch (DAOException e) {
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, "mentor", "getTopMentorsByLikeRateSubcrible",
                e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.NotificationEmailServiceImpl.java

/**
 * {@inheritDoc}/*from w ww .  ja  v  a2 s  . com*/
 */
@Override
@RequestMapping(value = "/contact", method = RequestMethod.POST)
public ResponseEntity<Response> contact(@RequestBody final RequestData request) {

    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("Name", request.getContact_data().getName());
        map.put("BODY", request.getContact_data().getMessage());
        map.put("PHONE", request.getContact_data().getPhone());

        logger.debug(map);
        NotifyByEmail notify = new NotifyByEmail();
        notify.setMailSender(mailSender);
        notify.setVelocityEngine(velocityEngine);
        notify.sendHmtlTemplateEmail(request.getContact_data().getEmail(),
                env.getProperty("spring.mail.username"), null, null, request.getContact_data().getSubject(),
                "MAIL_Notify_3.vm", map);
        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), "Thank you for contacting us. We will get back to you soon");
    } catch (Exception e) {
        logger.error(e);
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.NotificationEmailServiceImpl.java

/**
 * {@inheritDoc}/*from  w  w  w  .  j a v a  2 s  .c om*/
 */
@Override
@RequestMapping(value = "/forgotPassword", method = RequestMethod.POST)
public ResponseEntity<Response> forgotPassword(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse("" + Boolean.FALSE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }
        String email = request.getRequest_data().getEmail();

        // check email is exist
        List<Object> userType = dao.readObjects(SibConstants.SqlMapper.SQL_CHECK_USER_FORGOT_PASSWORD,
                new Object[] { email, email });
        if (!CollectionUtils.isEmpty(userType)) {
            String generateToken = CommonUtil.generateToken();

            // Update DB
            String add = "";
            boolean statusIn = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_USER_CODE,
                    new Object[] { generateToken, email });
            if (statusIn) {

                // Get address web configuration DB
                List<Object> readObjects = dao.readObjects(SibConstants.SqlMapper.SQL_GET_ADDRESS_WEB,
                        new Object[] { SibConstants.DOMAIN });
                for (Object object : readObjects) {
                    Map<String, String> mapObject = (HashMap<String, String>) object;
                    add = mapObject.get(Parameters.VALUE_OF);
                    break;
                }
            }

            HashMap<String, String> map = new HashMap<String, String>();
            String strUserType = ((HashMap<String, String>) userType.get(0)).get(Parameters.USER_TYPE);
            if (strUserType != null && !strUserType.equals(SibConstants.ROLE_TYPE.M.toString())) {
                map.put("FORGOT", add + "studentForgotPassword?token=" + generateToken);
            } else {
                map.put("FORGOT", add + "mentor/mentorForgotPassword?token=" + generateToken);
            }

            NotifyByEmail notify = new NotifyByEmail();
            notify.setMailSender(mailSender);
            notify.setVelocityEngine(velocityEngine);
            notify.sendHmtlTemplateEmail(null, email, null, null,
                    env.getProperty("app.subject-email.forgot-password"), "MAIL_Notify_4.vm", map);
            simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                    request.getRequest_data_method(), "You password was successfully changed");
        } else {
            // Error email is not exist
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                    request.getRequest_data_method(), email + " is not exist");
        }
    } catch (Exception e) {
        logger.error(e);
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.NotificationUserServiceImpl.java

/**
 * This API get notification of user who is not yet read content
 * //from  www .j av a  2s .  c  o m
 * {@inheritDoc}
 */
@Override
@RequestMapping(value = "/getNotificationNotReaded", method = RequestMethod.GET)
public ResponseEntity<Response> getNotificationNotReaded(@RequestParam final String uid) {

    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        String count = dao.getCount(SibConstants.SqlMapper.SQL_GET_NOTIFICATION_NOT_READED_COUNT,
                new Object[] { "N", uid });
        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "notification", "getNotificationNotReaded",
                "", count);
    } catch (DAOException e) {
        logger.error(e);
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, "notification", "getNotificationNotReaded",
                e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.NotificationUserServiceImpl.java

/**
 * {@inheritDoc}//from   w  w w  . j  a v  a2  s .com
 */
@Override
@RequestMapping(value = "/getNotificationReaded", method = RequestMethod.GET)
public ResponseEntity<Response> getNotificationReaded(@RequestParam final String uid) {

    SimpleResponse simpleResponse = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        String count = dao.getCount(SibConstants.SqlMapper.SQL_GET_NOTIFICATION_READED_COUNT,
                new Object[] { uid });
        simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "notification", "getNotificationReaded", "",
                count);
    } catch (DAOException e) {
        logger.error(e);
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, "notification", "getNotificationReaded",
                e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}