Skip to content

Commit

Permalink
Merge pull request #4170 from gchq/gh-4035-pipe-filter-ownership
Browse files Browse the repository at this point in the history
PR for #4035 - Pipeline Filter, Change ownership, nasty popup
  • Loading branch information
at055612 authored Mar 25, 2024
2 parents e84834c + bc5c360 commit f2655f8
Show file tree
Hide file tree
Showing 28 changed files with 444 additions and 177 deletions.
11 changes: 7 additions & 4 deletions stroom-core-shared/src/main/java/stroom/docstore/shared/Doc.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package stroom.docstore.shared;

import stroom.docref.DocRef;
import stroom.docref.HasType;
import stroom.docref.HasUuid;
import stroom.util.shared.HasAuditInfo;
import stroom.util.shared.Document;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -40,7 +38,8 @@
"createUser",
"updateUser"})
@JsonInclude(Include.NON_NULL)
public abstract class Doc implements HasAuditInfo, HasUuid, HasType {
// TODO Ought to be renamed AbstractDoc, job for master branch
public abstract class Doc implements Document {

@JsonProperty
private String type;
Expand Down Expand Up @@ -201,6 +200,10 @@ public String toString() {
'}';
}


// --------------------------------------------------------------------------------


public abstract static class AbstractBuilder<T extends Doc, B extends AbstractBuilder<T, ?>> {

protected String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public enum DocumentTypeGroup {
"Documents that are used as configuration for other documents."),
SYSTEM(100,
"System",
""),
INTERNAL(999,
"Internal",
"");

private final int priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ public String toString() {
'}';
}

/**
* @return A {@link DocRef} with uuid and type.
*/
public DocRef asDocRef() {
// Doesn't really have a name
return DocRef.builder()
Expand All @@ -446,6 +449,13 @@ public DocRef asDocRef() {
.build();
}

/**
* @return A new builder for creating a {@link DocRef} for this document's type.
*/
public static DocRef.TypedBuilder buildDocRef() {
return DocRef.builder(ENTITY_TYPE);
}

public Builder copy() {
return new Builder(this);
}
Expand All @@ -454,6 +464,10 @@ public static Builder builder() {
return new Builder();
}


// --------------------------------------------------------------------------------


public static class Builder {

private Integer id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package stroom.processor.shared;

import stroom.util.shared.Document;

/**
* A wrapper for a {@link ProcessorFilter} that has a name (which {@link ProcessorFilter}
* doesn't.
*/
public class ProcessorFilterDoc implements Document {

public static final String DOCUMENT_TYPE = ProcessorFilter.ENTITY_TYPE;

private final ProcessorFilter processorFilter;
private String name = null;

public ProcessorFilterDoc(final ProcessorFilter processorFilter) {
this.processorFilter = processorFilter;
}

public ProcessorFilterDoc(final ProcessorFilter processorFilter,
final String name) {
this.processorFilter = processorFilter;
this.name = name;
}

public ProcessorFilter getProcessorFilter() {
return processorFilter;
}

@Override
public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

@Override
public String getType() {
return ProcessorFilter.ENTITY_TYPE;
}

@Override
public String getUuid() {
return processorFilter.getUuid();
}

@Override
public Long getCreateTimeMs() {
return processorFilter.getCreateTimeMs();
}

@Override
public void setCreateTimeMs(final Long createTimeMs) {
processorFilter.setCreateTimeMs(createTimeMs);
}

@Override
public String getCreateUser() {
return processorFilter.getCreateUser();
}

@Override
public void setCreateUser(final String createUser) {
processorFilter.setCreateUser(createUser);
}

@Override
public Long getUpdateTimeMs() {
return processorFilter.getUpdateTimeMs();
}

@Override
public void setUpdateTimeMs(final Long updateTimeMs) {
processorFilter.setUpdateTimeMs(updateTimeMs);
}

@Override
public String getUpdateUser() {
return processorFilter.getUpdateUser();
}

@Override
public void setUpdateUser(final String updateUser) {
processorFilter.setUpdateUser(updateUser);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static Builder builder() {
return new Builder();
}


// --------------------------------------------------------------------------------


public static class Builder {

private DocRef docRef;
Expand Down
12 changes: 12 additions & 0 deletions stroom-docref/src/main/java/stroom/docref/DocRefHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package stroom.docref;

public interface DocRefHandler extends HasFindDocsByName {

/**
* Retrieve the audit information for a particular doc ref
*
* @param uuid The UUID to return the information for
* @return The Audit information about the given DocRef.
*/
DocRefInfo info(String uuid);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package stroom.docref;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand All @@ -18,7 +17,7 @@ public interface HasFindDocsByName {
default List<DocRef> findByName(final String name) {
// GWT so no List.of()
return name != null
? findByNames(Arrays.asList(name), false)
? findByNames(Collections.singletonList(name), false)
: Collections.emptyList();
}

Expand All @@ -29,7 +28,7 @@ default List<DocRef> findByName(final String name) {
default List<DocRef> findByName(final String name, final boolean allowWildCards) {
// GWT so no List.of()
return name != null
? findByNames(Arrays.asList(name), allowWildCards)
? findByNames(Collections.singletonList(name), allowWildCards)
: Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,45 @@


import stroom.docref.DocRef;
import stroom.docref.DocRefInfo;
import stroom.util.shared.Document;

public interface DocumentActionHandler<D> {
import java.util.Objects;

public interface DocumentActionHandler<D extends Document> {

D readDocument(DocRef docRef);

D writeDocument(D document);

/**
* @return The {@link DocRef} type that this handler supports.
*/
String getType();

/**
* Retrieve the audit information for a particular doc ref
*
* @param uuid The UUID to return the information for
* @return The Audit information about the given DocRef.
*/
DocRefInfo info(String uuid);

static DocRefInfo getDocRefInfo(final Document document) {

Objects.requireNonNull(document);

return DocRefInfo
.builder()
.docRef(DocRef.builder()
.type(document.getType())
.uuid(document.getUuid())
.name(document.getName())
.build())
.createTime(document.getCreateTimeMs())
.createUser(document.getCreateUser())
.updateTime(document.getUpdateTimeMs())
.updateUser(document.getUpdateUser())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package stroom.docstore.api;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Stream;

@Singleton
public class DocumentActionHandlers {

private final Map<DocumentType, DocumentActionHandler> handlersMap;

@Inject
public DocumentActionHandlers(final Map<DocumentType, DocumentActionHandler> handlersMap) {
this.handlersMap = handlersMap;
}

public DocumentActionHandler<?> getHandler(final String type) {
return handlersMap.get(new DocumentType(type));
}

public void forEach(Consumer<DocumentActionHandler> consumer) {
handlersMap.values()
.stream()
.filter(Objects::nonNull)
.forEach(consumer);
}

public Stream<DocumentActionHandler> stream() {
return handlersMap.values()
.stream()
.filter(Objects::nonNull);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import stroom.explorer.api.ExplorerActionHandler;
import stroom.importexport.api.ImportExportActionHandler;
import stroom.util.shared.Document;

public interface DocumentStore<D>
public interface DocumentStore<D extends Document>
extends ExplorerActionHandler, ImportExportActionHandler, DocumentActionHandler<D> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public D writeDocument(final D document) {
return update(document);
}

@Override
public String getType() {
return type;
}

////////////////////////////////////////////////////////////////////////
// END OF DocumentActionHandler
////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public interface DocRefInfoService extends DocRefDecorator {
* If allowWildCards is true '*' can be used to denote a 0-many char wild card.
* Names may not be unique for a given type, so a non-wild carded nameFilter may return
* more than one {@link DocRef}.
* @param type The {@link DocRef} type. Mandatory.
*
* @param type Can be null. If null all handlers will be searched
* @param nameFilter The name of the {@link DocRef}s to filter by. If allowWildCards is true
* find all matching else find those with an exact case-sensitive name match.
* find all matching else find those with an exact case-sensitive name match.
*/
List<DocRef> findByName(final String type,
final String nameFilter,
Expand All @@ -40,9 +41,10 @@ List<DocRef> findByName(final String type,
* Names may not be unique for a given type, so a non-wild carded nameFilter may return
* more than one {@link DocRef}. Applies all nameFilters using an OR, i.e. returns all docRefs
* associated with any of the passed nameFilters.
* @param type The {@link DocRef} type. Mandatory.
*
* @param type The {@link DocRef} type. Mandatory.
* @param nameFilters The names of the {@link DocRef}s to filter by. If allowWildCards is true
* find all matching else find those with an exact case-sensitive name match.
* find all matching else find those with an exact case-sensitive name match.
*/
List<DocRef> findByNames(final String type,
final List<String> nameFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* This interface is intended to be used by the explorer for document store operations that need not know much about the
* documents that are stored just how to create, copy, move and delete them.
*/
// TODO could move HasFindDocsByName/HasFindDocsByContent into DocumentActionHandler
// as they are not specific to docs in the explorer
public interface ExplorerActionHandler
extends HasDocumentType, HasDependencies, HasFindDocsByName, HasFindDocsByContent {

Expand All @@ -44,7 +46,7 @@ public interface ExplorerActionHandler
* Copy an existing document identified by uuid, to the specified location.
*
* @param docRef The docref of the document you want to copy.
* @param name The suggested name of the copied document.
* @param name The suggested name of the copied document.
* @param makeNameUnique Determine if the copied document should be forced to have a unique name.
* @param existingNames Names of documents that already exist in the destination folder.
* @return A doc ref for the new document copy.
Expand Down
Loading

0 comments on commit f2655f8

Please sign in to comment.