Cant Save relational Entities in breezejs - angularjs

I have two entities created through manager.createEntity(type);.. z-validate wont display validation errors if i try to create them otherwise
..entity orderdetails must have a valid key from order. and later...
... //changed some stuff but never keys
orderdetails.Time = new Date();
orderdetails.order = order; //am i creating the relation right here?
The app will work great offline but when i save changes to the server..
manager.saveChanges([order,orderdetails]);
The sever is returning
...orderdetails","KeyValues":["fd...28"],"PropertyName":"order",ErrorMessage":"The order field is required."
Any idea how i can go through this? i have been reading documentations for days.
Metadata looks like this
{
"schema": {
"namespace": "Inventory.API",
"alias": "Self",
"annotation:UseStrongSpatialTypes": "false",
"xmlns:annotation": "http://schemas.microsoft.com/ado/2009/02/edm/annotation",
"xmlns:customannotation": "http://schemas.microsoft.com/ado/2013/11/edm/customannotation",
"xmlns": "http://schemas.microsoft.com/ado/2009/11/edm",
"cSpaceOSpaceMapping": "[\"Inventory.API.Order\",\"Inventory.API.Entities.Order\"],[\"Inventory.API.OrderDetail\",\"Inventory.API.Entities.OrderDetail\"],[\"Inventory.API.DifferentDetail\",\"Inventory.API.Entities.DifferentDetail\"]",
"entityType": [ {
"name": "Order",
"customannotation:ClrType": "Inventory.API.Entities.Order, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "BarCode",
"type": "Edm.String",
"maxLength": "Max",
"fixedLength": "false",
"unicode": "true"
}, {
"name": "Name",
"type": "Edm.String",
"maxLength": "Max",
"fixedLength": "false",
"unicode": "true"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": [{
"name": "OrderDetails",
"relationship": "Self.OrderDetail_Order",
"fromRole": "OrderDetail_Order_Target",
"toRole": "OrderDetail_Order_Source"
}, {
"name": "DifferentDetails",
"relationship": "Self.DifferentDetail_Order",
"fromRole": "DifferentDetail_Order_Target",
"toRole": "DifferentDetail_Order_Source"
}]
}, {
"name": "OrderDetail",
"customannotation:ClrType": "Inventory.API.Entities.OrderDetail, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "Time",
"type": "Edm.DateTime",
"nullable": "false"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "TotalPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": {
"name": "Order",
"relationship": "Self.OrderDetail_Order",
"fromRole": "OrderDetail_Order_Source",
"toRole": "OrderDetail_Order_Target"
}
}, {
"name": "DifferentDetail",
"customannotation:ClrType": "Inventory.API.Entities.DifferentDetail, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "Time",
"type": "Edm.DateTime",
"nullable": "false"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "TotalPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": {
"name": "Order",
"relationship": "Self.DifferentDetail_Order",
"fromRole": "DifferentDetail_Order_Source",
"toRole": "DifferentDetail_Order_Target"
}
}],
"entityContainer": {
"name": "InventoryContext",
"customannotation:UseClrTypes": "true",
"entitySet": [{
"name": "Orders",
"entityType": "Self.Order"
}, {
"name": "OrderDetails",
"entityType": "Self.OrderDetail"
}, {
"name": "DifferentDetails",
"entityType": "Self.DifferentDetail"
}],
"associationSet": [{
"name": "OrderDetail_Order",
"association": "Self.OrderDetail_Order",
"end": [{
"role": "OrderDetail_Order_Source",
"entitySet": "OrderDetails"
}, {
"role": "OrderDetail_Order_Target",
"entitySet": "Orders"
}]
}, {
"name": "DifferentDetail_Order",
"association": "Self.DifferentDetail_Order",
"end": [{
"role": "DifferentDetail_Order_Source",
"entitySet": "DifferentDetails"
}, {
"role": "DifferentDetail_Order_Target",
"entitySet": "Orders"
}]
}
}
}

You need to map the orderId foreign key property of the OrderDetail and DifferentDetail entities. When Breeze sends the entities to the server, it communicates the relationship between entities using the foreign keys.

