List of usage examples for org.springframework.http ResponseEntity notFound
public static HeadersBuilder<?> notFound()
From source file:org.createnet.raptor.auth.service.controller.DeviceController.java
@RequestMapping(value = "/check", method = RequestMethod.POST) @ApiOperation(value = "Check user permission on a device", notes = "", response = AuthorizationResponse.class, nickname = "checkPermission") public ResponseEntity<?> checkPermission( @AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser, @RequestBody AuthorizationRequest body) { AuthorizationResponse response = new AuthorizationResponse(); switch (body.getOperation()) { case User:/* w ww . ja va 2s . c o m*/ response.result = true; response.userId = currentUser.getUuid(); response.roles = currentUser.getRoles().stream().map((r) -> r.getName()).collect(Collectors.toList()); break; case Permission: User user = (User) currentUser; if (body.userId != null) { user = userService.getByUuid(body.userId); } logger.debug("Check if user {} can `{}` on object {}", user.getUuid(), body.permission, body.objectId); Permission permission = RaptorPermission.fromLabel(body.permission); if (permission == null) { logger.warn("Permission not found for user {} `{}` on object {}", user.getUuid(), body.permission, body.objectId); return ResponseEntity.notFound().build(); } /** * @TODO CREATE permission should be attached to an user rather * than on the object itself */ final boolean isCreate = (body.objectId == null && permission == RaptorPermission.CREATE); if (isCreate) { response.result = true; } else { Device device = null; if (permission != RaptorPermission.LIST) { device = deviceService.getByUuid(body.objectId); if (device == null) { return ResponseEntity.notFound().build(); } } response.result = aclDeviceService.check(device, user, permission); } break; default: response.result = false; break; } logger.debug("Check request result: {}", response.result); return ResponseEntity.status(HttpStatus.OK).body(response); }
From source file:com.orange.clara.pivotaltrackermirror.controllers.MirrorReferenceController.java
@ApiOperation("Delete a specific mirror referenced by its id") @RequestMapping(method = RequestMethod.DELETE, value = "/{id:[0-9]*}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> delete(@PathVariable Integer id) throws SchedulerException { MirrorReference mirrorReference = this.mirrorReferenceRepo.findOne(id); if (mirrorReference == null) { return ResponseEntity.notFound().build(); }//from ww w.ja v a 2s .c o m scheduler.deleteJob(new JobKey(MirrorJob.JOB_KEY_NAME + mirrorReference.getId(), MirrorJob.JOB_KEY_GROUP)); this.mirrorReferenceRepo.delete(mirrorReference); return ResponseEntity.noContent().build(); }
From source file:org.springsource.restbucks.payment.web.PaymentController.java
/** * Takes the {@link Receipt} for the given {@link Order} and thus completes the process. * * @param order//from w ww . j a v a 2 s. c om * @return */ @RequestMapping(path = PaymentLinks.RECEIPT, method = DELETE) HttpEntity<?> takeReceipt(@PathVariable("id") Order order) { if (order == null || !order.isPaid()) { return ResponseEntity.notFound().build(); } return paymentService.takeReceiptFor(order).// map(receipt -> createReceiptResponse(receipt)).// orElseGet(() -> new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED)); }
From source file:com.onyxscheduler.web.JobController.java
@RequestMapping(value = "/groups/{group}/jobs/{name}", method = RequestMethod.DELETE) public ResponseEntity<Void> deleteJob(@PathVariable String group, @PathVariable String name) { if (!scheduler.deleteJob(new JobKey(group, name))) { return ResponseEntity.notFound().build(); }/*from w w w . j ava2s. c o m*/ return ResponseEntity.noContent().build(); }
From source file:alfio.controller.api.admin.ExtensionApiController.java
@RequestMapping(value = "{path}/{name}", method = RequestMethod.GET) public ResponseEntity<ExtensionSupport> loadSingle(@PathVariable("path") String path, @PathVariable("name") String name, Principal principal) throws UnsupportedEncodingException { ensureAdmin(principal);/* w w w. j av a 2s .co m*/ return extensionService.getSingle(URLDecoder.decode(path, "UTF-8"), name).map(ResponseEntity::ok) .orElseGet(() -> ResponseEntity.notFound().build()); }
From source file:com.orange.clara.pivotaltrackermirror.controllers.MirrorReferenceController.java
@ApiOperation("Force the app to refresh all stories inside a specific mirror") @RequestMapping(method = RequestMethod.GET, value = "/{id:[0-9]*}/force-update", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> forceUpdate(@PathVariable Integer id) throws SchedulerException { MirrorReference mirrorReference = this.mirrorReferenceRepo.findOne(id); if (mirrorReference == null) { return ResponseEntity.notFound().build(); }//from w ww .j a va 2 s .co m mirrorReference.setUpdatedAt(new Date(0L)); this.mirrorReferenceRepo.save(mirrorReference); JobKey jobKey = new JobKey(MirrorJob.JOB_KEY_NAME + id, MirrorJob.JOB_KEY_GROUP); scheduler.triggerJob(jobKey); return ResponseEntity.accepted().build(); }
From source file:com.couchbase.trombi.controllers.CoworkerController.java
@RequestMapping(value = "/{coworkerId}", method = RequestMethod.PUT) public ResponseEntity<?> updateCoworker(@PathVariable("coworkerId") int id, @RequestBody Coworker body) { String fullId = CoworkerRepository.PREFIX + id; if (!fullId.equals(body.getId())) { return ResponseEntity.badRequest().body(body); }/*from w ww . jav a 2 s . co m*/ if (!bucket.exists(fullId)) { return ResponseEntity.notFound().build(); } repository.save(body); return ResponseEntity.ok(body); }
From source file:org.openlmis.fulfillment.web.TransferPropertiesController.java
/** * Allows updating transfer properties.// ww w . j a v a2 s .c om * * @param properties A transfer properties bound to the request body * @param id UUID of transfer properties which we want to update * @return ResponseEntity containing the updated transfer properties */ @RequestMapping(value = "/transferProperties/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) @ResponseBody public ResponseEntity update(@RequestBody TransferPropertiesDto properties, @PathVariable("id") UUID id) { LOGGER.debug("Checking right to update transfer properties "); permissionService.canManageSystemSettings(); TransferProperties toUpdate = transferPropertiesRepository.findOne(id); if (null == toUpdate) { return ResponseEntity.notFound().build(); } else if (null == properties.getFacility() || !Objects.equals(toUpdate.getFacilityId(), properties.getFacility().getId())) { throw new IncorrectTransferPropertiesException(); } else { LOGGER.debug("Updating Transfer Properties with id: {}", id); } TransferProperties entity = TransferPropertiesFactory.newInstance(properties); if (!Objects.equals(entity.getClass(), toUpdate.getClass())) { transferPropertiesRepository.delete(toUpdate); } List<Message.LocalizedMessage> errors = validate(entity); if (isNotTrue(errors.isEmpty())) { return ResponseEntity.badRequest().body(errors); } toUpdate = transferPropertiesRepository.save(entity); LOGGER.debug("Updated Transfer Properties with id: {}", toUpdate.getId()); return ResponseEntity.ok(TransferPropertiesFactory.newInstance(toUpdate, exporter)); }
From source file:com.couchbase.trombi.controllers.CoworkerController.java
@RequestMapping(value = "/{coworkerId}", method = RequestMethod.PATCH) public ResponseEntity<?> patchCoworker(@PathVariable("coworkerId") int id, @RequestBody Map<String, Object> body) { String fullId = CoworkerRepository.PREFIX + id; if (!bucket.exists(fullId)) { return ResponseEntity.notFound().build(); }/*from ww w .j ava 2 s.c o m*/ MutateInBuilder builder = bucket.mutateIn(fullId); if (body.containsKey("name")) { builder.upsert("name", body.get("name"), false); } if (body.containsKey("description")) { builder.upsert("description", body.get("description"), false); } if (body.containsKey("team")) { builder.upsert("team", body.get("team"), false); } if (body.containsKey("skills")) { Iterable<Object> skills = (Iterable<Object>) body.get("skills"); for (Object skill : skills) { builder.arrayAddUnique("skills", skill, false); } } if (body.containsKey("imHandles")) { Map<String, Object> imHandles = (Map<String, Object>) body.get("imHandles"); for (Map.Entry<String, Object> entry : imHandles.entrySet()) { builder.upsert("imHandles." + entry.getKey(), entry.getValue(), true); } } if (body.containsKey("mainLocation")) { Map<String, Object> mainLocation = (Map<String, Object>) body.get("mainLocation"); if (mainLocation.containsKey("name")) { builder.replace("mainLocation.name", mainLocation.get("name")); } if (mainLocation.containsKey("description")) { builder.replace("mainLocation.description", mainLocation.get("description")); } //disallow anything else (coordinates and timezone) if (!mainLocation.containsKey("name") && !mainLocation.containsKey("description")) { return ResponseEntity.badRequest().body("Main location can only have name and description updated, " + "use a different API to switch to a whole new location"); } } if (body.containsKey("lastCheckin")) { return ResponseEntity.badRequest().body("Checkin can only be performed through the dedicated API"); } builder.execute(); Coworker result = repository.findOne(fullId); return ResponseEntity.ok().body(result); }
From source file:de.unimannheim.spa.process.rest.ProjectRestController.java
@RequestMapping(value = "/{projectID}", method = RequestMethod.DELETE) public ResponseEntity<Void> removeProject(@PathVariable String projectID) { ResponseEntity<Void> response = null; final Optional<Project> projectToRemove = spaService.findProjectById(PROJECT_BASE_URL + projectID); if (projectToRemove.isPresent()) { spaService.deleteProject(projectToRemove.get()); response = ResponseEntity.ok().build(); } else {/*from w w w. j ava2 s. com*/ response = ResponseEntity.notFound().build(); } return response; }