how to remove local isDirty objects from ember-data before loading a template? - rest

I am have a /customers. I am creating a new customer as :
var new_customer = this.store.createRecord('customer', customer_object);
new_customer.save().then(onSuccess, onError);
where customer_object contains a record for customer. When customer is created successfully, onSuccess gets called which then transit to newly created customer (/customers/<new_customer>). This flow is working as expected. When I get an error (say Unauthorized Access), onError is also getting called which then transit to /customers after showing an error-alert. The problem here is that, though the customer is not created at server-side, when I transit to /customers, it shows that newly created customer (with isDirty as true.) How can I remove such invalid objects from my local ember-array?

You can call
new_customer.deleteRecord();
in onError handler to remove the record after error has occured.

Related

Spring-data-JDBC Save (Update) doesn't update

I have a Spring application where the Domain Object identifier is not assigned by the database, but it generated by the application. The identifier is generated and added to the Domain Object during the BeforeSave callback. After saving the domain object (Insert), when trying to save the domain object with the same identifier (Update), I receive the following error
Caused by: org.springframework.dao.IncorrectUpdateSemanticsDataAccessException: Failed to update entity [com.example.UUIDTest.DomainObjectLongId#77ccded4]. Id [2997744842191684912] not found in database.
I have created several test examples. In the DomainObject example, I am generating the ID as a UUID. In the DomainObjectLongId example, I am generating the ID as a Long. In both of these examples, it fails on the save (Update) when using the Spring-Data-JDBC repository. Manually generating SQL and using it to update works successfully.
I have created a test example that has the DB autogenerating the ID. In this situation upon saving (Update), it succeeds without any errors.
How do I get Spring-Data-JDBC to update a domain object using a provided id?
Below is the Github repository with all 3 test classes. Two of which fail on save (Update) with provided identifier and one of which succeeds on save (Update) with auto generated identifier.
Github Spring-Data-JDBC-UUID-Test
Finally figured it out. I was always changing the ID of the DomainObject
aggregate.setId(UUID.randomUUID());
return aggregate;
I needed to check to see if it needed to be set
if (aggregate.getId() == null) {
aggregate.setId(UUID.randomUUID());
}
return aggregate;

Batch status - 'validating' after failed creation

Hi i`m tryng to work with shipping batches, after i create batch like this:
{"default_carrier_account":"9348***********50","default_servicelevel_token":"usps_priority","metadata":"test","label_filetype":"PDF_4x6","batch_shipments":[{"carrier_account":"93********************","servicelevel_token":"usps_priority","shipment":"c8c411c2ad8b497eb583decf7c3c614d","metadata":1},{"carrier_account":"9348ce6eecf**********ab850","servicelevel_token":"usps_priority","shipment":"768ae43826b04040b32490a6f069fa4f","metadata":2}]}
i get notification like this:
batch 0f0b69ae42bc475ab3c1421edddeb4fc creation failed
and after this i try to make api request and get batch data(status, messages, etc..) i did post request to : http://api.goshippo.com/batches/0f0b69ae42bc475ab3c1421edddeb4fc?page=1
and get response:
{
"object_id":"0f0b69ae42bc475ab3c1421edddeb4fc",
"object_owner":"info#skumatrix.com",
"status":"VALIDATING",
"object_created":"2017-04-16T16:35:24.925Z",
"object_updated":"2017-04-16T16:35:27.143Z",
"metadata":"test",
"default_carrier_account":"9***************b850",
"default_servicelevel_token":"usps_priority",
"label_filetype":"PDF_4x6",
"batch_shipments":{
"count":0,
"next":null,
"previous":null,
"results":{
}
},
"object_results":{
"purchase_succeeded":0,
"purchase_failed":0,
"creation_failed":0,
"creation_succeeded":0
},
"label_url":{
}
}
what i don`t understand is - why status is still validating and why there is no error messages ?
So, for starters, the default status of a Batch object in Shippo is VALIDATING. So this is why it would persist to stay in that state, although it might be a little confusing when there is an unexpected failure (which is what appears to have happened here).
As mentioned in the comments there, this failure occurred due to trying to do a Batch purchase using a collection of Shipment object_id's. The Batch endpoint is actually supposed to allow you to create a collection of Shipment objects en masse, and then later you can Batch purchase the labels for your desired rates on those Shipment objects.
Rate retrieval is generally the more time consuming process, depending on how many connected shipping accounts you have. So Batch creation is intended to allow you to have Shippo retrieve rates for a lot of packages and simply check on them once they are done (or get notified of their completion via Shippo's webhooks).
So moving forward, make sure that you first try to create the Batch with a collection of Shipments (see here). Then you can proceed to create the labels for the shipment like so.

Event handler not triggering when user created using SCIM/REST APIs for UDF

While creating user via OIM API--> My Event handler gets Triggered
While creating user via OIM GUI--> My Event handler gets Triggered
While creating user via OIM SCIM API--> My Event handler is NOT getting Triggered...
Any clues?
Using GET schemas you will get to under which Schema the attribute would belong.(In my case I had two custom attribute one is text field and other was of type lookup.While using GET schemas I only to got to know schema for the text field as it returned nothing for the lookup field.
"urn:ietf:params:scim:schemas:extension:oracle:2.0:OIG:User").
Take metadata export of the file User.xml .Search for the attribute name in that file and under <scim> tag enter the following entry in <value>
<name>scim</name>
<value>urn:ietf:params:scim:schemas:extension:oracle:2.0:OIG:User:<attrName></value>
<category>properties</category>
Then import the User.xml file
Restart OIM server. Then test the scenario, event handler will get triggered.
Although for the lookup field I didn't get it any under any schema but when I used the same schema as that of text field it started working fine.

Why JsonStore provides a commitchanges method

The extjs Jsonstore class has a method commitchanges().
Now considering that the javascript code will send an AJAX request to a servlet and not to a db directly, what do we need a commitchanges() method?
Whenever user changes anything in the form panel's or UI components that data is changed in record, but at this time record will maintain a list of modified properties in the record and store maintains a list of modified records in the store
So whenever you send a request to save the data to server, after successful save you will get back a success response, on this response store need to make sure that the saved record will be removed from the list of records that are modified in the store and also remove list of modifications from the record instance to indicate that save operation was successful
So the operations of removing list of modified properties from record instance is performed by record.commit method and operations of removing saved record from list of modified records from store is performed by store.commitChanges method which in turn will call record.commit for every record which is saved correctly on server

Request factory is sending back the entire List<EntityProxy> even if only one element is altered

When I load an entity proxy which has a nested collection of entity proxies (eg: AddressBook entity proxy containing a list of Contact proxies) and if I make changes to the inner list ( the List of Contacts) like removal of an item, and call a persist on it, Request Factory is sending the entire list of contacts. Is this the expected behaviour, or is it supposed to send only a command to delete the item on the server also?
The question is, does request factory send deltas just for field level changes, or does it calculate deltas for collections also?
ContactProxy
interface ContactProxy extends EntityProxy {
...
//Getters and setters for firstName, lastName, phoneNumber etc...
...
}
AddressBookProxy
interface AddressBookProxy extends EntityProxy {
...
List<ContactProxy> getContacts();
void setContacts(List<ContactProxy> contacts);
...
}
Focus code:
//Assume I received an abProxy from a previous context.
AddressBookRequestContext context = requestFactory.requestContext();
abProxy = context.edit(abProxy);
abProxy.getContacts().remove(0);
context.persist().using(abProxy).fire();
The above piece of code is sending the entire list of contacts received in the previous context, but I expected to send only a delete command to the server. Am I doing something wrong?
Now when I make a change to a single contact in the AddressBook entity proxy and make a call to persist, it is still sending the entire list of contacts. What is the workaround to get deltas working for these kind of collection level changes.
You're modifying the list from a list of 10 elements to a list of 9 elements, so RF sends the new list of 9 elements (and will call the setter with the new list on the server side).
However, it only sends the IDs of the contacts, not their properties, because those haven't changed (and yes, it means all contacts will have to be retrieved on the server-side, in order to populate the new list of 9 elements, before setting it into the address book).
There's probably room for improvement in RF though: when you edit() a proxy, it automatically edits all the proxies it references (recursively), so all 10 contacts are edit()ed, and thus all 10 contacts IDs are sent to the server, an all 10 contacts are retrieved from the database and validated, even though only 9 of them are used afterwards. As a result (and that could be seen as a feature) in the event the removed contact has been updated since originally retrieved on the client, the server will send an EntityProxyChange for the contact to the client in the response.
In a few words: there's no magic, everything comes to a cost, so be careful when designing your "APIs"; you might want to add a removeContact method to your RequestContext instead of modifying the list (and retrieve the address book again –batched in the same RequestContext– to get the update on the client-side)