epugh commented on code in PR #3200: URL: https://github.com/apache/solr/pull/3200#discussion_r1964253721
########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLRequestWriter.java: ########## @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.solrj.impl; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.util.ClientUtils; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.ShardParams; +import org.apache.solr.common.util.ContentStream; +import org.apache.solr.common.util.XML; + +public class XMLRequestWriter extends RequestWriter { + + /** + * Use this to do a push writing instead of pull. If this method returns null {@link + * org.apache.solr.client.solrj.request.RequestWriter#getContentStreams(SolrRequest)} is invoked + * to do a pull write. + */ + @Override + public RequestWriter.ContentWriter getContentWriter(SolrRequest<?> req) { + if (req instanceof UpdateRequest updateRequest) { + if (isEmpty(updateRequest)) return null; + return new RequestWriter.ContentWriter() { + @Override + public void write(OutputStream os) throws IOException { + OutputStreamWriter writer = new OutputStreamWriter(os, StandardCharsets.UTF_8); + writeXML(updateRequest, writer); + writer.flush(); + } + + @Override + public String getContentType() { + return ClientUtils.TEXT_XML; + } + }; + } + return req.getContentWriter(ClientUtils.TEXT_XML); + } + + @Override + public Collection<ContentStream> getContentStreams(SolrRequest<?> req) throws IOException { + if (req instanceof UpdateRequest) { + return null; + } + return req.getContentStreams(); + } + + @Override + public void write(SolrRequest<?> request, OutputStream os) throws IOException { + if (request instanceof UpdateRequest updateRequest) { + BufferedWriter writer = + new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); + writeXML(updateRequest, writer); + writer.flush(); + } + } + + @Override + public String getUpdateContentType() { + return ClientUtils.TEXT_XML; + } + + public void writeXML(UpdateRequest request, Writer writer) throws IOException { + List<Map<SolrInputDocument, Map<String, Object>>> getDocLists = getDocLists(request); + + for (Map<SolrInputDocument, Map<String, Object>> docs : getDocLists) { + + if (docs != null && !docs.isEmpty()) { + Map.Entry<SolrInputDocument, Map<String, Object>> firstDoc = + docs.entrySet().iterator().next(); + Map<String, Object> map = firstDoc.getValue(); + Integer cw = null; Review Comment: seems odd to have both `cw` and later `commitWithin`, and since we don't normally abbriveate variables, do `commitWithin` and `overwrite` everywhere? ########## solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java: ########## @@ -368,147 +368,39 @@ public void setDeleteQuery(List<String> deleteQuery) { // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- + /** + * @deprecated Method will be removed in Solr 10.0. Use {@link XMLRequestWriter} instead. + */ + @Deprecated(since = "9.9") Review Comment: thanks for the `since`, I like seeing those to help remind us when we can clean them up. Plus, you added a reminder in the docs! ########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLRequestWriter.java: ########## @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.solrj.impl; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.util.ClientUtils; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.ShardParams; +import org.apache.solr.common.util.ContentStream; +import org.apache.solr.common.util.XML; + +public class XMLRequestWriter extends RequestWriter { + + /** + * Use this to do a push writing instead of pull. If this method returns null {@link Review Comment: kind of nit, but what does a "push writing" mean versus pull? Maybe if I read other javadocs it would be clear what that concept is? ########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLRequestWriter.java: ########## @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.solrj.impl; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.util.ClientUtils; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.ShardParams; +import org.apache.solr.common.util.ContentStream; +import org.apache.solr.common.util.XML; + +public class XMLRequestWriter extends RequestWriter { + + /** + * Use this to do a push writing instead of pull. If this method returns null {@link Review Comment: maybe just looking for this javadoc to work a bit harder in explaining things! ########## solr/solrj/src/java/org/apache/solr/client/solrj/request/RequestWriter.java: ########## @@ -50,36 +47,14 @@ public interface ContentWriter { * org.apache.solr.client.solrj.request.RequestWriter#getContentStreams(SolrRequest)} is invoked * to do a pull write. */ - public ContentWriter getContentWriter(SolrRequest<?> req) { Review Comment: nice! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org