Skip to content

Commit 63a7af7

Browse files
Gayadependabot[bot]dennisoelkerslinuspahlEdmundo Alvarez
authored
master merge into okta (#10704)
* Bump lodash from 4.17.20 to 4.17.21 in /graylog2-web-interface (#10595) Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](lodash/lodash@4.17.20...4.17.21) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Centralize timeout multiplier handling in tests. (#10591) * Centralize timeout multiplier handling. In a couple of places we need to set custom timeouts for jest tests. In these cases we should take the `TIMEOUT_MULTIPLIER` env variable into account. In order to avoid having to handle that over and over again (parsing, validating, applying it), this change is adding two functions to the `jest-preset-graylog` module: - `timeoutMultiplier()`: returning the raw multiplier, `1.0` if not set or not parseable - `applyTimeoutMultiplier(x: number)`: applies the configured timeout multiplier to any given timeout The latter function should be used in tests to apply the multiplier to any custom timeout override. * Adding license header. * Use default values for scaling & interpolation if absent. (#10590) * Return default value for scaling factor if absent. * Use `linear` if interpolation mode is absent. * Allow emptying relative range value inputs in date time picker when entering new value. (#10612) * Allow to temporary empty relative range value inputs in date time picker. Before this change it was not possible to temporary empty the relative range value inputs. When a user tried to remove all numbers, we automatically inserted a 1. We mainly did this because we are always updating the form state `onChange`. If we would define for example `undefined` for the relative range value, we would loose the information which range type is selected. The range type is being inferred based on the time range form value. For example if the form state value for the relative range is 300, the `RelativeRangeSelect` displays: 5 (value) minutes (type). With this PR we are implementing a separate state for the `RelativeRangeSelect` which controls the relative range inputs. We are still updating the form state `onChange`. Every time the form state changes we are synchronizing the `RelativeRangeSelect`. When a user empties the range value input, we are defining `null` for the range form state. By implementing a separate state, we are able to remember the previous selected range type and consider the type when the user defines a completely new range value. * Creating separate component for `RelativeRangeValueInput` and wrapping it with `React.memo`. Before this change, the range value input cursor lost its position after the user changed the input value, because the input rerendered multiple times `onChange`. Now we are only rerendering the component when necessary. This way react remembers the cursor position. * Creating tests for new `RelativeRangeSelect` select changes. * Updating component name. * Fixing ts error. * Unifying test names. * Change back REQUEST_HEADERS access to public (#10621) * Do not require a defaultValue to be set in Heatmap (#10620) ## Motivation Prior to this change, the defaultValue was required to be set for a heatmap. But there is no technical reason for that. ## Description This change will set the required field to false and adjust the tests. * Adaptable Dashboard Tabs (#10371) * Make Dashboard Tabs responsive * throttled resize & functional component * fix Nav tab styles * styles * stylelint * tsc * stylelint-processor-styled-components * stylelint * remove flag * PR feedback * fixing invalid selector error * Updating colors to be a bit brighter in Noir * more active class fix * note about "failing" lint * working with sizeme * couple tests * stop scrolling after adding new tab & lock new tab to end * typing and getting proper tab to lock open * more typescript cleaning * snapshot * tsc error * tests * feedback from @linuspahl * tweak naming convention of new tabs to avoid duplicates * relock active tab after save as * relock active tab after save as cleanup * Fixing `Search.dashboard.test`. * Add tests for logic if query tabs should be displayed as main tabs or in more tabs dropdown. * Add further tests for query tabs creation and selection. * Fixing assignment of aria-hidden for query tabs in dropdown. * Fixing linter warning. Co-authored-by: Linus Pahl <[email protected]> * Limit field types retrieval to timerange of query. (#10562) * Extend `FieldTypesResource` to support optional timerange parameter. * Include time range in requests, refresh store when time range changes. * Provide widget field types through context. * Change wording for field set selection in sidebar. * Consider global override for field types retrieval. * Adding/adjusting tests. * Extracting custom `useCurrentQuery` hook. * Adding test for field types provider. * Extending test. * Adding license headers. * Migrating `SavedSearchControls` test to testing-library and adjust to change. * Migrating tests to testing-library. * Removing unused import. * Mocking `FieldTypesStore` in test. * Migrating `ExportModal` to use context instead of store. * Adjusting tests. * Removing unused mocks. * Removing unused mocks, use `PluginStore` instead of mocking it. * Mocking `FieldTypesStore` in more tests. * Mocking `WidgetStore` in test. * Adding field types POST endpoint to integration test API. * Do not include empty streams list in request. * Style common `Select` based on `FormGroup` validation state. (#10624) * Display `Select` styling based on `FormGroup` validation state. Our form components consider the validation state when being used inside a `FormGroup`. Before this change our common `Select`component was an exception. With this change we are updating the styling (mainly the border) accordingly. * Using darker border color for form components inside `FormGroup`. * Removing not perfectly working styles. * Updating snapshots. * Support form data for `fetch`/`Builder`. (#10638) * Support form data for `fetch`/`Builder`. * Simplifying conditional, thanks @edmundoa! * Fixing message loading when testing message against stream. (#10575) * Fixing submitting message id/index values. * Migrate `MessageLoader` component to TS and functional component. * Fixing indentation. * Replacing link with proper button, changing wording. * Use correct variable to decide if form should be expanded. * Fix focussing message id input when visibility of form changes. * Improving typing: making `messageId`/`index` props optional, set default values. * Fixing default value. * Renaming component to tsx. * Migrating to typed functional component. * add inputConfiguration type to PluginExports - add svg module definition * Update graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts Co-authored-by: Edmundo Alvarez <[email protected]> * Update graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts Co-authored-by: Edmundo Alvarez <[email protected]> * Configurations style (#10625) * Replace CSS file with styled-component * Avoid clipping by increasing the dd margin * Add some space after each configlet * Fix loading of Pipeline simulator page (#10664) * Fix issue rendering RawMessageLoader component The `inputs` prop of `RawMessageLoader` now receives an `ImmutableJS.Map` object but we didn't update usages of that prop. This resulted in an incorrect behaviour when using the JS standard API with the `ImmutableJS.Map` object, that could throw an error. This change uses the ImmutableJS API to work with the `inputs` prop, ensuring the code behaves as expected. Fixes #10663 * Make originalMessage proptype optional * Bump @testing-library/react-hooks (#10670) Bumps [@testing-library/react-hooks](https://github.com/testing-library/react-hooks-testing-library) from 5.1.3 to 6.0.0. - [Release notes](https://github.com/testing-library/react-hooks-testing-library/releases) - [Changelog](https://github.com/testing-library/react-hooks-testing-library/blob/main/CHANGELOG.md) - [Commits](testing-library/react-hooks-testing-library@v5.1.3...v6.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Use more secure TLS default ciphers (#10653) Our defaults (even with TLS 1.2 and 1.3 only) were still susceptible to LOGJAM, LUCKY13 and a possible DoS attack. We programatically use secure defaults for the JDK and for Netty with OpenSSL Fixes https://github.com/Graylog2/graylog-plugin-enterprise/issues/2202 * Better swagger specs through extracting inline models. (#10637) * Create proper swagger schema. * Handle generics properly. * Fixing corner cases and type names. * Add visitor to replace `type: any` values. * Extract inline objects. * Adding json annotation. * Fixing reference naming, cleaning up unused code. * Treat parameters identically to response types. * Fix multiple issues, keep parameter types inline if not objects. * Fix primitive method response types. * Fixing enums and longs. * Inline non-object models. * Falling back to value when parameter name is not present. * Use nickname over method name, if present. * Include missing import. * Fix creatable select focus and "create value" option label problem. (#10644) * Prevent loosing focus when removing content of creatable select input. Before this change it was possible to loose the react creatable select focus after removing its content, because we updated the component state unnecessarily. With this change we ensure that we only update the state when necessary. * Display "Create value" option label correctly when using `displayKey` select prop. * Prevent unnecessary search execution when unfocusing widget. (#10673) When introducing functionality, which limits search execution to the widget which is currently edited, a change was added that performs a search execution when leaving edit mode. Unfortunately the condition which was used to determine if widget editing is left was too broad, so it is performed whenever the widget focusing state changes. This leads to e.g. double search execution when loading a new/saved search. This PR is changing the condition to check if the previous state indicates widget editing mode and does not perform a new search execution otherwise. * Scratchpad Updates & Tests (#10667) * Fix Scratchpad Tooltip/Help not appearing * typo * Typescript scratchpad & redo status messages * Scratchpad tests * snapshot and clear timeout * Improving `SearchBar` and `DashboardSearchBar` responsiveness. (#10652) * Improving `SearchBar` responsiveness. * Improving responsiveness of `DashboardSearchBar`. * Fixing `SearchBar` test. * Temporary add `TopRow` component to test test CI behaviour. * Removing no longer needed search bar `TopRow` component. * Fix and centralize qualifying relative URLs with credentials. (#10675) * Adding `urijs` types. * Migrating `URLUtils` to TS. * Adding tests. * Qualify URLs with scheme/hostname from current location if server url is unqualified. * Reuse function to add session id to URL. * Make `qualifyUrl` idempotent. * Fix type errors introduced by typing `urijs`. * Adding license header. * Using empty string if server url is not present to avoid using `undefined`. * Do not pass `undefined` to `URI.session`. * Adding/fixing missing mocks in test. * Adding more mocks. * Exporting through frontend without buffering response in browser. (#10617) * First dirty working draft. * Some cleanup. * Registering media types for file extensions. * Adding audit events for export jobs. * Managing endpoint URL centrally. * Timestamping export jobs, removing expired ones. * Using UTC all the way. * Removing `downloadjs`. * Adding license headers. * Updating vendor module ids. * Throwing exception in tests if value is missing. * Reverting change that replaces anonymous instance with lambda, added comment. * Removing periodical, replacing with TTL index on mongo collection. * Serialize `createdAt` field. * Fixing href. * Cleaning up `MessagesResource`. * Removing unused import. * Reverting unneeded change. * A-element does not actually need to be in the dom. * Make use of `qualifyUrlWithSessionCredentials` to include session credentials in URL. * Returning 404 for invalid export job id. * Attach link to DOM. * Fix apache httpclient to version 4.5.13 (#10684) Managing and fixing the http client to a specific version works around resolving the dependency to different versions in plugins. This would cause unexpected problems as described in aws/aws-sdk-java-v2#1795 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dennis Oelkers <[email protected]> Co-authored-by: Linus Pahl <[email protected]> Co-authored-by: Edmundo Alvarez <[email protected]> Co-authored-by: Konrad Merz <[email protected]> Co-authored-by: Kyle Knight <[email protected]> Co-authored-by: Ousmane Samba <[email protected]> Co-authored-by: Marco Pfatschbacher <[email protected]> Co-authored-by: Othello Maurer <[email protected]>
1 parent 4e00d37 commit 63a7af7

File tree

138 files changed

+3776
-1383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3776
-1383
lines changed

graylog-project-parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@
564564
<artifactId>unboundid-ldapsdk</artifactId>
565565
<version>${unboundid-ldap.version}</version>
566566
</dependency>
567+
<dependency>
568+
<groupId>org.apache.httpcomponents</groupId>
569+
<artifactId>httpclient</artifactId>
570+
<version>${apache-httpclient.version}</version>
571+
</dependency>
567572

568573
<!-- Test dependencies -->
569574
<dependency>

graylog2-server/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@
673673
<version>1.5.0</version>
674674
<scope>test</scope>
675675
</dependency>
676+
<dependency>
677+
<groupId>org.apache.httpcomponents</groupId>
678+
<artifactId>httpclient</artifactId>
679+
</dependency>
676680
</dependencies>
677681

678682
<build>

graylog2-server/src/main/java/org/graylog/plugins/views/ViewsBindings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.graylog.plugins.views.search.filter.QueryStringFilter;
5050
import org.graylog.plugins.views.search.filter.StreamFilter;
5151
import org.graylog.plugins.views.search.rest.DashboardsResource;
52+
import org.graylog.plugins.views.search.rest.ExportJobsResource;
5253
import org.graylog.plugins.views.search.rest.FieldTypesResource;
5354
import org.graylog.plugins.views.search.rest.MessageExportFormatFilter;
5455
import org.graylog.plugins.views.search.rest.MessagesResource;
@@ -113,6 +114,7 @@ protected void configure() {
113114
addSystemRestResource(DashboardsResource.class);
114115
addSystemRestResource(FieldTypesResource.class);
115116
addSystemRestResource(MessagesResource.class);
117+
addSystemRestResource(ExportJobsResource.class);
116118
addSystemRestResource(PivotSeriesFunctionsResource.class);
117119
addSystemRestResource(QualifyingViewsResource.class);
118120
addSystemRestResource(SavedSearchesResource.class);

graylog2-server/src/main/java/org/graylog/plugins/views/audit/ViewsAuditEventTypes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class ViewsAuditEventTypes implements PluginAuditEventTypes {
4949
public static final String MESSAGES_EXPORT_REQUESTED = MESSAGES_EXPORT + "_requested";
5050
public static final String MESSAGES_EXPORT_SUCCEEDED = MESSAGES_EXPORT + "_succeeded";
5151

52+
public static final String EXPORT_JOB = "export_job";
53+
public static final String EXPORT_JOB_CREATED = PREFIX + EXPORT_JOB + ":created";
5254

5355
private static final ImmutableSet<String> EVENT_TYPES = ImmutableSet.<String>builder()
5456
.add(VIEW_CREATE)
@@ -68,6 +70,8 @@ public class ViewsAuditEventTypes implements PluginAuditEventTypes {
6870
.add(MESSAGES_EXPORT_REQUESTED)
6971
.add(MESSAGES_EXPORT_SUCCEEDED)
7072

73+
.add(EXPORT_JOB_CREATED)
74+
7175
.build();
7276

7377
@Override

graylog2-server/src/main/java/org/graylog/plugins/views/search/export/CommandFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private ExportMessagesCommand.Builder builderFrom(ResultFormat resultFormat) {
108108
requestBuilder.fieldsInOrder(resultFormat.fieldsInOrder());
109109

110110
if (resultFormat.limit().isPresent()) {
111-
requestBuilder.limit(resultFormat.limit().getAsInt());
111+
requestBuilder.limit(resultFormat.limit().orElseThrow(() -> new IllegalStateException("No value present!")));
112112
}
113113

114114
return requestBuilder;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.plugins.views.search.export;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.annotation.JsonSubTypes;
21+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
22+
import org.joda.time.DateTime;
23+
24+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = ExportJob.FIELD_TYPE)
25+
@JsonSubTypes({
26+
@JsonSubTypes.Type(value = MessagesRequestExportJob.class, name = MessagesRequestExportJob.TYPE),
27+
@JsonSubTypes.Type(value = SearchExportJob.class, name = SearchExportJob.TYPE),
28+
@JsonSubTypes.Type(value = SearchTypeExportJob.class, name = SearchTypeExportJob.TYPE)
29+
})
30+
public interface ExportJob {
31+
String FIELD_TYPE = "type";
32+
String FIELD_ID = "_id";
33+
String FIELD_CREATED_AT = "created_at";
34+
String id();
35+
36+
@JsonProperty
37+
DateTime createdAt();
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.plugins.views.search.export;
18+
19+
import org.bson.types.ObjectId;
20+
21+
import java.util.function.Supplier;
22+
23+
public class ExportJobFactory {
24+
private final Supplier<String> idGenerator = () -> new ObjectId().toHexString();
25+
26+
public ExportJob fromMessagesRequest(MessagesRequest messagesRequest) {
27+
return MessagesRequestExportJob.fromMessagesRequest(idGenerator.get(), messagesRequest);
28+
}
29+
30+
public ExportJob forSearch(String searchId, ResultFormat resultFormat) {
31+
return SearchExportJob.forSearch(idGenerator.get(), searchId, resultFormat);
32+
}
33+
34+
public ExportJob forSearchType(String searchId, String searchTypeId, ResultFormat resultFormat) {
35+
return SearchTypeExportJob.forSearchType(idGenerator.get(), searchId, searchTypeId, resultFormat);
36+
}
37+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.plugins.views.search.export;
18+
19+
import com.mongodb.BasicDBObject;
20+
import org.bson.types.ObjectId;
21+
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
22+
import org.graylog2.database.MongoConnection;
23+
import org.mongojack.JacksonDBCollection;
24+
import org.mongojack.WriteResult;
25+
26+
import javax.inject.Inject;
27+
import java.util.Optional;
28+
import java.util.concurrent.TimeUnit;
29+
30+
public class ExportJobService {
31+
protected final JacksonDBCollection<ExportJob, ObjectId> db;
32+
33+
@Inject
34+
public ExportJobService(MongoConnection mongoConnection,
35+
MongoJackObjectMapperProvider mapper) {
36+
db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("export_jobs"),
37+
ExportJob.class,
38+
ObjectId.class,
39+
mapper.get());
40+
41+
db.createIndex(new BasicDBObject(ExportJob.FIELD_CREATED_AT, 1), new BasicDBObject("expireAfterSeconds", TimeUnit.HOURS.toSeconds(1L)));
42+
}
43+
44+
public Optional<ExportJob> get(String id) {
45+
if (!ObjectId.isValid(id)) {
46+
return Optional.empty();
47+
}
48+
return Optional.ofNullable(db.findOneById(new ObjectId(id)));
49+
}
50+
51+
public String save(ExportJob exportJob) {
52+
final WriteResult<ExportJob, ObjectId> save = db.insert(exportJob);
53+
54+
return save.getSavedId().toHexString();
55+
}
56+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.plugins.views.search.export;
18+
19+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
import com.google.auto.value.AutoValue;
23+
import org.joda.time.DateTime;
24+
import org.joda.time.DateTimeZone;
25+
26+
@AutoValue
27+
@JsonAutoDetect
28+
public abstract class MessagesRequestExportJob implements ExportJob {
29+
static final String TYPE = "messages_export";
30+
private static final String FIELD_MESSAGES_REQUEST = "messages_request";
31+
32+
@JsonProperty("type")
33+
public String type() {
34+
return TYPE;
35+
}
36+
37+
@JsonProperty(FIELD_MESSAGES_REQUEST)
38+
public abstract MessagesRequest messagesRequest();
39+
40+
static MessagesRequestExportJob fromMessagesRequest(String id, MessagesRequest messagesRequest) {
41+
return new AutoValue_MessagesRequestExportJob(id, DateTime.now(DateTimeZone.UTC), messagesRequest);
42+
}
43+
44+
@JsonCreator
45+
static MessagesRequestExportJob create(
46+
@JsonProperty(FIELD_ID) String id,
47+
@JsonProperty(FIELD_MESSAGES_REQUEST) MessagesRequest messagesRequest
48+
) {
49+
return new AutoValue_MessagesRequestExportJob(id, DateTime.now(DateTimeZone.UTC), messagesRequest);
50+
}
51+
}

graylog2-server/src/main/java/org/graylog/plugins/views/search/export/ResultFormat.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.LinkedHashSet;
3131
import java.util.Map;
3232
import java.util.Optional;
33-
import java.util.OptionalInt;
3433

3534
import static org.graylog.plugins.views.search.export.ExportMessagesCommand.DEFAULT_FIELDS;
3635
import static org.graylog.plugins.views.search.export.LinkedHashSetUtil.linkedHashSetOf;
@@ -49,12 +48,14 @@ public abstract class ResultFormat {
4948
public abstract Optional<AbsoluteRange> timerange();
5049

5150
@JsonProperty
52-
@Positive
53-
public abstract OptionalInt limit();
51+
public abstract Optional<Integer> limit();
5452

5553
@JsonProperty
5654
public abstract Map<String, Object> executionState();
5755

56+
@JsonProperty
57+
public abstract Optional<String> filename();
58+
5859
public static ResultFormat.Builder builder() {
5960
return ResultFormat.Builder.create();
6061
}
@@ -73,14 +74,17 @@ public Builder fieldsInOrder(String... fields) {
7374
}
7475

7576
@JsonProperty
76-
public abstract Builder limit(Integer limit);
77+
public abstract Builder limit(@Positive @Nullable Integer limit);
7778

7879
@JsonProperty
7980
public abstract Builder executionState(Map<String, Object> executionState);
8081

8182
@JsonProperty
8283
public abstract Builder timerange(@Nullable AbsoluteRange timeRange);
8384

85+
@JsonProperty
86+
public abstract Builder filename(@Nullable String filename);
87+
8488
public abstract ResultFormat build();
8589

8690
@JsonCreator
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog.plugins.views.search.export;
18+
19+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
import com.google.auto.value.AutoValue;
23+
import org.joda.time.DateTime;
24+
import org.joda.time.DateTimeZone;
25+
26+
import javax.validation.constraints.NotEmpty;
27+
28+
@AutoValue
29+
@JsonAutoDetect
30+
public abstract class SearchExportJob implements ExportJob {
31+
static final String TYPE = "search_export";
32+
private static final String FIELD_SEARCH_ID = "search_id";
33+
private static final String FIELD_RESULT_FORMAT = "result_format";
34+
35+
@JsonProperty("type")
36+
public String type() {
37+
return TYPE;
38+
}
39+
40+
@JsonProperty(FIELD_SEARCH_ID)
41+
public abstract String searchId();
42+
43+
@JsonProperty(FIELD_RESULT_FORMAT)
44+
@NotEmpty
45+
public abstract ResultFormat resultFormat();
46+
47+
static SearchExportJob forSearch(String id, String searchId, ResultFormat resultFormat) {
48+
return new AutoValue_SearchExportJob(id, DateTime.now(DateTimeZone.UTC), searchId, resultFormat);
49+
}
50+
51+
@JsonCreator
52+
static SearchExportJob create(
53+
@JsonProperty(FIELD_ID) String id,
54+
@JsonProperty(FIELD_SEARCH_ID) String searchId,
55+
@JsonProperty(FIELD_RESULT_FORMAT) ResultFormat resultFormat
56+
) {
57+
return new AutoValue_SearchExportJob(id,
58+
DateTime.now(DateTimeZone.UTC),
59+
searchId,
60+
resultFormat);
61+
}
62+
}

0 commit comments

Comments
 (0)