Merge branch 'stable-3.1'
* stable-3.1: AbstractElasticIndex: Add helper method to invoke base64 decode Elasticsearch: Don't use JsonElement.toString ElasticChangeIndex: Consistently use static imported Base64.decodeBase64 MergeValidationListener: Add missing Javadoc Change-Id: I87136d6ae0872bf212c132cc4ffa67f03bea4fd6
This commit is contained in:
@@ -87,6 +87,10 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
protected static final String SEARCH = "_search";
|
||||
protected static final String SETTINGS = "settings";
|
||||
|
||||
protected static byte[] decodeBase64(String base64String) {
|
||||
return Base64.decodeBase64(base64String);
|
||||
}
|
||||
|
||||
protected static <T> List<T> decodeProtos(
|
||||
JsonObject doc, String fieldName, ProtoConverter<?, T> converter) {
|
||||
JsonArray field = doc.getAsJsonArray(fieldName);
|
||||
@@ -94,8 +98,8 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
return null;
|
||||
}
|
||||
return Streams.stream(field)
|
||||
.map(JsonElement::toString)
|
||||
.map(Base64::decodeBase64)
|
||||
.map(JsonElement::getAsString)
|
||||
.map(AbstractElasticIndex::decodeBase64)
|
||||
.map(bytes -> parseProtoFrom(bytes, converter))
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_S
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.apache.commons.codec.binary.Base64.decodeBase64;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
@@ -65,7 +64,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.elasticsearch.client.Response;
|
||||
|
||||
@@ -219,7 +217,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
|
||||
ChangeData cd =
|
||||
changeDataFactory.create(
|
||||
parseProtoFrom(Base64.decodeBase64(c.getAsString()), ChangeProtoConverter.INSTANCE));
|
||||
parseProtoFrom(decodeBase64(c.getAsString()), ChangeProtoConverter.INSTANCE));
|
||||
|
||||
// Any decoding that is done here must also be done in {@link LuceneChangeIndex}.
|
||||
|
||||
@@ -403,7 +401,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
private Iterable<byte[]> getByteArray(JsonObject source, String name) {
|
||||
JsonElement element = source.get(name);
|
||||
return element != null
|
||||
? Iterables.transform(element.getAsJsonArray(), e -> Base64.decodeBase64(e.getAsString()))
|
||||
? Iterables.transform(element.getAsJsonArray(), e -> decodeBase64(e.getAsString()))
|
||||
: Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -415,7 +413,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
|
||||
}
|
||||
ChangeField.parseSubmitRecords(
|
||||
FluentIterable.from(records)
|
||||
.transform(i -> new String(decodeBase64(i.toString()), UTF_8))
|
||||
.transform(i -> new String(decodeBase64(i.getAsString()), UTF_8))
|
||||
.toList(),
|
||||
opts,
|
||||
out);
|
||||
|
||||
@@ -37,6 +37,7 @@ public interface MergeValidationListener {
|
||||
* @param commit commit details
|
||||
* @param destProject the destination project
|
||||
* @param destBranch the destination branch
|
||||
* @param changeId the change ID
|
||||
* @param patchSetId the patch set ID
|
||||
* @param caller the user who initiated the merge request
|
||||
* @throws MergeValidationException if the commit fails to validate
|
||||
|
||||
Reference in New Issue
Block a user