OrganizationResourceLockKeyProvider implements ResourceLockKeyProvider { @Override public String getLockKey(String accountId) throws ServerException { String currentOrganizationId = accountId; try { Organization organization = organizationManager.getById(currentOrganizationId); while (organization.getParent() != null) { currentOrganizationId = organization.getParent(); organization = organizationManager.getById(currentOrganizationId); } return organization.getId(); } catch (NotFoundException e) { throw new ServerException(e.getLocalizedMessage(), e); } } @Inject  OrganizationResourceLockKeyProvider(OrganizationManager organizationManager); @Override String getLockKey(String accountId); @Override String getAccountType();  }
@Test public void shouldReturnRootOrganizationId() throws Exception { createOrganization("root", null); createOrganization("suborg", "root"); createOrganization("subsuborg", "suborg"); final String lockId = lockProvider.getLockKey("subsuborg"); assertEquals(lockId, "root"); }