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.ArticleServiceImpl.java

/**
 * {@inheritDoc}//from   www.  j  av a 2s. co m
 * 
 */
@Override
@RequestMapping(value = "/getArticleByUserPN", method = RequestMethod.POST)
public ResponseEntity<Response> getArticleByUserPN(@RequestBody final RequestData request) {

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

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

        Object[] queryParams = { request.getRequest_data_article().getAuthorId(), map.get(Parameters.FROM),
                map.get(Parameters.TO) };

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

        String count = dao.getCount(SibConstants.SqlMapper.SQL_GET_ARTICLE_BY_USER_PN_COUNT, queryParams);

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

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

/**
 * {@inheritDoc}/*from  w ww.  j  a v a2s  .c  o  m*/
 */
@Override
@RequestMapping(value = "/rateArticleAdmission", method = RequestMethod.POST)
public ResponseEntity<Response> rateArticleAdmission(@RequestBody final RequestData request) {
    String entityName = null;
    boolean status = false;
    SimpleResponse response = null;
    TransactionStatus statusDao = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        String arid = request.getRequest_data_article().getArId();
        String uid = request.getRequest_data_article().getUid();
        String rate = request.getRequest_data_article().getRating();

        // Return if vid or uid
        if (StringUtil.isNull(arid) || StringUtil.isNull(uid) || StringUtil.isNull(rate)) {
            response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                    request.getRequest_data_method(), "Parameter cannot null or Emppty.");
            return new ResponseEntity<Response>(response, HttpStatus.OK);
        }
        TransactionDefinition def = new DefaultTransactionDefinition();
        statusDao = transactionManager.getTransaction(def);
        // Check user rated yet
        Object[] queryParams = new Object[] { uid, arid };
        List<Object> videoRated = dao
                .readObjects(SibConstants.SqlMapper.SQL_SIB_GET_USER_RATE_ARTICAL_ADMISSION, queryParams);

        boolean isRated = videoRated.size() > 0 ? true : false;

        if (!isRated) {
            // New rating
            entityName = SibConstants.SqlMapper.SQL_SIB_RATE_ARTICAL_ADMISSION;
            queryParams = new Object[] { arid, uid, rate };
            status = dao.insertUpdateObject(entityName, queryParams);

            Object[] queryUpdateRate = { rate, arid };
            status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_AVG_RATE_ARTICAL_ADMISSION,
                    queryUpdateRate);
            // Activity Log
            activiLogService.insertActivityLog(new ActivityLogData(SibConstants.TYPE_ATICAL, "C",
                    "You rated a article", uid, String.valueOf(arid)));
        } else {
            Map<String, Integer> object = (Map<String, Integer>) videoRated.get(0);
            int rateOld = object.get(Parameters.RATING);
            int rateNew = Integer.parseInt(rate);
            if (rateNew != rateOld) {
                // Update rating
                queryParams = new Object[] { rate, arid, uid };
                entityName = SibConstants.SqlMapper.SQL_SIB_RATE_UPDATE_ARTICAL_ADMISSION;
                status = dao.insertUpdateObject(entityName, queryParams);

                Object[] queryUpdateRate = { rateNew - rateOld, arid };
                status = dao.insertUpdateObject(
                        SibConstants.SqlMapper.SQL_UPDATE_AVG_RATE_ARTICAL_ADMISSION_AGAIN, queryUpdateRate);
                // Activity Log
                activiLogService.insertActivityLog(new ActivityLogData(SibConstants.TYPE_ATICAL, "U",
                        "You updated the rating a artical", uid, String.valueOf(arid)));
            }
        }

        transactionManager.commit(statusDao);
        logger.info("Rating article successful " + new Date());

        response = new SimpleResponse("" + status, request.getRequest_data_type(),
                request.getRequest_data_method(), arid);
    } catch (Exception e) {
        if (statusDao != null) {
            transactionManager.rollback(statusDao);
        }
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

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

/**
 * {@inheritDoc}/*from  ww  w . ja v a 2  s  .co  m*/
 */
@Override
@RequestMapping(value = "/getUserRateArticle/{uid}/{arId}", method = RequestMethod.GET)
public ResponseEntity<Response> getUserRateArticle(@PathVariable(value = "uid") final long uid,
        @PathVariable(value = "arId") final long arId) {
    SimpleResponse response = null;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            response = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(response, HttpStatus.FORBIDDEN);
        }

        // Return if vid or uid
        if (StringUtil.isNull(arId) || StringUtil.isNull(uid)) {
            response = new SimpleResponse(SibConstants.FAILURE, "article", "getUserRateArticle",
                    "Parameter cannot null or Emppty.");
        } else {

            List<Object> readObjects = dao.readObjects(
                    SibConstants.SqlMapper.SQL_SIB_GET_USER_RATE_ARTICAL_ADMISSION, new Object[] { uid, arId });
            response = new SimpleResponse(SibConstants.SUCCESS, "article", "getUserRateArticle", readObjects);
        }
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, "article", "getUserRateArticle", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

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

/**
 * {@inheritDoc}//from   w w  w.  ja va2 s . c om
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/getNestedComments", method = RequestMethod.POST)
public ResponseEntity<Response> getNestedComments(@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);
        }

        Object[] queryParams = { request.getRequest_data().getCid() };
        List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_GET_NESTED_COMMENTS,
                queryParams);

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

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

/**
 * {@inheritDoc}//from w w w.  j  a  v  a  2  s . c om
 */
@Override
@RequestMapping(value = "/addNestedComment", method = RequestMethod.POST)
public ResponseEntity<Response> addNestedComment(@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);
        }
        Object[] queryParams = { request.getRequest_data().getCid(), request.getRequest_data().getAuthor(),
                request.getRequest_data().getAuthorID(), request.getRequest_data().getContent(),
                request.getRequest_data().getImage() };

        boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_INSERT_NESTED_COMMENT,
                queryParams);

        List<Object> readObject = null;
        if (status) {
            Object[] queryParams1 = { request.getRequest_data().getAuthorID(),
                    request.getRequest_data().getContent() };
            readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_GET_NESTED_CID, queryParams1);
            int childId = Integer.valueOf(((Map) readObject.get(0)).get("cid").toString());
            Object[] queryParams2 = { request.getRequest_data().getCid(), Integer.valueOf(childId).toString() };
            dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_INSERT_NESTED_TABLE, queryParams2);
        }

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

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

