java - Odata Client :Resource set reference navigation properties can only have a property annotation 'odata.bind' with an array value -
i using olingo java client api post data.following xml structure want post. http://services.odata.org/v4/(s(kfu42eshy4v0da0lifqbjdgc))/trippinservicerw
<?xml version="1.0" encoding="utf-8" standalone="no" ?> <people xmlns:edm="http://schemas.magicsoftware.com/edm" xmlns:ns1="http://schemas.magicsoftware.com/edm" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <row> <fields> <username>8people_username</username> <firstname>pople_firstname</firstname> <lastname>people_lastname</lastname> <addressinfo> <location> <address>address1</address> <city> <countryregion>in</countryregion> <name>contryregion</name> <region>reg</region> </city> </location> </addressinfo> </fields> <expanded_entities> <friends> <row> <fields> <username>rajesh</username> <firstname>v</firstname> <lastname>patil</lastname> </fields> </row> </friends> </expanded_entities> </row> </people>
i have issue expanded_entities getting error "the resource set reference navigation property 'friends' has property annotation 'odata.bind' string value. resource set reference navigation properties can have property annotation 'odata.bind' array value"
following snippet of code
private void buildexpended(arraylist<entitysimpledata> xpientity) throws exception { arraylist<entitysimpledata> expended = getelement(xpientity, expended); /* * running on first level properties */ if (expended != null){ string originalentityname = this.entityname; cliententity expendedentity = null; (entitysimpledata entitysimpledata : expended) { uri uri = uri.create(entitysimpledata.getname()); this.entityname = entitysimpledata.getname(); clientlinktype type = clientlinktype.entity_navigation; string navigationname = entitysimpledata.getname(); arraylist<entitysimpledata> rows = (arraylist<entitysimpledata>) entitysimpledata.getdata(); // linked entity edmelement edmelement = edmmanager.getedmelementbyname(resourcename, namespace, originalentityname, navigationname); if (!edmelement.iscollection()){ expendedentity = client.getobjectfactory().newentity(new fullqualifiedname(namespace, entitysimpledata.getname())); entitysimpledata row = rows.get(0); //"row" arraylist<entitysimpledata> fields = (arraylist<entitysimpledata>) row.getdata();// field entitysimpledata field = fields.get(0); //"field" arraylist<entitysimpledata> properties = (arraylist<entitysimpledata>) field.getdata();// properties (entitysimpledata entitysimpledata2 : properties) { expendedentity.getproperties().addall( buildit(entitysimpledata2,"")); } uri = null; clientinlineentity clientlink = new clientinlineentity(uri, type, navigationname, expendedentity); cliententity.getnavigationlinks().add(clientlink); }else{// multy cliententityset entityset = client.getobjectfactory().newentityset(); (entitysimpledata row : rows) { this.entityname = edmelement.gettype().getname(); expendedentity = client.getobjectfactory().newentity(new fullqualifiedname(namespace, this.entityname)); arraylist<entitysimpledata> fields = (arraylist<entitysimpledata>) row.getdata();// field entitysimpledata field = fields.get(0); //"field" arraylist<entitysimpledata> properties = (arraylist<entitysimpledata>) field.getdata();// properties (entitysimpledata entitysimpledata2 : properties) { expendedentity.getproperties().addall( buildit(entitysimpledata2,"")); } // uri = null; } entityset.getentities().add(expendedentity); clientinlineentityset clientlinks = new clientinlineentityset(uri, type, navigationname, entityset); cliententity.getnavigationlinks().add(clientlinks); } } } }
/* * each property build , if it's complex, build child's recursive */
private arraylist<clientproperty> buildit( entitysimpledata data,string parentcomplex) throws exception{ arraylist<clientproperty> props = new arraylist<clientproperty>(); string fullname = (parentcomplex.equals("")?data.getname():parentcomplex+edmmanager.complex_delimited+data.getname()); edmelement edmelement = edmmanager.getedmelementbyname(resourcename, namespace, entityname, fullname); edmprimitivetypekind edmtype=null; // if (edmelement == null) // throw new sdkexception (odatastepadaptor.err_infrastructure, "edm element not found in resource. resourcename["+resourcename+"] namespace["+namespace+"] entityname["+entityname+"] fullname["+fullname+"]"); if (edmelement != null) edmtype = (edmprimitivetypekind) edmmanager.getodataelementtype(edmelement); if(data.getelementgeneraltype().equals(entitysimpledata.type.simple)){ props.add(buildproperty(edmtype,data)); } else if(data.getelementgeneraltype().equals(entitysimpledata.type.complex )){ //complex boolean iscollection = false; if (edmelement != null) iscollection = edmelement.iscollection(); if (edmtype!=null){ if (iscollection) { collectionaddressinfo=client.getobjectfactory().newcollectionvalue(edmelement.gettype().getfullqualifiedname().getfullqualifiednameasstring()); props.add(client.getobjectfactory().newcollectionproperty(data.getname(), collectionaddressinfo)); arraylist<entitysimpledata> childrens = (arraylist<entitysimpledata>) data.getdata(); (entitysimpledata entitysimpledata : childrens) { string parentname = (parentcomplex.equals("")?data.getname():parentcomplex+edmmanager.complex_delimited+data.getname()); arraylist<clientproperty>complexprops= buildit(entitysimpledata,parentname); (clientproperty clientproperty : complexprops) { if(clientproperty.hascomplexvalue()) { collectionaddressinfo.add(clientproperty.getcomplexvalue()); } else if(clientproperty.hasprimitivevalue()){ collectionaddressinfo.add(clientproperty.getprimitivevalue()); } else if(clientproperty.hascollectionvalue()){ collectionaddressinfo.add(clientproperty.getcollectionvalue()); } } } } else // point props.add(edmgeohelper.buildpointproperty(client,edmtype,data)); } else{ // regular complex @suppresswarnings("unchecked") arraylist<entitysimpledata> childrens = (arraylist<entitysimpledata>) data.getdata(); clientcomplexvalue complex = client.getobjectfactory().newcomplexvalue(namespace+"."+data.getname()); props.add(client.getobjectfactory().newcomplexproperty(data.getname(), complex)); (entitysimpledata entitysimpledata : childrens) { string parentname = (parentcomplex.equals("")?data.getname():parentcomplex+edmmanager.complex_delimited+data.getname()); arraylist<clientproperty>complexprops= buildit(entitysimpledata,parentname); (clientproperty clientproperty : complexprops) { complex.add(clientproperty); } } } } else{// unknown logger.logmessage(loglevel.level_warn, odatastepadaptor.odata_client_log_module, "element ["+fullname+"] ignored. null value"); } return props; }
/** * * @param resourcename * @param schemanamespace * @param entityname * @param fieldname * @param iscollection - return if property collection * @return */
public static edmelement getedmelementbyname(string resourcename, string schemanamespace, string entityname, string fieldname) { // current schema namespace odataschemaimpl schema = odataresourcesmap.get(resourcename).get(schemanamespace); string[] fieldhierachy = fieldname.split(complex_delimited); edmstructuredtype edmstructured = null; // check if complex property if (fieldhierachy.length > 1) edmstructured = schema.getcomplextypes().get(fieldhierachy[fieldhierachy.length-2]); if(fieldhierachy.length == 1 || edmstructured ==null ) edmstructured = schema.getentitytypes().get(entityname); fieldname = fieldhierachy[fieldhierachy.length - 1]; if(edmstructured!=null) return edmstructured.getproperty(fieldname); else return null; }
/* * running on 1 entity properties (entitysimpledata), build cliententity , post server. */
public void postentity(string namespace, string entityname,entitysimpledata data,string servicename) throws exception { odataentitycreaterequest<cliententity> req = null; cliententitybuilder helper = null; cliententity cliententity = null; uri entityuri = null; try{ logger.logmessage(loglevel.level_debug, odatastepadaptor.odata_client_log_module, "postentity. entityname ["+entityname+"] data["+data+"] servicename [" + servicename + "]"); helper = new cliententitybuilder(data,client,namespace,service_root,entityname); cliententity = helper.buildcliententityparameters(); entityuri = client.newuribuilder(service_root).appendentitysetsegment(servicename).expand("friends").build(); logger.logmessage(loglevel.level_debug, odatastepadaptor.odata_client_log_module, "postentity. entityname ["+entityname+"] data["+data+"] servicename [" + servicename + "] entityuri[ " + entityuri + "] cliententity [" + cliententity + "]"); req = client.getcudrequestfactory().getentitycreaterequest(entityuri, cliententity); setheaders(req, headers); odataentitycreateresponse<cliententity> res = req.execute(); cliententity = res.getbody(); }catch(exception e){ logger.logmessage(loglevel.level_error, odatastepadaptor.odata_client_log_module, "postentity. entityname ["+entityname+"] data["+data+"] servicename [" + servicename + "] entityuri [ " + entityuri + "] cliententity [" + cliententity + "]",e,1); throw(e); } } odataentitycreateresponse<cliententity> res = req.execute(); line got above error
Comments
Post a Comment