Skip to content

Commit

Permalink
gh-4594 Add deletion of stored qrys, result stores, activities
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Dec 11, 2024
1 parent 1863f0e commit 96af0b3
Show file tree
Hide file tree
Showing 26 changed files with 292 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import stroom.activity.shared.Activity;
import stroom.activity.shared.ActivityValidationResult;
import stroom.util.shared.QuickFilterResultPage;
import stroom.util.shared.UserRef;
import stroom.util.shared.filter.FilterFieldDefinition;

import java.util.List;
Expand All @@ -31,7 +32,9 @@ public interface ActivityService {

Activity update(Activity activity);

boolean delete(int id);
boolean deleteAllByOwner(int id);

int deleteAllByOwner(UserRef ownerRef);

QuickFilterResultPage<Activity> find(final String filter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import stroom.util.NullSafe;
import stroom.util.exception.DataChangedException;
import stroom.util.json.JsonUtil;
import stroom.util.logging.LambdaLogger;
import stroom.util.logging.LambdaLoggerFactory;
import stroom.util.logging.LogUtil;
import stroom.util.shared.UserRef;

import jakarta.inject.Inject;
Expand All @@ -32,6 +35,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -41,8 +45,9 @@

public class ActivityDaoImpl implements ActivityDao {

private final ActivityDbConnProvider activityDbConnProvider;
private static final LambdaLogger LOGGER = LambdaLoggerFactory.getLogger(ActivityDaoImpl.class);

private final ActivityDbConnProvider activityDbConnProvider;

private static final Function<Record, Activity> RECORD_TO_ACTIVITY_MAPPER = record -> Activity.builder()
.id(record.get(ACTIVITY.ID))
Expand Down Expand Up @@ -186,4 +191,18 @@ public List<Activity> find(
}
});
}

