@Test public void updateFile_exception() throws Exception { AcmContainer acmContainer = new AcmContainer(); acmContainer.setContainerObjectType("CASE_FILE"); acmContainer.setContainerObjectId(101L); EcmFile in = new EcmFile(); in.setFileId(100L); in.setFileType("file_type"); in.setStatus("new_status"); in.setContainer(acmContainer); Capture<EcmFile> saved = Capture.newInstance(); expect(mockEcmFileService.findById(anyLong())).andReturn(in).anyTimes(); expect(mockEcmFileService.updateFile(capture(saved))).andReturn(null).anyTimes(); expect(mockAuthentication.getName()).andReturn("user").anyTimes(); replayAll(); try { mockMvc.perform( post("/api/latest/service/ecm/file/metadata/{fileId}", "101") .content(new ObjectMapper().writeValueAsString(in)) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .principal(mockAuthentication)) .andExpect(status().isBadRequest()) .andExpect(content().contentType(MediaType.TEXT_PLAIN)); } catch (Exception e) { } verifyAll(); }
@PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication) throws AcmUserActionFailedException, AcmObjectNotFoundException { if (file == null || file.getFileId() == null || fileId == null || !fileId.equals(file.getFileId())) { log.error("Invalid incoming file [{}]", file == null ? "unknown" : file.toString()); throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, null, "Invalid incoming file", null); } file = getEcmFileService().updateFile(file); if (file != null) { return file; } throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, fileId, "Failed to update file with fileId: " + fileId, null); }
UpdateFileMetadataAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication) throws AcmUserActionFailedException, AcmObjectNotFoundException { if (file == null || file.getFileId() == null || fileId == null || !fileId.equals(file.getFileId())) { log.error("Invalid incoming file [{}]", file == null ? "unknown" : file.toString()); throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, null, "Invalid incoming file", null); } file = getEcmFileService().updateFile(file); if (file != null) { return file; } throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, fileId, "Failed to update file with fileId: " + fileId, null); } }
UpdateFileMetadataAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication) throws AcmUserActionFailedException, AcmObjectNotFoundException { if (file == null || file.getFileId() == null || fileId == null || !fileId.equals(file.getFileId())) { log.error("Invalid incoming file [{}]", file == null ? "unknown" : file.toString()); throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, null, "Invalid incoming file", null); } file = getEcmFileService().updateFile(file); if (file != null) { return file; } throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, fileId, "Failed to update file with fileId: " + fileId, null); }  }
UpdateFileMetadataAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication) throws AcmUserActionFailedException, AcmObjectNotFoundException { if (file == null || file.getFileId() == null || fileId == null || !fileId.equals(file.getFileId())) { log.error("Invalid incoming file [{}]", file == null ? "unknown" : file.toString()); throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, null, "Invalid incoming file", null); } file = getEcmFileService().updateFile(file); if (file != null) { return file; } throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, fileId, "Failed to update file with fileId: " + fileId, null); }  @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication); EcmFileService getEcmFileService(); void setEcmFileService(EcmFileService ecmFileService); }
UpdateFileMetadataAPIController { @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication) throws AcmUserActionFailedException, AcmObjectNotFoundException { if (file == null || file.getFileId() == null || fileId == null || !fileId.equals(file.getFileId())) { log.error("Invalid incoming file [{}]", file == null ? "unknown" : file.toString()); throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, null, "Invalid incoming file", null); } file = getEcmFileService().updateFile(file); if (file != null) { return file; } throw new AcmUserActionFailedException(EcmFileConstants.USER_ACTION_UPDATE_FILE, EcmFileConstants.OBJECT_FILE_TYPE, fileId, "Failed to update file with fileId: " + fileId, null); }  @PreAuthorize("hasPermission(#fileId, 'FILE', 'write|group-write')") @RequestMapping(value = "/file/metadata/{fileId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EcmFile updateFile(@RequestBody EcmFile file, @PathVariable("fileId") Long fileId, Authentication authentication); EcmFileService getEcmFileService(); void setEcmFileService(EcmFileService ecmFileService);  }