From a18dea7b81096f980e796cd27da78a98952cc053 Mon Sep 17 00:00:00 2001 From: at055612 <22818309+at055612@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:51:46 +0000 Subject: [PATCH 1/2] gh-4035 Add info to DocumentActionHandler Change DocRefInfoCache to get its info from DocumentActionHandler so it includes non-explorer documents --- .../main/java/stroom/docstore/shared/Doc.java | 11 +- .../explorer/shared/DocumentTypeGroup.java | 3 + .../processor/shared/ProcessorFilter.java | 14 ++ .../processor/shared/ProcessorFilterDoc.java | 88 ++++++++ .../stroom/docref/DocContentHighlights.java | 4 + .../java/stroom/docref/DocRefHandler.java | 12 + .../java/stroom/docref/HasFindDocsByName.java | 5 +- .../docstore/api/DocumentActionHandler.java | 37 +++- .../docstore/api/DocumentActionHandlers.java | 37 ++++ .../stroom/docstore/api/DocumentStore.java | 3 +- .../java/stroom/docstore/impl/StoreImpl.java | 5 + .../docrefinfo/api/DocRefInfoService.java | 10 +- .../explorer/api/ExplorerActionHandler.java | 4 +- .../stroom/explorer/impl/DocRefInfoCache.java | 32 ++- .../explorer/impl/DocRefInfoServiceImpl.java | 12 +- .../explorer/impl/ExplorerActionHandlers.java | 12 + .../explorer/impl/TestDocRefInfoCache.java | 205 +++++++++++------- .../api/NonExplorerDocRefProvider.java | 9 + .../processor/api/ProcessorFilterService.java | 4 +- .../impl/db/ProcessorFilterDaoImpl.java | 53 ++--- .../impl/MockProcessorFilterDao.java | 16 +- .../impl/MockProcessorFilterService.java | 5 + .../processor/impl/ProcessorFilterDao.java | 3 + ...rocessorFilterImportExportHandlerImpl.java | 113 +++++++--- .../impl/ProcessorFilterServiceImpl.java | 6 + .../processor/impl/ProcessorModule.java | 5 + .../java/stroom/util/shared/Document.java | 11 +- .../stroom/util/shared/HasFetchByUuid.java | 8 + 28 files changed, 550 insertions(+), 177 deletions(-) create mode 100644 stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilterDoc.java create mode 100644 stroom-docref/src/main/java/stroom/docref/DocRefHandler.java create mode 100644 stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandlers.java create mode 100644 stroom-util-shared/src/main/java/stroom/util/shared/HasFetchByUuid.java diff --git a/stroom-core-shared/src/main/java/stroom/docstore/shared/Doc.java b/stroom-core-shared/src/main/java/stroom/docstore/shared/Doc.java index e5b16129e51..3ac00948893 100644 --- a/stroom-core-shared/src/main/java/stroom/docstore/shared/Doc.java +++ b/stroom-core-shared/src/main/java/stroom/docstore/shared/Doc.java @@ -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; @@ -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; @@ -201,6 +200,10 @@ public String toString() { '}'; } + + // -------------------------------------------------------------------------------- + + public abstract static class AbstractBuilder> { protected String type; diff --git a/stroom-core-shared/src/main/java/stroom/explorer/shared/DocumentTypeGroup.java b/stroom-core-shared/src/main/java/stroom/explorer/shared/DocumentTypeGroup.java index 8defcd1a5fb..a053be74c2e 100644 --- a/stroom-core-shared/src/main/java/stroom/explorer/shared/DocumentTypeGroup.java +++ b/stroom-core-shared/src/main/java/stroom/explorer/shared/DocumentTypeGroup.java @@ -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; diff --git a/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilter.java b/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilter.java index 284cfff6d22..05ffdf2d956 100644 --- a/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilter.java +++ b/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilter.java @@ -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() @@ -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); } @@ -454,6 +464,10 @@ public static Builder builder() { return new Builder(); } + + // -------------------------------------------------------------------------------- + + public static class Builder { private Integer id; diff --git a/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilterDoc.java b/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilterDoc.java new file mode 100644 index 00000000000..4e4cbfdfa6b --- /dev/null +++ b/stroom-core-shared/src/main/java/stroom/processor/shared/ProcessorFilterDoc.java @@ -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); + } +} diff --git a/stroom-docref/src/main/java/stroom/docref/DocContentHighlights.java b/stroom-docref/src/main/java/stroom/docref/DocContentHighlights.java index 2af63b278b5..6762584f321 100644 --- a/stroom-docref/src/main/java/stroom/docref/DocContentHighlights.java +++ b/stroom-docref/src/main/java/stroom/docref/DocContentHighlights.java @@ -67,6 +67,10 @@ public static Builder builder() { return new Builder(); } + + // -------------------------------------------------------------------------------- + + public static class Builder { private DocRef docRef; diff --git a/stroom-docref/src/main/java/stroom/docref/DocRefHandler.java b/stroom-docref/src/main/java/stroom/docref/DocRefHandler.java new file mode 100644 index 00000000000..846dcccc340 --- /dev/null +++ b/stroom-docref/src/main/java/stroom/docref/DocRefHandler.java @@ -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); +} diff --git a/stroom-docref/src/main/java/stroom/docref/HasFindDocsByName.java b/stroom-docref/src/main/java/stroom/docref/HasFindDocsByName.java index 4b84c2a8c55..7eb1037b305 100644 --- a/stroom-docref/src/main/java/stroom/docref/HasFindDocsByName.java +++ b/stroom-docref/src/main/java/stroom/docref/HasFindDocsByName.java @@ -1,6 +1,5 @@ package stroom.docref; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -18,7 +17,7 @@ public interface HasFindDocsByName { default List findByName(final String name) { // GWT so no List.of() return name != null - ? findByNames(Arrays.asList(name), false) + ? findByNames(Collections.singletonList(name), false) : Collections.emptyList(); } @@ -29,7 +28,7 @@ default List findByName(final String name) { default List 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(); } diff --git a/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandler.java b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandler.java index 0b76ef82f11..704d6531b75 100644 --- a/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandler.java +++ b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandler.java @@ -19,10 +19,45 @@ import stroom.docref.DocRef; +import stroom.docref.DocRefInfo; +import stroom.util.shared.Document; -public interface DocumentActionHandler { +import java.util.Objects; + +public interface DocumentActionHandler { 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(); + } } diff --git a/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandlers.java b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandlers.java new file mode 100644 index 00000000000..5a8bf1a5fb5 --- /dev/null +++ b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentActionHandlers.java @@ -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 handlersMap; + + @Inject + public DocumentActionHandlers(final Map handlersMap) { + this.handlersMap = handlersMap; + } + + public DocumentActionHandler getHandler(final String type) { + return handlersMap.get(new DocumentType(type)); + } + + public void forEach(Consumer consumer) { + handlersMap.values() + .stream() + .filter(Objects::nonNull) + .forEach(consumer); + } + + public Stream stream() { + return handlersMap.values() + .stream() + .filter(Objects::nonNull); + } +} diff --git a/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentStore.java b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentStore.java index c0c346f546f..c440abb72fb 100644 --- a/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentStore.java +++ b/stroom-docstore/stroom-docstore-api/src/main/java/stroom/docstore/api/DocumentStore.java @@ -19,8 +19,9 @@ import stroom.explorer.api.ExplorerActionHandler; import stroom.importexport.api.ImportExportActionHandler; +import stroom.util.shared.Document; -public interface DocumentStore +public interface DocumentStore extends ExplorerActionHandler, ImportExportActionHandler, DocumentActionHandler { } diff --git a/stroom-docstore/stroom-docstore-impl/src/main/java/stroom/docstore/impl/StoreImpl.java b/stroom-docstore/stroom-docstore-impl/src/main/java/stroom/docstore/impl/StoreImpl.java index f797cd258fa..d63ea200f31 100644 --- a/stroom-docstore/stroom-docstore-impl/src/main/java/stroom/docstore/impl/StoreImpl.java +++ b/stroom-docstore/stroom-docstore-impl/src/main/java/stroom/docstore/impl/StoreImpl.java @@ -309,6 +309,11 @@ public D writeDocument(final D document) { return update(document); } + @Override + public String getType() { + return type; + } + //////////////////////////////////////////////////////////////////////// // END OF DocumentActionHandler //////////////////////////////////////////////////////////////////////// diff --git a/stroom-explorer/stroom-docrefinfo-api/src/main/java/stroom/docrefinfo/api/DocRefInfoService.java b/stroom-explorer/stroom-docrefinfo-api/src/main/java/stroom/docrefinfo/api/DocRefInfoService.java index ebbf3264b3b..a070c2a30b9 100644 --- a/stroom-explorer/stroom-docrefinfo-api/src/main/java/stroom/docrefinfo/api/DocRefInfoService.java +++ b/stroom-explorer/stroom-docrefinfo-api/src/main/java/stroom/docrefinfo/api/DocRefInfoService.java @@ -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 findByName(final String type, final String nameFilter, @@ -40,9 +41,10 @@ List 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 findByNames(final String type, final List nameFilters, diff --git a/stroom-explorer/stroom-explorer-api/src/main/java/stroom/explorer/api/ExplorerActionHandler.java b/stroom-explorer/stroom-explorer-api/src/main/java/stroom/explorer/api/ExplorerActionHandler.java index b285e946a26..711a3eb8ae7 100644 --- a/stroom-explorer/stroom-explorer-api/src/main/java/stroom/explorer/api/ExplorerActionHandler.java +++ b/stroom-explorer/stroom-explorer-api/src/main/java/stroom/explorer/api/ExplorerActionHandler.java @@ -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 { @@ -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. diff --git a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoCache.java b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoCache.java index 5ee7f964dd7..0b0dcfb51d3 100644 --- a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoCache.java +++ b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoCache.java @@ -20,8 +20,9 @@ import stroom.cache.api.LoadingStroomCache; import stroom.docref.DocRef; import stroom.docref.DocRefInfo; -import stroom.explorer.api.ExplorerActionHandler; -import stroom.explorer.shared.DocumentType; +import stroom.docstore.api.DocumentActionHandler; +import stroom.docstore.api.DocumentActionHandlers; +import stroom.docstore.api.DocumentNotFoundException; import stroom.security.api.SecurityContext; import stroom.util.entityevent.EntityAction; import stroom.util.entityevent.EntityEvent; @@ -50,15 +51,17 @@ class DocRefInfoCache implements EntityEvent.Handler, Clearable { // Effectively docUuid => optDocRefInfo private final LoadingStroomCache> cache; private final SecurityContext securityContext; - private final ExplorerActionHandlers explorerActionHandlers; + // Provider to avoid circular guice dependency issue + private final Provider documentActionHandlersProvider; + @Inject DocRefInfoCache(final CacheManager cacheManager, - final ExplorerActionHandlers explorerActionHandlers, final Provider explorerConfigProvider, - final SecurityContext securityContext) { + final SecurityContext securityContext, + final Provider documentActionHandlersProvider) { this.securityContext = securityContext; - this.explorerActionHandlers = explorerActionHandlers; + this.documentActionHandlersProvider = documentActionHandlersProvider; cache = cacheManager.createLoadingCache( CACHE_NAME, @@ -73,7 +76,8 @@ private Optional loadDocRefInfo(final DocRefCacheKey docRefCacheKey) docRefInfo = securityContext.asProcessingUserResult(() -> { final DocRef docRef = docRefCacheKey.getDocRef(); if (docRef.getType() != null) { - final ExplorerActionHandler handler = explorerActionHandlers.getHandler(docRef.getType()); + final DocumentActionHandler handler = documentActionHandlersProvider.get() + .getHandler(docRef.getType()); if (handler == null) { return null; } @@ -82,12 +86,15 @@ private Optional loadDocRefInfo(final DocRefCacheKey docRefCacheKey) final String uuid = docRef.getUuid(); // No type so need to check all handlers and return the one that has it. // Hopefully next time it will still be in the cache so this won't be needed - final Optional optInfo = explorerActionHandlers.getTypes() + final Optional optInfo = documentActionHandlersProvider.get() .stream() - .map(DocumentType::getType) - .map(explorerActionHandlers::getHandler) - .filter(Objects::nonNull) - .map(handler -> handler.info(uuid)) + .map(handler -> { + try { + return handler.info(uuid); + } catch (DocumentNotFoundException e) { + return null; + } + }) .filter(Objects::nonNull) .findAny(); return optInfo.orElse(null); @@ -129,6 +136,7 @@ public void onChange(final EntityEvent event) { * the doc's UUID. The UUID is unique without the type. */ private static class DocRefCacheKey { + private final DocRef docRef; private transient int hashCode = -1; diff --git a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoServiceImpl.java b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoServiceImpl.java index 818f3680e81..4d7e2ba1688 100644 --- a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoServiceImpl.java +++ b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/DocRefInfoServiceImpl.java @@ -4,7 +4,6 @@ import stroom.docref.DocRefInfo; import stroom.docrefinfo.api.DocRefInfoService; import stroom.explorer.api.ExplorerActionHandler; -import stroom.explorer.shared.DocumentType; import stroom.feed.shared.FeedDoc; import stroom.security.api.SecurityContext; import stroom.util.NullSafe; @@ -76,14 +75,11 @@ public List findByName(final String type, } else { return securityContext.asProcessingUserResult(() -> { if (type == null) { + // No type so have to search all handlers final List result = new ArrayList<>(); - for (final DocumentType documentType : explorerActionHandlers.getTypes()) { - final ExplorerActionHandler handler = - explorerActionHandlers.getHandler(documentType.toString()); - if (handler != null) { - result.addAll(handler.findByName(nameFilter, allowWildCards)); - } - } + explorerActionHandlers.forEach((handlerType, handler) -> { + result.addAll(handler.findByName(nameFilter, allowWildCards)); + }); return result; } else { final ExplorerActionHandler handler = explorerActionHandlers.getHandler(type); diff --git a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/ExplorerActionHandlers.java b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/ExplorerActionHandlers.java index fe3eaf4e0ee..f8d3ac2a80d 100644 --- a/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/ExplorerActionHandlers.java +++ b/stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/ExplorerActionHandlers.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiConsumer; @Singleton class ExplorerActionHandlers { @@ -66,6 +67,17 @@ private Handlers getHandlers() { return handlers; } + /** + * @param consumer {@link BiConsumer} of the document type and {@link ExplorerActionHandler} + */ + public void forEach(final BiConsumer consumer) { + getHandlers().allHandlers.forEach((type, handler) -> { + if (handler != null) { + consumer.accept(type, handler); + } + }); + } + // -------------------------------------------------------------------------------- diff --git a/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java b/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java index 7278ecc0920..0769804f79e 100644 --- a/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java +++ b/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java @@ -1,24 +1,20 @@ package stroom.explorer.impl; import stroom.cache.impl.CacheManagerImpl; -import stroom.docref.DocContentHighlights; -import stroom.docref.DocContentMatch; import stroom.docref.DocRef; import stroom.docref.DocRefInfo; -import stroom.docref.StringMatch; -import stroom.explorer.api.ExplorerActionHandler; -import stroom.explorer.shared.DocumentType; -import stroom.explorer.shared.DocumentTypeGroup; +import stroom.docstore.api.DocumentActionHandler; +import stroom.docstore.api.DocumentActionHandlers; +import stroom.docstore.api.DocumentType; import stroom.security.api.SecurityContext; import stroom.security.mock.MockSecurityContext; -import stroom.svg.shared.SvgImage; import stroom.util.NullSafe; +import stroom.util.shared.Document; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -53,16 +49,16 @@ class TestDocRefInfoCache { @BeforeEach void setUp() { - final ExplorerActionHandlers explorerActionHandlers = new ExplorerActionHandlers( - Set.of( - new MyExplorerActionHandler(Set.of(DOC_REF_1, DOC_REF_2)), - new MyExplorerActionHandler(Set.of(DOC_REF_3, DOC_REF_4)))); + final DocumentActionHandlers documentActionHandlers = new DocumentActionHandlers( + Map.of( + new DocumentType(TYPE_FOO), new MyDocumentActionHandler(Set.of(DOC_REF_1, DOC_REF_2)), + new DocumentType(TYPE_BAR), new MyDocumentActionHandler(Set.of(DOC_REF_3, DOC_REF_4)))); docRefInfoCache = new DocRefInfoCache( cacheManager, - explorerActionHandlers, ExplorerConfig::new, - securityContext); + securityContext, + () -> documentActionHandlers); } @Test @@ -122,12 +118,118 @@ private static DocRef stripType(final DocRef docRef) { // -------------------------------------------------------------------------------- - private static class MyExplorerActionHandler implements ExplorerActionHandler { +// private static class MyExplorerActionHandler implements ExplorerActionHandler { +// +// private final Map docRefs = new HashMap<>(); +// private final String type; +// +// private MyExplorerActionHandler(final Set docRefs) { +// docRefs.forEach(docRef -> this.docRefs.put(docRef.getUuid(), docRef)); +// final Set types = docRefs.stream() +// .map(DocRef::getType) +// .collect(Collectors.toSet()); +// if (types.size() != 1) { +// throw new IllegalArgumentException("Expecting one type only"); +// } +// this.type = types.iterator().next(); +// } +// +// @Override +// public Set listDocuments() { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public List findByNames(final List names, final boolean allowWildCards) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocRef createDocument(final String name) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocRef copyDocument(final DocRef docRef, +// final String name, +// final boolean makeNameUnique, +// final Set existingNames) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocRef moveDocument(final String uuid) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocRef renameDocument(final String uuid, final String name) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public void deleteDocument(final String uuid) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocRefInfo info(final String uuid) { +// return NullSafe.get( +// docRefs.get(uuid), +// docRef -> new DocRefInfo( +// docRef, +// System.currentTimeMillis(), +// System.currentTimeMillis(), +// "user1", +// "user1", +// null)); +// } +// +// @Override +// public DocumentType getDocumentType() { +// return new DocumentType( +// DocumentTypeGroup.CONFIGURATION, +// type, +// type, +// SvgImage.OK); +// } +// +// @Override +// public Map> getDependencies() { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public Set getDependencies(final DocRef docRef) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public void remapDependencies(final DocRef docRef, final Map remappings) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public List findByContent(final StringMatch filter) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public DocContentHighlights fetchHighlights(final DocRef docRef, +// final String extension, +// final StringMatch filter) { +// throw new UnsupportedOperationException(); +// } +// } + + // -------------------------------------------------------------------------------- + + private static class MyDocumentActionHandler implements DocumentActionHandler { private final Map docRefs = new HashMap<>(); private final String type; - private MyExplorerActionHandler(final Set docRefs) { + public MyDocumentActionHandler(final Set docRefs) { docRefs.forEach(docRef -> this.docRefs.put(docRef.getUuid(), docRef)); final Set types = docRefs.stream() .map(DocRef::getType) @@ -139,41 +241,18 @@ private MyExplorerActionHandler(final Set docRefs) { } @Override - public Set listDocuments() { - throw new UnsupportedOperationException(); - } - - @Override - public List findByNames(final List names, final boolean allowWildCards) { - throw new UnsupportedOperationException(); - } - - @Override - public DocRef createDocument(final String name) { - throw new UnsupportedOperationException(); + public Document readDocument(final DocRef docRef) { + return null; } @Override - public DocRef copyDocument(final DocRef docRef, - final String name, - final boolean makeNameUnique, - final Set existingNames) { - throw new UnsupportedOperationException(); + public Document writeDocument(final Document document) { + return null; } @Override - public DocRef moveDocument(final String uuid) { - throw new UnsupportedOperationException(); - } - - @Override - public DocRef renameDocument(final String uuid, final String name) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteDocument(final String uuid) { - throw new UnsupportedOperationException(); + public String getType() { + return type; } @Override @@ -188,41 +267,5 @@ public DocRefInfo info(final String uuid) { "user1", null)); } - - @Override - public DocumentType getDocumentType() { - return new DocumentType( - DocumentTypeGroup.CONFIGURATION, - type, - type, - SvgImage.OK); - } - - @Override - public Map> getDependencies() { - throw new UnsupportedOperationException(); - } - - @Override - public Set getDependencies(final DocRef docRef) { - throw new UnsupportedOperationException(); - } - - @Override - public void remapDependencies(final DocRef docRef, final Map remappings) { - throw new UnsupportedOperationException(); - } - - @Override - public List findByContent(final StringMatch filter) { - throw new UnsupportedOperationException(); - } - - @Override - public DocContentHighlights fetchHighlights(final DocRef docRef, - final String extension, - final StringMatch filter) { - throw new UnsupportedOperationException(); - } } } diff --git a/stroom-importexport/stroom-importexport-api/src/main/java/stroom/importexport/api/NonExplorerDocRefProvider.java b/stroom-importexport/stroom-importexport-api/src/main/java/stroom/importexport/api/NonExplorerDocRefProvider.java index 976ee9fdada..c7f03df9a15 100644 --- a/stroom-importexport/stroom-importexport-api/src/main/java/stroom/importexport/api/NonExplorerDocRefProvider.java +++ b/stroom-importexport/stroom-importexport-api/src/main/java/stroom/importexport/api/NonExplorerDocRefProvider.java @@ -18,6 +18,7 @@ package stroom.importexport.api; import stroom.docref.DocRef; +import stroom.docref.DocRefInfo; import java.util.Map; @@ -44,4 +45,12 @@ DocRef getOwnerDocument(DocRef docRef, * @return A string that represents a suitable name for this docref. */ String findNameOfDocRef(final DocRef docRef); + + /** + * 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); } diff --git a/stroom-processor/stroom-processor-api/src/main/java/stroom/processor/api/ProcessorFilterService.java b/stroom-processor/stroom-processor-api/src/main/java/stroom/processor/api/ProcessorFilterService.java index dd7f7a11b67..bd776583ee1 100644 --- a/stroom-processor/stroom-processor-api/src/main/java/stroom/processor/api/ProcessorFilterService.java +++ b/stroom-processor/stroom-processor-api/src/main/java/stroom/processor/api/ProcessorFilterService.java @@ -27,13 +27,15 @@ import stroom.processor.shared.ProcessorListRow; import stroom.processor.shared.ProcessorType; import stroom.processor.shared.ReprocessDataInfo; +import stroom.util.shared.HasFetchByUuid; import stroom.util.shared.HasIntCrud; import stroom.util.shared.ResultPage; import java.util.List; import java.util.Optional; -public interface ProcessorFilterService extends HasIntCrud { +public interface ProcessorFilterService + extends HasIntCrud, HasFetchByUuid { ProcessorFilter create(CreateProcessFilterRequest request); diff --git a/stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorFilterDaoImpl.java b/stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorFilterDaoImpl.java index 6433d998782..3c7bc680ebf 100644 --- a/stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorFilterDaoImpl.java +++ b/stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorFilterDaoImpl.java @@ -38,6 +38,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; @@ -310,17 +311,23 @@ public Optional fetch(final int id) { .on(PROCESSOR_FILTER.FK_PROCESSOR_ID.eq(PROCESSOR.ID)) .where(PROCESSOR_FILTER.ID.eq(id)) .fetchOptional()) - .map(record -> { - final Processor processor = RECORD_TO_PROCESSOR_MAPPER.apply(record); - final ProcessorFilter processorFilter = RECORD_TO_PROCESSOR_FILTER_MAPPER.apply(record); - final ProcessorFilterTracker processorFilterTracker = - RECORD_TO_PROCESSOR_FILTER_TRACKER_MAPPER.apply(record); - - processorFilter.setProcessor(processor); - processorFilter.setProcessorFilterTracker(processorFilterTracker); + .map(this::mapRecord); + } - return marshaller.unmarshal(processorFilter); - }); + @Override + public Optional fetchByUuid(final String uuid) { + Objects.requireNonNull(uuid); + return JooqUtil.contextResult(processorDbConnProvider, context -> + context + .select() + .from(PROCESSOR_FILTER) + .join(PROCESSOR_FILTER_TRACKER) + .on(PROCESSOR_FILTER.FK_PROCESSOR_FILTER_TRACKER_ID.eq(PROCESSOR_FILTER_TRACKER.ID)) + .join(PROCESSOR) + .on(PROCESSOR_FILTER.FK_PROCESSOR_ID.eq(PROCESSOR.ID)) + .where(PROCESSOR_FILTER.UUID.eq(uuid)) + .fetchOptional()) + .map(this::mapRecord); } @Override @@ -341,21 +348,17 @@ public ResultPage find(final ExpressionCriteria criteria) { .orderBy(orderFields) .limit(offset, limit) .fetch()) - .map(record -> { - final Processor processor = RECORD_TO_PROCESSOR_MAPPER.apply(record); - final ProcessorFilter processorFilter = RECORD_TO_PROCESSOR_FILTER_MAPPER.apply(record); - final ProcessorFilterTracker processorFilterTracker = - RECORD_TO_PROCESSOR_FILTER_TRACKER_MAPPER.apply(record); - - processorFilter.setProcessor(processor); - processorFilter.setProcessorFilterTracker(processorFilterTracker); - - try { - return marshaller.unmarshal(processorFilter); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); + .map(this::mapRecord); return ResultPage.createCriterialBasedList(list, criteria); } + + private ProcessorFilter mapRecord(final Record record) { + final Processor processor = RECORD_TO_PROCESSOR_MAPPER.apply(record); + final ProcessorFilter processorFilter = RECORD_TO_PROCESSOR_FILTER_MAPPER.apply(record); + final ProcessorFilterTracker processorFilterTracker = + RECORD_TO_PROCESSOR_FILTER_TRACKER_MAPPER.apply(record); + processorFilter.setProcessor(processor); + processorFilter.setProcessorFilterTracker(processorFilterTracker); + return marshaller.unmarshal(processorFilter); + } } diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterDao.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterDao.java index fd12d3eb144..4e20c4e6f10 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterDao.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterDao.java @@ -9,9 +9,10 @@ import jakarta.inject.Singleton; import java.time.Instant; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; @Singleton public class MockProcessorFilterDao implements ProcessorFilterDao, Clearable { @@ -62,14 +63,19 @@ public int physicalDeleteOldProcessorFilters(final Instant deleteThreshold) { } @Override - public ResultPage find(final ExpressionCriteria criteria) { - final List list = dao + public Optional fetchByUuid(final String uuid) { + return dao .getMap() .values() .stream() -// .filter(pf -> criteria.getPipelineUuidCriteria().getString().equals(pf.getPipelineUuid())) - .collect(Collectors.toList()); + .filter(processorFilter -> + Objects.equals(processorFilter.getUuid(), uuid)) + .findAny(); + } + @Override + public ResultPage find(final ExpressionCriteria criteria) { + final List list = new ArrayList<>(dao.getMap().values()); return ResultPage.createCriterialBasedList(list, criteria); } diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterService.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterService.java index cfee1f284f4..fb7867f0ad1 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterService.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/MockProcessorFilterService.java @@ -150,4 +150,9 @@ public boolean delete(int id) { public Optional getPipelineName(final ProcessorType processorType, final String uuid) { return Optional.empty(); } + + @Override + public Optional fetchByUuid(final String uuid) { + return dao.fetchByUuid(uuid); + } } diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterDao.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterDao.java index ca8885448af..f6b6d842fa0 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterDao.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterDao.java @@ -6,9 +6,12 @@ import stroom.util.shared.ResultPage; import java.time.Instant; +import java.util.Optional; public interface ProcessorFilterDao extends HasIntCrud { + Optional fetchByUuid(String uuid); + ResultPage find(ExpressionCriteria criteria); int logicalDeleteByProcessorFilterId(int processorFilterId); diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterImportExportHandlerImpl.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterImportExportHandlerImpl.java index 0d64053e019..fa042db4a69 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterImportExportHandlerImpl.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterImportExportHandlerImpl.java @@ -18,9 +18,12 @@ package stroom.processor.impl; import stroom.docref.DocRef; +import stroom.docref.DocRefInfo; import stroom.docrefinfo.api.DocRefInfoService; import stroom.docstore.api.AuditFieldFilter; import stroom.docstore.api.DependencyRemapper; +import stroom.docstore.api.DocumentActionHandler; +import stroom.docstore.api.DocumentNotFoundException; import stroom.docstore.api.Serialiser2; import stroom.docstore.api.Serialiser2Factory; import stroom.entity.shared.ExpressionCriteria; @@ -39,14 +42,17 @@ import stroom.processor.shared.Processor; import stroom.processor.shared.ProcessorFields; import stroom.processor.shared.ProcessorFilter; +import stroom.processor.shared.ProcessorFilterDoc; import stroom.processor.shared.ProcessorFilterFields; import stroom.processor.shared.ProcessorType; import stroom.query.api.v2.ExpressionOperator; import stroom.query.api.v2.ExpressionTerm; +import stroom.util.logging.LogUtil; import stroom.util.shared.Message; import stroom.util.shared.ResultPage; import jakarta.inject.Inject; +import jakarta.inject.Provider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,10 +60,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; -public class ProcessorFilterImportExportHandlerImpl implements ImportExportActionHandler, NonExplorerDocRefProvider { +public class ProcessorFilterImportExportHandlerImpl + implements ImportExportActionHandler, NonExplorerDocRefProvider, DocumentActionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ProcessorFilterImportExportHandlerImpl.class); private static final String META = "meta"; @@ -65,7 +74,11 @@ public class ProcessorFilterImportExportHandlerImpl implements ImportExportActio private final ImportExportDocumentEventLog importExportDocumentEventLog; private final ProcessorFilterService processorFilterService; private final ProcessorService processorService; - private final DocRefInfoService docRefInfoService; + // Need to use a provider to avoid circular dependency. + // DocRefInfoService uses this class to find its documents, but this class + // uses DocRefInfoService to find details of pipelines. Be careful not to + // make an infinite loop + private final Provider docRefInfoServiceProvider; private final Serialiser2 delegate; @@ -74,12 +87,12 @@ public class ProcessorFilterImportExportHandlerImpl implements ImportExportActio final ProcessorService processorService, final ImportExportDocumentEventLog importExportDocumentEventLog, final Serialiser2Factory serialiser2Factory, - final DocRefInfoService docRefInfoService) { + final Provider docRefInfoServiceProvider) { this.processorFilterService = processorFilterService; this.processorService = processorService; this.importExportDocumentEventLog = importExportDocumentEventLog; this.delegate = serialiser2Factory.createSerialiser(ProcessorFilter.class); - this.docRefInfoService = docRefInfoService; + this.docRefInfoServiceProvider = docRefInfoServiceProvider; } @Override @@ -190,29 +203,21 @@ private ProcessorFilter findProcessorFilter(final DocRef docRef) { return null; } - final ExpressionOperator expression = ExpressionOperator.builder() - .addDateTerm(ProcessorFilterFields.UUID, ExpressionTerm.Condition.EQUALS, docRef.getUuid()).build(); - - ExpressionCriteria criteria = new ExpressionCriteria(expression); - ResultPage page = processorFilterService.find(criteria); - - if (page != null && page.size() == 1) { - ProcessorFilter filter = page.getFirst(); - - if (filter.getPipelineName() == null && filter.getPipelineUuid() != null) { - final Optional optional = docRefInfoService.name(new DocRef(PipelineDoc.DOCUMENT_TYPE, - filter.getPipelineUuid())); - filter.setPipelineName(optional.orElse(null)); - if (filter.getPipelineName() == null) { - LOGGER.warn("Unable to find Pipeline " + filter.getPipelineUuid() + - " associated with ProcessorFilter " + filter.getUuid() + " (id: " + filter.getId() + ")"); - } - } - - return filter; - } - - return null; + return processorFilterService.fetchByUuid(docRef.getUuid()) + .map(filter -> { + if (filter.getPipelineName() == null && filter.getPipelineUuid() != null) { + final Optional optional = docRefInfoServiceProvider.get() + .name(new DocRef(PipelineDoc.DOCUMENT_TYPE, filter.getPipelineUuid())); + filter.setPipelineName(optional.orElse(null)); + if (filter.getPipelineName() == null) { + LOGGER.warn("Unable to find Pipeline " + filter.getPipelineUuid() + + " associated with ProcessorFilter " + filter.getUuid() + + " (id: " + filter.getId() + ")"); + } + } + return filter; + }) + .orElse(null); } @Override @@ -245,10 +250,32 @@ public Map exportDocument(final DocRef docRef, boolean omitAudit return data; } - @Override public Set listDocuments() { - return null; + return processorFilterService.find(new ExpressionCriteria()) + .stream() + .map(ProcessorFilter::asDocRef) + .collect(Collectors.toSet()); + } + + @Override + public ProcessorFilterDoc readDocument(final DocRef docRef) { + Objects.requireNonNull(docRef.getUuid()); + + return processorFilterService.fetchByUuid(docRef.getUuid()) + .map(processorFilter -> { + final String name = findNameOfDocRef(docRef); + return new ProcessorFilterDoc(processorFilter, name); + }) + .orElseThrow(() -> new DocumentNotFoundException(docRef)); + } + + @Override + public ProcessorFilterDoc writeDocument(final ProcessorFilterDoc document) { + Objects.requireNonNull(document); + final ProcessorFilter processorFilter = processorFilterService.create(document.getProcessorFilter()); + final String name = findNameOfDocRef(processorFilter.asDocRef()); + return new ProcessorFilterDoc(processorFilter, name); } @Override @@ -286,6 +313,32 @@ public String findNameOfDocRef(final DocRef docRef) { return null; } + @Override + public DocRefInfo info(final String uuid) { + return processorFilterService.fetchByUuid(uuid) + .map(processorFilter -> { + // Gets the name of the pipe as the proc filter has no name + final String name = this.findNameOfDocRef(ProcessorFilter.buildDocRef() + .uuid(uuid) + .build()); + + final DocRef decoratedDocRef = processorFilter.asDocRef() + .copy() + .name(name) + .build(); + + return DocRefInfo.builder() + .docRef(decoratedDocRef) + .createTime(processorFilter.getCreateTimeMs()) + .createUser(processorFilter.getCreateUser()) + .updateTime(processorFilter.getUpdateTimeMs()) + .updateUser(processorFilter.getUpdateUser()) + .build(); + }) + .orElseThrow(() -> new IllegalArgumentException(LogUtil.message( + "Processor filter with UUID {} not found", uuid))); + } + private Processor findProcessorForFilter(final ProcessorFilter filter) { Processor processor = filter.getProcessor(); if (processor == null) { @@ -383,7 +436,7 @@ public Map> getDependencies() { } private String getPipelineName(final DocRef pipeline) { - return docRefInfoService.name(pipeline).orElse("Unknown"); + return docRefInfoServiceProvider.get().name(pipeline).orElse("Unknown"); } @Override diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterServiceImpl.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterServiceImpl.java index 1fc4489c3ad..a04871dfc4b 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterServiceImpl.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorFilterServiceImpl.java @@ -199,6 +199,12 @@ public Optional fetch(final int id) { processorFilterDao.fetch(id)); } + @Override + public Optional fetchByUuid(final String uuid) { + return securityContext.secureResult(PERMISSION, () -> + processorFilterDao.fetchByUuid(uuid)); + } + @Override public ProcessorFilter update(final ProcessorFilter processorFilter) { // Check the user has update permissions on the pipeline. diff --git a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorModule.java b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorModule.java index 734eee6bc58..02438ce5595 100644 --- a/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorModule.java +++ b/stroom-processor/stroom-processor-impl/src/main/java/stroom/processor/impl/ProcessorModule.java @@ -16,6 +16,7 @@ package stroom.processor.impl; +import stroom.docstore.api.DocumentActionHandlerBinder; import stroom.importexport.api.ImportExportActionHandler; import stroom.job.api.DistributedTaskFactory; import stroom.job.api.ScheduledJobsBinder; @@ -23,6 +24,7 @@ import stroom.processor.api.ProcessorFilterService; import stroom.processor.api.ProcessorService; import stroom.processor.api.ProcessorTaskService; +import stroom.processor.shared.ProcessorFilterDoc; import stroom.processor.shared.ProcessorResource; import stroom.processor.shared.ProcessorTaskResource; import stroom.searchable.api.Searchable; @@ -69,6 +71,9 @@ protected void configure() { GuiceUtil.buildMultiBinder(binder(), ImportExportActionHandler.class) .addBinding(ProcessorFilterImportExportHandlerImpl.class); + DocumentActionHandlerBinder.create(binder()) + .bind(ProcessorFilterDoc.DOCUMENT_TYPE, ProcessorFilterImportExportHandlerImpl.class); + HasSystemInfoBinder.create(binder()) .bind(ProcessorTaskQueueManagerImpl.class); diff --git a/stroom-util-shared/src/main/java/stroom/util/shared/Document.java b/stroom-util-shared/src/main/java/stroom/util/shared/Document.java index 84bde0deb4b..aa4be4d2910 100644 --- a/stroom-util-shared/src/main/java/stroom/util/shared/Document.java +++ b/stroom-util-shared/src/main/java/stroom/util/shared/Document.java @@ -16,9 +16,18 @@ package stroom.util.shared; +import stroom.docref.DocRef; +import stroom.docref.HasName; import stroom.docref.HasType; import stroom.docref.HasUuid; -public interface Document extends HasType, HasUuid { +public interface Document extends HasType, HasUuid, HasName, HasAuditInfo { + default DocRef asDocRef() { + return DocRef.builder() + .type(getType()) + .name(getName()) + .uuid(getUuid()) + .build(); + } } diff --git a/stroom-util-shared/src/main/java/stroom/util/shared/HasFetchByUuid.java b/stroom-util-shared/src/main/java/stroom/util/shared/HasFetchByUuid.java new file mode 100644 index 00000000000..ff444e5b50f --- /dev/null +++ b/stroom-util-shared/src/main/java/stroom/util/shared/HasFetchByUuid.java @@ -0,0 +1,8 @@ +package stroom.util.shared; + +import java.util.Optional; + +public interface HasFetchByUuid { + + Optional fetchByUuid(final String uuid); +} From bc5c3608b594c9a842870ebdfe325e3b5a17a82f Mon Sep 17 00:00:00 2001 From: at055612 <22818309+at055612@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:56:52 +0000 Subject: [PATCH 2/2] gh-4035 Remove commented code --- .../explorer/impl/TestDocRefInfoCache.java | 106 ------------------ 1 file changed, 106 deletions(-) diff --git a/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java b/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java index 0769804f79e..431f25a21e5 100644 --- a/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java +++ b/stroom-explorer/stroom-explorer-impl/src/test/java/stroom/explorer/impl/TestDocRefInfoCache.java @@ -118,112 +118,6 @@ private static DocRef stripType(final DocRef docRef) { // -------------------------------------------------------------------------------- -// private static class MyExplorerActionHandler implements ExplorerActionHandler { -// -// private final Map docRefs = new HashMap<>(); -// private final String type; -// -// private MyExplorerActionHandler(final Set docRefs) { -// docRefs.forEach(docRef -> this.docRefs.put(docRef.getUuid(), docRef)); -// final Set types = docRefs.stream() -// .map(DocRef::getType) -// .collect(Collectors.toSet()); -// if (types.size() != 1) { -// throw new IllegalArgumentException("Expecting one type only"); -// } -// this.type = types.iterator().next(); -// } -// -// @Override -// public Set listDocuments() { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public List findByNames(final List names, final boolean allowWildCards) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocRef createDocument(final String name) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocRef copyDocument(final DocRef docRef, -// final String name, -// final boolean makeNameUnique, -// final Set existingNames) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocRef moveDocument(final String uuid) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocRef renameDocument(final String uuid, final String name) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public void deleteDocument(final String uuid) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocRefInfo info(final String uuid) { -// return NullSafe.get( -// docRefs.get(uuid), -// docRef -> new DocRefInfo( -// docRef, -// System.currentTimeMillis(), -// System.currentTimeMillis(), -// "user1", -// "user1", -// null)); -// } -// -// @Override -// public DocumentType getDocumentType() { -// return new DocumentType( -// DocumentTypeGroup.CONFIGURATION, -// type, -// type, -// SvgImage.OK); -// } -// -// @Override -// public Map> getDependencies() { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public Set getDependencies(final DocRef docRef) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public void remapDependencies(final DocRef docRef, final Map remappings) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public List findByContent(final StringMatch filter) { -// throw new UnsupportedOperationException(); -// } -// -// @Override -// public DocContentHighlights fetchHighlights(final DocRef docRef, -// final String extension, -// final StringMatch filter) { -// throw new UnsupportedOperationException(); -// } -// } - - // -------------------------------------------------------------------------------- - private static class MyDocumentActionHandler implements DocumentActionHandler { private final Map docRefs = new HashMap<>();