Skip to content

Commit a1b491c

Browse files
committed
gh-5042 Allow the import of deleted proc filters
1 parent 25e2b3b commit a1b491c

File tree

26 files changed

+663
-150
lines changed

26 files changed

+663
-150
lines changed

stroom-core-client/src/main/java/stroom/importexport/client/presenter/ImportConfigConfirmPresenter.java

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
import stroom.importexport.shared.ImportSettings;
3636
import stroom.importexport.shared.ImportSettings.ImportMode;
3737
import stroom.importexport.shared.ImportState;
38+
import stroom.importexport.shared.ImportState.State;
3839
import stroom.security.shared.DocumentPermission;
3940
import stroom.svg.client.Preset;
4041
import stroom.svg.client.SvgPresets;
4142
import stroom.util.shared.Message;
43+
import stroom.util.shared.NullSafe;
4244
import stroom.util.shared.ResourceKey;
4345
import stroom.util.shared.Severity;
4446
import stroom.widget.popup.client.event.HidePopupRequestEvent;
@@ -67,7 +69,10 @@
6769

6870
import java.util.ArrayList;
6971
import java.util.List;
72+
import java.util.Map;
7073
import java.util.function.Consumer;
74+
import java.util.function.Function;
75+
import java.util.stream.Collectors;
7176

7277
public class ImportConfigConfirmPresenter extends
7378
MyPresenter<ImportConfigConfirmPresenter.ImportConfigConfirmView,
@@ -158,7 +163,9 @@ public void onConfirmImport(final ImportConfigConfirmEvent event) {
158163

159164
@Override
160165
protected void revealInParent() {
161-
final PopupSize popupSize = PopupSize.resizable(800, 800, 380, 480);
166+
final PopupSize popupSize = PopupSize.resizable(
167+
1200, 800,
168+
380, 480);
162169
ShowPopupEvent.builder(this)
163170
.popupType(PopupType.OK_CANCEL_DIALOG)
164171
.popupSize(popupSize)
@@ -226,26 +233,75 @@ public void onHideRequest(final HidePopupRequestEvent e) {
226233
AlertEvent.fireWarn(
227234
ImportConfigConfirmPresenter.this,
228235
"No items are selected for import", e::reset);
229-
} else if (warnings) {
230-
ConfirmEvent.fireWarn(ImportConfigConfirmPresenter.this,
231-
"There are warnings in the items selected. Are you sure you want to import?.",
232-
result -> {
233-
if (result) {
234-
importData(e);
235-
} else {
236-
// Re-enable popup buttons.
237-
e.reset();
238-
}
239-
});
240-
241236
} else {
242-
importData(e);
237+
final String ownedDocumentsMsg = checkOwnedDocuments();
238+
if (NullSafe.isNonEmptyString(ownedDocumentsMsg)) {
239+
AlertEvent.fireWarn(ImportConfigConfirmPresenter.this, ownedDocumentsMsg, e::reset);
240+
} else if (warnings) {
241+
ConfirmEvent.fireWarn(ImportConfigConfirmPresenter.this,
242+
"There are warnings in the items selected. Are you sure you want to import?.",
243+
result -> {
244+
if (result) {
245+
importData(e);
246+
} else {
247+
// Re-enable popup buttons.
248+
e.reset();
249+
}
250+
});
251+
} else {
252+
importData(e);
253+
}
243254
}
244255
} else {
245256
abortImport(e);
246257
}
247258
}
248259

