Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for arrays #459

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
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
Loading