@Test void testGetGroupNotFound() { Fetch fetch = buildGroupFetch(); when(groupMetadata.getAttribute(GroupMetadata.NAME)).thenReturn(attribute); @SuppressWarnings("unchecked") Query<Group> query = mock(Query.class, RETURNS_SELF); when(dataService.query(GroupMetadata.GROUP, Group.class)).thenReturn(query); when(query.eq(GroupMetadata.NAME, "devs").fetch(fetch).findOne()).thenReturn(null); assertThrows(UnknownEntityException.class, () -> groupService.getGroup("devs")); }
@RunAsSystem public Group getGroup(String groupName) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch fetch = new Fetch() .field(GroupMetadata.ROLES, roleFetch) .field(GroupMetadata.NAME) .field(GroupMetadata.LABEL) .field(GroupMetadata.DESCRIPTION) .field(GroupMetadata.ID) .field(GroupMetadata.PUBLIC) .field(GroupMetadata.ROOT_PACKAGE); Group group = dataService .query(GroupMetadata.GROUP, Group.class) .eq(GroupMetadata.NAME, groupName) .fetch(fetch) .findOne(); if (group == null) { throw new UnknownEntityException( groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName); } return group; }
GroupService { @RunAsSystem public Group getGroup(String groupName) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch fetch = new Fetch() .field(GroupMetadata.ROLES, roleFetch) .field(GroupMetadata.NAME) .field(GroupMetadata.LABEL) .field(GroupMetadata.DESCRIPTION) .field(GroupMetadata.ID) .field(GroupMetadata.PUBLIC) .field(GroupMetadata.ROOT_PACKAGE); Group group = dataService .query(GroupMetadata.GROUP, Group.class) .eq(GroupMetadata.NAME, groupName) .fetch(fetch) .findOne(); if (group == null) { throw new UnknownEntityException( groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName); } return group; } }
GroupService { @RunAsSystem public Group getGroup(String groupName) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch fetch = new Fetch() .field(GroupMetadata.ROLES, roleFetch) .field(GroupMetadata.NAME) .field(GroupMetadata.LABEL) .field(GroupMetadata.DESCRIPTION) .field(GroupMetadata.ID) .field(GroupMetadata.PUBLIC) .field(GroupMetadata.ROOT_PACKAGE); Group group = dataService .query(GroupMetadata.GROUP, Group.class) .eq(GroupMetadata.NAME, groupName) .fetch(fetch) .findOne(); if (group == null) { throw new UnknownEntityException( groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName); } return group; } @SuppressWarnings("java:S107")  GroupService(
      PackageFactory packageFactory,
      DataService dataService,
      GroupMetadata groupMetadata,
      RoleMembershipService roleMembershipService,
      RoleMembershipMetadata roleMembershipMetadata,
      MutableAclService aclService,
      PermissionService permissionService); }
GroupService { @RunAsSystem public Group getGroup(String groupName) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch fetch = new Fetch() .field(GroupMetadata.ROLES, roleFetch) .field(GroupMetadata.NAME) .field(GroupMetadata.LABEL) .field(GroupMetadata.DESCRIPTION) .field(GroupMetadata.ID) .field(GroupMetadata.PUBLIC) .field(GroupMetadata.ROOT_PACKAGE); Group group = dataService .query(GroupMetadata.GROUP, Group.class) .eq(GroupMetadata.NAME, groupName) .fetch(fetch) .findOne(); if (group == null) { throw new UnknownEntityException( groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName); } return group; } @SuppressWarnings("java:S107")  GroupService(
      PackageFactory packageFactory,
      DataService dataService,
      GroupMetadata groupMetadata,
      RoleMembershipService roleMembershipService,
      RoleMembershipMetadata roleMembershipMetadata,
      MutableAclService aclService,
      PermissionService permissionService); @Transactional void persist(GroupValue groupValue); @RunAsSystem Collection<Group> getGroups(); @RunAsSystem Group getGroup(String groupName); @RunAsSystem void addMember(final Group group, final User user, final Role role); @RunAsSystem void removeMember(final Group group, final User user); @RunAsSystem void updateMemberRole(final Group group, final User member, final Role newRole); @RunAsSystem boolean isGroupNameAvailable(final GroupValue groupValue); void deleteGroup(String groupName); void updateExtendsRole(Group group, Role groupRole, Role memberRole); void removeExtendsRole(Group group, Role memberRole); void grantDefaultPermissions(GroupValue groupValue); }
GroupService { @RunAsSystem public Group getGroup(String groupName) { Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL); Fetch fetch = new Fetch() .field(GroupMetadata.ROLES, roleFetch) .field(GroupMetadata.NAME) .field(GroupMetadata.LABEL) .field(GroupMetadata.DESCRIPTION) .field(GroupMetadata.ID) .field(GroupMetadata.PUBLIC) .field(GroupMetadata.ROOT_PACKAGE); Group group = dataService .query(GroupMetadata.GROUP, Group.class) .eq(GroupMetadata.NAME, groupName) .fetch(fetch) .findOne(); if (group == null) { throw new UnknownEntityException( groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName); } return group; } @SuppressWarnings("java:S107")  GroupService(
      PackageFactory packageFactory,
      DataService dataService,
      GroupMetadata groupMetadata,
      RoleMembershipService roleMembershipService,
      RoleMembershipMetadata roleMembershipMetadata,
      MutableAclService aclService,
      PermissionService permissionService); @Transactional void persist(GroupValue groupValue); @RunAsSystem Collection<Group> getGroups(); @RunAsSystem Group getGroup(String groupName); @RunAsSystem void addMember(final Group group, final User user, final Role role); @RunAsSystem void removeMember(final Group group, final User user); @RunAsSystem void updateMemberRole(final Group group, final User member, final Role newRole); @RunAsSystem boolean isGroupNameAvailable(final GroupValue groupValue); void deleteGroup(String groupName); void updateExtendsRole(Group group, Role groupRole, Role memberRole); void removeExtendsRole(Group group, Role memberRole); void grantDefaultPermissions(GroupValue groupValue); static final String MANAGER; static final String EDITOR; static final String VIEWER; static final String AUTHORITY_MANAGER; static final String AUTHORITY_EDITOR; static final String AUTHORITY_VIEWER; static final Set<String> DEFAULT_ROLES; }