exceptionfactory commented on code in PR #7181:
URL: https://github.com/apache/nifi/pull/7181#discussion_r1170473571


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java:
##########
@@ -4461,6 +4465,62 @@ public Set<UserEntity> getUsers() {
             .collect(Collectors.toSet());
     }
 
+    /**
+     * Search for User and Group Tenants with optimized conversion from 
specific objects to Tenant objects
+     *
+     * @param query Search query where null or empty returns unfiltered results
+     * @return Tenants Entity containing zero or more matching Users and Groups
+     */
+    @Override
+    public TenantsEntity searchTenants(final String query) {
+        final PermissionsDTO permissions = 
dtoFactory.createPermissionsDto(authorizableLookup.getTenant());
+
+        final Set<TenantEntity> usersFound = userDAO.getUsers()
+                .stream()
+                .filter(user -> isMatched(user.getIdentity(), query))
+                .map(user -> createTenantEntity(user, permissions))
+                .collect(Collectors.toSet());
+
+        final Set<TenantEntity> userGroupsFound = userGroupDAO.getUserGroups()
+                .stream()
+                .filter(userGroup -> isMatched(userGroup.getName(), query))
+                .map(userGroup -> createTenantEntity(userGroup, permissions))
+                .collect(Collectors.toSet());
+
+        final TenantsEntity tenantsEntity = new TenantsEntity();
+        tenantsEntity.setUsers(usersFound);
+        tenantsEntity.setUserGroups(userGroupsFound);
+        return tenantsEntity;
+    }
+
+    private boolean isMatched(final String label, final String query) {
+        return StringUtils.isEmpty(query) || containsIgnoreCase(label, query);
+    }
+
+    private TenantEntity createTenantEntity(final User user, final 
PermissionsDTO permissions) {
+        final TenantDTO tenant = dtoFactory.createTenantDTO(user);
+        return createTenantEntity(tenant, permissions);
+    }
+
+    private TenantEntity createTenantEntity(final Group userGroup, final 
PermissionsDTO permissions) {

Review Comment:
   Thanks for pointer to `EntityFactory`, I pushed an update removing the 
private methods and adjusting the stream function to make use of 
`EntityFactory.createTenantEntity()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to