Seem like i didn't capture use cases where there is complexAttribute with simple content.
Bodymorphology doesn't contain simple content. Just a thought off the top of my head without testing, if (currStepDescriptor.getMinOccurs() == 0) { return null; } If we were to ommit if (currStepDescriptor.getMinOccurs() == 0) { and just return null, DataAccessMappingIterator might be able to pick it up and do the validation. Not too sure about this and it might fail the other tests. -----Original Message----- From: victor....@csiro.au [mailto:victor....@csiro.au] Sent: Tuesday, 5 October 2010 5:30 PM To: Angreani, Rini (CESRE, Kensington); Caradoc-Davies, Ben (CESRE, Kensington); andrea.a...@geo-solutions.it Cc: geotools-devel@lists.sourceforge.net Subject: Re: [Geotools-devel] [ExternalEmail] Re: Mapping an optional element whose attributes are not optional Hi Andrea, I have done some work on this and your mapping looks similar to the unit test I have written. Comparing your mapping to my in ValidationTest bodymorphology. It should have let you pass and if all child attribute were null, omit the attribute if parent minOccur=0. In xpath.set if (isLastStep) { // reached the leaf if (currStepDescriptor == null) { throw new IllegalArgumentException(currStep + " is not a valid location path for type " + _parentType.getName()); } if (value == null && !currStepDescriptor.isNillable() && sourceExpression != null && !sourceExpression.equals(Expression.NIL)) { if (currStepDescriptor.getMinOccurs() == 0) { return null; } } int index = currStep.getIndex(); Attribute attribute = setValue(currStepDescriptor, id, value, index, parent, targetNodeType, isXlinkRef); return attribute; it should have either return null or value==emptyArray. "I hoped the > app-schema store was smart enough to see all the attributes were null > and decide not to create the positionAccuracy attribute" That was the intention :) I will be happy to further investigate this if you send your mapping files over to me :) Victor Tey Software Engineer ASRDC CSIRO Earth Science and Resource Engineering Phone: +61 8 6436 8944 victor....@csiro.au | www.csiro.au | Address: Australian Resources Research Centre, 26 Dick Perry Avenue, Kensington WA 6151 PLEASE NOTE The information contained in this email may be confidential or privileged. Any unauthorised use or disclosure is prohibited. If you have received this email in error, please delete it immediately and notify the sender by return email. Thank you. To the extent permitted by law, CSIRO does not represent, warrant and/or guarantee that the integrity of this communication has been maintained or that the communication is free of errors, virus, interception or interference. Please consider the environment before printing this email. -----Original Message----- From: rini.angre...@csiro.au [mailto:rini.angre...@csiro.au] Sent: Tuesday, 5 October 2010 4:45 PM To: Caradoc-Davies, Ben (CESRE, Kensington); andrea.a...@geo-solutions.it Cc: geotools-devel@lists.sourceforge.net Subject: [ExternalEmail] Re: [Geotools-devel] Mapping an optional element whose attributes are not optional You can only use functions to skip the attribute if you use the feature chaining syntax. I said "syntax", because you can omit linkField, therefore it's not really chaining it and won't generate the extra "joining" queries, it only recycles the syntax. http://docs.geoserver.org/latest/en/user/data/app-schema/polymorphism.html#data-type-polymorphism "You can omit the linkField and OCQL if the FeatureTypeMapping being linked to has the same sourceType with the container type. This would save us from unnecessary extra queries, which would affect performance." Anyway, you can't use the functions because you can't "chain" simple attributes (seeing both x and y are xs:integer). However, I know what the problem is. If you refer to this: http://jira.codehaus.org/browse/GEOT-2679, it was decided that if the value is null and: 1. IF minOccur == 0 THEN skip the attribute silently 2. IF minOccur > 0 && nillable THEN let it pass through validation in Types.validate() 3. IF minOccur > 0 && !nillable THEN it will throw an error through validation in Types.validate() So, it's correct that it throws the error, as the attribute shouldn't be null. Normally, we put an xlink:href in the ClientProperty when the values are missing, i.e. one of these: urn:ogc:def:nil:OGC::inapplicable urn:ogc:def:nil:OGC::missing urn:ogc:def:nil:OGC::template urn:ogc:def:nil:OGC::unknown urn:ogc:def:nil:OGC::withheld Maybe that's what you need, and the use case that's missing is: 4. IF minOccur > 0 && !nillable && has xlink HREF THEN it should pass through validation Types.validate() We never had this problem for complex attributes, because they never have null as a value, but an empty array instead(since the binding is a Collection for complex types). Actually, Niels is working on the same problem, but it's for Geometry attributes, and you're working on simple attributes. What I think we should do is add another condition in the validate method to check for xlink:href (from the attribute descriptor user data): if (attributeContent == null) { --> check for xlink:href here and skip the following if (!attribute.isNillable()) { throw new IllegalAttributeException(attribute.getDescriptor(), type.getName() + " not nillable"); } return; } I will get Niels to speak to you as well. I like that you're working on app-schema and fix all our existing problems :) Cheers Rini -----Original Message----- From: Caradoc-Davies, Ben (CESRE, Kensington) Sent: Tuesday, 5 October 2010 4:14 PM To: Andrea Aime Cc: Geotools-Devel list; Angreani, Rini (CESRE, Kensington) Subject: Re: [Geotools-devel] Mapping an optional element whose attributes are not optional I think you want these: http://docs.geoserver.org/latest/en/user/data/app-schema/polymorphism.html#null-or-missing-value http://docs.geoserver.org/latest/en/user/data/app-schema/polymorphism.html#recode-function But I don't know if they will help without feature chaining. Rini? On 05/10/10 16:04, Andrea Aime wrote: > Hi, > in my target schema I have this attribute: > > <xs:element name="positionAccuracyVector" > type="csn:PositionAccuracyVectorType" minOccurs="0"/> > > <xs:complexType name="PositionAccuracyVectorType"> > <xs:sequence> > <xs:element name="x" type="xs:integer"> > </xs:element> > <xs:element name="y" type="xs:integer"> > </xs:element> > </xs:sequence> > </xs:complexType> > > As you can see the attribute is optional, but the x/y inside of it are not. > I made the following mappings (no feature chaining): > > <AttributeMapping> > <targetAttribute> > csndc:positionAccuracyVector/x > </targetAttribute> > <sourceExpression> > <OCQL>position_accuracy_x</OCQL> > </sourceExpression> > </AttributeMapping> > <AttributeMapping> > <targetAttribute> > csndc:positionAccuracyVector/y > </targetAttribute> > <sourceExpression> > <OCQL>position_accuracy_y</OCQL> > </sourceExpression> > </AttributeMapping> > > > But the database contains also nulls for the two attributes. I hoped the > app-schema store was smart enough to see all the attributes were null > and decide not to create the positionAccuracy attribute, but unfortunately > that did not work and I get the following exception: > > org.geotools.feature.IllegalAttributeException:http://www.w3.org/2001/XMLSchema:integer > not nillable:null value:null > at org.geotools.feature.type.Types.validate(Types.java:112) > at org.geotools.feature.type.Types.validate(Types.java:80) > at org.geotools.feature.AttributeImpl.<init>(AttributeImpl.java:51) > at > org.geotools.feature.AppSchemaFeatureFactoryImpl.createAttribute(AppSchemaFeatureFactoryImpl.java:63) > at > org.geotools.feature.AttributeBuilder.create(AttributeBuilder.java:583) > at org.geotools.feature.AttributeBuilder.add(AttributeBuilder.java:495) > at org.geotools.data.complex.filter.XPath.setValue(XPath.java:769) > > Looking at the docs and the AppSchemaDataAccess.xsd grammar I see no > way to tell > the app schema store whether a attribute is actually present or not. > > Am I missing some feature, is this a bug or... what? :-) > Maybe feature chaining can be used to solve this riddle, but I'm > trying to avoid it like a plague, > I cannot have n queries made for each feature returned. > I guess this might be yet another candidate for xslt-ing... > > Cheers > Andrea > > ----------------------------------------------------- > Ing. Andrea Aime > Senior Software Engineer > > GeoSolutions S.A.S. > Via Poggio alle Viti 1187 > 55054 Massarosa (LU) > Italy > > phone: +39 0584962313 > fax: +39 0584962313 > > http://www.geo-solutions.it > http://geo-solutions.blogspot.com/ > http://www.linkedin.com/in/andreaaime > http://twitter.com/geowolf > > ----------------------------------------------------- > > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2& L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb > _______________________________________________ > Geotools-devel mailing list > Geotools-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-devel > -- Ben Caradoc-Davies <ben.caradoc-dav...@csiro.au> Software Engineering Team Leader CSIRO Earth Science and Resource Engineering Australian Resources Research Centre ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel