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

[MODFQMMGR-457] Re-instate old entity-type source values logic #400

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/main/java/org/folio/fqm/service/EntityTypeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ public ColumnValues getFieldValues(UUID entityTypeId, String fieldName, @Nullabl

if (field.getSource() != null) {
if (field.getSource().getType() == SourceColumn.TypeEnum.ENTITY_TYPE) {
return getFieldValuesFromEntityType(entityType, fieldName, searchText);
EntityType sourceEntityType = entityTypeFlatteningService.getFlattenedEntityType(field.getSource().getEntityTypeId(), null);

permissionsService.verifyUserHasNecessaryPermissions(sourceEntityType, false);

return getFieldValuesFromEntityType(sourceEntityType, field.getSource().getColumnName(), searchText);
} else if (field.getSource().getType() == SourceColumn.TypeEnum.FQM) {
switch (Objects.requireNonNull(field.getSource().getName(), "Value sources with the FQM type require the source name to be configured")) {
case "currency" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@
valueFunction: 'lower(:value)',
source: {
entityTypeId: '58148257-bfb0-4687-8c42-d2833d772f3e',
columnName: 'cost_currency',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jackson's handling of json5, for some reason, uses a strategy for duplicate keys last-value-wins. IMO, this is stupid, but it technically matches the way JS handles it (grumble, grumble, there's even a draft spec to fix this)

name: 'fqm',
columnName: 'currency',
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void shouldGetValueWithLabel() {
.id(entityTypeId.toString())
.name("whatever")
.columns(List.of(new EntityTypeColumn().name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.type(SourceColumn.TypeEnum.ENTITY_TYPE))));

ColumnValues expectedColumnValueLabel = new ColumnValues()
Expand Down Expand Up @@ -208,7 +208,7 @@ void shouldReturnValueAsLabelIfIdColumnDoNotExist() {
.id(entityTypeId.toString())
.name("the entity type")
.columns(List.of(new EntityTypeColumn().name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.type(SourceColumn.TypeEnum.ENTITY_TYPE))));

when(queryProcessorService.processQuery(any(EntityType.class), any(), any(), any(), any()))
Expand Down Expand Up @@ -239,7 +239,7 @@ void shouldFilterBySearchText() {
.id(entityTypeId.toString())
.name("this is a thing")
.columns(List.of(new EntityTypeColumn().name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.type(SourceColumn.TypeEnum.ENTITY_TYPE))));
String searchText = "search text";
String expectedFql = "{\"" + valueColumnName + "\": {\"$regex\": " + "\"" + searchText + "\"}}";
Expand All @@ -256,7 +256,7 @@ void shouldHandleNullSearchText() {
.id(entityTypeId.toString())
.name("yep")
.columns(List.of(new EntityTypeColumn().name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.type(SourceColumn.TypeEnum.ENTITY_TYPE))));
List<String> fields = List.of("id", valueColumnName);
String expectedFql = "{\"" + valueColumnName + "\": {\"$regex\": " + "\"\"}}";
Expand Down Expand Up @@ -378,7 +378,7 @@ void shouldReturnCurrencies() {
.name("currency-test")
.columns(List.of(new EntityTypeColumn()
.name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.name("currency") // The special FQM source uses "currency" as the name of the currency value source
.type(SourceColumn.TypeEnum.FQM))
));
Expand All @@ -405,7 +405,7 @@ void shouldReturnTenantId() {
.name("tenant-id-test")
.columns(List.of(new EntityTypeColumn()
.name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.name("tenant_id") // The special FQM source uses "tenant_id" as the name of the currency value source
.type(SourceColumn.TypeEnum.FQM))
));
Expand All @@ -431,7 +431,7 @@ void shouldIncludeCentralTenantIdInResponseForSimpleInstanceEntityType() {
.name("tenant-id-test")
.columns(List.of(new EntityTypeColumn()
.name(valueColumnName)
.source(new SourceColumn(entityTypeId.toString(), valueColumnName)
.source(new SourceColumn(entityTypeId, valueColumnName)
.name("tenant_id") // The special FQM source uses "tenant_id" as the name of the currency value source
.type(SourceColumn.TypeEnum.FQM))
));
Expand Down