diff --git a/dspace-api/src/main/java/org/dspace/app/util/Util.java b/dspace-api/src/main/java/org/dspace/app/util/Util.java index ff487ca8db..c714f2e94b 100644 --- a/dspace-api/src/main/java/org/dspace/app/util/Util.java +++ b/dspace-api/src/main/java/org/dspace/app/util/Util.java @@ -9,16 +9,23 @@ package org.dspace.app.util; import java.io.IOException; import java.io.InputStream; +import java.sql.SQLException; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; import java.util.Locale; import java.util.Properties; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; +import org.dspace.content.Collection; +import org.dspace.content.DCValue; +import org.dspace.content.Item; import org.dspace.core.Constants; +import org.dspace.core.I18nUtil; /** @@ -350,4 +357,113 @@ public class Util { } return sourceVersion; } + + /** + * Get a list of all the respective "displayed-value(s)" from the given + * "stored-value(s)" for a specific metadata field of a DSpace Item, by + * reading input-forms.xml + * + * @param item + * The Dspace Item + * @param values + * A DCValue[] array of the specific "stored-value(s)" + * @param schema + * A String with the schema name of the metadata field + * @param element + * A String with the element name of the metadata field + * @param qualifier + * A String with the qualifier name of the metadata field + * @return A list of the respective "displayed-values" + */ + + public static List getControlledVocabulariesDisplayValueLocalized( + Item item, DCValue[] values, String schema, String element, + String qualifier, Locale locale) throws SQLException, + DCInputsReaderException + { + List toReturn = new ArrayList(); + DCInput myInputs = null; + boolean myInputsFound = false; + String formFileName = I18nUtil.getInputFormsFileName(locale); + String col_handle = ""; + + Collection collection = item.getOwningCollection(); + + if (collection == null) + { + // set an empty handle so to get the default input set + col_handle = ""; + } + else + { + col_handle = collection.getHandle(); + } + + // Read the input form file for the specific collection + DCInputsReader inputsReader = new DCInputsReader(formFileName); + + DCInputSet inputSet = inputsReader.getInputs(col_handle); + + // Replace the values of DCValue[] with the correct ones in case of + // controlled vocabularies + String currentField = schema + "." + element + + (qualifier == null ? "" : "." + qualifier); + + if (inputSet != null) + { + + int pageNums = inputSet.getNumberPages(); + + for (int p = 0; p < pageNums; p++) + { + + DCInput[] inputs = inputSet.getPageRows(p, false, false); + + if (inputs != null) + { + + for (int i = 0; i < inputs.length; i++) + { + String inputField = inputs[i].getSchema() + + "." + + inputs[i].getElement() + + (inputs[i].getQualifier() == null ? "" : "." + + inputs[i].getQualifier()); + if (currentField.equals(inputField)) + { + + myInputs = inputs[i]; + myInputsFound = true; + break; + + } + } + } + if (myInputsFound) + break; + } + } + + if (myInputsFound) + { + + for (int j = 0; j < values.length; j++) + { + + String pairsName = myInputs.getPairsType(); + String stored_value = values[j].value; + String displayVal = myInputs.getDisplayString(pairsName, + stored_value); + + if (displayVal != null && !"".equals(displayVal)) + { + + toReturn.add(displayVal); + } + + } + } + + return toReturn; + } } diff --git a/dspace-api/src/main/java/org/dspace/search/DSIndexer.java b/dspace-api/src/main/java/org/dspace/search/DSIndexer.java index fdbb686e77..d104e95505 100644 --- a/dspace-api/src/main/java/org/dspace/search/DSIndexer.java +++ b/dspace-api/src/main/java/org/dspace/search/DSIndexer.java @@ -66,6 +66,9 @@ import org.dspace.handle.HandleManager; import org.dspace.sort.SortOption; import org.dspace.sort.OrderFormat; +import org.dspace.app.util.DCInputsReaderException; +import org.dspace.app.util.Util; + /** * DSIndexer contains the methods that index Items and their metadata, * collections, communities, etc. It is meant to either be invoked from the @@ -251,7 +254,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - public static void indexContent(Context context, DSpaceObject dso) throws SQLException + public static void indexContent(Context context, DSpaceObject dso) throws SQLException, DCInputsReaderException { indexContent(context, dso, false); } @@ -267,7 +270,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - public static void indexContent(Context context, DSpaceObject dso, boolean force) throws SQLException + public static void indexContent(Context context, DSpaceObject dso, boolean force) throws SQLException, DCInputsReaderException { try { @@ -649,7 +652,7 @@ public class DSIndexer } - static IndexingTask prepareIndexingTask(DSpaceObject dso, boolean force) throws SQLException, IOException + static IndexingTask prepareIndexingTask(DSpaceObject dso, boolean force) throws SQLException, IOException, DCInputsReaderException { String handle = dso.getHandle(); Term term = new Term("handle", handle); @@ -1037,7 +1040,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - private static Document buildDocumentForItem(Item item) throws SQLException, IOException + private static Document buildDocumentForItem(Item item) throws SQLException, IOException, DCInputsReaderException { String handle = item.getHandle(); @@ -1065,7 +1068,49 @@ public class DSIndexer mydc = item.getMetadata(indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, Item.ANY); } - for (j = 0; j < mydc.length; j++) + + //Index the controlled vocabularies localized display values for all localized input-forms.xml (e.g. input-forms_el.xml) + if ("inputform".equalsIgnoreCase(indexConfigArr[i].type)){ + + List newValues = new ArrayList(); + Locale[] supportedLocales=I18nUtil.getSupportedLocales(); + + // Get the display value of the respective stored value + for (int k = 0; k < supportedLocales.length; k++) + { + List displayValues = Util + .getControlledVocabulariesDisplayValueLocalized( + item, mydc, indexConfigArr[i].schema, + indexConfigArr[i].element, + indexConfigArr[i].qualifier, + supportedLocales[k]); + if (displayValues != null && !displayValues.isEmpty()) + { + for (int d = 0; d < displayValues.size(); d++) + { + newValues.add(displayValues.get(d)); + } + } + + } + + if (newValues!=null){ + for (int m=0;m In case we have different input-forms for different repository supported locales (e.g input-forms_el.xml, input-forms_pt.xml etc). In this case, the +# stored and the displayed value from all input-forms are indexed. If the stored value is not found in input-forms, it is indexed anyway. +# e.g.:search.index.12 = language:dc.language:inputform +# ### changing these will change your search results, ### ### but will NOT automatically change your search displays ###