260+
private String checkOwnedDocuments() {
261+
//noinspection SimplifyStreamApiCallChains // Cos GWT
262+
final List<ImportState> selectedAndOwned = NullSafe.stream(confirmList)
263+
.filter(ImportState::isAction)
264+
.filter(importState -> importState.getState() != State.IGNORE)
265+
.filter(importState -> importState.getOwnerDocRef() != null)
266+
.collect(Collectors.toList());
267+
268+
if (!selectedAndOwned.isEmpty()) {
269+
final Map<DocRef, ImportState> selectedDocRefToStateMap = NullSafe.stream(confirmList)
270+
.collect(Collectors.toMap(ImportState::getDocRef, Function.identity()));
271+
272+
for (final ImportState importState : selectedAndOwned) {
273+
final DocRef ownerDocRef = importState.getOwnerDocRef();
274+
final ImportState ownerImportState = selectedDocRefToStateMap.get(ownerDocRef);
275+
276+
final DocRef ownedDocRef = importState.getDocRef();
277+
if (ownerImportState == null
278+
|| (!ownerImportState.isAction()
279+
&& (ownerImportState.getState() == State.NEW || ownerImportState.getState() == State.IGNORE))) {
280+
return "You have selected " + docRefToString(ownedDocRef)
281+
+ " without selecting its parent document " + docRefToString(ownerDocRef)
282+
+ ". You must also select its parent.";
283+
} else if (ownerImportState.getSeverity().greaterThanOrEqual(Severity.ERROR)) {
284+
return "You have selected " + docRefToString(ownedDocRef)
285+
+ " but its parent document " + docRefToString(ownerDocRef)
286+
+ " cannot be imported due to an error. You cannot import this document.";
287+
}
288+
}
289+
}
290+
return null;
291+
}
292+
293+
private String docRefToString(final DocRef docRef) {
294+
if (docRef == null) {
295+
return "";
296+
} else {
297+
if (docRef.getName() != null) {
298+
return docRef.getType() + " '" + docRef.getName() + "' (" + docRef.getUuid() + ")";
299+
} else {
300+
return docRef.getType() + " " + docRef.getUuid();
301+
}
302+
}
303+
}
304+
249305
private void addColumns() {
250306
addSelectedColumn();
251307
addInfoColumn();
@@ -445,13 +501,16 @@ public void abortImport(final HidePopupRequestEvent e) {
445501

446502
restFactory
447503
.create(CONTENT_RESOURCE)
448-
.method(res -> res.importContent(new ImportConfigRequest(resourceKey,
449-
importSettingsBuilder.build(),
450-
new ArrayList<>())))
451-
.onSuccess(result2 -> AlertEvent.fireWarn(ImportConfigConfirmPresenter.this,
504+
.method(res -> {
505+
res.abortImport(resourceKey);
506+
return null;
507+
})
508+
.onSuccess(ignored -> AlertEvent.fireWarn(
509+
ImportConfigConfirmPresenter.this,
452510
"Import Aborted",
453511
e::hide))
454-
.onFailure(caught -> AlertEvent.fireError(ImportConfigConfirmPresenter.this,
512+
.onFailure(caught -> AlertEvent.fireError(
513+
ImportConfigConfirmPresenter.this,
455514
caught.getMessage(),
456515
e::hide))
457516
.taskMonitorFactory(this)

stroom-core-client/src/main/java/stroom/processor/client/presenter/ProcessorPresenter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,22 @@ private void removeProcessor() {
429429
.filter(s -> s instanceof ProcessorFilterRow)
430430
.map(s -> (ProcessorFilterRow) s)
431431
.collect(Collectors.toList());
432-
if (rows.size() > 0) {
432+
if (!rows.isEmpty()) {
433433
String message = "Are you sure you want to delete the selected filter?";
434434
if (rows.size() > 1) {
435435
message = "Are you sure you want to delete the selected filters?";
436436
}
437437
ConfirmEvent.fire(this, message, result -> {
438438
if (result) {
439-
final CountDownAndRun countDownAndRun = new CountDownAndRun(rows.size(), () ->
440-
processorListPresenter.refresh());
439+
final CountDownAndRun countDownAndRun = new CountDownAndRun(
440+
rows.size(), processorListPresenter::refresh);
441441
for (final ProcessorFilterRow row : rows) {
442442
restFactory
443443
.create(PROCESSOR_FILTER_RESOURCE)
444444
.method(res -> res.delete(row.getProcessorFilter().getId()))
445445
.onSuccess(res ->
446446
countDownAndRun.countdown())
447-
.onFailure(new DefaultErrorHandler(this, () ->
448-
countDownAndRun.countdown()))
447+
.onFailure(new DefaultErrorHandler(this, countDownAndRun::countdown))
449448
.taskMonitorFactory(this)
450449
.exec();
451450
}

stroom-core-shared/src/main/java/stroom/importexport/shared/ContentResource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import stroom.util.shared.DocRefs;
2020
import stroom.util.shared.ResourceGeneration;
21+
import stroom.util.shared.ResourceKey;
2122
import stroom.util.shared.ResourcePaths;
2223
import stroom.util.shared.RestResource;
2324
import stroom.util.shared.ResultPage;
@@ -47,6 +48,14 @@ public interface ContentResource extends RestResource, DirectRestService {
4748
ImportConfigResponse importContent(
4849
@NotNull @Parameter(description = "request", required = true) ImportConfigRequest request);
4950

51+
@POST
52+
@Path("abortImport")
53+
@Operation(
54+
summary = "Abort Import",
55+
operationId = "abortImport")
56+
void abortImport(
57+
@NotNull @Parameter(description = "request", required = true) ResourceKey resourceKey);
58+
5059
@POST
5160
@Path("export")
5261
@Operation(

stroom-core-shared/src/main/java/stroom/importexport/shared/ImportSettings.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static boolean ok(final ImportSettings importSettings,
7474
}
7575

7676
return ImportMode.IGNORE_CONFIRMATION.equals(importSettings.getImportMode())
77-
|| (ImportMode.ACTION_CONFIRMATION.equals(importSettings.getImportMode()) && importState.isAction());
77+
|| (ImportMode.ACTION_CONFIRMATION.equals(importSettings.getImportMode()) && importState.isAction());
7878
}
7979

8080
public static Builder builder() {
@@ -108,15 +108,16 @@ public boolean equals(final Object o) {
108108
}
109109
final ImportSettings that = (ImportSettings) o;
110110
return enableFilters == that.enableFilters &&
111-
useImportNames == that.useImportNames &&
112-
useImportFolders == that.useImportFolders &&
113-
importMode == that.importMode &&
114-
Objects.equals(enableFiltersFromTime, that.enableFiltersFromTime) &&
115-
Objects.equals(rootDocRef, that.rootDocRef);
111+
useImportNames == that.useImportNames &&
112+
useImportFolders == that.useImportFolders &&
113+
importMode == that.importMode &&
114+
Objects.equals(enableFiltersFromTime, that.enableFiltersFromTime) &&
115+
Objects.equals(rootDocRef, that.rootDocRef);
116116
}
117117

118118
/**
119119
* toString to aid debugging import
120+
*
120121
* @return Meaningful string describing the object.
121122
*/
122123
@Override
@@ -141,14 +142,20 @@ public int hashCode() {
141142
rootDocRef);
142143
}
143144

145+
146+
// --------------------------------------------------------------------------------
147+
148+
144149
public enum ImportMode {
145150
CREATE_CONFIRMATION,
146151
ACTION_CONFIRMATION,
147152
IGNORE_CONFIRMATION
148153
}
149154

155+
150156
// --------------------------------------------------------------------------------
151157

158+
152159
public static class Builder {
153160

154161
private ImportMode importMode;

stroom-core-shared/src/main/java/stroom/importexport/shared/ImportState.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class ImportState {
5050
private final List<String> updatedFieldList;
5151
@JsonProperty
5252
private State state;
53+
@JsonProperty
54+
private DocRef ownerDocRef;
5355

5456
@JsonCreator
5557
public ImportState(@JsonProperty("docRef") final DocRef docRef,
@@ -58,14 +60,16 @@ public ImportState(@JsonProperty("docRef") final DocRef docRef,
5860
@JsonProperty("action") final boolean action,
5961
@JsonProperty("messageList") final List<Message> messageList,
6062
@JsonProperty("updatedFieldList") final List<String> updatedFieldList,
61-
@JsonProperty("state") final State state) {
63+
@JsonProperty("state") final State state,
64+
@JsonProperty("ownerDocRef") final DocRef ownerDocRef) {
6265
this.docRef = docRef;
6366
this.sourcePath = sourcePath;
6467
this.destPath = destPath;
6568
this.action = action;
6669
this.messageList = messageList;
6770
this.updatedFieldList = updatedFieldList;
6871
this.state = state;
72+
this.ownerDocRef = ownerDocRef;
6973
}
7074

7175
public ImportState(final DocRef docRef, final String sourcePath) {
@@ -95,6 +99,25 @@ public void setDestPath(final String destPath) {
9599
this.destPath = destPath;
96100
}
97101

102+
/**
103+
* @return The owner document, if this is a non-explorer document that belongs to another document,
104+
* e.g. a processor filter belongs to a Pipeline.
105+
*/
106+
public DocRef getOwnerDocRef() {
107+
return ownerDocRef;
108+
}
109+
110+
/**
111+
* @param ownerDocRef The owner document, if this is a non-explorer document that belongs to another document,
112+
* e.g. a processor filter belongs to a Pipeline.
113+
*/
114+
public void setOwnerDocRef(final DocRef ownerDocRef) {
115+
this.ownerDocRef = ownerDocRef;
116+
}
117+
118+
/**
119+
* @return True if this item has been selected for import by the user.
120+
*/
98121
public boolean isAction() {
99122
return action;
100123
}
@@ -158,11 +181,16 @@ public String toString() {
158181
return docRef.toString();
159182
}
160183

184+
185+
// --------------------------------------------------------------------------------
186+
187+
161188
public enum State implements HasDisplayValue {
162189
NEW("New"),
163190
UPDATE("Update"),
164191
EQUAL("Equal"),
165-
IGNORE("Ignore");
192+
IGNORE("Ignore"),
193+
;
166194

167195
private final String displayValue;
168196

stroom-core-shared/src/main/java/stroom/processor/shared/Processor.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,17 @@ public void setDeleted(final boolean deleted) {
228228
@Override
229229
public String toString() {
230230
return "Processor{" +
231-
"id=" + id +
232-
", version=" + version +
233-
", createTimeMs=" + createTimeMs +
234-
", createUser='" + createUser + '\'' +
235-
", updateTimeMs=" + updateTimeMs +
236-
", updateUser='" + updateUser + '\'' +
237-
", processorType='" + processorType + '\'' +
238-
", pipelineUuid='" + pipelineUuid + '\'' +
239-
", enabled=" + enabled +
240-
", deleted=" + deleted +
241-
'}';
231+
"id=" + id +
232+
", version=" + version +
233+
", createTimeMs=" + createTimeMs +
234+
", createUser='" + createUser + '\'' +
235+
", updateTimeMs=" + updateTimeMs +
236+
", updateUser='" + updateUser + '\'' +
237+
", processorType='" + processorType + '\'' +
238+
", pipelineUuid='" + pipelineUuid + '\'' +
239+
", enabled=" + enabled +
240+
", deleted=" + deleted +
241+
'}';
242242
}
243243

244244
@Override
@@ -257,4 +257,20 @@ public boolean equals(final Object o) {
257257
public int hashCode() {
258258
return Objects.hash(id);
259259
}
260+
261+
/**
262+
* @return A new {@link DocRef} for this document's type with the supplied uuid.
263+
*/
264+
public static DocRef getDocRef(final String uuid) {
265+
return DocRef.builder(ENTITY_TYPE)
266+
.uuid(uuid)
267+
.build();
268+
}
269+
270+
/**
271+
* @return A new builder for creating a {@link DocRef} for this document's type.
272+
*/
273+
public static DocRef.TypedBuilder buildDocRef() {
274+
return DocRef.builder(ENTITY_TYPE);
275+
}
260276
}

0 commit comments

Comments
 (0)