Skip to content

Commit

Permalink
[#17725] SearchIndex - truncate value with maxSize for DB update
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltansuller committed May 22, 2024
1 parent 237be16 commit a077002
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public void updateIndexWithData(List<SearchIndexObject> changeList) {

return u;
}), updateResult,
Collections.emptyMap());
Collections.emptyMap(),
true);
// Update the entity definitions by the table data in the result.
objectMapping.merge(updateResult, Collections.emptyList());

Expand All @@ -276,10 +277,10 @@ private final SearchEntityTableDataResult readAllObjects(SearchEntityTableDataRe
objectMapping.readObjects(
allObjectUris.stream().map(u -> new SearchIndexObject().objectNode(objectApi.load(u))),
result,
Collections.emptyMap());
Collections.emptyMap(), false);
} else {
objectMapping.readObjects(objectNodes.map(n -> new SearchIndexObject().objectNode(n)), result,
Collections.emptyMap());
Collections.emptyMap(), false);
}

return result;
Expand All @@ -301,7 +302,8 @@ public TableData<?> tableDataOfUris(Stream<URI> uris) {
SearchEntityTableDataResult entityResult = constructResult();
objectMapping.readObjects(uris.map(u -> new SearchIndexObject().objectNode(objectApi.load(u))),
entityResult,
Collections.emptyMap());
Collections.emptyMap(),
false);
return entityResult.result;
}

Expand All @@ -312,7 +314,7 @@ public TableData<?> tableDataOfObjects(Stream<O> objects) {
objects.map(o -> new SearchIndexObject().objectNode(objectApi
.create(StringConstant.EMPTY, o))),
entityResult,
Collections.emptyMap());
Collections.emptyMap(), false);
return entityResult.result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private boolean isPrimaryKey(String propertyName) {
}

final void readObjects(Stream<SearchIndexObject> objects,
SearchEntityTableDataResult result, Map<String, Object> defaultValues) {
SearchEntityTableDataResult result, Map<String, Object> defaultValues, boolean useLength) {

// Create detail TableDatas
for (Entry<String, DetailDefinition> entry : result.searchEntityDefinition.detailsByName
Expand All @@ -363,12 +363,12 @@ final void readObjects(Stream<SearchIndexObject> objects,
Object value = null;
Object defaultValue = defaultValues.get(col.getProperty().getName());
Object forcedValue = o.getValues().get(col.getName());
SearchIndexMappingProperty mapping = property(col.getProperty().getName());
if (forcedValue != null) {
value = forcedValue;
} else if (defaultValue != null) {
value = defaultValue;
} else {
SearchIndexMappingProperty mapping = property(col.getProperty().getName());
if (mapping.path != null && mapping.processor == null
&& mapping.complexProcessor == null) {
value = n.getValue(mapping.path);
Expand All @@ -386,6 +386,9 @@ final void readObjects(Stream<SearchIndexObject> objects,
if (value != null && !col.getProperty().type().isInstance(value)) {
value = objectApi.asType(col.getProperty().type(), value);
}
if (useLength && mapping.length > 0 && value instanceof String) {
value = truncateString((String) value, mapping.length);
}
tableData.setObject(col, row, value);
}
// Read all the details also.
Expand Down Expand Up @@ -431,14 +434,22 @@ final void readObjects(Stream<SearchIndexObject> objects,
detailResult,
entry.getValue().masterJoin.getReferences().get(0).joins().stream()
.collect(toMap(j -> j.getSourceProperty().getName(),
j -> tableData.get(tableData.getColumn(j.getTargetProperty()), row))));
j -> tableData.get(tableData.getColumn(j.getTargetProperty()), row))),
useLength);

}
}
});

}

public final String truncateString(String str, int maxSize) {
if (str == null) {
return null;
}
return str.length() > maxSize ? str.substring(0, maxSize) : str;
}

public final SearchIndexMappingObject filterClass(Class<?> filterClass) {
this.filterClass = filterClass;
return this;
Expand Down

0 comments on commit a077002

Please sign in to comment.