|
| 1 | +/** |
| 2 | + * The contents of this file are subject to the license and copyright |
| 3 | + * detailed in the LICENSE and NOTICE files at the root of the source |
| 4 | + * tree and available online at |
| 5 | + * |
| 6 | + * http://www.dspace.org/license/ |
| 7 | + */ |
| 8 | +package edu.jhu.library.dspace.discovery.indexobject; |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | +import java.sql.SQLException; |
| 12 | + |
| 13 | +import org.apache.solr.client.solrj.SolrServerException; |
| 14 | +import org.apache.solr.common.SolrInputDocument; |
| 15 | +import org.apache.solr.common.SolrInputField; |
| 16 | +import org.dspace.access.status.DefaultAccessStatusHelper; |
| 17 | +import org.dspace.core.Context; |
| 18 | +import org.dspace.discovery.indexobject.IndexableItem; |
| 19 | +import org.dspace.discovery.indexobject.ItemIndexFactoryImpl; |
| 20 | + |
| 21 | +/** |
| 22 | + * This is an extended ItemIndexFactoryImpl for JHU. This class is needed for when changes are needed in the creation |
| 23 | + * and writing of the solr item document that cannot be done using solr plugins. For example, we needed to not write |
| 24 | + * fulltext to the solr document if the access_status_filter was not open.access, but fulltext is added to the document |
| 25 | + * in the writeDocument method instead of in buildDocument where the plugins are executed. |
| 26 | + */ |
| 27 | +public class JhuItemIndexFactoryImpl extends ItemIndexFactoryImpl { |
| 28 | + |
| 29 | + @Override |
| 30 | + public void writeDocument(Context context, IndexableItem indexableObject, SolrInputDocument solrInputDocument) |
| 31 | + throws SQLException, IOException, SolrServerException { |
| 32 | + SolrInputField field = solrInputDocument.getField("access_status_filter"); |
| 33 | + if (field != null && DefaultAccessStatusHelper.OPEN_ACCESS.equals(field.getValue())) { |
| 34 | + super.writeDocument(context, indexableObject, solrInputDocument); |
| 35 | + } else { |
| 36 | + writeDocument(solrInputDocument, null); |
| 37 | + } |
| 38 | + } |
| 39 | +} |
0 commit comments