List of usage examples for org.springframework.http HttpStatus FORBIDDEN
HttpStatus FORBIDDEN
To view the source code for org.springframework.http HttpStatus FORBIDDEN.
Click Source Link
From source file:com.siblinks.ws.service.impl.NotificationUserServiceImpl.java
/** * {@inheritDoc}//from w w w . j a v a 2 s.com */ @Override @RequestMapping(value = "/updateStatusNotification", method = RequestMethod.POST) public ResponseEntity<Response> updateStatusNotification(@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); } boolean readObject = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_STATUS_NOTIFICATION, new Object[] { request.getRequest_data().getNid(), request.getRequest_data().getStatus() }); simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(), request.getRequest_data_method(), readObject); } catch (DAOException e) { logger.error(e); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "notification", "updateStatusNotification", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.NotificationUserServiceImpl.java
/** * {@inheritDoc}/* w w w. java 2 s . co m*/ */ @Override @RequestMapping(value = "/getAllNotification", method = RequestMethod.GET) public ResponseEntity<Response> getAllNotification(@RequestParam final String uid, @RequestParam final String pageno, @RequestParam final String limit) { 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(pageno, limit); Object[] queryParams = { uid, Integer.parseInt(map.get(Parameters.FROM)), Integer.parseInt(map.get(Parameters.TO)) }; List<Object> readObject = dao.readObjects(SibConstants.SqlMapper.SQL_GET_ALL_NOTIFICATION, queryParams); if (readObject.size() > 0) { String count = dao.getCount(SibConstants.SqlMapper.SQL_GET_ALL_NOTIFICATION_COUNT, new Object[] { uid }); simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "notification", "getAllNotification", readObject, count); } else { simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "notification", "getAllNotification", readObject, "0"); } } catch (Exception e) { logger.error(e); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "notification", "getAllNotification", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.NotificationUserServiceImpl.java
/** * {@inheritDoc}// www . j a v a 2s . c o m */ @Override @RequestMapping(value = "/updateStatusAllNotification", method = RequestMethod.POST) public ResponseEntity<Response> updateStatusAllNotification(@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().getUid() }; boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_STATUS_ALL_NOTIFICATION, queryParams); simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(), request.getRequest_data_method(), status); } catch (Exception 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.PostServiceImpl.java
/** * {@inheritDoc}// w ww . j av a 2 s . c o m */ @Override @RequestMapping(value = "/createPost", method = RequestMethod.POST) public ResponseEntity<Response> createPost(@RequestParam("content") final String content, @RequestParam("userId") final String userId, @RequestParam("file") final MultipartFile[] files, @RequestParam("subjectId") final String subjectId) { SimpleResponse simpleResponse = null; MultipartFile file = null; try { if (!AuthenticationFilter.isAuthed(context)) { // Return authentication simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } long id = 0l; String error = validateFileImage(files); if (StringUtil.isNull(content)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", "Content is not empty."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } else if (content.length() > 4000) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", "Content must be less than 4000 characters."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } String strContent = CommonUtil.filterWord(content, cachedDao.getAllWordFilter()); if (!StringUtil.isNull(error)) { // Return is not exist image simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } // Get Image files String filePath = ""; String pathget = environment.getProperty("directoryGetImageQuestion"); if (files != null && files.length > 0) { for (int i = 0; i < files.length; i++) { file = files[i]; filePath += pathget + uploadFile(file, "directoryImageQuestion") + ".png"; if (i < files.length - 1) { filePath += ";"; } } } // Insert question id = dao.insertObject(SibConstants.SqlMapper.SQL_CREATE_QUESTION, new Object[] { userId, subjectId, strContent, filePath }); simpleResponse = new SimpleResponse("" + (id > 0), "post", "createPost", id); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e.getCause()); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}/* www. j ava 2 s . c o m*/ */ @Override @RequestMapping(value = "/createAnswer", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Response> createAnswer(@RequestParam("pid") final String pid, @RequestParam("content") final String content, @RequestParam("studentId") final String studentId, @RequestParam("mentorId") final String mentorId, @RequestParam("file") final MultipartFile[] files, @RequestParam("subjectId") final String subjectId) { SimpleResponse simpleResponse = null; TransactionStatus statusBD = null; try { if (!AuthenticationFilter.isAuthed(context)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } boolean status = false; long id = 0l; String error = validateFileImage(files); if (StringUtil.isNull(content)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createAnswer", "Content is not empty."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } else if (content.length() > 4000) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createAnswer", "Content must be less than 4000 characters."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } if (!StringUtil.isNull(error)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createAnswer", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } TransactionDefinition def = new DefaultTransactionDefinition(); statusBD = transactionManager.getTransaction(def); MultipartFile file = null; String filePath = ""; String pathget = environment.getProperty("directoryGetImageAnswer"); if (files != null && files.length > 0) { for (int i = 0; i < files.length; i++) { file = files[i]; filePath += pathget + uploadFile(file, "directoryImageAnswer") + ".png"; if (i < files.length - 1) { filePath += ";"; } } } String strContent = CommonUtil.filterWord(content, cachedDao.getAllWordFilter()); Object[] queryParamsAnswer = { pid, mentorId, strContent, filePath }; String strContentNofi = strContent; if (!StringUtil.isNull(strContent) && strContent.length() > Parameters.MAX_LENGTH_TO_NOFICATION) { strContentNofi = strContent.substring(0, Parameters.MAX_LENGTH_TO_NOFICATION); } id = dao.insertObject(SibConstants.SqlMapper.SQL_CREATE_ANSWER, queryParamsAnswer); Object[] queryParams = { mentorId, studentId, SibConstants.NOTIFICATION_TYPE_ANSWER_QUESTION, SibConstants.NOTIFICATION_TITLE_ANSWER_QUESTION, strContentNofi, subjectId, pid }; dao.insertUpdateObject(SibConstants.SqlMapper.SQL_UPDATE_NUMREPLIES_QUESTION, new Object[] { pid }); status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_CREATE_NOTIFICATION, queryParams); // Push message notification String toTokenId = userservice.getTokenUser(studentId); if (!StringUtil.isNull(toTokenId)) { fireBaseNotification.sendMessage(toTokenId, SibConstants.NOTIFICATION_TITLE_ANSWER_QUESTION, SibConstants.TYPE_QUENSION_ANSWER, pid, strContent, SibConstants.NOTIFICATION_ICON, SibConstants.NOTIFICATION_PRIPORITY_HIGH); } if (id > 0 && status == true) { status = true; } activityLogSerservice.insertActivityLog(new ActivityLogData(SibConstants.TYPE_QUENSION_ANSWER, "C", "You answered a question", mentorId, pid)); transactionManager.commit(statusBD); logger.info("Insert Menu success " + new Date()); simpleResponse = new SimpleResponse("" + status, "POST", "createAnswer", status); } catch (Exception e) { e.printStackTrace(); if (statusBD != null) { transactionManager.rollback(statusBD); } logger.info("Create answer Error:" + e.getMessage(), e.getCause()); simpleResponse = new SimpleResponse(e.getMessage(), "POST", "createAnswer", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}/*from w w w . j a va 2 s.co m*/ */ @Override @RequestMapping(value = "/editPost", method = RequestMethod.POST) public ResponseEntity<Response> editPost(@RequestParam("content") final String content, @RequestParam("qid") final String qid, @RequestParam("file") final MultipartFile[] files, @RequestParam("subjectId") final String subjectId, @RequestParam("oldImagePathEdited") final String oldImagePathEdited, @RequestParam("oldImagePath") final String oldImagePath) { SimpleResponse simpleResponse = null; try { if (!AuthenticationFilter.isAuthed(context)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } if (StringUtil.isNull(content)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", "Content is not empty."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } else if (content.length() > 4000) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "createPost", "Content must be less than 4000 characters."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } String error = ""; if (files != null && files.length > 0) { error = validateFileImage(files); } if (!StringUtil.isNull(error)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editPost", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } String filePathEdited = mergeImage(oldImagePath, oldImagePathEdited); String maxLength = environment.getProperty("file.upload.image.length"); String pathget = environment.getProperty("directoryGetImageQuestion"); // Check total file length int totalLength = 0; for (String pathImage : filePathEdited.split(";")) { if (!StringUtil.isNull(pathImage)) { String oldPathFile = environment.getProperty("directoryImageQuestion") + pathImage.substring(pathImage.lastIndexOf("/")); totalLength += new File(oldPathFile).length(); } } if (files != null && files.length > 0) { if ((files.length + filePathEdited.split(";").length) > Integer.parseInt(maxLength)) { error = "You only upload " + maxLength + " image"; simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editPost", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } for (int i = 0; i < files.length; i++) { totalLength += files[i].getSize(); } } int maxSize = Integer.parseInt(environment.getProperty("file.upload.image.size")); if (totalLength > maxSize) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editPost", "File size must be less than 5MB."); } else { // upload file String filePath = ""; for (int i = 0; i < files.length; i++) { filePath += pathget + uploadFile(files[i], "directoryImageQuestion") + ".png"; if (i < files.length - 1) { filePath += ";"; } } // remove file when edit question removeFileEdit(oldImagePathEdited, "directoryImageQuestion"); String strContent = CommonUtil.filterWord(content, cachedDao.getAllWordFilter()); dao.insertUpdateObject(SibConstants.SqlMapper.SQL_POST_EDIT, new Object[] { fixFilePath(filePathEdited + filePath), strContent, subjectId, qid }); // TODO can add user edit // activityLogSerservice.insertActivityLog(new // ActivityLogData(SibConstants.TYPE_QUENSION_ANSWER, "C", // "You answered a question", studentId, qid)); simpleResponse = new SimpleResponse(SibConstants.SUCCESS, "post", "editPost", ""); } } catch (Exception e) { e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "editPost", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}//from ww w . j a v a 2s. c om */ @Override @RequestMapping(value = "/removePost", method = RequestMethod.POST) public ResponseEntity<Response> removePost(@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().getPid() }; boolean status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_POST, queryParams); if (status) { dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_ANSWER_BY_POST, queryParams); } simpleResponse = new SimpleResponse("" + status, request.getRequest_data_type(), request.getRequest_data_method(), status); } catch (Exception e) { e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "removePost", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}//from ww w. java 2 s .c om */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @RequestMapping(value = "/searchPosts", method = RequestMethod.POST) public ResponseEntity<Response> searchPosts(@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>(); String value = request.getRequest_data().getContent().trim(); queryParams.put("content", value); queryParams.put("content1", value); List<List<Object>> resParentObject = new ArrayList<List<Object>>(); List<Object> readObject = null; readObject = dao.readObjects(SibConstants.SqlMapper.SQL_SEARCH_POST, queryParams); if (readObject != null) { for (Object object : readObject) { List<Object> resChildObject = new ArrayList<Object>(); Map<String, Object> map = (Map) object; String pid = (String) map.get("pid"); queryParams.put("pid", pid); List<Object> readObject1 = dao.readObjects(SibConstants.SqlMapper.SQL_POST_GET_TAGS, queryParams); Map<String, Object> tags = null; try { if (readObject1 != null) { for (Object obj : readObject1) { tags = (Map) obj; Iterator<Entry<String, Object>> it = tags.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = it.next(); if (pairs.getKey().equals("pid")) { it.remove(); } } } } } catch (Exception e) { logger.error(e); } Map<String, Object> mymap = new HashMap<String, Object>(); mymap.put("tags", readObject1); resChildObject.add(map); resChildObject.add(mymap); resParentObject.add(resChildObject); } } simpleResponse = new SimpleResponse(SibConstants.SUCCESS, request.getRequest_data_type(), request.getRequest_data_method(), readObject); } catch (Exception e) { e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "removePost", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}/*from w ww .j a va 2 s . c o m*/ */ @Override @RequestMapping(value = "/editAnswer", method = RequestMethod.POST) public ResponseEntity<Response> editAnswer(@RequestParam("content") final String content, @RequestParam("aid") final String aid, @RequestParam("file") final MultipartFile[] files, @RequestParam("oldImagePathEdited") final String oldImagePathEdited, @RequestParam("oldImagePath") final String oldImagePath) { SimpleResponse simpleResponse = null; try { if (!AuthenticationFilter.isAuthed(context)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } if (StringUtil.isNull(content)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editAnswer", "Content is not empty."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } else if (content.length() > 4000) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editAnswer", "Content must be less than 4000 characters."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } String error = validateFileImage(files); if (!StringUtil.isNull(error)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editAnswer", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } boolean status = true; MultipartFile file; String filePathEdited = mergeImage(oldImagePath, oldImagePathEdited); String maxLength = environment.getProperty("file.upload.image.length"); // Check total file length int totalLength = 0; for (String pathImage : filePathEdited.split(";")) { if (!StringUtil.isNull(pathImage)) { String oldPathFile = environment.getProperty("directoryImageAnswer") + pathImage.substring(pathImage.lastIndexOf("/")); totalLength += new File(oldPathFile).length(); } } if (files != null && files.length > 0) { if ((files.length + filePathEdited.split(";").length) > Integer.parseInt(maxLength)) { error = "You only upload " + maxLength + " image"; simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editAnswer", error); return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); } for (int i = 0; i < files.length; i++) { totalLength += files[i].getSize(); } } int maxSize = Integer.parseInt(environment.getProperty("file.upload.image.size")); if (totalLength > maxSize) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "post", "editAnswer", "File size must be less than 5MB."); } else { String filePath = ""; for (int i = 0; i < files.length; i++) { file = files[i]; filePath += environment.getProperty("directoryGetImageAnswer") + uploadFile(file, "directoryImageAnswer") + ".png"; if (i < files.length - 1) { filePath += ";"; } } // remove file when edit question removeFileEdit(oldImagePathEdited, "directoryImageAnswer"); String strContent = CommonUtil.filterWord(content, cachedDao.getAllWordFilter()); dao.insertUpdateObject(SibConstants.SqlMapper.SQL_ANSWER_EDIT, new Object[] { strContent, fixFilePath(filePathEdited + filePath), aid }); simpleResponse = new SimpleResponse("" + status, "Post", "editAnswer", ""); } } catch (Exception e) { e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "editAnswer", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:com.siblinks.ws.service.impl.PostServiceImpl.java
/** * {@inheritDoc}/*from ww w . ja v a2 s . c o m*/ */ @Override @RequestMapping(value = "/removeAnswer", method = RequestMethod.POST) public ResponseEntity<Response> removeAnswer(@RequestBody final RequestData request) { SimpleResponse simpleResponse = null; TransactionStatus statusDB = null; boolean status = true; try { if (!AuthenticationFilter.isAuthed(context)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } Object[] queryParams = { request.getRequest_data().getAid() }; TransactionDefinition def = new DefaultTransactionDefinition(); statusDB = transactionManager.getTransaction(def); status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_NUM_REPLIES_UPDATE_DELETE, queryParams); status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_ANSWER, queryParams); dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_ANSWER_LIKE, queryParams); transactionManager.commit(statusDB); simpleResponse = new SimpleResponse("" + status, request.getRequest_data_type(), request.getRequest_data_method(), request.getRequest_data().getAid()); } catch (Exception e) { transactionManager.rollback(statusDB); logger.info("Delete answer Error:" + e.getMessage()); e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "editAnswer", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }