@Test void testGetMemberships() { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); @SuppressWarnings("unchecked") Query<RoleMembership> query = mock(Query.class, RETURNS_SELF); when(dataService.query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class)) .thenReturn(query); when(query .in(RoleMembershipMetadata.ROLE, ImmutableList.of(editor, viewer)) .fetch(fetch) .findAll()) .thenReturn(Stream.of(oldRoleMembership, roleMembership)); when(roleMembership.isCurrent()).thenReturn(true); assertEquals( singletonList(roleMembership), roleMembershipService.getMemberships(of(editor, viewer))); }
@RunAsSystem @Override public Collection<RoleMembership> getMemberships(Collection<Role> roles) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); return dataService .query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class) .in(RoleMembershipMetadata.ROLE, roles) .fetch(fetch) .findAll() .filter(RoleMembership::isCurrent) .collect(Collectors.toList()); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public Collection<RoleMembership> getMemberships(Collection<Role> roles) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); return dataService .query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class) .in(RoleMembershipMetadata.ROLE, roles) .fetch(fetch) .findAll() .filter(RoleMembership::isCurrent) .collect(Collectors.toList()); } }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public Collection<RoleMembership> getMemberships(Collection<Role> roles) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); return dataService .query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class) .in(RoleMembershipMetadata.ROLE, roles) .fetch(fetch) .findAll() .filter(RoleMembership::isCurrent) .collect(Collectors.toList()); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public Collection<RoleMembership> getMemberships(Collection<Role> roles) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); return dataService .query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class) .in(RoleMembershipMetadata.ROLE, roles) .fetch(fetch) .findAll() .filter(RoleMembership::isCurrent) .collect(Collectors.toList()); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); @RunAsSystem @Override void addUserToRole(String username, String roleName); @RunAsSystem @Override void addUserToRole(final User user, final Role role); @RunAsSystem @Override void removeMembership(final RoleMembership roleMembership); @RunAsSystem @Override void updateMembership(RoleMembership roleMembership, Role newRole); @RunAsSystem @Override Collection<RoleMembership> getMemberships(Collection<Role> roles); }
RoleMembershipServiceImpl implements RoleMembershipService { @RunAsSystem @Override public Collection<RoleMembership> getMemberships(Collection<Role> roles) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch userFetch = new Fetch().field(UserMetadata.USERNAME).field(UserMetadata.ID); Fetch fetch = new Fetch() .field(RoleMembershipMetadata.ROLE, roleFetch) .field(RoleMembershipMetadata.USER, userFetch) .field(RoleMembershipMetadata.FROM) .field(RoleMembershipMetadata.TO) .field(RoleMembershipMetadata.ID); return dataService .query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class) .in(RoleMembershipMetadata.ROLE, roles) .fetch(fetch) .findAll() .filter(RoleMembership::isCurrent) .collect(Collectors.toList()); } RoleMembershipServiceImpl(
      UserService userService,
      RoleMembershipFactory roleMembershipFactory,
      DataService dataService,
      UserMetadata userMetadata,
      RoleMetadata roleMetadata); @RunAsSystem @Override void addUserToRole(String username, String roleName); @RunAsSystem @Override void addUserToRole(final User user, final Role role); @RunAsSystem @Override void removeMembership(final RoleMembership roleMembership); @RunAsSystem @Override void updateMembership(RoleMembership roleMembership, Role newRole); @RunAsSystem @Override Collection<RoleMembership> getMemberships(Collection<Role> roles);  }