fix filter (use different crud methods instead of in-memory filtering, which failed to support count)
This commit is contained in:
parent
7ab07f6ca3
commit
c34d93f58d
7 changed files with 38 additions and 27 deletions
|
@ -1,7 +1,11 @@
|
|||
package com.faendir.acra.sql.data;
|
||||
|
||||
import com.faendir.acra.sql.model.App;
|
||||
import com.faendir.acra.sql.model.Permission;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -11,9 +15,20 @@ import java.util.Optional;
|
|||
* @since 11.12.2017
|
||||
*/
|
||||
public interface AppRepository extends JpaRepository<App, Integer> {
|
||||
|
||||
Optional<App> findByReporterUsername(@NonNull String username);
|
||||
|
||||
@Query("select app from App app where app not in (select permission.app from User user join user.permissions permission where user.username = ?1 and permission.level < ?2)")
|
||||
Slice<App> findAllByPermissionWithDefaultIncluded(@NonNull String username, @NonNull Permission.Level level, @NonNull Pageable pageable);
|
||||
|
||||
@Query("select app from App app where app in (select permission.app from User user join user.permissions permission where user.username = ?1 and permission.level >= ?2)")
|
||||
Slice<App> findAllByPermissionWithDefaultExcluded(@NonNull String username, @NonNull Permission.Level level, @NonNull Pageable pageable);
|
||||
|
||||
@Query("select count(app) from App app where app not in (select permission.app from User user join user.permissions permission where user.username = ?1 and permission.level < ?2)")
|
||||
int countByPermissionWithDefaultIncluded(@NonNull String username, @NonNull Permission.Level level);
|
||||
|
||||
@Query("select count(app) from App app where app in (select permission.app from User user join user.permissions permission where user.username = ?1 and permission.level >= ?2)")
|
||||
int countByPermissionWithDefaultExcluded(@NonNull String username, @NonNull Permission.Level level);
|
||||
|
||||
@SuppressWarnings("SpringDataMethodInconsistencyInspection")
|
||||
default Optional<App> findByEncodedId(String encodedId) {
|
||||
try {
|
||||
|
|
|
@ -15,8 +15,12 @@ import java.util.Optional;
|
|||
*/
|
||||
public interface BugRepository extends JpaRepository<Bug, Integer> {
|
||||
Slice<Bug> findAllByApp(@NonNull App app, @NonNull Pageable pageable);
|
||||
|
||||
Slice<Bug> findAllByAppAndSolvedFalse(@NonNull App app, @NonNull Pageable pageable);
|
||||
|
||||
int countAllByApp(@NonNull App app);
|
||||
|
||||
int countAllByAppAndSolvedFalse(@NonNull App app);
|
||||
|
||||
Optional<Bug> findBugByAppAndStacktrace(@NonNull App app, @NonNull String stacktrace);
|
||||
}
|
||||
|
|
|
@ -26,18 +26,16 @@ public interface ReportRepository extends JpaRepository<Report, String> {
|
|||
int countAllByBugApp(@NonNull App app);
|
||||
|
||||
@SuppressWarnings("SpringDataRepositoryMethodReturnTypeInspection")
|
||||
@Query("select new com.faendir.acra.sql.util.DayCount(report.date, count(report)) from Report report join Bug bug on report.bug = bug " +
|
||||
"where bug.app = ?1 and report.date > ?2 group by function('year',report.date), function('month',report.date), function('day',report.date)")
|
||||
@Query("select new com.faendir.acra.sql.util.DayCount(report.date, count(report)) from Report report join Bug bug on report.bug = bug "
|
||||
+ "where bug.app = ?1 and report.date > ?2 group by function('year',report.date), function('month',report.date), function('day',report.date)")
|
||||
List<DayCount> countAllByDayAfter(@NonNull App app, @NonNull Date date);
|
||||
|
||||
List<Report> findAllByBug(@NonNull Bug bug);
|
||||
|
||||
Slice<Report> findAllByBug(@NonNull Bug bug, @NonNull Pageable pageable);
|
||||
|
||||
int countAllByBug(@NonNull Bug bug);
|
||||
|
||||
@SuppressWarnings("SpringDataRepositoryMethodReturnTypeInspection")
|
||||
@Query("select new com.faendir.acra.sql.util.AndroidVersionCount(report.androidVersion, count(report)) from Report report join Bug bug on report.bug = bug " +
|
||||
"where bug.app = ?1 group by report.androidVersion")
|
||||
@Query("select new com.faendir.acra.sql.util.AndroidVersionCount(report.androidVersion, count(report)) from Report report join Bug bug on report.bug = bug "
|
||||
+ "where bug.app = ?1 group by report.androidVersion")
|
||||
List<AndroidVersionCount> countAllByAndroidVersion(@NonNull App app);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class UserManager {
|
|||
|
||||
@Autowired
|
||||
public UserManager(@NonNull UserRepository userRepository, @NonNull PasswordEncoder passwordEncoder, @NonNull AcraConfiguration acraConfiguration,
|
||||
@NonNull SecureRandom secureRandom) {
|
||||
@NonNull SecureRandom secureRandom) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.acraConfiguration = acraConfiguration;
|
||||
|
@ -66,9 +66,7 @@ public class UserManager {
|
|||
username = generator.generate(16);
|
||||
} while (userRepository.existsById(username));
|
||||
String password = generator.generate(16);
|
||||
User user = new User(username, passwordEncoder.encode(password), Collections.singleton(ROLE_REPORTER));
|
||||
userRepository.save(user);
|
||||
return Pair.of(user, password);
|
||||
return Pair.of(new User(username, passwordEncoder.encode(password), Collections.singleton(ROLE_REPORTER)), password);
|
||||
}
|
||||
|
||||
public boolean checkPassword(@Nullable User user, @NonNull String password) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.faendir.acra.ui.view.base.NamedView;
|
|||
import com.faendir.acra.ui.view.base.Popup;
|
||||
import com.faendir.acra.util.BufferedDataProvider;
|
||||
import com.faendir.acra.util.Style;
|
||||
import com.vaadin.data.provider.ConfigurableFilterDataProvider;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.spring.annotation.SpringView;
|
||||
import com.vaadin.ui.Button;
|
||||
|
@ -24,8 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author Lukas
|
||||
* @since 23.03.2017
|
||||
|
@ -46,10 +43,11 @@ public class Overview extends NamedView {
|
|||
|
||||
@Override
|
||||
public void enter(ViewChangeListener.ViewChangeEvent event) {
|
||||
ConfigurableFilterDataProvider<App, Void, Predicate<App>> dataProvider = new BufferedDataProvider<>(appRepository::findAll,
|
||||
() -> Math.toIntExact(appRepository.count())).withConfigurableFilter();
|
||||
dataProvider.setFilter(app -> SecurityUtils.hasPermission(app, Permission.Level.VIEW));
|
||||
grid = new MyGrid<>("Apps", dataProvider);
|
||||
grid = new MyGrid<>("Apps", new BufferedDataProvider<>(SecurityUtils.hasRole(UserManager.ROLE_ADMIN), (admin, pageable) -> admin ?
|
||||
appRepository.findAllByPermissionWithDefaultIncluded(SecurityUtils.getUsername(), Permission.Level.VIEW, pageable) :
|
||||
appRepository.findAllByPermissionWithDefaultExcluded(SecurityUtils.getUsername(), Permission.Level.VIEW, pageable), admin -> admin ?
|
||||
appRepository.countByPermissionWithDefaultIncluded(SecurityUtils.getUsername(), Permission.Level.VIEW) :
|
||||
appRepository.countByPermissionWithDefaultExcluded(SecurityUtils.getUsername(), Permission.Level.VIEW)));
|
||||
grid.setWidth(100, Unit.PERCENTAGE);
|
||||
grid.setSelectionMode(Grid.SelectionMode.NONE);
|
||||
grid.addColumn(App::getName, "Name");
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.faendir.acra.ui.view.tabs;
|
|||
import com.faendir.acra.sql.data.AppRepository;
|
||||
import com.faendir.acra.sql.data.ReportRepository;
|
||||
import com.faendir.acra.sql.model.App;
|
||||
import com.faendir.acra.sql.model.Permission;
|
||||
import com.faendir.acra.sql.model.User;
|
||||
import com.faendir.acra.sql.user.UserManager;
|
||||
import com.faendir.acra.ui.NavigationManager;
|
||||
import com.faendir.acra.ui.annotation.RequiresAppPermission;
|
||||
import com.faendir.acra.ui.view.base.ConfigurationLabel;
|
||||
import com.faendir.acra.ui.view.base.MyTabSheet;
|
||||
import com.faendir.acra.ui.view.base.Popup;
|
||||
|
@ -30,6 +32,7 @@ import java.util.Date;
|
|||
* @author Lukas
|
||||
* @since 19.05.2017
|
||||
*/
|
||||
@RequiresAppPermission(Permission.Level.ADMIN)
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class PropertiesTab implements MyTabSheet.Tab {
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.List;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -19,7 +18,7 @@ import java.util.stream.Stream;
|
|||
* @author Lukas
|
||||
* @since 13.12.2017
|
||||
*/
|
||||
public class BufferedDataProvider<T> extends AbstractBackEndDataProvider<T, Predicate<T>> {
|
||||
public class BufferedDataProvider<T> extends AbstractBackEndDataProvider<T, Void> {
|
||||
private static final int PAGE_SIZE = 32;
|
||||
private final Function<Pageable, Slice<T>> getter;
|
||||
private final IntSupplier counter;
|
||||
|
@ -30,12 +29,11 @@ public class BufferedDataProvider<T> extends AbstractBackEndDataProvider<T, Pred
|
|||
}
|
||||
|
||||
public <P> BufferedDataProvider(P parameter, BiFunction<P, Pageable, Slice<T>> getter, Function<P, Integer> counter) {
|
||||
this.getter = pageable -> getter.apply(parameter, pageable);
|
||||
this.counter = () -> counter.apply(parameter);
|
||||
this(pageable -> getter.apply(parameter, pageable), () -> counter.apply(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<T> fetchFromBackEnd(Query<T, Predicate<T>> query) {
|
||||
protected Stream<T> fetchFromBackEnd(Query<T, Void> query) {
|
||||
Sort sort = Sort.by(query.getSortOrders().stream().map(OrderAdapter::new).collect(Collectors.toList()));
|
||||
Slice<T> slice = getter.apply(PageRequest.of(query.getOffset() / PAGE_SIZE, PAGE_SIZE, sort));
|
||||
if (!slice.hasContent()) return Stream.empty();
|
||||
|
@ -51,14 +49,11 @@ public class BufferedDataProvider<T> extends AbstractBackEndDataProvider<T, Pred
|
|||
result = Stream.concat(result, content.stream());
|
||||
}
|
||||
}
|
||||
if(query.getFilter().isPresent()){
|
||||
result = result.filter(query.getFilter().get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int sizeInBackEnd(Query<T, Predicate<T>> query) {
|
||||
protected int sizeInBackEnd(Query<T, Void> query) {
|
||||
return counter.getAsInt();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue