Skip to content

Commit

Permalink
added support for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Dec 20, 2024
1 parent 2164f82 commit e28d9f2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public class ViewerConstants {
public static final String SOLR_DYN_LOCATION_RPT = "_srpt";
public static final String SOLR_DYN_LONG = "_l";
public static final String SOLR_DYN_STRING = "_s";
public static final String SOLR_DYN_STRING_MULTI = "_ss";
public static final String SOLR_DYN_TEXT_GENERAL = "_t";
public static final String SOLR_DYN_TEXT_MULTI = "_txt";
public static final String SOLR_DYN_NEST_MULTI = "_nst";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
* @author Bruno Ferreira <bferreira@keep.pt>
Expand All @@ -17,6 +18,7 @@ public class ViewerCell implements Serializable {
@Serial
private static final long serialVersionUID = -5345114836590659380L;
private String value;
private List<String> listValue;
private String mimeType;
private String fileExtension;
private ViewerLobStoreType storeType;
Expand Down Expand Up @@ -53,6 +55,19 @@ public void setValue(String value) {
this.value = value;
}

/**
* Gets the value of this cell as list of strings
*
* @return the value or null if the database cell value was NULL
*/
public List<String> getListValue() {
return listValue;
}

public void setListValue(List<String> listValue) {
this.listValue = listValue;
}

public String getMimeType() {
return mimeType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ public SolrInputDocument toSolrDocument(ViewerRow row) throws ViewerException, R
doc.setField(SOLR_ROWS_TABLE_UUID, row.getTableUUID());
for (Map.Entry<String, ViewerCell> cellEntry : row.getCells().entrySet()) {
String solrColumnName = cellEntry.getKey();
String cellValue = cellEntry.getValue().getValue();
doc.addField(solrColumnName, cellValue);
if (solrColumnName.endsWith(ViewerConstants.SOLR_DYN_STRING_MULTI)) {
doc.addField(solrColumnName, cellEntry.getValue().getListValue());
} else {
String cellValue = cellEntry.getValue().getValue();
doc.addField(solrColumnName, cellValue);
}
}

for (Map.Entry<String, ViewerMimeType> cellEntry : row.getColsMimeTypeList().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import com.databasepreservation.model.data.ArrayCell;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -67,7 +68,6 @@
import com.databasepreservation.common.client.models.structure.ViewerTable;
import com.databasepreservation.common.client.models.structure.ViewerTrigger;
import com.databasepreservation.common.client.models.structure.ViewerType;
import com.databasepreservation.common.client.models.structure.ViewerTypeArray;
import com.databasepreservation.common.client.models.structure.ViewerTypeStructure;
import com.databasepreservation.common.client.models.structure.ViewerUserStructure;
import com.databasepreservation.common.client.models.structure.ViewerView;
Expand Down Expand Up @@ -687,7 +687,7 @@ private static String getColumnSolrName(int index, Type type, ViewerType viewerT
} else if (type instanceof SimpleTypeString) {
suffix = ViewerConstants.SOLR_DYN_TEXT_GENERAL;
} else if (type instanceof ComposedTypeArray) {
throw new ViewerException("Arrays are not yet supported.");
suffix = ViewerConstants.SOLR_DYN_STRING_MULTI;
} else if (type instanceof ComposedTypeStructure) {
throw new ViewerException("Composed types are not yet supported.");
} else {
Expand Down Expand Up @@ -735,10 +735,11 @@ private static ViewerType getType(Type type) throws ViewerException {
result.setDbType(ViewerType.dbTypes.STRING);
}
} else if (type instanceof ComposedTypeArray) {
result = new ViewerTypeArray();
// result = new ViewerTypeArray();
result.setDbType(ViewerType.dbTypes.COMPOSED_ARRAY);
// set type of elements in the array
((ViewerTypeArray) result).setElementType(getType(((ComposedTypeArray) type).getElementType()));
// ((ViewerTypeArray) result).setElementType(getType(((ComposedTypeArray)
// type).getElementType()));
} else if (type instanceof ComposedTypeStructure) {
result = new ViewerTypeStructure();
result.setDbType(ViewerType.dbTypes.COMPOSED_STRUCTURE);
Expand Down Expand Up @@ -897,6 +898,13 @@ private static ViewerCell getCell(CollectionStatus collectionConfiguration, View
default:
result.setValue(removeUnicode(simpleCell.getSimpleData()));
}
} else if (cell instanceof ArrayCell) {
ArrayCell arrayCell = (ArrayCell) cell;
List<String> valuesList = new ArrayList<>();
arrayCell.forEach(arrayElement -> {
valuesList.add(((SimpleCell) arrayElement.getValue()).getSimpleData());
});
result.setListValue(valuesList);
} else if (!(cell instanceof NullCell)) {
// nothing to do for null cells
throw new ViewerException("Unexpected cell type");
Expand Down

0 comments on commit e28d9f2

Please sign in to comment.