-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TemplateConfigDirChangeMonitorImpl WIP
- Loading branch information
Showing
7 changed files
with
331 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
stroom-core/src/main/java/stroom/core/receive/TemplateConfigDirChangeMonitorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package stroom.core.receive; | ||
|
||
import stroom.receive.common.AutoContentCreationConfig; | ||
import stroom.util.NullSafe; | ||
import stroom.util.io.AbstractDirChangeMonitor; | ||
import stroom.util.io.SimplePathCreator; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Provider; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.EnumSet; | ||
import java.util.function.Predicate; | ||
|
||
@Singleton | ||
public class TemplateConfigDirChangeMonitorImpl extends AbstractDirChangeMonitor { | ||
|
||
private static final Predicate<Path> FILE_INCLUDE_FILTER = path -> | ||
path != null | ||
&& Files.isRegularFile(path) | ||
&& path.getFileName().toString().endsWith(".json"); | ||
|
||
private final Provider<AutoContentCreationConfig> autoContentCreationConfigProvider; | ||
private final Provider<ContentAutoCreationService> contentAutoCreationServiceProvider; | ||
|
||
@Inject | ||
public TemplateConfigDirChangeMonitorImpl( | ||
final Provider<AutoContentCreationConfig> autoContentCreationConfigProvider, | ||
final SimplePathCreator simplePathCreator, | ||
final Provider<ContentAutoCreationService> contentAutoCreationServiceProvider) { | ||
super( | ||
getDataFeedDir(autoContentCreationConfigProvider, simplePathCreator), | ||
FILE_INCLUDE_FILTER, | ||
EnumSet.allOf(EventType.class)); | ||
this.autoContentCreationConfigProvider = autoContentCreationConfigProvider; | ||
this.contentAutoCreationServiceProvider = contentAutoCreationServiceProvider; | ||
} | ||
|
||
private static Path getDataFeedDir( | ||
final Provider<AutoContentCreationConfig> autoContentCreationConfigProvider, | ||
final SimplePathCreator simplePathCreator) { | ||
|
||
final AutoContentCreationConfig autoContentCreationConfig = autoContentCreationConfigProvider.get(); | ||
return NullSafe.get( | ||
autoContentCreationConfig.getTemplateConfigDir(), | ||
simplePathCreator::toAppPath); | ||
} | ||
|
||
@Override | ||
protected void onInitialisation() { | ||
|
||
} | ||
|
||
@Override | ||
protected void onEntryModify(final Path path) { | ||
|
||
} | ||
|
||
@Override | ||
protected void onEntryCreate(final Path path) { | ||
|
||
} | ||
|
||
@Override | ||
protected void onEntryDelete(final Path path) { | ||
|
||
} | ||
|
||
@Override | ||
protected void onOverflow() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...m-receive/stroom-receive-common/src/main/java/stroom/receive/common/ContentTemplates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package stroom.receive.common; | ||
|
||
import stroom.docref.DocRef; | ||
import stroom.util.NullSafe; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
@JsonPropertyOrder(alphabetic = true) | ||
public class ContentTemplates { | ||
|
||
@JsonProperty | ||
private final Set<ContentTemplate> contentTemplates; | ||
|
||
@JsonCreator | ||
public ContentTemplates( | ||
@JsonProperty("contentTemplates") final Set<ContentTemplate> contentTemplates) { | ||
this.contentTemplates = contentTemplates; | ||
} | ||
|
||
public Set<ContentTemplate> getContentTemplates() { | ||
return contentTemplates; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ContentTemplates that = (ContentTemplates) o; | ||
return Objects.equals(contentTemplates, that.contentTemplates); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(contentTemplates); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ContentTemplates{" + | ||
"contentTemplates=" + contentTemplates + | ||
'}'; | ||
} | ||
|
||
// -------------------------------------------------------------------------------- | ||
|
||
|
||
@JsonPropertyOrder(alphabetic = true) | ||
public static class ContentTemplate { | ||
|
||
@JsonProperty | ||
private final Map<String, String> attributeMap; | ||
@JsonProperty | ||
private final TemplateType templateType; | ||
@JsonProperty | ||
private final DocRef pipeline; | ||
|
||
@JsonCreator | ||
public ContentTemplate(@JsonProperty("attributeMap") final Map<String, String> attributeMap, | ||
@JsonProperty("templateType") final TemplateType templateType, | ||
@JsonProperty("pipeline") final DocRef pipeline) { | ||
this.attributeMap = Objects.requireNonNull(attributeMap); | ||
this.templateType = Objects.requireNonNull(templateType); | ||
this.pipeline = Objects.requireNonNull(pipeline); | ||
} | ||
|
||
/** | ||
* A map of header arguments and their values | ||
* that describe a certain shape of data that can | ||
* be processed by pipeline. | ||
*/ | ||
public Map<String, String> getAttributeMap() { | ||
return attributeMap; | ||
} | ||
|
||
/** | ||
* The nature of the content templating. | ||
*/ | ||
public TemplateType getTemplateType() { | ||
return templateType; | ||
} | ||
|
||
/** | ||
* The pipeline to process the data with or to inherit from (depending | ||
* on the value of templateType). | ||
*/ | ||
public DocRef getPipeline() { | ||
return pipeline; | ||
} | ||
|
||
public boolean hasAttribute(final String key, final String value) { | ||
if (NullSafe.isNonBlankString(key)) { | ||
return NullSafe.test(attributeMap.get(key), val -> Objects.equals(val, value)); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ContentTemplate that = (ContentTemplate) o; | ||
return Objects.equals(attributeMap, | ||
that.attributeMap) && templateType == that.templateType && Objects.equals(pipeline, | ||
that.pipeline); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(attributeMap, templateType, pipeline); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ContentTemplate{" + | ||
"attributeMap=" + attributeMap + | ||
", templateType=" + templateType + | ||
", pipeline=" + pipeline + | ||
'}'; | ||
} | ||
} | ||
|
||
|
||
// -------------------------------------------------------------------------------- | ||
|
||
|
||
public enum TemplateType { | ||
/** | ||
* Create a processor filter specific to the feed on an existing pipeline that | ||
* is appropriate to the attributeMap values. | ||
*/ | ||
PROCESSOR_FILTER, | ||
/** | ||
* Create a new pipeline (and associated filter specific to the feed) that inherits | ||
* from an existing template pipeline that is appropriate to the attributeMap values. | ||
*/ | ||
INHERIT_PIPELINE, | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.