odata create entity with one to many relationship - post

In Odata create entity i am having one to many relationship, with below request json am getting,
{
"parentProperty1":"",
"parentProperty2":"",
"parentProperty3":"",
"NavigationProperty":[
{
"childProperty1":""
}
]
}
Error
org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException: "OData - JPA Runtime: JPA create request is not correct"
at org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.throwException(ODataJPARuntimeException.java:100 undefined) ~[olingo-odata2-jpa-processor-api-2.0.12.jar:2.0.12]
at org.apache.olingo.odata2.jpa.processor.core.access.data.JPALink.linkJPAEntities(JPALink.java:242 undefined) ~[olingo-odata2-jpa-processor-core-2.0.12.jar:2.0.12

Related

Consume expanded EntitySet in UI5 without GetEntiySet Implementation

I'm new in UI5 and I'd like to read an EntitySet without implemention of Get EntitySet
oModel1.read("/LinesSet?$expand=ToCells&$filter=IdQuery%20eq%20%27ZSMKPI_QM_TOTAL_USERS%27", {
success: function(oData) {
console.log(" expand");
},
error: function(oError) {
console.log("errooooooor expand");
}
});
Error message :
errordetails":[{"code":"/IWBEP/CX_MGW_NOT_IMPL_EXC","message":"Method
'LINESSET_GET_ENTITYSET' not implemented in data provider
class.","propertyref":"","severity":"error"}]}}} -
It's not implemented. I want to skip this method and consume $expand directly.
It is possible by creating Association and Navigation between the entity sets.

Successfactors ODATA update entities with one to many relation

im trying to use Successfactors' ODATA API to update an entity.
This entity has got a one to many relationship to another entity.
The Model looks like:
Candidate
- custAnrede (PicklistOption (1:*)
I try to call
PUT <server>/odata/v2/Candidate('myId')
data:
{"custAnrede" : {"id":"555"}}
}
This call fails with:
Inline entity are not supported for property custAnrede in non insert request.
When calling with data:
{"custAnrede": {
"__metadata": {
"uri": "PicklistOption('HRUser')"
}
}}
it suceeds, but the value of custAnrede has not been changed.
Does anybody know how a one to many relationship with ODATA can be modified ?
Thanks,
Detlef
I've done something similar but with different objects (Parent - Child)
{
"__metadata":{
"uri":"cust_Overeenkomst(cust_ParentOvereenkomst_effectiveStartDate=datetime'2017-01-12T00:00:00',cust_ParentOvereenkomst_externalCode='1109',externalCode=2502L)"
},
"cust_event": "SO",
"cust_eventreason":"SO-01",
"cust_to_childsalarisgegevens":{
"__metadata":{
"uri":"cust_ChildSalarisgegevens(cust_Overeenkomst_externalCode=2502L,cust_ParentOvereenkomst_effectiveStartDate=datetime'2017-01-12T00:00:00',cust_ParentOvereenkomst_externalCode='1109',externalCode='SalComp_26')"
},
"cust_opmerking":"TEST Vincent",
"cust_paycomponent":"BRUTOMAAND",
"cust_paycompvalue":"1000"
}
}

breeze: creating client-side entities with data coming from third-party service

I'm getting data from a third-party service and while I had no issues converting to breeze entities, I have one particular scenario that puzzles me:
the data structure I receive is this one (simplified for the sake of clarity)
{
TotalRecords: 72,
Contractors: [ { name: 'test} , {name: 'test2'}]
}
in my jsonResultAdpater, I have created an extractResults method, which returns data.results.Contractors.
And in my visitNode method, I can convert objects of the Contactors array to breeze entities.
But I've lost the TotalRecords property on the way.... This should be passed somehow to the controller that initiated the call to the third-party webservice.
How would I do that ?
adapter:
extractResults: function (data) {
var results = data.results;
return results && results.Contractors
},
visitNode: function (node, parseContext, nodeContext) {
if (node && node.Type === 'ContractorFrameworkDTO') {
return { entityType: "Freelancer" };
}
}
actually it was as simple as filling the inlineCount property in the extractResults method:
data.inlineCount = results.TotalRecords;

Find id for specific entity after savechanges

I have a situation, where I am saving multiple types of entities during a single SaveChanges. In some cases, this save will include my "target entity", in some cases not. In those cases where the save does include a "target entity", i need to be able to trap the entity's id as returned from the server using saveChanges() saveResult.
I have been trying to figure out how to use the Breeze EntityType to see if my "target entity" in the the saveResult, but I keep on getting undefined in the approach below. Clearly I'm not understanding how to use this feature?
function trapTargetEntityId(saveResult) {
saveResult.entities.forEach(function(entity) {
if (entity.EntityType === 'targetEntity') {
targetEntitId = entity.id;
}
return;
});
}
Not sure I understand. But if you are looking for a specific entity by key after the save
// make sure that targetType is NOT null
var targetType = myEntityManager.metadataStore.getEntityType("Customer");
var targetId = 23452; // arbitrary id
function trapTargetEntityId(saveResult) {
saveResult.entities.forEach(function(entity) {
// assumes that you have a data property called 'id' on the 'Customer' entityType
if (entity.entityType === targetType && entity.id === targetId) {
targetEntity = entity;
// do something with 'targetEntity'
}
});
}
... and be careful with your casing - in your example it should have been 'entity.entityType' not 'entity.EntityType'

Sproutcore datasources and creating new records with relationships

I'm trying to get my head around datasources and related models in sproutcore and am getting no where fast was wondering if anyone could maybe help me understand this all bit better.
Basically I have two related models Client and Brand, Clients can have many Brands and Brands can have a single Client, I have defined my models correctly and everything is pulling back as expected. The problem I'm having is working out how to create a new Brand and setup its relationship.
So on my Brand controller I have a createBrand method like so:
var brand = DBs.store.createRecord(DBs.Brand, {
title: this.get('title')
}, Math.floor(Math.random()*1000000));
brand.set('client', this.get('client'));
MyApp.store.commitRecords();
So as this is a new Brand I randomly generate a new ID for it (the second argument to createRecord). This is calling my createRecord in my datasource to create the new Brand, and then it also calls the updateRecord for the client.
The problem I'm having is that the clientUpdate is being passed the temporary (randomly generated id) in the relationship. How should I be structuring my creating of the new brand? Should I be waiting for the server to return the newly created brands ID and then updating the client relationship? If so how would I go about doing this?
Thanks
Mark
Right, after sitting in the sproutcore IRC channel and talking to mauritslamers he recommended creating a framework to handle all the server interactions for me manually.
So I setup a framework called CoreIo, which contains all my models, store and data source.
The data source is only used for fetching records from the server ie:
fetch: function(store, query) {
var recordType = query.get('recordType'),
url = recordType.url;
if (url) {
SC.Request.getUrl(CoreIo.baseUrl+url)
.header({ 'Accept': 'application/json'})
.json()
.notify(this, '_didFetch', store, query, recordType)
.send();
return YES;
}
return NO;
},
_didFetch: function (response, store, query, recordType) {
if (SC.ok(response)) {
store.loadRecords(recordType, response.get('body'));
store.dataSourceDidFetchQuery(query);
} else {
store.dataSourceDidErrorQuery(query, response);
}
},
Then the CoreIo framework has creation methods for my models ie:
CoreIo.createBrand = function (brand, client) {
var data = brand,
url = this.getModelUrl(CoreIo.Brand);
data.client_id = client.get('id');
SC.Request.postUrl(url)
.json()
.notify(this, this.brandDidCreate, client)
.send(data);
};
CoreIo.brandDidCreate = function (request, client) {
var json = request.get('body'),
id = json.id;
var ret = CoreIo.store.pushRetrieve(CoreIo.Brand, id, json);
var brand = CoreIo.store.find(CoreIo.Brand, id);
if (ret) {
client.get('brands').pushObject(brand);
}
};
I would then call into these 'actions' to create my new models which would setup the relationships as well.

Resources