Skip to content

Commit

Permalink
removed "lastModified" Instant from SearchResult
Browse files Browse the repository at this point in the history
* this was a temporary leftover from the search "wildcard index" cutover

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jun 27, 2022
1 parent 5dab650 commit 9a24fe2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Receive createReceive() {
// shortcuts: we don't have to look up the things
// - for no search results
// - if only the "thingId" was selected in the QueryThings commands
originatingSender.tell(stripLastModifiedTimestampFromSearchResult(qtr), getSelf());
originatingSender.tell(qtr, getSelf());
stopMyself();
} else {
final Optional<JsonFieldSelector> selectedFieldsWithThingId = getSelectedFieldsWithThingId();
Expand Down Expand Up @@ -166,15 +166,6 @@ public Receive createReceive() {
.build();
}

private static QueryThingsResponse stripLastModifiedTimestampFromSearchResult(
final QueryThingsResponse queryThingsResponse) {

return queryThingsResponse.setEntity(queryThingsResponse.getSearchResult().toBuilder()
.lastModified(null)
.build()
.toJson());
}

private boolean queryThingsOnlyContainsThingIdSelector() {
final Optional<JsonFieldSelector> fields = queryThings.getFields();
return fields.isPresent() && fields.get().getPointers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.time.Instant;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -41,14 +40,12 @@ final class ImmutableSearchResult implements SearchResult {
private final JsonArray items;
@Nullable private final Long nextPageOffset;
@Nullable private final String cursor;
@Nullable private final Instant lastModified;

private ImmutableSearchResult(final JsonArray items, @Nullable final Long nextPageOffset,
@Nullable final String cursor, @Nullable final Instant lastModified) {
@Nullable final String cursor) {
this.items = checkNotNull(items, "items");
this.nextPageOffset = nextPageOffset;
this.cursor = cursor;
this.lastModified = lastModified;
}

/**
Expand All @@ -57,7 +54,7 @@ private ImmutableSearchResult(final JsonArray items, @Nullable final Long nextPa
* @return instance.
*/
public static SearchResult empty() {
return of(JsonFactory.newArray(), NO_NEXT_PAGE, null, null);
return of(JsonFactory.newArray(), NO_NEXT_PAGE, null);
}

/**
Expand All @@ -71,10 +68,9 @@ public static SearchResult empty() {
*/
public static ImmutableSearchResult of(final JsonArray items,
@Nullable final Long nextPageOffset,
@Nullable final String cursor,
@Nullable final Instant lastModified) {
@Nullable final String cursor) {

return new ImmutableSearchResult(items, nextPageOffset, cursor, lastModified);
return new ImmutableSearchResult(items, nextPageOffset, cursor);
}

/**
Expand All @@ -90,9 +86,8 @@ public static ImmutableSearchResult fromJson(final JsonObject jsonObject) {
final JsonArray extractedItems = jsonObject.getValueOrThrow(JsonFields.ITEMS);
final Long extractedNextPageOffset = jsonObject.getValue(JsonFields.NEXT_PAGE_OFFSET).orElse(null);
final String extractedCursor = jsonObject.getValue(JsonFields.CURSOR).orElse(null);
final Instant lastModified = jsonObject.getValue(JsonFields.LAST_MODIFIED).map(Instant::parse).orElse(null);

return of(extractedItems, extractedNextPageOffset, extractedCursor, lastModified);
return of(extractedItems, extractedNextPageOffset, extractedCursor);
}

@Override
Expand All @@ -110,11 +105,6 @@ public Optional<String> getCursor() {
return Optional.ofNullable(cursor);
}

@Override
public Optional<Instant> getLastModified() {
return Optional.ofNullable(lastModified);
}

@Override
public boolean hasNextPage() {
return cursor != null || nextPageOffset != null && nextPageOffset != NO_NEXT_PAGE;
Expand Down Expand Up @@ -148,8 +138,6 @@ public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<
builder.set(JsonFields.ITEMS, items, predicate);
getNextPageOffset().ifPresent(offset -> builder.set(JsonFields.NEXT_PAGE_OFFSET, offset, predicate));
getCursor().ifPresent(cur -> builder.set(JsonFields.CURSOR, cur, predicate));
getLastModified().ifPresent(lastModified ->
builder.set(JsonFields.LAST_MODIFIED, lastModified.toString(), predicate));
return builder.build();
}

Expand All @@ -164,21 +152,19 @@ public boolean equals(final Object o) {
final ImmutableSearchResult that = (ImmutableSearchResult) o;
return Objects.equals(nextPageOffset, that.nextPageOffset) &&
Objects.equals(cursor, that.cursor) &&
Objects.equals(items, that.items) &&
Objects.equals(lastModified, that.lastModified);
Objects.equals(items, that.items);
}

@Override
public int hashCode() {
return Objects.hash(items, nextPageOffset, cursor, lastModified);
return Objects.hash(items, nextPageOffset, cursor);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [items=" + items +
", nextPageOffset=" + nextPageOffset +
", cursor=" + cursor +
", lastModified=" + lastModified +
"]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.time.Instant;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

Expand All @@ -33,7 +31,6 @@ final class ImmutableSearchResultBuilder implements SearchResultBuilder {
private final JsonArrayBuilder jsonArrayBuilder;
@Nullable private Long offset;
@Nullable private String cursor;
@Nullable private Instant lastModified;

private ImmutableSearchResultBuilder(final JsonArrayBuilder theJsonArrayBuilder) {
jsonArrayBuilder = theJsonArrayBuilder;
Expand Down Expand Up @@ -63,11 +60,9 @@ public static SearchResultBuilder of(final SearchResult searchResult) {
final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(searchResult.getItems());
final Long nextPageOffset = searchResult.getNextPageOffset().orElse(null);
final String cursor = searchResult.getCursor().orElse(null);
final Instant lastModified = searchResult.getLastModified().orElse(null);

return new ImmutableSearchResultBuilder(jsonArrayBuilder).nextPageOffset(nextPageOffset)
.cursor(cursor)
.lastModified(lastModified);
.cursor(cursor);
}

@Override
Expand All @@ -82,12 +77,6 @@ public SearchResultBuilder cursor(@Nullable final String cursor) {
return this;
}

@Override
public SearchResultBuilder lastModified(@Nullable final Instant lastModified) {
this.lastModified = lastModified;
return this;
}

@Override
public SearchResultBuilder add(final JsonValue value, final JsonValue... furtherValues) {
jsonArrayBuilder.add(value, furtherValues);
Expand All @@ -109,7 +98,7 @@ public SearchResultBuilder remove(final JsonValue value) {
@Override
public SearchResult build() {
final JsonArray searchResultsJsonArray = jsonArrayBuilder.build();
return ImmutableSearchResult.of(searchResultsJsonArray, offset, cursor, lastModified);
return ImmutableSearchResult.of(searchResultsJsonArray, offset, cursor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import static org.eclipse.ditto.base.model.exceptions.DittoJsonException.wrapJsonRuntimeException;

import java.time.Instant;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.json.JsonArray;
Expand Down Expand Up @@ -54,22 +52,7 @@ private SearchModelFactory() {
* @throws NullPointerException if {@code items} is {@code null}.
*/
public static SearchResult newSearchResult(final JsonArray items, final long nextPageOffset) {
return ImmutableSearchResult.of(items, nextPageOffset, null, null);
}

/**
* Creates a new {@link SearchResult}.
*
* @param items the items.
* @param nextPageOffset the offset of the next page or {@link org.eclipse.ditto.thingsearch.model.SearchResult#NO_NEXT_PAGE}.
* @param lastModified the last modified timestamp.
* @return the new immutable search results object.
* @throws NullPointerException if {@code items} is {@code null}.
* @since 2.5.0
*/
public static SearchResult newSearchResult(final JsonArray items, final long nextPageOffset,
@Nullable final Instant lastModified) {
return ImmutableSearchResult.of(items, nextPageOffset, null, lastModified);
return ImmutableSearchResult.of(items, nextPageOffset, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.eclipse.ditto.thingsearch.model;

import java.time.Instant;
import java.util.Optional;
import java.util.stream.Stream;

Expand Down Expand Up @@ -82,14 +81,6 @@ default SearchResultBuilder toBuilder() {
*/
Optional<String> getCursor();

/**
* Get the timestamp of the last modification of the search result.
*
* @return the timestamp.
* @since 2.5.0
*/
Optional<Instant> getLastModified();

/**
* Returns {@code true} if there is a next page and thus {@link #getNextPageOffset()} does not equal
* {@link #NO_NEXT_PAGE}, otherwise {@code false}.
Expand Down Expand Up @@ -171,9 +162,6 @@ final class JsonFields {
public static final JsonFieldDefinition<String> CURSOR =
JsonFactory.newStringFieldDefinition("cursor", FieldType.REGULAR, JsonSchemaVersion.V_2);

public static final JsonFieldDefinition<String> LAST_MODIFIED =
JsonFactory.newStringFieldDefinition("lastModified", FieldType.SPECIAL, JsonSchemaVersion.V_2);

private JsonFields() {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.eclipse.ditto.thingsearch.model;

import java.time.Instant;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

Expand Down Expand Up @@ -43,15 +41,6 @@ public interface SearchResultBuilder {
*/
SearchResultBuilder cursor(@Nullable String cursor);

/**
* Set the timestamp of the last modification of the search result.
*
* @param lastModified the timestamp.
* @return this builder.
* @since 2.5.0
*/
SearchResultBuilder lastModified(@Nullable Instant lastModified);

/**
* Adds at least one {@link JsonValue} to the {@code SearchResult} to be built.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import static org.eclipse.ditto.thingsearch.model.assertions.DittoSearchAssertions.assertThat;

import java.time.Instant;

import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonFactory;
import org.junit.Before;
Expand All @@ -42,7 +40,7 @@ public void tryToCreateNewInstanceWithNullSearchResult() {
public void copySearchResultWithBuilder() {
final JsonArray items = JsonFactory.newArrayBuilder().add("foo", "bar", "baz").build();
final long offset = 25;
final SearchResult searchResult = SearchModelFactory.newSearchResult(items, offset, null);
final SearchResult searchResult = SearchModelFactory.newSearchResult(items, offset);

final SearchResultBuilder underTest = ImmutableSearchResultBuilder.of(searchResult);

Expand All @@ -53,7 +51,7 @@ public void copySearchResultWithBuilder() {
public void copyAndModifyExistingSearchResultWithBuilder() {
final JsonArray items = JsonFactory.newArrayBuilder().add("foo", "bar", "baz").build();
final long offset = 25;
final SearchResult searchResult = SearchModelFactory.newSearchResult(items, offset, null);
final SearchResult searchResult = SearchModelFactory.newSearchResult(items, offset);

final SearchResult newSearchResult = ImmutableSearchResultBuilder.of(searchResult)
.nextPageOffset(SearchResult.NO_NEXT_PAGE)
Expand Down Expand Up @@ -114,14 +112,6 @@ public void setNextPageOffset() {
.isEmpty();
}

@Test
public void setLastModified() {
final Instant expectedLastModified = Instant.now();
final SearchResult searchResult = underTest.lastModified(expectedLastModified).build();

assertThat(searchResult.getLastModified()).contains(expectedLastModified);
}

@Test(expected = NullPointerException.class)
public void tryToAddAllNull() {
ImmutableSearchResultBuilder.newInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import java.time.Instant;

import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonArray;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void constructorAndGetters() {
final JsonArray items = JsonFactory.newArray("[1,2,3]");
final long nextPageOffset = 10L;

final SearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null, null);
final SearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null);

assertThat(searchResult.getItems()).isEqualTo(items);
assertThat(searchResult.getNextPageOffset()).contains(nextPageOffset);
Expand All @@ -77,14 +75,12 @@ public void toJsonReturnsExpected() {
.add(1, 2, 3)
.build();
final long nextPageOffset = 10L;
final Instant now = Instant.now();
final JsonObject expected = JsonFactory.newObjectBuilder()
.set(SearchResult.JsonFields.ITEMS, items)
.set(SearchResult.JsonFields.NEXT_PAGE_OFFSET, nextPageOffset)
.set(SearchResult.JsonFields.LAST_MODIFIED, now.toString())
.build();

final Jsonifiable<?> underTest = ImmutableSearchResult.of(items, nextPageOffset, null, now);
final Jsonifiable<?> underTest = ImmutableSearchResult.of(items, nextPageOffset, null);

assertThat(underTest.toJson()).isEqualTo(expected);
}
Expand All @@ -94,7 +90,7 @@ public void toJsonWithAllFieldTypes() {
final String itemsArray = "[1,2,3]";
final JsonArray items = JsonFactory.newArray(itemsArray);
final long nextPageOffset = 10L;
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null, null);
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null);

final String jsonStr = searchResult.toJsonString(FieldType.regularOrSpecial());

Expand All @@ -106,7 +102,7 @@ public void toJsonWithRegularFieldTypes() {
final String itemsArray = "[1,2,3]";
final JsonArray items = JsonFactory.newArray(itemsArray);
final long nextPageOffset = 10L;
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null, null);
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null);

final String jsonStr = searchResult.toJsonString();

Expand Down Expand Up @@ -150,7 +146,7 @@ public void ensureSearchResultNewBuilderWorks() {
final String itemsArray = "[1,2,3]";
final JsonArray items = JsonFactory.newArray(itemsArray);
final long nextPageOffset = 10L;
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null, null);
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null);

final SearchResultBuilder searchResultBuilder = SearchResult.newBuilder()
.addAll(items)
Expand All @@ -164,7 +160,7 @@ public void ensureRelationsToBuilderWorks() {
final String itemsArray = "[1,2,3]";
final JsonArray items = JsonFactory.newArray(itemsArray);
final long nextPageOffset = 10L;
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null, null);
final ImmutableSearchResult searchResult = ImmutableSearchResult.of(items, nextPageOffset, null);

DittoJsonAssertions.assertThat(searchResult).isEqualTo(searchResult.toBuilder().build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void assertImmutability() {
@Test
public void newSearchResult() {
final SearchResult searchResult =
SearchModelFactory.newSearchResult(JsonFactory.newArray(), SearchResult.NO_NEXT_PAGE, null);
SearchModelFactory.newSearchResult(JsonFactory.newArray(), SearchResult.NO_NEXT_PAGE);

assertThat(searchResult) //
.hasNoNextPage() //
Expand Down
Loading

0 comments on commit 9a24fe2

Please sign in to comment.