@@ -65,10 +65,9 @@ public final class MappingContext {
6565 private final Map <String , Value > transformationProperties ;
6666 private static final Pattern projectVarPattern = Pattern .compile ("\\ {\\ {project:([^}]+)}}" );
6767
68- /**
69- * Stores the feature schema builders generated while processing the alignment
70- */
71- private final Map <String , ImmutableFeatureSchema .Builder > featureTypeMappings = new LinkedHashMap <>();
68+ /** Stores the feature schema builders generated while processing the alignment */
69+ private final Map <String , ImmutableFeatureSchema .Builder > featureTypeMappings =
70+ new LinkedHashMap <>();
7271
7372 private final Map <String , Codelist > codeLists = new LinkedHashMap <>();
7473
@@ -82,35 +81,38 @@ public final class MappingContext {
8281 // TODO - not sure if we need a separate set of "current" featureTypeMappings ... maybe in the
8382 // future for cases of multiple type-relations for the same target type
8483
85- // private final Map<String, ImmutableFeatureSchema.Builder> currentMappingTables = new LinkedHashMap<>();
86- // private final Set<String> missingAssociationTargets = new TreeSet<String>();
84+ // private final Map<String, ImmutableFeatureSchema.Builder> currentMappingTables = new
85+ // LinkedHashMap<>();
86+ // private final Set<String> missingAssociationTargets = new TreeSet<String>();
8787
8888 private final URI applicationSchemaUri ;
8989 private final ProjectInfo projectInfo ;
9090 private final URI projectLocation ;
9191 private final IOReporter reporter ;
9292 private final LdproxyCfgWriter ldproxyCfg ;
93- private Map <Property ,Builder > currentFirstObjectBuilderMappings = new HashMap <>();
94- private Map <String ,List <PropertyTransformationHandler >> currentPropertyHandlersByTargetPropertyPath = new HashMap <>();
93+ private Map <Property , Builder > currentFirstObjectBuilderMappings = new HashMap <>();
94+ private Map <String , List <PropertyTransformationHandler >>
95+ currentPropertyHandlersByTargetPropertyPath = new HashMap <>();
9596
9697 /**
9798 * Constructor Only the first schema is used
9899 *
99- * @param alignment the Alignment with all cells
100- * @param schemaspace the target schema
100+ * @param alignment the Alignment with all cells
101+ * @param schemaspace the target schema
101102 * @param transformationProperties Properties used in transformations
102- * @param projectInfo project info
103- * @param projectLocation project file
104- * @param reporter reporter
105- * @param ldproxyCfg ldproxyCfg
103+ * @param projectInfo project info
104+ * @param projectLocation project file
105+ * @param reporter reporter
106+ * @param ldproxyCfg ldproxyCfg
106107 */
107108 public MappingContext (
108- final Alignment alignment ,
109- final SchemaSpace schemaspace ,
110- final Map <String , Value > transformationProperties ,
111- final ProjectInfo projectInfo ,
112- final URI projectLocation ,
113- final IOReporter reporter , LdproxyCfgWriter ldproxyCfg ) {
109+ final Alignment alignment ,
110+ final SchemaSpace schemaspace ,
111+ final Map <String , Value > transformationProperties ,
112+ final ProjectInfo projectInfo ,
113+ final URI projectLocation ,
114+ final IOReporter reporter ,
115+ LdproxyCfgWriter ldproxyCfg ) {
114116 this .alignment = Objects .requireNonNull (alignment );
115117 this .transformationProperties = Objects .requireNonNull (transformationProperties );
116118
@@ -155,7 +157,7 @@ public Map<String, ImmutableFeatureSchema.Builder> getFeatureTypeMappings() {
155157 return this .featureTypeMappings ;
156158 }
157159
158- public Map <String ,Codelist > getCodeLists () {
160+ public Map <String , Codelist > getCodeLists () {
159161 return this .codeLists ;
160162 }
161163
@@ -182,30 +184,43 @@ ImmutableFeatureSchema.Builder addNextFeatureSchema(final QName featureTypeName)
182184 if (currentFeatureTypeMapping != null ) {
183185 FeatureSchema tmpSchema = currentFeatureTypeMapping .build ();
184186 if (!tmpSchema .getPropertyMap ().isEmpty ()) {
185- currentFeatureTypeMapping .addConcatBuilder ().name (tmpSchema .getName ()).type (Type .OBJECT ).sourcePath (tmpSchema .getSourcePath ()).propertyMap (tmpSchema .getPropertyMap ());
187+ currentFeatureTypeMapping
188+ .addConcatBuilder ()
189+ .name (tmpSchema .getName ())
190+ .type (Type .OBJECT )
191+ .sourcePath (tmpSchema .getSourcePath ())
192+ .propertyMap (tmpSchema .getPropertyMap ());
186193 }
187- currentFeatureTypeMapping .type (Type .OBJECT ).propertyMap (Map .of ()).sourcePath (Optional .empty ());
188- Builder subMapping = currentFeatureTypeMapping .addConcatBuilder ().name (
189- featureTypeName .getLocalPart ().toLowerCase (Locale .ENGLISH )).type (Type .OBJECT );
194+ currentFeatureTypeMapping
195+ .type (Type .OBJECT )
196+ .propertyMap (Map .of ())
197+ .sourcePath (Optional .empty ());
198+ Builder subMapping =
199+ currentFeatureTypeMapping
200+ .addConcatBuilder ()
201+ .name (featureTypeName .getLocalPart ().toLowerCase (Locale .ENGLISH ))
202+ .type (Type .OBJECT );
190203
191204 return subMapping ;
192205 }
193206
194207 currentFeatureTypeMapping =
195- new ImmutableFeatureSchema .Builder ().name (
196- featureTypeName .getLocalPart ().toLowerCase (Locale .ENGLISH )).type (Type .OBJECT );
208+ new ImmutableFeatureSchema .Builder ()
209+ .name (featureTypeName .getLocalPart ().toLowerCase (Locale .ENGLISH ))
210+ .type (Type .OBJECT );
197211 featureTypeMappings .put (key , currentFeatureTypeMapping );
198212
199213 return currentFeatureTypeMapping ;
200214 }
201215
202- // void addCurrentMappingTable(final String tableName, final ImmutableFeatureSchema.Builder mappingTable) {
203- // this.currentMappingTables.put(tableName, mappingTable);
204- // }
205- //
206- // Collection<ImmutableFeatureSchema.Builder> getCurrentMappingTables() {
207- // return this.currentMappingTables.values();
208- // }
216+ // void addCurrentMappingTable(final String tableName, final ImmutableFeatureSchema.Builder
217+ // mappingTable) {
218+ // this.currentMappingTables.put(tableName, mappingTable);
219+ // }
220+ //
221+ // Collection<ImmutableFeatureSchema.Builder> getCurrentMappingTables() {
222+ // return this.currentMappingTables.values();
223+ // }
209224
210225 void buildAndClearCurrentInfos () {
211226 if (this .currentFeatureTypeMapping == null ) {
@@ -219,11 +234,12 @@ void buildAndClearCurrentInfos() {
219234 this .currentMainSortKeyField = null ;
220235 this .currentJoinInfoByJoinTableName = new HashMap <>();
221236 this .currentFirstObjectBuilderMappings = new HashMap <>();
222- // this.currentMappingTables.clear();
237+ // this.currentMappingTables.clear();
223238 this .currentPropertyHandlersByTargetPropertyPath = new HashMap <>();
224239 }
225240
226- public Map <String ,List <PropertyTransformationHandler >> getPropertyHandlersByTargetPropertyPath () {
241+ public Map <String , List <PropertyTransformationHandler >>
242+ getPropertyHandlersByTargetPropertyPath () {
227243 return this .currentPropertyHandlersByTargetPropertyPath ;
228244 }
229245
@@ -246,18 +262,22 @@ public ImmutableFeatureSchema.Builder getFeatureBuilder() {
246262 return this .currentFeatureTypeMapping ;
247263 }
248264
249- // /**
250- // * Return all property paths for which no association target could be found in the schema.
251- // *
252- // * @return list of properties with missing association targets
253- // */
254- // public Set<String> getMissingAssociationTargets() {
255- // return this.missingAssociationTargets;
256- // }
265+ public boolean hasCurrentFeatureTypePrimaryGeometry () {
266+ return getFeatureBuilder ().build ().getPrimaryGeometry ().isPresent ();
267+ }
268+
269+ // /**
270+ // * Return all property paths for which no association target could be found in the schema.
271+ // *
272+ // * @return list of properties with missing association targets
273+ // */
274+ // public Set<String> getMissingAssociationTargets() {
275+ // return this.missingAssociationTargets;
276+ // }
257277
258- // void addMissingAssociationTarget(final String associationTarget) {
259- // this.missingAssociationTargets.add(associationTarget);
260- // }
278+ // void addMissingAssociationTarget(final String associationTarget) {
279+ // this.missingAssociationTargets.add(associationTarget);
280+ // }
261281
262282 Value getTransformationProperty (final String name ) {
263283 final Value val = this .transformationProperties .get (name );
@@ -267,24 +287,26 @@ Value getTransformationProperty(final String name) {
267287 return Value .NULL ;
268288 }
269289
270- // /**
271- // * Retrieve table from current FeatureTypeMapping
272- // *
273- // * @param tableName Mapping Table name
274- // * @return MappingTable
275- // */
276- // Optional<ImmutableFeatureSchema.Builder> getTableMapping(String tableName) {
277- // return Optional.ofNullable(currentMappingTables.get(tableName));
278- // }
279-
280- // void addValueMappingForTable(
281- // final Property target, final ImmutableFeatureSchema.Builder valueMapping, final String tableName) {
282- // final ImmutableFeatureSchema.Builder tableMapping =
283- // getTableMapping(tableName)
284- // .orElseThrow(() -> new IllegalArgumentException("Table " + tableName + " not found"));
285- //
286- // tableMapping.putProperties2(valueMapping.build().getName(), (Builder) valueMapping);
287- // }
290+ // /**
291+ // * Retrieve table from current FeatureTypeMapping
292+ // *
293+ // * @param tableName Mapping Table name
294+ // * @return MappingTable
295+ // */
296+ // Optional<ImmutableFeatureSchema.Builder> getTableMapping(String tableName) {
297+ // return Optional.ofNullable(currentMappingTables.get(tableName));
298+ // }
299+
300+ // void addValueMappingForTable(
301+ // final Property target, final ImmutableFeatureSchema.Builder valueMapping, final
302+ // String tableName) {
303+ // final ImmutableFeatureSchema.Builder tableMapping =
304+ // getTableMapping(tableName)
305+ // .orElseThrow(() -> new IllegalArgumentException("Table " + tableName + "
306+ // not found"));
307+ //
308+ // tableMapping.putProperties2(valueMapping.build().getName(), (Builder) valueMapping);
309+ // }
288310
289311 public IOReporter getReporter () {
290312 return reporter ;
@@ -317,18 +339,17 @@ public FeatureProviderDataV2 getProviderData(String id) {
317339 projectInfo .getHaleVersion (),
318340 projectLocation != null ? projectLocation : projectInfo .getName ()));
319341
320- ImmutableFeatureProviderSqlData .Builder providerData = ldproxyCfg . builder (). entity (). provider ()
321- .id (id );
342+ ImmutableFeatureProviderSqlData .Builder providerData =
343+ ldproxyCfg . builder (). entity (). provider () .id (id );
322344
323345 providerData
324346 .labelTemplate ("{{value}}{{unit | prepend:' [' | append:']'}}" )
325347 .connectionInfoBuilder ()
326348 .dialect (Dialect .PGIS .name ())
327- .host (String .format ("${%s.db.host}" , id ))
328- .database (String .format ("${%s.db.name}" , id ))
329- .user (String .format ("${%s.db.user}" , id ))
330- .password (String .format ("${%s.db.password}" , id ))
331- .addSchemas (String .format ("${%s.db.schema:-public}" , id ));
349+ .host (String .format ("${%s.db.host:-${db.host}}" , id ))
350+ .database (String .format ("${%s.db.name:-${db.name}}" , id ))
351+ .user (String .format ("${%s.db.user:-${db.user}}" , id ))
352+ .password (String .format ("${%s.db.password:-${db.password}}" , id ));
332353
333354 featureTypeMappings .values ().stream ()
334355 .map (ImmutableFeatureSchema .Builder ::build )
@@ -353,7 +374,7 @@ private FeatureSchema applyTransformations(FeatureSchema original) {
353374 *
354375 * @param str input string
355376 * @return string with replaced project variables, unresolved variables are replaced with
356- * 'PROJECT_VARIABLE_<VARIABLE_NAME>_NOT_SET'
377+ * 'PROJECT_VARIABLE_<VARIABLE_NAME>_NOT_SET'
357378 */
358379 public String resolveProjectVars (final String str ) {
359380 final Matcher m = projectVarPattern .matcher (str );
@@ -393,8 +414,15 @@ public Optional<String> computeJoinSourcePath(PropertyEntityDefinition sourcePro
393414 // add join-statement
394415 JoinInfo ji = this .getCurrentJoinInfoByJoinTableName ().get (tableName );
395416
396- result = "[" + ji .getBaseTableJoinField () + "=" + ji .getJoinTableJoinField () + "]"
397- + ji .getJoinTableName () + "/" + result ;
417+ result =
418+ "["
419+ + ji .getBaseTableJoinField ()
420+ + "="
421+ + ji .getJoinTableJoinField ()
422+ + "]"
423+ + ji .getJoinTableName ()
424+ + "/"
425+ + result ;
398426
399427 tableName = ji .getBaseTableName ();
400428 }
@@ -420,7 +448,7 @@ public LdproxyCfgWriter getLdproxyCfg() {
420448 }
421449
422450 public void addFirstObjectBuilderMapping (Property targetProperty , Builder firstObjectBuilder ) {
423- this .currentFirstObjectBuilderMappings .put (targetProperty ,firstObjectBuilder );
451+ this .currentFirstObjectBuilderMappings .put (targetProperty , firstObjectBuilder );
424452 }
425453
426454 public boolean hasFirstObjectBuilderMapping (Property targetProperty ) {
0 commit comments