1111import lombok .experimental .UtilityClass ;
1212import org .folio .fql .model .FqlCondition ;
1313import org .folio .fql .model .field .MarcFieldName ;
14+ import org .folio .fql .service .MarcFieldFactory ;
1415import org .folio .fqm .exception .InvalidEntityTypeDefinitionException ;
1516import org .folio .querytool .domain .dto .EntityType ;
1617import org .folio .querytool .domain .dto .EntityTypeColumn ;
2021 * Builds the SQL-bearing synthetic columns and query contexts for dynamic MARC fields.
2122 *
2223 * <p>MARC field-name parsing, recognition, placeholder detection, and metadata-only column generation are owned
23- * by the shared lib ({@link org.folio.fql.service.MarcFieldFactory}), so the grammar lives in exactly one place.
24- * This class layers the mod-fqm-manager-specific SQL onto the lib's parsed results: the {@code valueGetter} that
25- * correlates against the marc_indexers view, the filter/value functions, and the row-level predicates used for
26- * querying.
24+ * by the shared lib ({@link MarcFieldFactory}), so the grammar lives in exactly one place. This class layers the
25+ * mod-fqm-manager-specific SQL onto the lib's parsed results: the {@code valueGetter} that correlates against the
26+ * marc_indexers view, the filter/value functions, and the row-level predicates used for querying.
2727 */
2828@ UtilityClass
29- public class MarcFieldFactory {
29+ public class MarcSqlFactory {
3030
3131 private static final String MARC_INDEXERS_VIEW = "${tenant_id}_mod_fqm_manager.src_srs_marc_indexers" ;
3232 private static final String MARC_VALUE_FUNCTION = "lower(:value)" ;
3333 private static final Pattern MARC_TABLE_PATTERN =
3434 Pattern .compile ("FROM\\ s+(?<table>\\ S+)\\ s+marc" , Pattern .CASE_INSENSITIVE );
3535
36- // ---- Delegation to the shared lib -----------------------------------------------------------------------
37- // Thin pass-throughs so existing mod-fqm-manager call sites keep a single entry point while the grammar and
38- // placeholder logic live in the lib.
39-
40- public static Set <String > getReferencedMarcFieldNames (String rawQuery ) {
41- return org .folio .fql .service .MarcFieldFactory .getReferencedMarcFieldNames (rawQuery );
42- }
43-
44- public static Set <String > getReferencedMarcFieldNames (FqlCondition <?> condition ) {
45- return org .folio .fql .service .MarcFieldFactory .getReferencedMarcFieldNames (condition );
46- }
47-
48- public static Optional <EntityTypeColumn > findMarcPlaceholder (EntityType entityType ) {
49- return org .folio .fql .service .MarcFieldFactory .findMarcPlaceholder (entityType );
50- }
51-
52- public static boolean isGenericMarcPlaceholder (EntityTypeColumn column ) {
53- return org .folio .fql .service .MarcFieldFactory .isGenericMarcPlaceholder (column );
54- }
55-
5636 // ---- Synthetic column construction ----------------------------------------------------------------------
5737
5838 public static EntityType addSyntheticColumns (EntityType entityType , String rawQuery , String tenantId ) {
59- return addSyntheticColumns (entityType , getReferencedMarcFieldNames (rawQuery ), tenantId );
39+ return addSyntheticColumns (entityType , MarcFieldFactory . getReferencedMarcFieldNames (rawQuery ), tenantId );
6040 }
6141
6242 public static EntityType addSyntheticColumns (EntityType entityType , FqlCondition <?> condition , String tenantId ) {
63- return addSyntheticColumns (entityType , getReferencedMarcFieldNames (condition ), tenantId );
43+ return addSyntheticColumns (entityType , MarcFieldFactory . getReferencedMarcFieldNames (condition ), tenantId );
6444 }
6545
6646 public static EntityType addSyntheticColumns (EntityType entityType , Collection <String > fieldNames , String tenantId ) {
@@ -88,8 +68,8 @@ public static EntityType addSyntheticColumns(EntityType entityType, Collection<S
8868 }
8969
9070 public static Optional <EntityTypeColumn > createSyntheticColumn (EntityType entityType , String fieldName , String tenantId ) {
91- Optional <MarcFieldName > parsedField = org . folio . fql . service . MarcFieldFactory .parse (fieldName );
92- Optional <EntityTypeColumn > placeholder = findMarcPlaceholder (entityType );
71+ Optional <MarcFieldName > parsedField = MarcFieldFactory .parse (fieldName );
72+ Optional <EntityTypeColumn > placeholder = MarcFieldFactory . findMarcPlaceholder (entityType );
9373
9474 if (parsedField .isEmpty () || placeholder .isEmpty ()) {
9575 return Optional .empty ();
@@ -113,15 +93,15 @@ public static Optional<EntityTypeColumn> createSyntheticColumn(EntityType entity
11393
11494 MarcFieldName marcField = parsedField .get ();
11595 // The lib supplies the metadata-only column (name, label, marcType); mod-fqm-manager layers on the SQL.
116- return Optional .of (org . folio . fql . service . MarcFieldFactory .toColumn (marcField )
96+ return Optional .of (MarcFieldFactory .toColumn (marcField )
11797 .valueGetter (buildValueGetter (marcField , marcPlaceholder .getValueGetter (), tenantId ))
11898 .filterValueGetter (filterValueGetter (marcField ))
11999 .valueFunction (MARC_VALUE_FUNCTION ));
120100 }
121101
122102 public static Optional <MarcQueryContext > createQueryContext (EntityType entityType , String fieldName ) {
123- Optional <MarcFieldName > parsedField = org . folio . fql . service . MarcFieldFactory .parse (fieldName );
124- Optional <EntityTypeColumn > placeholder = findMarcPlaceholder (entityType );
103+ Optional <MarcFieldName > parsedField = MarcFieldFactory .parse (fieldName );
104+ Optional <EntityTypeColumn > placeholder = MarcFieldFactory . findMarcPlaceholder (entityType );
125105 Optional <EntityTypeColumn > syntheticField = EntityTypeUtils .findColumn (entityType , fieldName );
126106
127107 if (parsedField .isEmpty () || placeholder .isEmpty () || syntheticField .isEmpty ()) {
@@ -205,7 +185,7 @@ public record MarcQueryContext(MarcFieldName marcField, String tableName, String
205185
206186 /** SQL expression the search value is compared against (the value column, or an indicator column). */
207187 public String filterValueGetter () {
208- return MarcFieldFactory .filterValueGetter (marcField );
188+ return MarcSqlFactory .filterValueGetter (marcField );
209189 }
210190
211191 public String whereClause () {
0 commit comments