Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Jan 25, 2024
2 parents fde267c + 3f27f6f commit 2b6af6c
Show file tree
Hide file tree
Showing 66 changed files with 998 additions and 1,605 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ public static boolean isBaseSnapshot(@NonNull Snapshot snapshot) {
return Boolean.parseBoolean(annotations.get(Snapshot.KEEP_RAW_ANNO));
}

public static String toSubjectRefKey(Ref subjectRef) {
return subjectRef.getGroup() + "/" + subjectRef.getKind() + "/" + subjectRef.getName();
}
}
10 changes: 10 additions & 0 deletions api/src/main/java/run/halo/app/extension/ListResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
import lombok.Data;
Expand Down Expand Up @@ -144,6 +145,15 @@ public static <T> List<T> subList(List<T> list, int page, int size) {
return listSort;
}

/**
* Gets the first element of the list result.
*/
public static <T> Optional<T> first(ListResult<T> listResult) {
return Optional.ofNullable(listResult)
.map(ListResult::getItems)
.map(list -> list.isEmpty() ? null : list.get(0));
}

@Override
public Stream<T> get() {
return items.stream();
Expand Down
17 changes: 17 additions & 0 deletions api/src/main/java/run/halo/app/extension/Scheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ public static GVK getGvkFromType(@NonNull Class<? extends Extension> type) {
"Missing annotation " + GVK.class.getName() + " on type " + type.getName());
return gvk;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Scheme scheme = (Scheme) o;
return groupVersionKind.equals(scheme.groupVersionKind);
}

@Override
public int hashCode() {
return groupVersionKind.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package run.halo.app.extension.router.selector;

import java.util.Objects;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import run.halo.app.extension.index.query.Query;
import run.halo.app.extension.index.query.QueryFactory;

public record FieldSelector(Query query) {
public record FieldSelector(@NonNull Query query) {
public FieldSelector(Query query) {
this.query = Objects.requireNonNullElseGet(query, QueryFactory::all);
}

public static FieldSelector of(Query query) {
return new FieldSelector(query);
}

public static FieldSelector all() {
return new FieldSelector(QueryFactory.all());
}

public FieldSelector andQuery(Query other) {
Assert.notNull(other, "Query must not be null");
return of(QueryFactory.and(query(), other));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ public boolean test(@NonNull Map<String, String> labels) {
.allMatch(matcher -> matcher.test(labels.get(matcher.getKey())));
}

/**
* Returns a new label selector that is the result of ANDing the current selector with the
* given selector.
*
* @param other the selector to AND with
* @return a new label selector
*/
public LabelSelector and(LabelSelector other) {
var labelSelector = new LabelSelector();
var matchers = new ArrayList<SelectorMatcher>();
matchers.addAll(this.matchers);
matchers.addAll(other.matchers);
labelSelector.setMatchers(matchers);
return labelSelector;
}

public static LabelSelectorBuilder builder() {
return new LabelSelectorBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public static ListOptions labelAndFieldSelectorToListOptions(
listOptions.setLabelSelector(new LabelSelector().setMatchers(labelMatchers));
if (!fieldQuery.isEmpty()) {
listOptions.setFieldSelector(FieldSelector.of(QueryFactory.and(fieldQuery)));
} else {
listOptions.setFieldSelector(FieldSelector.all());
}
return listOptions;
}
Expand Down
129 changes: 0 additions & 129 deletions application/src/main/java/run/halo/app/content/DefaultIndexer.java

This file was deleted.

79 changes: 0 additions & 79 deletions application/src/main/java/run/halo/app/content/Indexer.java

This file was deleted.

Loading

0 comments on commit 2b6af6c

Please sign in to comment.