I needed to map the orderId foreign key property of the OrderDetail and DifferentDetail entities. When Breeze sends the entities to the server, it communicates the relationship between entities using the foreign keys.
... The relation was there but breeze wont see it as it was defined like this
[Required]
public Order Order { get; set; }
And therefore I changed it to this
[Required]
public Guid Order_Id { get; set; }
[ForeignKey("Order_Id")]
public virtual Order Order{get; set;}
in the DBContext POCO classes then created a new copy of Metadata.

Related

In Avro schema, how to wrap the array to an object and put it as a union instead of putting just array as union

I have the following data and I want to wrap the OPTIONAL array as an object and then put in as a union but since I am new to this, I am not sure how to do this.
This is how I have done so far so could someone help me correct the below structure in the expected output. Note that this dataRefs is an optional field and this entire structure may or may not be present.
{
"name": "dataRefs",
"default": null,
"type": ["null",
{
"type": "array",
"items": {
"name": "dataRef",
"type": "record",
"fields": [
{
"name": "dataId",
"type": "string",
"avro.java.string": "String"
},
{
"name": "email",
"type": ["null" ,"string"],
"avro.java.string": "String"
},
{
"name": "phone",
"type": ["null" ,"string"],
"avro.java.string": "String"
},
{
"name": "userName",
"type": ["null" ,"string"],
"avro.java.string": "String"
},
{
"name": "addressRef",
"default": null,
"type": ["null", {
"name": "addressRefRecord",
"type": "record",
"fields": [
{
"name": "addrRefId",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "addrType",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "addressLine1",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "addressLine2",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "city",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "province",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "country",
"type": ["null","string"],
"avro.java.string": "String"
},
{
"name": "postalCode",
"type": ["null","string"],
"avro.java.string": "String"
}
]
}
]
}
]
}
}
]
}
My JSON data that I intend to map to above schema looks like follows:
"dataRefs": [{
"addressRef": {
"addrRefId": "0",
"addrType": "ADDRESS",
"addressLine1": "DA 81",
"addressLine2": "",
"city": "Amsterdam",
"country": "Netherlands",
"postalCode": "xxxx LN",
"province": ""
},
"dataId": "0",
"email": "xyz#abc.com"
}],
This is how I was able to do so:
{
"name": "dataRefs",
"type": [
"null",
{
"type": "record",
"name": "dataRefsObject",
"fields": [
{
"name": "dataRefsArray",
"type": {
"type": "array",
"items": {
"name": "dataRef",
"type": "record",
"fields": [
{
"name": "dataId",
"type": ["null", "string"],
"avro.java.string": "String"
},
{
"name": "userName",
"type": [
"null",
"string"
],
"avro.java.string": "String"
},
....

Elastic - JSON Array nested in Array

I have to index a json to Elastic which look like the below format. My problem is that the key "variable" is array that contains json objects (I thought about "nested" datatype of Elastic) but some of those objects it's possible to contain nested json arrays inside them. (see variable CUSTOMERS).
POST /example_data/data {
"process_name": "TEST_PROCESS",
"process_version ": 0,
"process_id": "1111",
"activity_id": "111",
"name": "update_data",
"username": "testUser",
"datetime": "2018-01-01 10:00:00",
"variables": [{
"name": "ΒΑΝΚ",
"data_type": "STRING",
"value": "EUROBANK"
},{
"name": "CITY",
"data_type": "STRING",
"value": "LONDON"
}, {
"name": "CUSTOMERS",
"data_type": "ENTITY",
"value": [{
"variables": [{
"name": "CUSTOMER_NAME",
"data_type": "STRING",
"value": "JOHN"
}, {
"name": " CUSTOMER_CITY",
"data_type": "STRING",
"value": "LONDON"
}
]
}
]
}, {
"name": "CUSTOMERS",
"data_type": "ENTITY",
"value": [{
"variables": [{
"name": "CUSTOMER_NAME",
"data_type": "STRING",
"value": "ΑΘΗΝΑ"
}, {
"name": " CUSTOMER_CITY ",
"data_type": "STRING",
"value": "LIVERPOOL"
}, {
"name": " CUSTOMER_NUMBER",
"data_type": "STRING",
"value": "1234567890"
}
]
}
]
}
] }
When I'm trying to index it I get the following error
{ "error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]"
}
],
"type": "illegal_argument_exception",
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]" }, "status": 400 }
Mapping
{ "example_data": {
"mappings": {
"data": {
"properties": {
"activity_id": {
"type": "text"
},
"name": {
"type": "text"
},
"process_name": {
"type": "text"
},
"process_version": {
"type": "integer"
}
"process_id": {
"type": "text"
},
"datetime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"username": {
"type": "text",
"analyzer": "greek"
},
"variables": {
"type": "nested",
"properties": {
"data_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}}}
When I remove the variable CUSTOMERS that contains the array, then It works properly because there are only json objects.
Is there a way to handle that? Thanks in advance

Join 2 arrays by key and value (AngularJS)

I have 2 objects
{
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
},
and
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Object one defines what a field should be and what it is called
The second object is a job description.
What i need is to match a field to each key (this even sounds confusing i my head, so here is an example)
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true,
"value": "THIS IS MY REF"
}
},
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Here you go:
var def = {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
};
var jobDesc = {
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
};
var jobDescKeysArr = Object.keys(jobDesc);
if (jobDescKeysArr.indexOf(def.name) !== -1) {
// A match.
def.value = jobDesc[def.name];
jobDesc[def.name] = Object.assign({}, def);
console.log(jobDesc)
}

Json schema for array of objects doesn't validate

I have this schema for a json response
{
"title": "Products",
"description": "schema for products",
"type": "array",
"properties": {
"id": {
"description": "id of a product",
"type": "integer"
},
"name": {
"description": "name of the product",
"type": "string"
},
"created_at": {
"description": "record created_at",
"type": "string",
"format": "date-time"
},
"updated_at": {
"description": "record updated_at",
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name"]
}
and I want to match this schema with this json
[{
"id": 1,
"name": "Cricket Ball"
}, {
"id": 2,
"name": "Soccer Ball"
}, {
"id": 3,
"name": "football ball"
}, {
"id": 4,
"name": "Basketball ball"
}, {
"id": 5,
"name": "Table Tennis ball"
}, {
"id": 6,
"name": "Tennis ball"
}]
This schema matches the response but it also matches the schema in which the required field is this
"required": ["ids", "names"]
I think the schema is validated against the array and the objects in the array are not validated.
The way you have it set up now, your properties key refers to the array itself, not to each item, and is being ignored (because arrays don't have properties, they just have items). You need to use the items key to validate each item in the array, like so:
{
"title": "Products",
"description": "schema for products",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"description": "id of a product",
"type": "integer"
},
"name": {
"description": "name of the product",
"type": "string"
},
"created_at": {
"description": "record created_at",
"type": "string",
"format": "date-time"
},
"updated_at": {
"description": "record updated_at",
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name"]
}
}
try map
new_array = response.map{ |k| { 'id': k['properties']['id']['description'], 'name': k['properties']['name']['description'] } }

How to define the min size of array in the json schema

I want to make a schema of json file.It's for an array of products.
The json schema is similar as below:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
},
"required": ["length", "width", "height"]
},
"warehouseLocation": {
"description": "Coordinates of the warehouse with the product",
"$ref": "http://json-schema.org/geo"
}
},
"required": ["id", "name", "price"]
}
}
The array should at least one item in it. How can I define the minimum of the array?
Do I need to add the minimun defination?
To set the minimum # of item in an array, use the "minItems".
See:
https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.3.3
and
http://jsonary.com/documentation/json-schema/?section=keywords/Array%20validation
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 4,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}
It looks like draft v4 permits what you are looking for. From http://json-schema.org/example1.html:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}
Notice that the "tags" property is defined as an array, with a minimum number of items (1).
I suppose no, at least looking to working draft the minimum is applied only for numeric values, not arrays.
5.1. Validation keywords for numeric instances (number and integer)
...
5.1.3. minimum and exclusiveMinimum
So you should be good with min/maxItems for arrays.

Resources