class CurrentUserEndpointMerger extends AbstractSingleEntityEndpoint<CurrentUserEntity> {

    @Override
    protected void mergeResponses(final CurrentUserEntity clientEntity, final Map<NodeIdentifier, CurrentUserEntity> entityMap,
                                  final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {

        for (final Map.Entry<NodeIdentifier, CurrentUserEntity> entry : entityMap.entrySet()) {
            final CurrentUserEntity entity = entry.getValue();
            if (entity != clientEntity) {
                mergePermissions(clientEntity.getControllerPermissions(), entity.getControllerPermissions());
                mergePermissions(clientEntity.getCountersPermissions(), entity.getCountersPermissions());
                mergePermissions(clientEntity.getPoliciesPermissions(), entity.getPoliciesPermissions());
                mergePermissions(clientEntity.getProvenancePermissions(), entity.getProvenancePermissions());
                mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());
                mergePermissions(clientEntity.getSystemPermissions(), entity.getSystemPermissions());
                mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());

                final Set<ComponentRestrictionPermissionDTO> clientEntityComponentRestrictionsPermissions = clientEntity.getComponentRestrictionPermissions();
                final Set<ComponentRestrictionPermissionDTO> entityComponentRestrictionsPermissions = entity.getComponentRestrictionPermissions();

                // only retain the component restriction permissions in common
                clientEntityComponentRestrictionsPermissions.retainAll(entityComponentRestrictionsPermissions);

                // merge the component restriction permissions
                clientEntityComponentRestrictionsPermissions.forEach(clientEntityPermission -> {
                    final ComponentRestrictionPermissionDTO entityPermission = entityComponentRestrictionsPermissions.stream().filter(entityComponentRestrictionsPermission -> {
                        return entityComponentRestrictionsPermission.getRequiredPermission().getId().equals(clientEntityPermission.getRequiredPermission().getId());
                    }).findFirst().orElse(null);

                    mergePermissions(clientEntityPermission.getPermissions(), entityPermission.getPermissions());
                });
            }
        }
    }

}