List of usage examples for org.springframework.http ResponseEntity ok
public static BodyBuilder ok()
From source file:org.dawnsci.marketplace.controllers.PageController.java
@RequestMapping(value = "/pages/**", method = RequestMethod.GET) @ResponseBody/*from ww w . j a v a 2 s . c o m*/ public ResponseEntity<FileSystemResource> picture(HttpServletRequest request) { String resource = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .substring(1); Path path = fileService.getPageFile(resource).toPath(); File file = path.toAbsolutePath().toFile(); if (file.exists() && file.isFile()) { try { String detect = tika.detect(file); MediaType mediaType = MediaType.parseMediaType(detect); return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType) .body(new FileSystemResource(file)); } catch (IOException e) { e.printStackTrace(); } } else { throw new ResourceNotFoundException(); } return null; }
From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java
@RequestMapping(method = RequestMethod.GET, value = "/files/{filename}") public ResponseEntity<?> getFile(@PathVariable String filename) { GridFsResource file = this.fileService.findOne(filename); if (file == null) { return ResponseEntity.notFound().build(); }//from w w w . j ava 2s .c om try { return ResponseEntity.ok().contentLength(file.contentLength()) .contentType(MediaType.parseMediaType(file.getContentType())) .body(new InputStreamResource(file.getInputStream())); } catch (IOException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } }
From source file:de.lgblaumeiser.ptm.rest.BookingRestController.java
@RequestMapping(method = RequestMethod.POST, value = "/{dayString}/{booking}") public ResponseEntity<?> endBooking(@PathVariable String dayString, @PathVariable String booking, @RequestBody BookingBody changedData) { services.bookingStore().retrieveById(valueOf(booking)) .ifPresent(b -> services.bookingService().endBooking(b, parse(changedData.endtime))); return ResponseEntity.ok().build(); }
From source file:sagan.projects.support.BadgeController.java
/** * Creates a SVG badge for a project with a given {@link ReleaseStatus}. * * @param projectId/*from www.ja v a2 s. c o m*/ * @param releaseStatus * @return * @throws IOException */ private ResponseEntity<byte[]> badgeFor(String projectId, ReleaseStatus releaseStatus) throws IOException { Project project = service.getProject(projectId); if (project == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Optional<ProjectRelease> gaRelease = getRelease(project.getProjectReleases(), projectRelease -> projectRelease.getReleaseStatus() == releaseStatus); if (!gaRelease.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } byte[] svgBadge = versionBadgeService.createSvgBadge(project, gaRelease.get()); return ResponseEntity.ok().eTag(gaRelease.get().getVersion()) .cacheControl(CacheControl.maxAge(1L, TimeUnit.HOURS)).body(svgBadge); }
From source file:de.unimannheim.spa.process.rest.ProjectRestController.java
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<List<Map<String, Object>>> getAllProjects() { List<Map<String, Object>> allProjects = Lists.newArrayList(); for (Project project : spaService.findAllProjects()) { Rekord<Project> projectTmp = ProjectBuilder.rekord.with(ProjectBuilder.id, project.getId()) .with(ProjectBuilder.label, project.getLabel()) .with(ProjectBuilder.dataPools, DataPoolBuilder.rekord.with(DataPoolBuilder.buckets, project.getDataPools().get(0).getDataBuckets())) .with(ProjectBuilder.linkedSchemas, project.getLinkedSchemas()); allProjects.add(projectTmp.serialize(new MapSerializer())); }//from w ww.j a v a 2 s . c o m return ResponseEntity.ok().contentType(JSON_CONTENT_TYPE).body(allProjects); }
From source file:com.saasovation.identityaccess.resource.UserResource.java
private ResponseEntity<String> userInRoleResponse(User aUser, String aRoleName) { UserInRoleRepresentation userInRoleRepresentation = new UserInRoleRepresentation(aUser, aRoleName); String representation = ObjectSerializer.instance().serialize(userInRoleRepresentation); return ResponseEntity.ok().cacheControl(this.cacheControlFor(60)).body(representation); }
From source file:de.lgblaumeiser.ptm.rest.BookingRestController.java
@RequestMapping(method = RequestMethod.DELETE, value = "/{dayString}/{booking}") public ResponseEntity<?> deleteBooking(@PathVariable String dayString, @PathVariable String booking) { services.bookingStore().deleteById(valueOf(booking)); return ResponseEntity.ok().build(); }
From source file:com.todo.backend.web.rest.TodoApi.java
@RequestMapping(value = "/todos", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed/*w w w .jav a2 s .c o m*/ @Transactional(readOnly = true) @PreAuthorize("hasAuthority('ADMIN') or hasAuthority('MEMBER')") public ResponseEntity<List<TodosResponse>> todos() { log.debug("GET /todos"); final List<TodoUserTuple> result = todoRepository.todos(); return ResponseEntity.ok() .body(result.stream().map(this::convertToTodosResponse).collect(Collectors.toList())); }
From source file:de.document.controller.ICDNummerController.java
@RequestMapping(value = "/delete/gesamt/", method = { RequestMethod.POST }) public ResponseEntity delete(@RequestBody String code) { this.service.delete(code); return ResponseEntity.ok().build(); }
From source file:com.todo.backend.web.rest.UserApi.java
@RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed/*from ww w . ja v a 2s. c om*/ @Transactional(readOnly = true) @PreAuthorize("hasAuthority('ADMIN')") public ResponseEntity<List<UsersResponse>> users() { log.debug("GET /users"); final List<User> result = userRepository.users(); return ResponseEntity.ok() .body(result.stream().map(this::convertToUsersResponse).collect(Collectors.toList())); }