@Test public void updateFileType() throws Exception { EcmFile file = new EcmFile(); file.setFileId(100L); file.setFileType("file_type"); String newFileType = "new_file_type"; Capture<EcmFile> saved = new Capture<>(); expect(mockAuthentication.getName()).andReturn("user"); expect(mockEcmFileDao.find(file.getId())).andReturn(file); expect(mockEcmFileDao.save(capture(saved))).andReturn(file); replayAll(); MvcResult result = mockMvc.perform( post("/api/latest/service/ecm/file/{fileId}/type/{fileType}", file.getId(), newFileType) .principal(mockAuthentication) .contentType(MediaType.APPLICATION_JSON)) .andReturn(); verifyAll(); LOG.info("Results: {}", result.getResponse().getContentAsString()); ObjectMapper objectMapper = new ObjectMapper(); EcmFile resultEcmFile = objectMapper.readValue(result.getResponse().getContentAsString(), EcmFile.class); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertEquals(newFileType, saved.getValue().getFileType()); assertEquals(newFileType, resultEcmFile.getFileType()); }
@PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { log.debug("Updating file type to '{}'", fileType); EcmFile file = updateFileType(fileId, fileType); if (file == null) { throw new AcmObjectNotFoundException("EcmFile", fileId, "Cannot update file type."); } return file; }
UpdateFileTypeAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { log.debug("Updating file type to '{}'", fileType); EcmFile file = updateFileType(fileId, fileType); if (file == null) { throw new AcmObjectNotFoundException("EcmFile", fileId, "Cannot update file type."); } return file; } }
UpdateFileTypeAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { log.debug("Updating file type to '{}'", fileType); EcmFile file = updateFileType(fileId, fileType); if (file == null) { throw new AcmObjectNotFoundException("EcmFile", fileId, "Cannot update file type."); } return file; }  }
UpdateFileTypeAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { log.debug("Updating file type to '{}'", fileType); EcmFile file = updateFileType(fileId, fileType); if (file == null) { throw new AcmObjectNotFoundException("EcmFile", fileId, "Cannot update file type."); } return file; }  @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType,
            Authentication authentication, HttpSession session); @RequestMapping(value = "/file/bulk/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<EcmFile> bulkUpdateFileType(@RequestBody List<Long> fileIds, @PathVariable("fileType") String fileType,
            Authentication authentication, HttpSession session); EcmFileService getEcmFileService(); void setEcmFileService(EcmFileService ecmFileService); }
UpdateFileTypeAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType, Authentication authentication, HttpSession session) throws AcmObjectNotFoundException { log.debug("Updating file type to '{}'", fileType); EcmFile file = updateFileType(fileId, fileType); if (file == null) { throw new AcmObjectNotFoundException("EcmFile", fileId, "Cannot update file type."); } return file; }  @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/{fileId}/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EcmFile updateFileType(@PathVariable("fileId") Long fileId, @PathVariable("fileType") String fileType,
            Authentication authentication, HttpSession session); @RequestMapping(value = "/file/bulk/type/{fileType}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<EcmFile> bulkUpdateFileType(@RequestBody List<Long> fileIds, @PathVariable("fileType") String fileType,
            Authentication authentication, HttpSession session); EcmFileService getEcmFileService(); void setEcmFileService(EcmFileService ecmFileService);  }