@Override
public int deleteAllByOwner(final UserRef ownerRef) {
Objects.requireNonNull(ownerRef);
final int delCount = JooqUtil.contextResult(activityDbConnProvider, dslContext -> dslContext
.deleteFrom(ACTIVITY)
.where(ACTIVITY.USER_UUID.eq(ownerRef.getUuid()))
.execute());

LOGGER.debug(() -> LogUtil.message("Deleted {} {} records for user {}",
delCount, ACTIVITY.getName(), ownerRef.toInfoString()));

return delCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void before() {
void test() {
// Delete all existing.
ResultPage<Activity> list = activityService.find(null);
list.forEach(activity -> activityService.delete(activity.getId()));
list.forEach(activity -> activityService.deleteAllByOwner(activity.getId()));

// Create 1
Activity activity1 = activityService.create();
Expand Down Expand Up @@ -106,12 +106,12 @@ void test() {
assertThat(list3.getFirst().getId()).isEqualTo(activity2.getId());

// Delete one
activityService.delete(activity1.getId());
activityService.deleteAllByOwner(activity1.getId());
final ResultPage<Activity> list4 = activityService.find(null);
assertThat(list4.size()).isEqualTo(1);

// Delete the other
activityService.delete(activity2.getId());
activityService.deleteAllByOwner(activity2.getId());
final ResultPage<Activity> list5 = activityService.find(null);
assertThat(list5.size()).isEqualTo(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import stroom.activity.api.FindActivityCriteria;
import stroom.activity.shared.Activity;
import stroom.util.shared.HasIntCrud;
import stroom.util.shared.UserRef;

import java.util.List;
import java.util.function.Function;
Expand All @@ -15,4 +16,6 @@ public interface ActivityDao extends HasIntCrud<Activity> {
List<Activity> find(
final FindActivityCriteria criteria,
final Function<Stream<Activity>, Stream<Activity>> streamFunction);

int deleteAllByOwner(UserRef ownerRef);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public QuickFilterResultPage<Activity> list(final String filter) {
private Query buildRawQuery(final String userInput) {
return Query.builder()
.withRaw("Activity matches \""
+ Objects.requireNonNullElse(userInput, "")
+ "\"")
+ Objects.requireNonNullElse(userInput, "")
+ "\"")
.build();
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public Activity update(final Integer id, final Activity activity) {

@Override
public Boolean delete(final Integer id) {
activityServiceProvider.get().delete(id);
activityServiceProvider.get().deleteAllByOwner(id);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import stroom.activity.shared.Activity;
import stroom.activity.shared.ActivityValidationResult;
import stroom.security.api.SecurityContext;
import stroom.security.shared.AppPermission;
import stroom.util.AuditUtil;
import stroom.util.filter.FilterFieldMapper;
import stroom.util.filter.FilterFieldMappers;
Expand All @@ -29,6 +30,7 @@
import stroom.util.logging.LambdaLoggerFactory;
import stroom.util.logging.LogUtil;
import stroom.util.shared.EntityServiceException;
import stroom.util.shared.PermissionException;
import stroom.util.shared.QuickFilterResultPage;
import stroom.util.shared.UserRef;
import stroom.util.shared.filter.FilterFieldDefinition;
Expand All @@ -38,6 +40,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
Expand Down Expand Up @@ -99,11 +102,11 @@ public Activity update(final Activity activity) {
}

@Override
public boolean delete(final int id) {
public boolean deleteAllByOwner(final int id) {
return securityContext.secureResult(() -> {
final Activity activity = fetch(id);
if (activity != null) {
if (!securityContext.getUserRef().equals(activity.getUserRef())) {
if (!securityContext.isCurrentUser(activity.getUserRef())) {
throw new EntityServiceException("Attempt to update another persons activity");
}
return dao.delete(id);
Expand All @@ -112,6 +115,22 @@ public boolean delete(final int id) {
});
}

@Override
public int deleteAllByOwner(final UserRef ownerRef) {
Objects.requireNonNull(ownerRef);
return securityContext.secureResult(() -> {
if (securityContext.hasAppPermission(AppPermission.MANAGE_USERS_PERMISSION)
|| securityContext.isCurrentUser(ownerRef)) {
return dao.deleteAllByOwner(ownerRef);

} else {
throw new PermissionException(securityContext.getUserRef(),
LogUtil.message("You must be the owner to delete all activities for {} or hold {}",
ownerRef, AppPermission.MANAGE_USERS_PERMISSION));
}
});
}

@Override
public QuickFilterResultPage<Activity> find(final String filter) {
return securityContext.secureResult(() -> {
Expand Down Expand Up @@ -162,8 +181,8 @@ private List<FilterFieldDefinition> buildFieldDefinitions(final List<Activity> a
.stream()
.flatMap(activity -> {
if (activity != null
&& activity.getDetails() != null
&& activity.getDetails().getProperties() != null) {
&& activity.getDetails() != null
&& activity.getDetails().getProperties() != null) {
// We want to search all fields by default
return activity.getDetails().getProperties().stream()
.map(prop -> FilterFieldDefinition.defaultField(prop.getName()));
Expand Down Expand Up @@ -203,17 +222,17 @@ public ActivityValidationResult validate(final Activity activity) {
valid = false;
if (Strings.isNullOrEmpty(prop.getValidationMessage())) {
messages.add("Invalid value '" + value
+ "' for property '" + prop.getId()
+ "' must match '" + prop.getValidation() + "'");
+ "' for property '" + prop.getId()
+ "' must match '" + prop.getValidation() + "'");
} else {
messages.add(prop.getValidationMessage());
}
}
} catch (final PatternSyntaxException e) {
valid = false;
messages.add("Unable to parse validation regex '"
+ prop.getValidation() + "' for property '"
+ prop.getId() + "'");
+ prop.getValidation() + "' for property '"
+ prop.getId() + "'");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package stroom.widget.tab.client.view;

import stroom.util.shared.EqualsUtil;
import stroom.widget.menu.client.presenter.IconMenuItem;
import stroom.widget.menu.client.presenter.Item;
import stroom.widget.menu.client.presenter.ShowMenuEvent;
Expand Down Expand Up @@ -50,6 +49,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public abstract class AbstractTabBar extends Widget implements TabBar, RequiresResize {
Expand All @@ -68,10 +68,10 @@ public abstract class AbstractTabBar extends Widget implements TabBar, RequiresR

public AbstractTabBar() {
sinkEvents(Event.ONMOUSEDOWN |
Event.ONMOUSEUP |
Event.ONMOUSEOVER |
Event.ONMOUSEOUT |
Event.ONKEYDOWN);
Event.ONMOUSEUP |
Event.ONMOUSEOVER |
Event.ONMOUSEOUT |
Event.ONKEYDOWN);
}

protected abstract AbstractTab createTab(TabData tabData);
Expand All @@ -84,7 +84,7 @@ protected Element createSeparator() {

@Override
public void addTab(final TabData tabData) {
if (tabs.size() == 0) {
if (tabs.isEmpty()) {
keyboardSelectedTab = tabData;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public void removeTab(final TabData tabData) {
tabs.remove(tabData);
tabPriority.remove(tabData);

if (tabPriority.size() > 0) {
if (!tabPriority.isEmpty()) {
keyboardSelectedTab = tabPriority.get(0);
fireTabSelection(tabPriority.get(0));
onResize();
Expand Down Expand Up @@ -150,7 +150,7 @@ private void updateTabCount() {

@Override
public void selectTab(final TabData tabData) {
if (!EqualsUtil.isEquals(tabData, selectedTab)) {
if (!Objects.equals(tabData, selectedTab)) {
selectedTab = tabData;
keyboardSelectedTab = tabData;
if (selectedTab != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import stroom.svg.client.IconColour;
import stroom.svg.shared.SvgImage;
import stroom.task.client.TaskMonitor;
import stroom.util.shared.GwtNullSafe;
import stroom.widget.spinner.client.SpinnerSmall;
import stroom.widget.util.client.SvgImageUtil;

Expand All @@ -37,7 +38,11 @@ public class CurveTab extends AbstractTab {
private final SpinnerSmall spinnerSmall;
private final boolean allowClose;

public CurveTab(final SvgImage icon, final IconColour iconColour, final String text, final boolean allowClose) {
public CurveTab(final SvgImage icon,
final IconColour iconColour,
final String text,
final String tooltip,
final boolean allowClose) {
this.allowClose = allowClose;

element = DOM.createDiv();
Expand All @@ -46,10 +51,12 @@ public CurveTab(final SvgImage icon, final IconColour iconColour, final String t
final Element background = DOM.createDiv();
background.setClassName("curveTab-background");
element.appendChild(background);
final String title = GwtNullSafe.requireNonNullElse(tooltip, text);

if (icon != null) {
final Element iconElement = DOM.createDiv();
iconElement.addClassName("curveTab-icon " + iconColour.getClassName());
iconElement.setTitle(title);
SvgImageUtil.setSvgAsInnerHtml(iconElement, icon);
element.appendChild(iconElement);
}
Expand All @@ -63,7 +70,7 @@ public CurveTab(final SvgImage icon, final IconColour iconColour, final String t
label.setInnerText(text);
}

label.setTitle(text);
label.setTitle(title);
element.appendChild(label);

close = DOM.createDiv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ protected void onDetach() {

@Override
protected AbstractTab createTab(final TabData tabData) {
return new CurveTab(tabData.getIcon(), tabData.getIconColour(), tabData.getLabel(), tabData.isCloseable());
return new CurveTab(
tabData.getIcon(),
tabData.getIconColour(),
tabData.getLabel(),
tabData.getTooltip().orElse(null),
tabData.isCloseable());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
import stroom.task.client.SimpleTask;
import stroom.task.client.Task;
import stroom.task.client.TaskMonitor;
import stroom.util.shared.GwtNullSafe;
import stroom.widget.button.client.ButtonPanel;
import stroom.widget.button.client.ButtonView;
import stroom.widget.button.client.SvgButton;
import stroom.widget.tab.client.presenter.TabData;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.EventBus;
Expand All @@ -49,6 +47,7 @@

import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

public abstract class DocumentEditTabPresenter<V extends LinkTabPanelView, D>
Expand Down Expand Up @@ -89,12 +88,12 @@ public DocumentEditTabPresenter(final EventBus eventBus,
addEntry(commonTabsMap, CommonDocLinkTab.PERMISSIONS, this::getPermissionsTab);
}

private void addEntry(final Map<CommonDocLinkTab, TabData> map,
private void addEntry(final Map<CommonDocLinkTab, TabData> commonTabsMap,
final CommonDocLinkTab commonDocLinkTab,
final Supplier<TabData> tabDataSupplier) {
final TabData tabData = tabDataSupplier.get();
if (tabData != null) {
map.put(commonDocLinkTab, tabData);
commonTabsMap.put(commonDocLinkTab, tabData);
}
}

Expand Down Expand Up @@ -152,7 +151,7 @@ public void selectCommonTab(final OpenDocumentEvent.CommonDocLinkTab commonDocLi
}

public void selectTab(final TabData tab) {
GWT.log("docRef: " + docRef + ", selecting tab " + GwtNullSafe.get(tab, TabData::getLabel));
// GWT.log("docRef: " + docRef + ", selecting tab " + GwtNullSafe.get(tab, TabData::getLabel));
final TaskMonitor taskMonitor = createTaskMonitor();
final Task task = new SimpleTask("Selecting tab");
taskMonitor.onStart(task);
Expand Down Expand Up @@ -248,6 +247,16 @@ public SvgImage getIcon() {
return DocumentTypeImages.get(getType());
}

@Override
public Optional<String> getTooltip() {
final String type = docRef.getType();
if (type != null) {
return Optional.of(type + " - " + docRef.getName());
} else {
return Optional.of(docRef.getName());
}
}

@Override
public void onDirty(final boolean dirty) {
super.onDirty(dirty);
Expand Down
Loading

0 comments on commit 96af0b3

Please sign in to comment.