@Override
@RequestMapping(value = "/addComment", method = RequestMethod.POST)
public ResponseEntity<Response> addComment(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    String content = request.getRequest_data().getContent();
    if (content != null && content.length() > 1024) {
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, MSG_LONGER_THAN_1024);
    } else {/*from  w w  w  .j a v  a2  s . com*/
        TransactionStatus statusDB = null;
        try {

            if (!AuthenticationFilter.isAuthed(context)) {
                simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
                return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
            }
            TransactionDefinition def = new DefaultTransactionDefinition();
            statusDB = transactionManager.getTransaction(def);

            content = CommonUtil.filterWord(content, cachedDao.getAllWordFilter());

            // Get request data
            String userName = request.getRequest_data().getAuthor();
            String authorId = request.getRequest_data().getAuthorID();
            String userId = request.getRequest_data().getUid();
            boolean status = true, statusUpdateCmtVideo = false;
            int cid = 0;
            boolean isCeateNofi = true;
            String userIdTemp = userId;
            if (StringUtil.isNull(userId)) {
                userIdTemp = authorId;
                isCeateNofi = false;
            }

            Object[] queryParams = { userName, userIdTemp, content };
            long idComent = dao.insertObject(SibConstants.SqlMapper.SQL_SIB_ADD_COMMENT, queryParams);
            if (idComent > 0) {
                // Insert comment video table
                String vid = request.getRequest_data().getVid();
                Object[] queryParamsIns2 = { idComent, vid };
                status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_INSERT_VIDEO_COMMENT,
                        queryParamsIns2);
                if (status) {
                    statusUpdateCmtVideo = dao.insertUpdateObject(
                            SibConstants.SqlMapper.SQL_VIDEO_COMMENT_UPDATE,
                            new Object[] { request.getRequest_data().getVid() });
                }
                status = status && statusUpdateCmtVideo ? true : false;

                // Insert notification table
                if (isCeateNofi) {
                    String subjectId = request.getRequest_data().getSubjectId();
                    String contentNofi = content;
                    if (!StringUtil.isNull(content) && content.length() > Parameters.MAX_LENGTH_TO_NOFICATION) {
                        contentNofi = content.substring(0, Parameters.MAX_LENGTH_TO_NOFICATION);
                    }
                    Object[] queryParamsIns3 = { userId, authorId, SibConstants.NOTIFICATION_TYPE_COMMENT_VIDEO,
                            SibConstants.NOTIFICATION_TITLE_COMMENT_VIDEO, contentNofi, subjectId, vid };
                    status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_CREATE_NOTIFICATION,
                            queryParamsIns3);

                    // send message fire base
                    String toTokenId = userservice.getTokenUser(authorId);
                    if (!StringUtil.isNull(toTokenId)) {

                        fireBaseNotification.sendMessage(toTokenId,
                                SibConstants.NOTIFICATION_TITLE_COMMENT_VIDEO, SibConstants.TYPE_VIDEO, vid,
                                contentNofi, SibConstants.NOTIFICATION_ICON,
                                SibConstants.NOTIFICATION_PRIPORITY_HIGH);
                    }
                    // log activity
                    activityLogSerservice.insertActivityLog(new ActivityLogData(SibConstants.TYPE_VIDEO, "C",
                            "Someone commented your video", userId, vid));
                }
            }

            transactionManager.commit(statusDB);

            simpleResponse = new SimpleResponse("" + status, request.getRequest_data_type(),
                    request.getRequest_data_method(), cid);
        } catch (Exception e) {
            if (statusDB != null) {
                transactionManager.rollback(statusDB);
            }
            e.printStackTrace();
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, e.getMessage());
        }
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}

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

@Override
@RequestMapping(value = "/addCommentMobile", method = RequestMethod.POST)
public ResponseEntity<Response> addCommentMobile(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {/* w  w  w . ja  v  a 2s .  c  om*/
        String content = request.getRequest_data().getContent();
        if (content != null && content.length() > 1024) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, MSG_LONGER_THAN_1024);
        } else {
            if (!AuthenticationFilter.isAuthed(context)) {
                simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
                return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
            }

            content = CommonUtil.filterWord(content, cachedDao.getAllWordFilter());
            Object[] queryParams = { request.getRequest_data().getAuthorID(), content,
                    request.getRequest_data().getImage() };

            boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_ADD_COMMENT, queryParams);
            int cid = 0;
            if (status) {
                Object[] queryParams1 = { content, request.getRequest_data().getAuthorID() };

                List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_LAST_INSERTED_COMMENT,
                        queryParams1);
                Map lastInsertComment = (Map) readObject.get(0);
                Object[] queryParamsIns = { lastInsertComment.get(Parameters.CID).toString(),
                        request.getRequest_data().getVid() };
                boolean flag = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_INSERT_VIDEO_COMMENT,
                        queryParamsIns);

                if (flag) {
                    Object[] queryParamsUpdate = { request.getRequest_data().getVid() };
                    dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_UPDATE_VIDEO_COMMENT,
                            queryParamsUpdate);
                }
            }

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

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

/**
 * {@inheritDoc}/*from w w w  .  j a  v  a2 s.  c  om*/
 */
