ModelService.save(dispute) is removing the Object record from db in hybris - sap-commerce-cloud

I fetched the record to be updated from the db and updated the details and saved again , process goes on without any flaw but dont know why the record gets deleted after getting saved.
AviationDisputeModel dispute = aviationDisputeService.getDisputeDetails(resolveDisputeDetails.get("DispId").toString());
if (Objects.nonNull(dispute) && StringUtils.isNotEmpty(String.valueOf(resolveDisputeDetails.get("DispId")))
&& StringUtils.isNotEmpty(String.valueOf(resolveDisputeDetails.get("DspStat")))
&& StringUtils.isNotEmpty(String.valueOf(resolveDisputeDetails.get("RES_CODE"))))
{
try
{
dispute.setDisputeStatus((resolveDisputeDetails.get("DspStat").toString()));
dispute.setResolutionCode(resolveDisputeDetails.get("RES_CODE").toString());
dispute.setDisputeCategory(resolveDisputeDetails.get("RES_CODE").toString());
dispute.setResolutionCategory(resolveDisputeDetails.get("RES_CODE").toString());
modelService.save(dispute);
return "SUCCESS";
}
catch (Exception e)
{
LOG.error("Error while resolving Dispute" + e.getMessage());
return "FAILURE";
}

Related

Snyc Azure local Tables with Azure Server tables in xamarin forms

I am using following method to sync Azure DB local table with server table but the changes which I made on my local DB are not reflecting to the Azure server,
public async Task PushDataAsync()
{
try
{
await _mobileService.SyncContext.PushAsync();
}
catch (Exception exc)
{
throw exc;
}
}
While using above method I am getting Error :-
Push Operation Fail.
Any Help will appreciated.
you are using right method to sync your offline store with server which is :-
await _mobileService.SyncContext.PushAsync();
I would suggest you to wrote few line of code in catch block which will help you to find out the reasons why the operations are not performed on server side
please use code bellow in catch block:-
public async Task PushDataAsync()
{
try
{
await _mobileService.SyncContext.PushAsync();
}
catch (MobileServicePushFailedException exc)
{
if (exc.PushResult != null)
{
syncErrors = exc.PushResult.Errors;
}
}
// Simple error/conflict handling.
if (syncErrors != null)
{
foreach (var error in syncErrors)
{
if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null || error.OperationKind == MobileServiceTableOperationKind.Insert && error.Result != null || error.OperationKind == MobileServiceTableOperationKind.Delete && error.Result != null)
{
//Update failed, reverting to server's copy.
await error.CancelAndUpdateItemAsync(error.Result);
}
else
{
// Discard local change.
await error.CancelAndDiscardItemAsync();
}
Debug.WriteLine(#"Error executing sync {2} operation. Item: {0} ({1}). Operation discarded.",
error.TableName, error.Item["id"], error.OperationKind);
}
}
}
Remember that PushAsync() pushes ALL changes from your local store to the cloud and that PullAsync first performs a Push. I would get rid of the service variable for each table and just use the service as a singleton class across your app. Here is my initialization. After this method returns, my local db is synced with the cloud and I can start using my tables:
public async Task InitializeStoreAsync()
{
try
{
var sqliteStore = _platform.MobileServiceSqliteStore;
sqliteStore.DefineTable<Memory>();
sqliteStore.DefineTable<User> ();
sqliteStore.DefineTable<Comment> ();
sqliteStore.DefineTable<Status>();
await _zumoClient.SyncContext.InitializeAsync(sqliteStore);
_memoryTable = _zumoClient.GetSyncTable<Memory> ();
_userTable = _zumoClient.GetSyncTable<User> ();
_commentTable = _zumoClient.GetSyncTable<Comment> ();
_statusTable = _zumoClient.GetSyncTable<Status>();
await _userTable.PullAsync ();
await _memoryTable.PullAsync ();
await _commentTable.PullAsync ();
await _statusTable.PullAsync();
}
catch (Exception ex)
{
Debug.WriteLine ("Initialize Store failed: {0}", ex.Message);
}
}
https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/client/ search for "Handling Conflict Resolution"

