com.codahale.metrics.annotation.Timed Java Examples
The following examples show how to use
com.codahale.metrics.annotation.Timed.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * DELETE /documents/:id : delete the "id" document. * @param id the id of the document to delete * @return the ResponseEntity with status 200 (OK) or 403 Forbidden */ @DeleteMapping("/documents/{id}") @Timed public ResponseEntity<Void> deleteDocument(HttpServletRequest httpServletRequest, @PathVariable Long id) { log.debug("REST request to delete Document : {}", id); Document document = documentRepository.findOne(id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null == userLogin || !userLogin.equals(document.getAuthorLogin())) { return ResponseEntity.status(403).build(); // 403 Forbidden } documentRepository.delete(id); return ResponseEntity.ok().build(); }
Example #2
Source File: MessageResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * POST /messages : Send a new message. * * @param message the message to create * @return the ResponseEntity with status 200 OK */ @PostMapping("/messages/send") @Timed public ResponseEntity<Void> sendMessage(HttpServletRequest httpServletRequest, @Valid @RequestBody Message message) { log.debug("REST request to send Message : {}", message); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null != userLogin) { message.setSender(userLogin); message.setId(null); message.setViewed(false); message.setDeleted(false); message.setCreatedDate(Instant.now()); message.setModifiedDate(Instant.now()); messageRepository.save(message); return ResponseEntity.ok().build(); } else { return ResponseEntity.badRequest().build(); } }
Example #3
Source File: UserResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * GET /users/:login : get the "login" user. * * @param login the login of the user to find * @return the ResponseEntity with status 200 (OK) and with body the "login" user, or with status 404 (Not Found) */ @GetMapping("/users/{login:" + Constants.LOGIN_REGEX + "}") @Timed public ResponseEntity<UserDTO> getUser(HttpServletRequest httpServletRequest, @PathVariable String login) { log.debug("REST request to get User : {}", login); String userLogin = JwtUtil.getUserLogin(httpServletRequest); String userRoles = JwtUtil.getUserRoles(httpServletRequest); if (null == userLogin || !(userLogin.equals(login) || userLogin.equals("system") || (userRoles != null && userRoles.contains("ROLE_ADMIN")))) { // 只能由申请者自己或者ROLE_ADMIN查询用户信息 return ResponseEntity.status(403).build(); // 403 Forbidden } return ResponseUtil.wrapOrNotFound( userService.getUserWithAuthoritiesByLogin(login) .map(UserDTO::new)); }
Example #4
Source File: MessageResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /messages/deleted : Updates an existing message' deleted. * * @param id the message id to update * @param deleted the message deleted to update * @return the ResponseEntity with status 200 (OK) or 400 (badRequest) */ @PutMapping("/messages/deleted") @Timed public ResponseEntity<Message> updateMessageDeleted(HttpServletRequest httpServletRequest, @RequestParam(value = "id") Long id, @RequestParam(value = "deleted") Boolean deleted) throws URISyntaxException { log.debug("REST request to update Message deleted: {}", id); Message message = messageRepository.findOne(id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null != userLogin && message.getReceiver().equals(userLogin)) { message.setDeleted(deleted); messageRepository.save(message); return ResponseEntity.ok().build(); } else { return ResponseEntity.badRequest().build(); } }
Example #5
Source File: ArtifactResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * DELETE /artifacts/:id : delete the "id" artifact. * @param id the id of the artifact to delete * @return the ResponseEntity with status 200 (OK) or 403 Forbidden */ @DeleteMapping("/artifacts/{id}") @Timed public ResponseEntity<Void> deleteArtifact(HttpServletRequest httpServletRequest, @PathVariable Long id) { log.debug("REST request to delete Artifact : {}", id); Artifact artifact = artifactRepository.findOne(id); Solution solution = solutionRepository.findAllByUuid(artifact.getSolutionUuid()).get(0); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null == userLogin || !(userLogin.equals(solution.getAuthorLogin()) || userLogin.equals("system"))) { // 只能由作者自己删除,或者由umu微服务中的onboardService异步服务删除 return ResponseEntity.status(403).build(); // 403 Forbidden } artifactRepository.delete(id); return ResponseEntity.ok().build(); }
Example #6
Source File: SolutionFavoriteResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * GET /solution-favorites : get pageable solution-favorites. * * @return the ResponseEntity with status 200 (OK) and the list of solution-favorites in body */ @GetMapping("/solution-favorites") @Timed public ResponseEntity<List<SolutionFavorite>> getAllSolutionFavorite(@RequestParam(value = "userLogin") String userLogin, @RequestParam(value = "solutionUuid", required = false) String solutionUuid, Pageable pageable) { log.debug("REST request to get all solution-favorites"); Page<SolutionFavorite> page; if (null != solutionUuid) { page = solutionFavoriteRepository.findAllByUserLoginAndSolutionUuid(userLogin, solutionUuid, pageable); } else { page = solutionFavoriteRepository.findAllByUserLogin(userLogin, pageable); } HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/solution-favorites"); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
Example #7
Source File: SolutionFavoriteResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * DELETE /solution-favorites/:id : delete the "id" solutionFavorite. * * @param id the id of the solutionFavorite to delete * @return the ResponseEntity with status 200 (OK) */ @DeleteMapping("/solution-favorites/{id}") @Timed public ResponseEntity<Void> deleteSolutionFavorite(HttpServletRequest httpServletRequest, @PathVariable Long id) { log.debug("REST request to delete SolutionFavorite : {}", id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); SolutionFavorite solutionFavorite = solutionFavoriteRepository.findOne(id); if (null == userLogin || !userLogin.equals(solutionFavorite.getUserLogin())) { return ResponseEntity.status(403).build(); // 403 Forbidden } solutionFavoriteRepository.delete(id); return ResponseEntity.ok().build(); }
Example #8
Source File: SolutionRatingResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /solution-ratings/score : Updates an existing solutionRating's score. * @param jsonObject JSONObject with fields to be updated * @return the ResponseEntity with status 200 (OK) and with body the updated solutionRating, or with status 403 Forbidden */ @PutMapping("/solution-ratings/score") @Timed public ResponseEntity<SolutionRating> updateSolutionRatingScore(HttpServletRequest httpServletRequest, @Valid @RequestBody JSONObject jsonObject) { log.debug("REST request to update SolutionRating : {}", jsonObject); SolutionRating solutionRating = solutionRatingRepository.findOne(jsonObject.getLong("id")); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null == userLogin || !userLogin.equals(solutionRating.getUserLogin())) { return ResponseEntity.status(403).build(); // 403 Forbidden } solutionRating.setRatingScore(jsonObject.getInteger("score")); SolutionRating result = solutionRatingRepository.save(solutionRating); return ResponseEntity.ok().body(result); }
Example #9
Source File: UserResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /users : Updates an existing User. * * @param userDTO the user to update * @return the ResponseEntity with status 200 (OK) and with body the updated user * @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already in use * @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already in use */ @PutMapping("/users") @Timed @Secured({AuthoritiesConstants.ADMIN}) public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody UserDTO userDTO) { log.debug("REST request to update User : {}", userDTO); Optional<User> existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) { throw new EmailAlreadyUsedException(); } existingUser = userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) { throw new LoginAlreadyUsedException(); } Optional<UserDTO> updatedUser = userService.updateUser(userDTO); return ResponseUtil.wrapOrNotFound(updatedUser, HeaderUtil.createAlert("A user is updated with identifier " + userDTO.getLogin(), userDTO.getLogin())); }
Example #10
Source File: TaskResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /tasks : Updates an existing task. * @param task the task to update * @return the ResponseEntity with status 200 (OK) or 403 Forbidden */ @PutMapping("/tasks") @Timed public ResponseEntity<Task> updateTask(HttpServletRequest httpServletRequest, @Valid @RequestBody Task task) { log.debug("REST request to update Task : {}", task); String userLogin = JwtUtil.getUserLogin(httpServletRequest); // updateTask只能由umu微服务中的异步任务OnBoardingServie调用,不能由前端用户调用 if (null == userLogin || !userLogin.equals("system")) { return ResponseEntity.status(403).build(); } Task result = taskRepository.save(task); return ResponseEntity.ok().body(result); }
Example #11
Source File: AccountResource.java From flair-engine with Apache License 2.0 | 6 votes |
/** * POST /account : update the current user information. * * @param userDTO the current user information * @return the ResponseEntity with status 200 (OK), or status 400 (Bad Request) or 500 (Internal Server Error) if the user couldn't be updated */ @PostMapping("/account") @Timed public ResponseEntity saveAccount(@Valid @RequestBody UserDTO userDTO) { final String userLogin = SecurityUtils.getCurrentUserLogin(); Optional<User> existingUser = userRepository.findOneByEmail(userDTO.getEmail()); if (existingUser.isPresent() && (!existingUser.get().getLogin().equalsIgnoreCase(userLogin))) { return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("user-management", "emailexists", "Email already in use")).body(null); } return userRepository .findOneByLogin(userLogin) .map(u -> { userService.updateUser(userDTO.getFirstName(), userDTO.getLastName(), userDTO.getEmail(), userDTO.getLangKey(), userDTO.getImageUrl()); return new ResponseEntity(HttpStatus.OK); }) .orElseGet(() -> new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); }
Example #12
Source File: DownloadResource.java From cubeai with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/download", method = RequestMethod.GET) @Timed public void downloadArtifact(@RequestParam(value = "url") String url, HttpServletResponse response) { log.debug("REST request to download artifact/document file"); // 暂时不在HTTP响应头中传递文件名,因为文件名可能是中文 // String fileName = url.substring(artifactUrl.lastIndexOf("/") + 1); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "0"); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); // response.setHeader("x-filename", fileName); // response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); response.setHeader("Content-Disposition", "attachment"); response.setStatus(HttpServletResponse.SC_OK); try { ByteArrayOutputStream byteArrayOutputStream = nexusArtifactClient.getArtifact(url); byteArrayOutputStream.writeTo(response.getOutputStream()); response.flushBuffer(); if (null != byteArrayOutputStream) { byteArrayOutputStream.close(); } } catch (Exception e) { } }
Example #13
Source File: UeditorResource.java From cubeai with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/ueditor", method = RequestMethod.GET) @Timed public String getConfig(@RequestParam(value = "action") String action) { log.debug("REST request to get config json string"); Ueditor ueditor = new Ueditor(); if (action.equals("config")) { try { ClassPathResource classPathResource = new ClassPathResource("ueditor/config.json"); InputStream stream = classPathResource.getInputStream(); String config = IOUtils.toString(stream, "UTF-8"); stream.close(); return config; } catch (Exception e) { ueditor.setState("找不到配置文件!"); return JSONObject.toJSONString(ueditor); } } else { ueditor.setState("不支持操作!"); return JSONObject.toJSONString(ueditor); } }
Example #14
Source File: UserResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * POST /users : Creates a new user. * <p> * Creates a new user if the login and email are not already used, and sends an * mail with an activation link. * The user needs to be activated on creation. * * @param userDTO the user to create * @return the ResponseEntity with status 201 (Created) and with body the new user, or with status 400 (Bad Request) if the login or email is already in use * @throws URISyntaxException if the Location URI syntax is incorrect * @throws BadRequestAlertException 400 (Bad Request) if the login or email is already in use */ @PostMapping("/users") @Timed @Secured({AuthoritiesConstants.ADMIN}) public ResponseEntity<User> createUser(@Valid @RequestBody UserDTO userDTO) throws URISyntaxException { log.debug("REST request to save User : {}", userDTO); if (userDTO.getId() != null) { throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists"); // Lowercase the user login before comparing with database } else if (userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()).isPresent()) { throw new LoginAlreadyUsedException(); } else if (userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).isPresent()) { throw new EmailAlreadyUsedException(); } else { User newUser = userService.createUser(userDTO); // mailService.sendCreationEmail(newUser); // huolongshe: 创建用户不发邮件通知 return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin())) .headers(HeaderUtil.createAlert( "A user is created with identifier " + newUser.getLogin(), newUser.getLogin())) .body(newUser); } }
Example #15
Source File: TaskResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * GET /tasks : get pageable tasks. * * @return the ResponseEntity with status 200 (OK) and the list of tasks in body */ @GetMapping("/tasks") @Timed public ResponseEntity<List<Task>> getTasks(@RequestParam(value = "uuid", required = false) String uuid, @RequestParam(value = "userLogin", required = false) String userLogin, @RequestParam(value = "taskStatus", required = false) String taskStatus, Pageable pageable) { log.debug("REST request to get all tasks"); Page<Task> page; if (null != uuid) { page = taskRepository.findAllByUuid(uuid, pageable); } else if (null != userLogin) { if (null != taskStatus) { page = taskRepository.findAllByUserLoginAndTaskStatus(userLogin, taskStatus, pageable); } else { page = taskRepository.findAllByUserLogin(userLogin, pageable); } } else { page = taskRepository.findAll(pageable); } HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/tasks"); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
Example #16
Source File: SolutionResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /solutions/subjects : 更新Solution对象中的subjectdeng诸字段 * @param jsonObject the JSONObject with subjects to be updated * @return the ResponseEntity with status 200 (OK) and with body the updated solution, or status 400 (Bad Request) */ @PutMapping("/solutions/subjects") @Timed @Secured({"ROLE_MANAGER"}) // subject字段只能由平台管理员更新 public ResponseEntity<Solution> updateSolutionSubjects(@Valid @RequestBody JSONObject jsonObject) { log.debug("REST request to update Solution subjects: {}", jsonObject); Solution solution = solutionRepository.findOne(jsonObject.getLong("id")); solution.setSubject1(jsonObject.getString("subject1")); solution.setSubject2(jsonObject.getString("subject2")); solution.setSubject3(jsonObject.getString("subject3")); solution.setDisplayOrder(jsonObject.getLong("displayOrder")); solution.setModifiedDate(Instant.now()); Solution result = solutionRepository.save(solution); return ResponseEntity.ok().body(result); }
Example #17
Source File: AbilityResource.java From cubeai with Apache License 2.0 | 6 votes |
@CrossOrigin @PostMapping("/{deploymentUuid}/{modelMethod}") @Timed public ResponseEntity<String> openAbility(@PathVariable String deploymentUuid, @PathVariable String modelMethod, @Valid @RequestBody String requestBody, @RequestHeader MultiValueMap<String,String> requestHeader) { log.debug("REST request to access AI open ability"); List<Deployment> deploymentList = this.ummClient.getDeployment(deploymentUuid); if(deploymentList.isEmpty()) { return ResponseEntity.status(404).body("Cannot find deployment: " + deploymentUuid); } List<Solution> solutions = ummClient.getSolutionsByUuid(deploymentList.get(0).getSolutionUuid()); if (!solutions.isEmpty()) { if (solutions.get(0).getToolkitType().equals("模型组合")) { return abilityService.callComposer(solutions.get(0).getUuid(), modelMethod, requestBody, requestHeader); } } Integer k8sPort = deploymentList.get(0).getk8sPort(); if(k8sPort == null) { return ResponseEntity.status(404).body("Deployment: " + deploymentUuid + " is not running"); } String url = "http://" + internalIP + ":" + k8sPort + "/model/methods/" + modelMethod; return abilityService.apiGateway(url, requestBody, requestHeader); }
Example #18
Source File: AbilityResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * GET /ability : get deployments by uuid. * * @return the ResponseEntity with status 200 (OK) and the list of deployments in body */ @GetMapping("/ability") @Timed public List<Deployment> getAllDeployments(@RequestParam(value = "uuid") String uuid) { log.debug("REST request to get all Deployments by uuid"); List<Deployment> deploymentList = this.deploymentRepository.findAllByUuid(uuid); if (!deploymentList.isEmpty()) { // 该接口只有在用户调用AI能力时才会被调用,所以选择在这里递加能力的接口调用次数 Deployment deployment = deploymentList.get(0); deployment.setCallCount(deployment.getCallCount() + 1); this.deploymentRepository.save(deployment); } return deploymentList; }
Example #19
Source File: AuthResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * Authenticates a user setting the access and refresh token cookies. * * @param request the HttpServletRequest holding - among others - the headers passed from the client. * @param response the HttpServletResponse getting the cookies set upon successful authentication. * @param params the login params (username, password, rememberMe). * @return the access token of the authenticated user. Will return an error code if it fails to authenticate the user. */ @RequestMapping(value = "/login", method = RequestMethod.POST, consumes = MediaType .APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<OAuth2AccessToken> authenticate(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> params) { if (params.get("username").equals("system")) { return ResponseEntity.badRequest().build(); } int verifyResult = this.uaaClient.validateVerifyCode(params); if (1 == verifyResult) { return authenticationService.authenticate(request, response, params); } else { return ResponseEntity.badRequest().build(); } }
Example #20
Source File: UserResource.java From flair-engine with Apache License 2.0 | 6 votes |
/** * PUT /users : Updates an existing User. * * @param managedUserVM the user to update * @return the ResponseEntity with status 200 (OK) and with body the updated user, * or with status 400 (Bad Request) if the login or email is already in use, * or with status 500 (Internal Server Error) if the user couldn't be updated */ @PutMapping("/users") @Timed @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody ManagedUserVM managedUserVM) { log.debug("REST request to update User : {}", managedUserVM); Optional<User> existingUser = userRepository.findOneByEmail(managedUserVM.getEmail()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) { return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "emailexists", "Email already in use")).body(null); } existingUser = userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) { return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "userexists", "Login already in use")).body(null); } Optional<UserDTO> updatedUser = userService.updateUser(managedUserVM); return ResponseUtil.wrapOrNotFound(updatedUser, HeaderUtil.createAlert("A user is updated with identifier " + managedUserVM.getLogin(), managedUserVM.getLogin())); }
Example #21
Source File: SolutionResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * DELETE /solutions/:id : delete the "id" solution. * @param id the id of the solution to delete * @return the ResponseEntity with status 200 (OK) */ @DeleteMapping("/solutions/{id}") @Timed public ResponseEntity<Void> deleteSolution(HttpServletRequest httpServletRequest, @PathVariable Long id) { log.debug("REST request to delete Solution : {}", id); Solution solution = solutionRepository.findOne(id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null == userLogin || !(userLogin.equals(solution.getAuthorLogin()) || userLogin.equals("system"))) { // solution只能由作者自己删除,或者由umu微服务中的onboardService异步服务删除 return ResponseEntity.status(403).build(); // 403 Forbidden } solutionRepository.delete(id); return ResponseEntity.ok().build(); }
Example #22
Source File: PublishRequestResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * GET /publish-requests : get pageable publishRequests. * @return the ResponseEntity with status 200 (OK) and the list of publishRequests in body */ @GetMapping("/publish-requests") @Timed public ResponseEntity<List<PublishRequest>> getPublishRequests(@RequestParam(value = "reviewed", required = false) Boolean reviewed, @RequestParam(value = "requestType", required = false) String requestType, @RequestParam(value = "solutionUuid", required = false) String solutionUuid, Pageable pageable) { log.debug("REST request to get all PublishRequests"); Page<PublishRequest> page; if (null != reviewed) { if (null != requestType) { page = publishRequestRepository.findAllByReviewedAndRequestType(reviewed, requestType, pageable); } else { page = publishRequestRepository.findAllByReviewed(reviewed, pageable); } } else if (null != solutionUuid) { page = publishRequestRepository.findAllBySolutionUuid(solutionUuid, pageable); } else { page = publishRequestRepository.findAll(pageable); } HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/publish-requests"); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
Example #23
Source File: MessageResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * PUT /messages/viewed : Updates an existing message' viewed. * * @param id the message id to update * @param viewed the message viewed to update * @return the ResponseEntity with status 200 (OK) or 400 (badRequest) */ @PutMapping("/messages/viewed") @Timed public ResponseEntity<Message> updateMessageViewed(HttpServletRequest httpServletRequest, @RequestParam(value = "id") Long id, @RequestParam(value = "viewed") Boolean viewed) throws URISyntaxException { log.debug("REST request to update Message viewed: {}", id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); Message message = messageRepository.findOne(id); if (null != userLogin && message.getReceiver().equals(userLogin)) { message.setViewed(viewed); messageRepository.save(message); return ResponseEntity.ok().build(); } else { return ResponseEntity.badRequest().build(); } }
Example #24
Source File: ArticleResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * DELETE /articles/:id : delete the "id" article. * @param id the id of the article to delete * @return the ResponseEntity with status 200 (OK) */ @DeleteMapping("/articles/{id}") @Timed @Secured({"ROLE_CONTENT"}) public ResponseEntity<Void> deleteArticle(HttpServletRequest httpServletRequest, @PathVariable Long id) { log.debug("REST request to delete Article : {}", id); Article article = articleRepository.findOne(id); String userLogin = JwtUtil.getUserLogin(httpServletRequest); if (null == userLogin || !userLogin.equals(article.getAuthorLogin())) { return ResponseEntity.status(403).build(); // 403 Forbidden } articleRepository.delete(id); return ResponseEntity.ok().build(); }
Example #25
Source File: AccountResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * POST /account/reset-password/init : Send an email to reset the password of the user * * @param params the mail of the user * @throws EmailNotFoundException 400 (Bad Request) if the email address is not registered */ @PostMapping(path = "/account/reset-password/init") @Timed public void requestPasswordReset(@Valid @RequestBody Map<String, String> params) { if (1 == this.verifyCodeService.validateVerifyCode(Long.valueOf(params.get("verifyId")), params.get("verifyCode"))) { mailService.sendPasswordResetMail( userService.requestPasswordReset(params.get("email")) .orElseThrow(EmailNotFoundException::new) ); } else { throw new EmailNotFoundException(); // 这里实际上是验证码比对错误,但是我们仍抛出email找不到的异常 } }
Example #26
Source File: AuthResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * Logout current user deleting his cookies. * * @param request the HttpServletRequest holding - among others - the headers passed from the client. * @param response the HttpServletResponse getting the cookies set upon successful authentication. * @return an empty response entity. */ @RequestMapping(value = "/logout", method = RequestMethod.POST) @Timed public ResponseEntity<?> logout(HttpServletRequest request, HttpServletResponse response) { log.info("logging out user {}", SecurityContextHolder.getContext().getAuthentication().getName()); authenticationService.logout(request, response); return ResponseEntity.ok(null); }
Example #27
Source File: GatewayResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @GetMapping("/routes") @Timed public ResponseEntity<List<RouteVM>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteVM> routeVMs = new ArrayList<>(); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation())); routeVMs.add(routeVM); }); return new ResponseEntity<>(routeVMs, HttpStatus.OK); }
Example #28
Source File: MailResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * POST /mail : send mail. * * @param mail the mail to send * @return the ResponseEntity with status 200 OK */ @PostMapping("/mail") @Timed public ResponseEntity<Void> sendMail(@Valid @RequestBody Mail mail) { log.debug("REST request to send mail : {}", mail); this.mailService.sendEmail(mail.getTo(), mail.getSubject(), mail.getContent(), mail.getIsMultipart(), mail.getIsHtml()); return ResponseEntity.ok().build(); }
Example #29
Source File: AccountResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * POST /account/reset-password/finish : Finish to reset the password of the user * * @param keyAndPassword the generated key and the new password * @throws InvalidPasswordException 400 (Bad Request) if the password is incorrect * @throws RuntimeException 500 (Internal Server Error) if the password could not be reset */ @PostMapping(path = "/account/reset-password/finish") @Timed public void finishPasswordReset(@RequestBody KeyAndPasswordVM keyAndPassword) { if (!checkPasswordLength(keyAndPassword.getNewPassword())) { throw new InvalidPasswordException(); } Optional<User> user = userService.completePasswordReset(keyAndPassword.getNewPassword(), keyAndPassword.getKey()); if (!user.isPresent()) { throw new InternalServerErrorException("No user was found for this reset key"); } }
Example #30
Source File: SolutionFavoriteResource.java From cubeai with Apache License 2.0 | 5 votes |
/** * POST /solution-favorites : Create a new solutionFavorite. * @param solutionFavorite the solutionFavorite to create * @return the ResponseEntity with status 201 (Created) or 401 Unauthorized */ @PostMapping("/solution-favorites") @Timed public ResponseEntity<SolutionFavorite> createSolutionFavorite(HttpServletRequest httpServletRequest, @Valid @RequestBody SolutionFavorite solutionFavorite) { log.debug("REST request to save SolutionFavorite : {}", solutionFavorite); String userLogin = JwtUtil.getUserLogin(httpServletRequest); solutionFavorite.setUserLogin(userLogin); solutionFavorite.setFavoriteDate(Instant.now()); solutionFavoriteRepository.save(solutionFavorite); return ResponseEntity.status(201).build(); }