|
107 | 107 | @Slf4j |
108 | 108 | public class SearchIndexFactory { |
109 | 109 |
|
| 110 | + /** |
| 111 | + * Returns the minimal set of fields the reindex path must request from |
| 112 | + * {@code EntityRepository.setFields} for the given entity type. Probes the corresponding |
| 113 | + * index class via {@link #buildIndex(String, Object)} with a {@code null} entity and calls |
| 114 | + * {@link SearchIndex#getRequiredReindexFields()}. Index constructors must be safe with a null |
| 115 | + * entity for this probe to work — they are today because field declarations are static. |
| 116 | + */ |
| 117 | + public java.util.Set<String> getReindexFieldsFor(String entityType) { |
| 118 | + try { |
| 119 | + SearchIndex probe = buildIndex(entityType, null); |
| 120 | + if (probe != null) { |
| 121 | + return probe.getRequiredReindexFields(); |
| 122 | + } |
| 123 | + } catch (Exception e) { |
| 124 | + LOG.warn( |
| 125 | + "Failed to probe reindex fields for entity type {}; falling back to common set: {}", |
| 126 | + entityType, |
| 127 | + e.getMessage()); |
| 128 | + } |
| 129 | + return SearchIndex.COMMON_REINDEX_FIELDS; |
| 130 | + } |
| 131 | + |
110 | 132 | public SearchIndex buildIndex(String entityType, Object entity) { |
111 | 133 | return switch (entityType) { |
112 | 134 | case Entity.TABLE -> new TableIndex((Table) entity); |
@@ -177,7 +199,9 @@ public SearchIndex buildIndex(String entityType, Object entity) { |
177 | 199 | case Entity.PIPELINE_EXECUTION -> { |
178 | 200 | PipelineExecutionIndex.PipelineExecutionData data = |
179 | 201 | (PipelineExecutionIndex.PipelineExecutionData) entity; |
180 | | - yield new PipelineExecutionIndex(data.getPipeline(), data.getPipelineStatus()); |
| 202 | + yield data == null |
| 203 | + ? new PipelineExecutionIndex(null, null) |
| 204 | + : new PipelineExecutionIndex(data.getPipeline(), data.getPipelineStatus()); |
181 | 205 | } |
182 | 206 | default -> buildExternalIndexes(entityType, entity); |
183 | 207 | }; |
|
0 commit comments