Hi all,
playing with the new GeoServer REST API for uploading app-schema
mappings, I stumbled upon what might be an issue in app-schema's
implementation of the DataAccess interface, AppSchemaDataAccess:
https://github.com/geotools/geotools/blob/master/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/AppSchemaDataAccess.java
The following is the body of the "List<Name> getNames()" method:
/**
* Return the names of the target features.
*
* @see org.geotools.data.DataAccess#getNames()
*/
public List<Name> getNames() {
List<Name> names = new LinkedList<Name>();
names.addAll(mappings.keySet());
return names;
}
The returned names are taken from the "mappings" hash map: this implies
that, if a feature type mapping defines a "mappingName", that is
returned; otherwise, the mapping's "targetElement" is returned.
In contrast, the "FeatureSource getFeatureSource(Name typeName)" method
is implemented thus:
return new MappingFeatureSource(this, getMappingByElement(typeName));
Here is the relevant part of the "getMappingByElement(Name typeName)"
method:
for (FeatureTypeMapping mapping : mappings.values()) {
if (mapping.getTargetFeature().getName().equals(typeName)) {
return mapping;
}
}
The provided "typeName" is not used as hash key in the mappings map, but
rather compared to the mapped feature's
"targetElement" (mapping.getTargetFeature().getName()), so the lookup
will find nothing when a "mappingName" is specified in the type's
mapping configuration.
I noticed AppSchemaDataAccess provides another getFeatureSource* method,
"getFeatureSourceByName(Name typeName)", which does the right thing (in
my opinion) and:
"Returns a feature source that can be used to obtain features of a
particular name. This name would be the mappingName in the TypeMapping
if it exists, otherwise it's the target element name"
as the JavaDoc puts it. However, this method is not part of the
DataAccess interface, so client code like the following, written against
the DataAccess interface, will fail when at least one type mapping
defines a "mappingName":
DataAccess source = ...; // obtain AppSchemaDataAccess somehow
List<Name> featureTypeNames = source.getNames();
for ( int i = 0; i < featureTypeNames.size(); i++ ) {
// will throw 'mappingName not found' exception!
FeatureSource fs = source.getFeatureSource(featureTypeNames.get(i));
}
I was wondering why an alternative method, getFeatureSourceByName(Name),
was created, instead of making it the one and only getFeature(Name)
method?
--
Best regards,
Stefano Costa
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==
Dott. Stefano Costa
Senior Software Engineer
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
http://www.geo-solutions.it
http://twitter.com/geosolutions_it
-------------------------------------------------------
AVVERTENZE AI SENSI DEL D.Lgs. 196/2003
Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate.
Il loro utilizzo è consentito esclusivamente al destinatario del
messaggio, per le finalità indicate nel messaggio stesso. Qualora
riceviate questo messaggio senza esserne il destinatario, Vi preghiamo
cortesemente di darcene notizia via e-mail e di procedere alla
distruzione del messaggio stesso, cancellandolo dal Vostro sistema.
Conservare il messaggio stesso, divulgarlo anche in parte,
distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità
diverse, costituisce comportamento contrario ai principi dettati dal
D.Lgs. 196/2003.
The information in this message and/or attachments, is intended solely
for the attention and use of the named addressee(s) and may be
confidential or proprietary in nature or covered by the provisions of
privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New
Data Protection Code).Any use not in accord with its purpose, any
disclosure, reproduction, copying, distribution, or either
dissemination, either whole or partial, is strictly forbidden except
previous formal approval of the named addressee(s). If you are not the
intended recipient, please contact immediately the sender by
telephone, fax or e-mail and delete the information in this message
that has been received in error. The sender does not give any warranty
or accept liability as the content, accuracy or completeness of sent
messages and accepts no responsibility for changes made after they
were sent or for other risks which arise as a result of e-mail
transmission, viruses, etc.
------------------------------------------------------------------------------
_______________________________________________
GeoTools-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel