@Test public void testLockObject() throws Exception { final String user = "user"; final Date expiry = new Date(); expect(mockAuthentication.getName()).andReturn(user).anyTimes(); Capture<Authentication> authenticationCapture = EasyMock.newCapture(); expect(objectLockingManagerMock.acquireObjectLock(eq(1123l), eq("CASE_FILE"), eq("OBJECT_LOCK"), eq(null), eq(true), eq(user))) .andAnswer(() -> { AcmObjectLock lock = new AcmObjectLock(); lock.setCreator(user); lock.setId(1l); lock.setObjectId(1123l); lock.setObjectType("CASE_FILE"); lock.setExpiry(expiry); return lock; }); session.setAttribute("acm_ip_address", "127.0.0.1"); replayAll(); MvcResult result = mockMvc.perform(put("/api/v1/plugin/CASE_FILE/1123/lock").session(session).principal(mockAuthentication)) .andExpect(status().isOk()).andReturn(); ObjectMapper mapper = new ObjectMapper(); AcmObjectLock objLock = mapper.readValue(result.getResponse().getContentAsString(), AcmObjectLock.class); assertEquals(Long.valueOf(1l), objLock.getId()); assertEquals(Long.valueOf(1123l), objLock.getObjectId()); assertEquals("CASE_FILE", objLock.getObjectType()); assertEquals(user, objLock.getCreator()); assertEquals(expiry, objLock.getExpiry()); verifyAll(); }
@PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId, @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication) throws MuleException, IOException, AcmObjectLockException { return objectLockingManager.acquireObjectLock(objectId, objectType, lockType, null, true, authentication.getName()); }
AcmObjectLockAPIController { @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId, @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication) throws MuleException, IOException, AcmObjectLockException { return objectLockingManager.acquireObjectLock(objectId, objectType, lockType, null, true, authentication.getName()); } }
AcmObjectLockAPIController { @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId, @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication) throws MuleException, IOException, AcmObjectLockException { return objectLockingManager.acquireObjectLock(objectId, objectType, lockType, null, true, authentication.getName()); }  }
AcmObjectLockAPIController { @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId, @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication) throws MuleException, IOException, AcmObjectLockException { return objectLockingManager.acquireObjectLock(objectId, objectType, lockType, null, true, authentication.getName()); }  @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType,
            @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication); @PreAuthorize("hasPermission(#objectId, #objectType, 'unlock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.OK) void unlockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType,
            @RequestParam(value = "lockId", required = false) Long lockId, Authentication auth); @RequestMapping(value = { "/api/v1/plugin/objects/{objectType}/locked", "/api/latest/plugin/objects/{objectType}/locked" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String listObjectsWithLock(@PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "firstRow", defaultValue = "0", required = false) int firstRow,
            @RequestParam(value = "maxRows", defaultValue = "1000", required = false) int maxRows,
            @RequestParam(value = "sort", defaultValue = "", required = false) String sort, Authentication authentication); @RequestMapping(value = { "/api/v1/plugin/locks/{objectType}", "/api/latest/plugin/locks/{objectType}" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String listLocks(@RequestParam(value = "parentObjectId", required = false, defaultValue = "") String objectId,
            @RequestParam(value = "creator", required = false, defaultValue = "") String creator,
            @PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "firstRow", defaultValue = "0", required = false) int firstRow,
            @RequestParam(value = "maxRows", defaultValue = "1000", required = false) int maxRows,
            @RequestParam(value = "sort", defaultValue = "", required = false) String sort, Authentication authentication); @PreAuthorize("hasPermission(#objectIds, #objectType, 'unlock')") @RequestMapping(value = { "/api/latest/plugin/locks/{objectType}/lock", "/api/v1/plugin/locks/{objectType}/lock" }, method = RequestMethod.DELETE) @ResponseBody String releaseMultipleLocks(@PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "parentObjectIds") List<Long> objectIds,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, Authentication auth); void setObjectLockingManager(AcmObjectLockingManager objectLockingManager); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService); }
AcmObjectLockAPIController { @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId, @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication) throws MuleException, IOException, AcmObjectLockException { return objectLockingManager.acquireObjectLock(objectId, objectType, lockType, null, true, authentication.getName()); }  @PreAuthorize("hasPermission(#objectId, #objectType, 'lock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmObjectLock lockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType,
            @RequestParam(value = "lockInDB", required = false, defaultValue = "true") boolean lockInDB, Authentication authentication); @PreAuthorize("hasPermission(#objectId, #objectType, 'unlock')") @RequestMapping(value = { "/api/v1/plugin/{objectType}/{objectId}/lock", "/api/latest/plugin/{objectType}/{objectId}/lock" }, method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.OK) void unlockObject(@PathVariable(value = "objectType") String objectType, @PathVariable(value = "objectId") Long objectId,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType,
            @RequestParam(value = "lockId", required = false) Long lockId, Authentication auth); @RequestMapping(value = { "/api/v1/plugin/objects/{objectType}/locked", "/api/latest/plugin/objects/{objectType}/locked" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String listObjectsWithLock(@PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "firstRow", defaultValue = "0", required = false) int firstRow,
            @RequestParam(value = "maxRows", defaultValue = "1000", required = false) int maxRows,
            @RequestParam(value = "sort", defaultValue = "", required = false) String sort, Authentication authentication); @RequestMapping(value = { "/api/v1/plugin/locks/{objectType}", "/api/latest/plugin/locks/{objectType}" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String listLocks(@RequestParam(value = "parentObjectId", required = false, defaultValue = "") String objectId,
            @RequestParam(value = "creator", required = false, defaultValue = "") String creator,
            @PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "firstRow", defaultValue = "0", required = false) int firstRow,
            @RequestParam(value = "maxRows", defaultValue = "1000", required = false) int maxRows,
            @RequestParam(value = "sort", defaultValue = "", required = false) String sort, Authentication authentication); @PreAuthorize("hasPermission(#objectIds, #objectType, 'unlock')") @RequestMapping(value = { "/api/latest/plugin/locks/{objectType}/lock", "/api/v1/plugin/locks/{objectType}/lock" }, method = RequestMethod.DELETE) @ResponseBody String releaseMultipleLocks(@PathVariable(value = "objectType") String objectType,
            @RequestParam(value = "parentObjectIds") List<Long> objectIds,
            @RequestParam(value = "lockType", required = false, defaultValue = "OBJECT_LOCK") String lockType, Authentication auth); void setObjectLockingManager(AcmObjectLockingManager objectLockingManager); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService);  }