platformRequest not working in J2ME

I'm triyng to play .mp3 file using platformRequest(). I verified the file path and it is correct. And I'm using Nokia 210 for testing. Please help me to fix this issue.
try {
platformRequest("file:///C:/song.mp3");
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
I know you have already verified whether there is file or not. though check my below code once and post comment with results.
Added -
public boolean isFileExisted(String path) {
boolean isExisted = false;
FileConnection filecon = null;
try {
filecon = (FileConnection) Connector.open(path, Connector.READ);
isExisted = filecon.exists();
} catch (java.lang.SecurityException e) {
} catch (Exception e) {
} finally {
try {
if (filecon != null) {
filecon.close();
}
catch (Exception e) {
}
}
return isExisted;
}
}
public void playFileFromSDCard() {
String path1 = "file:///C:/song.mp3";
String path2 = "file:///E:/song.mp3";
if (isFileExisted(path1)) {
try {
System.out.println("path1 exist -> calling platform request " + path1);
platformRequest(path1);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
else if (isFileExisted(path2)) {
try {
System.out.println("path2 exist -> calling platform request " + path2);
platformRequest(path2);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
else {
System.out.println("both path doesnt exists");
}
}
After so many searches i found some reasons for the issue. This may help for people in future who is having the same problem. refer the following links.
Open file with MIDlet.platformRequest() ,
How to play media file in System media player in j2me????

handling file not found exception?

I made this code to empty some files that I regularly delete, such as temp files in Windows. Several friends may wish to use the same application and I am working on the best way to handle the file not found exception.
How can this best be handled for use by multiple users?
public void Deletefiles()
{
try
{
string[] DirectoryList = Directory.GetDirectories("C:\\Users\\user\\Desktop\\1");
string[] FileList = Directory.GetFiles("C:\\Users\\user\\Desktop\\1");
foreach (string x in DirectoryList)
{
Directory.Delete(x, true);
FoldersCounter++;
}
foreach (string y in FileList)
{
File.Delete(y);
FilesCounter++;
}
MessageBox.Show("Done...\nFiles deleted - " + FileList.Length + "\nDirectories deleted - " + DirectoryList.Length + "\n" + FilesCounter + "\n", "message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception z)
{
if (z.Message.Contains("NotFound"))
{
MessageBox.Show("File Not Found");
}
else
{
throw (z);
}
//throw new FileNotFoundException();
}
}
Modifying you code as little as possible, you could simply wrap your Delete calls in a try/catch:
foreach (string x in DirectoryList)
{
try {
Directory.Delete(x, true);
}
catch (DirectoryNotFoundException e)
{
// do something, or not...
}
FoldersCounter++;
}
foreach (string y in FileList)
{
try
{
File.Delete(y);
}
catch (FileNotFoundException e)
{
// do something, or not...
}
FilesCounter++;
}
Remove the top level try/catch and just let the foreach statements cycle through -- trying and catching any exceptions as they come.
You don't necessarily need to alert the user that the file wasn't found. It is there it is going to be deleted, so the fact that it isn't there doesn't really effect the outcome of the program.
This isn't the most resource friendly method, but it is a simple enough application to not cause an issue.

Duplicate entry '0' for key 'PRIMARY' while adding data to MYSQL([JDBCExceptionReporter:76])

getting following exception while inserting 2nd time in database from my liferay portlet.
[JDBCExceptionReporter:76] Duplicate entry '0' for key 'PRIMARY'.(i think its because my primary key value not getting auto increment)
I think have done mistake while auto incrementing the primary key in my custom portlet .but i don't know where i have to make changes for that.
if anyone can guide me about to where make the changes to solve this auto increment issue?
this is the code from auto increment been set
try {
restVar = restaurantPersistence.create(counterLocalService
.increment(restaurant.class.toString()));
} catch (SystemException e) {
e.printStackTrace();
return restVar = null;
}
try {
resourceLocalService.addResources(0,restParam.getGroupId(), restParam.getUserId(),
restaurant.class.getName(),restParam.getPrimaryKey(), false,true,true);
} catch (PortalException e) {
e.printStackTrace();
return restVar = null;
} catch (SystemException e) {
e.printStackTrace();
return restVar = null;
}
Try this one..
long primaryKeyId = CounterLocalServiceUtil.increment(ClassName.class.getName());
XYZDetails XYZDetails = XYZDetailsLocalServiceUtil.createXYZDetails(primaryKeyId);
Add other details using XYZDetails Obj
e.g
XYZDetails.setName("Name");
Then Save the Details..
XYZDetailsLocalServiceUtil.addXYZDetails(XYZDetails);
Hope this may help you !!!

Is it possible to use IMAP Query Terms in Javamail with GMail?

I am trying to programmatically retrieve the Call Log messages that are backup up from my android phone by a little application called SMSBackup (highly recommended).
What I want to do is to be able to retrieve the call logs for a particular day. I have tried the following program, using JavaMail:
public List<CallLogEntry> getCallLog(String username, String password, Date date, TimeZone tz) {
Store store = null;
try {
store = MailUtils.getGmailImapStore(username, password);
Folder folder = store.getDefaultFolder();
if (folder == null)
throw new Exception("No default folder");
Folder inboxfolder = folder.getFolder("Call log");
if (inboxfolder == null)
throw new Exception("No INBOX");
inboxfolder.open(Folder.READ_ONLY);
Date fromMidnight = new Date(TimeUtils.fromMidnight(date.getTime(), tz));
Date toMidnight = new Date(TimeUtils.toMidnight(date.getTime(), 0, tz));
SentDateTerm fromTerm = new SentDateTerm(SentDateTerm.GT, fromMidnight);
SentDateTerm toTerm = new SentDateTerm(SentDateTerm.LT, toMidnight);
AndTerm searchTerms = new AndTerm(fromTerm, toTerm);
Message[] msgs = inboxfolder.search(searchTerms);
FetchProfile fp = new FetchProfile();
fp.add("Subject");
fp.add("Content");
fp.add("From");
fp.add("SentDate");
inboxfolder.fetch(msgs, fp);
List<CallLogEntry> callLog = new ArrayList<CallLogEntry>();
for (Message message : msgs) {
CallLogEntry entry = new CallLogEntry();
entry.subject = message.getSubject();
entry.body = (String) message.getContent();
callLog.add(entry);
}
inboxfolder.close(false);
store.close();
return callLog;
} catch (NoSuchProviderException ex) {
ex.printStackTrace();
} catch (MessagingException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (store != null)
store.close();
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
return null;
}
My two utility methods (fromMidnight / toMidnight):
public static final long fromMidnight(long time, TimeZone tz) {
Calendar c = Calendar.getInstance(tz);
c.setTimeInMillis(time);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 1);
return c.getTimeInMillis();
}
public static final long toMidnight(long time, int nDays, TimeZone tz) {
Calendar c = Calendar.getInstance(tz);
c.setTimeInMillis(time + nDays*MILLIS_IN_DAY);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 999);
return c.getTimeInMillis();
}
However, for some reason:
while eventually executing, it takes about 3 minutes to complete
I'm getting back the entire Call log, i.e. the entire content of the "Call Log" folder in my mailbox
What am I missing?
The main thing that you're missing is that the underlying IMAP SEARCH syntax supports only dates, not date-times. So your query will result in JavaMail issuing the command:
A001 SEARCH SENTBEFORE 16-JAN-2011 SENTSINCE 16-JAN-2011 ALL
(Put a breakpoint in IMAPProtocol.issueSearch() to see this.)
GMail appears to freak out on this query, which logically cannot match any messages. Try switching your logic to a single term using SentDateTerm.EQ (which maps to SENTON) and it should work:
SentDateTerm term = new SentDateTerm(SentDateTerm.EQ, date.getTime());
Message[] msgs = inboxfolder.search(term);

Resources