@Override
@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResponseEntity<Response> update(@RequestBody final RequestData request) {
    SimpleResponse reponse = null;
    try {
        String content = request.getRequest_data().getContent();
        if (content != null && content.length() > 1024) {
            reponse = new SimpleResponse(SibConstants.FAILURE, MSG_LONGER_THAN_1024);
        } else {
            if (!AuthenticationFilter.isAuthed(context)) {
                SimpleResponse simpleResponse = new SimpleResponse(SibConstants.FAILURE,
                        "Authentication required.");
                ResponseEntity<Response> entity = new ResponseEntity<Response>(simpleResponse,
                        HttpStatus.FORBIDDEN);
                return entity;
            }
            content = CommonUtil.filterWord(content, cachedDao.getAllWordFilter());
            Object[] queryParams = { request.getRequest_data().getCid(), content };
            boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_EDIT_COMMENT, queryParams);
            reponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                    request.getRequest_data_method(), status);
        }
    } catch (DAOException e) {
        e.printStackTrace();
        reponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), e.getMessage());
    }
    ResponseEntity<Response> entity = new ResponseEntity<Response>(reponse, HttpStatus.OK);
    return entity;
}

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

/**
 * {@inheritDoc}/*from   w w  w .ja v a2s . c  o  m*/
 */
@Override
@RequestMapping(value = "/remove", method = RequestMethod.POST)
public ResponseEntity<Response> remove(@RequestBody final RequestData request) {

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

    Object[] queryParams = { request.getRequest_data().getCid() };

    TransactionDefinition def = new DefaultTransactionDefinition();
    TransactionStatus status = transactionManager.getTransaction(def);
    SimpleResponse reponse = null;
    try {
        dao.insertUpdateObject(SibConstants.SqlMapperBROT163.SQL_DELETE_COMMENT_VIDEO, queryParams);
        dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_REMOVE_COMMENT, queryParams);
        transactionManager.commit(status);
        reponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(),
                request.getRequest_data_method(), "Success");
    } catch (Exception e) {
        e.printStackTrace();
        transactionManager.rollback(status);
        reponse = new SimpleResponse(SibConstants.FAILURE, request.getRequest_data_type(),
                request.getRequest_data_method(), "Failed");
    }
    ResponseEntity<Response> entity = new ResponseEntity<Response>(reponse, HttpStatus.OK);
    return entity;
}

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

/**
 * {@inheritDoc}//from w w w  .j a v  a  2  s. co m
 */
@Override
@RequestMapping(value = "/addCommentArticle", method = RequestMethod.POST)
public ResponseEntity<Response> addCommentArticle(@RequestBody final RequestData request) {
    SimpleResponse simpleResponse = null;
    try {
        String content = request.getRequest_data().getContent();
        if (content != null && content.length() > 1024) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, MSG_LONGER_THAN_1024);

        } else {
            if (!AuthenticationFilter.isAuthed(context)) {
                simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
                return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
            }
            String strContent = CommonUtil.filterWord(content, cachedDao.getAllWordFilter());

            Object[] queryParams = { request.getRequest_data_article().getAuthorId(), strContent,
                    request.getRequest_data_article().getArId() };

            boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_ADD_COMMENT, queryParams);
            int cid = 0;
            if (status) {
                List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SIB_LAST_INSERTED_COMMENT,
                        queryParams);
                cid = Integer.valueOf(((Map) readObject.get(0)).get(Parameters.CID).toString());
                Object[] queryParamsIns = { ((Map) readObject.get(0)).get(Parameters.CID).toString(),
                        request.getRequest_data_article().getArId() };
                boolean flag = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_INSERT_ARTICLE_COMMENT,
                        queryParamsIns);

                readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_INFO_ARTICLE, queryParamsIns);
                Object[] queryParamsIns1 = { ((Map) readObject.get(0)).get(Parameters.AUTHOR_ID).toString(),
                        request.getRequest_data_article().getAuthorId(), "commentArticle",
                        "New comment of article",
                        "commented a article: " + ((Map) readObject.get(0)).get("title").toString() };
                if (!((Map) readObject.get(0)).get("authorId").toString()
                        .equalsIgnoreCase(request.getRequest_data_article().getAuthorId())) {
                    dao.insertUpdateObject(SibConstants.SqlMapper.SQL_CREATE_NOTIFICATION, queryParamsIns1);
                }

                if (flag) {
                    Object[] queryParamsUpdate = { request.getRequest_data_article().getArId() };
                    dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_UPDATE_ARTICLE_COMMENT,
                            queryParamsUpdate);
                }
            }

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