Exchange Calendar, creating appointments and unique ids - java

I am using ews-java-api and having a lot of problems
I create appointments and also listen for appointments created elsewhere.
My problem is I create the appointment with
new Appointment(exchangeService).save(notificationMode)
I also save the appointment details including uniqueId, lets call it x, to my db
I see the appointment appear in exchange no problem, I then see a notification that it has been autoaccepted (I can turn off auto accept for the room and still get the same problem below.
Then I see my exchange subscriber kick off as it receives the notification events from exchange that a new appointment has been created. I seem to get 4 events each time, a created event, two modified events and move event.
The problem is each of these events have a uniqueId of y not x as I would expect.
This means that I cant check to see if this is an appointment I have already created.
I never get an event with the original uniqueId x as I would expect. I know that unique ids can change, and that sucks, but there does not seem to be any other field I can use.
Any ideas what I can do to work around / fix this?

A given id for an item will change when the active directory in which it resides changes. It sounds like your auto accept is moving the item. I have not tested this scenario.
If you do a simple .save() you will get a create and a modify event back from exchange on your next push/pull. There doesn't appear to be a way to prevent this. They should have the same id as the one that you got from your save. You just need to check to see if you already have the item for the create. For the modify, well I can't speak for Microsoft as to why we get a modify but it should be exactly the same as the create.
You are then getting a modify, and a move event when the item changed directories. These 2 items will have different ids than the one that you received during the original save. The ItemEvent has an oldItemId that I believe you can use. It's also possible to parse out the GUID from these ids which doesn't change but no real need to do that I think. Best approach might be to use the OldItemId and process the move event.

Related

Possible overwriting to database table

Let's say you have a database table name table1 with columns name and surname. Two different clients open the same view from the java application and get the data for same person at the same time.
1) First client changed the name and pressed save button to update database record.
2) Client2 still sees the old record on the screen and then pressed to save button to change the surname.
It actually overwrite the record by old name. I think to check and get the latest data before updating the database when I click button but I do not like this solution because of making a second query before update.
So how can we solve this problem by using Hibernate and without using Hibarnete. Any idea?
Of course if you do not want that something will be overridden, then you have to check the data before an update. But it will be not always a real query with a good caching strategy. You could also use a timestamp with last update to compare it easier. Another strategy would be to lock the entities when the first user will read them. But that is normally not a good design for web applications or you have to integrate a messaging service, which will all user inform for an update who actually have open that entity. But I think that is not so easy to implement and a more advanced feature.
In short, compare the timestamp of an entity and if already updated, then compare the changes and show them for the user who wanted update that entity.

Lock record and release lock after user action from jsp pages

I have a requirement where in my page i have table having list of records.
When user clicked on one record, record should be locked and someone else with old view of overview screen tries to click on the record, it shows a pop up with a message 'Sorry this record is in progress'.
I thought of adding a column in db table where i will make entry say 'In prodress' when someone click and see particular record and later when he close that record i will update that column with say 'Free'. But i have a issue here if somebody select record and close browser directly without closing properly and releasing that lock in that case nobody will be able to see that record.
Please let me know if there is any other way to implement this or how we can implement this in above mention case.
Condition 1 : Two user login at same time record is available to both in normal color say green. User 1 click on record and start editing. In this case there should be some kind of lock so that if user two tries to open same record he will get pop up message 'In progress'.
Condition 2 : User 1 login and see record in green color. Then user 2 login and see same record in grey color. Now he should not be able to click that record.
The problem you have is exactly why it is usually not done that way. If you really have a hard lock on the record, your best options is to have some kind of timeout. How long the timeout is, depends on your application. Have your client refresh the lock regularly, and you can make the timeout shorter.
A better solution might be not to lock at all, but to check whether someone has already changed the data before saving your changes. This is usually done using a timestamp or version number in the record to be updated. The concept to look for is "optimistic locking".
However, this only works if possible conflicts are relatively improbable. Call center workers updating customer records are a typical case, since it is hardly ever the case that two call center places talk to the same customer at the same time. If it ever happens, one of them will get an error, and has to re-load he data and make the changes again.

Know when app data from Application Manager is deleted

I need to have an event that is called at the moment when the user of the phone has clicked 'Clear Data' in the 'Application Manager'. Is there a way to do that?
I need to know that because I got a database that holds very important information and I need to know when that information is deleted. I tried to look for database events for that and even events for data deletion with no luck.
There is no such event.
The first opportunity to detect this is when your app is started next.
(If you're using SQLiteOpenHelper, your onCreate method will get called.)
However, there is no guarantee that the user will actually use your app again.

checking if any Calendar Event/ Media Files got updated

Am working on one of my requirement, halfway through am stuck on an issue. As per my requirement I need to know if any calendar event has been updated, say like any new participant is added or any event fields has been updated say Title,Description or location. As of now am able to know precisely if any event is added or deleted from system, but unfortunately am not able to detect out any update.
The same scenario goes to media, i need to know if any fields related to a media is changed, say name,title or parent folder/path etc.
to summaries my requirement is to know if any filed in Media or Calendar db is updated. to detect Insert or Delete am using Content Observers, as it only tells me something is changed by through onChange() call back, but it never tells you which rows was updated.
regards,
techfist
I had a similar problem with the browser. I made use of shared preferences.
When I read the DB, I know that I have read all the entries until the time stored in shared preferences. So each time I read DB, I need to check for all the changes after the time that was stored in shared preferences and update the time in the shared preferences to current time. For code and my implementation can can look to my solution in Android History Content Observer

How to create an undo function in spring MVC based web app.?

I have an employee and a corresponding employee history table.
Both the tables have same structure. History table is used to track the historical changes made to the employee over a period of time.
Now, I need to add an undo function to the changes made to the employee.
e.g. Employees title is changed on 1st August. Now, This will update the employees title in Employee table and insert an corresponding history record in employee_history table.
Now, I need to undo this change. Employee edit page will have a list of changes made to employee datewise with an undo button beside it.
Clicking on undo should revert changes in Employee table to previous value. Also I think the record in history table which says title is changed, should also be removed.
Also when I revert tghe changes to employee table i.e. revert title to previous title, this will fire an insert to history table, which I dont want.
I am not sure what is the best possible way to do this.
Any suggestions will be helpful.
In case you want to implement a "persistent" undo - one that would survive an application restart/session timeout, you should consider extending your DB schema width timestamp fields and either delete the last entry or replace it with an appropriate earlier entry.
A "light" version would be using a stack to store last interactions, including the original and the new value. You could persist the stack on session invalidation of course to combine both approaches. This seems to be what you are actually doing.
You could extend this solution by creating and storing or exporting SQL migration scripts for each change, recording the change and, if possible, the opposite action. So you could even transfer the scripts between application instances and environments and would have a complete "replayability" of your DB states.
tl;dr - it looks like you have already implemented a good solution
I would suggest using a flag telling the trigger/history logic to keep off while you have your undo running and not writing history data.
Normally this would be done by serializer-class feeding from your history table and restoring employee data and later cleaning up history-entries/unlocking history again.
You could maybe use the rollback feature of the transaction.

Categories