if (originalOpportunity != null) {
ActionContext context = ActionContext.getContext();
Map<String, Object> session = context.getSession();
String entityName = Opportunity.class.getSimpleName();
Integer recordID = opportunity.getId();
User loginUser = (User) session
.get(AuthenticationSuccessListener.LOGIN_USER);
changeLogs = new ArrayList<ChangeLog>();
String oldName = CommonUtil.fromNullToEmpty(originalOpportunity
.getName());
String newName = CommonUtil.fromNullToEmpty(opportunity.getName());
createChangeLog(changeLogs, entityName, recordID,
"entity.name.label", oldName, newName, loginUser);
String oldAccountName = "";
Account oldAccount = originalOpportunity.getAccount();
if (oldAccount != null) {
oldAccountName = CommonUtil.fromNullToEmpty(oldAccount
.getName());
}
String newAccountName = "";
Account newAccount = opportunity.getAccount();
if (newAccount != null) {
newAccountName = CommonUtil.fromNullToEmpty(newAccount
.getName());
}
createChangeLog(changeLogs, entityName, recordID,
"entity.account.label", oldAccountName, newAccountName,
loginUser);
String oldCurrencyName = "";
Currency oldCurrency = originalOpportunity.getCurrency();
if (oldCurrency != null) {
oldCurrencyName = CommonUtil.fromNullToEmpty(oldCurrency
.getName());
}
String newCurrencyName = "";
Currency newCurrency = opportunity.getCurrency();
if (newCurrency != null) {
newCurrencyName = CommonUtil.fromNullToEmpty(newCurrency
.getName());
}
createChangeLog(changeLogs, entityName, recordID,
"entity.currency.label", oldCurrencyName, newCurrencyName,
loginUser);
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constant.DATE_EDIT_FORMAT);
String oldExpectCloseDateValue = "";
Date oldExpectCloseDate = originalOpportunity
.getExpect_close_date();
if (oldExpectCloseDate != null) {
oldExpectCloseDateValue = dateFormat.format(oldExpectCloseDate);
}
String newExpectCloseDateValue = "";
Date newExpectCloseDate = opportunity.getExpect_close_date();
if (newExpectCloseDate != null) {
newExpectCloseDateValue = dateFormat.format(newExpectCloseDate);
}
createChangeLog(changeLogs, entityName, recordID,
"opportunity.expect_close_date.label",
oldExpectCloseDateValue, newExpectCloseDateValue, loginUser);
String oldOpportunityAmount = CommonUtil
.fromNullToEmpty(originalOpportunity
.getOpportunity_amount());
String newOpportunityAmount = CommonUtil
.fromNullToEmpty(opportunity.getOpportunity_amount());
createChangeLog(changeLogs, entityName, recordID,
"opportunity.opportunity_amount.label",
oldOpportunityAmount, newOpportunityAmount, loginUser);
String oldOpportunityType = getOptionValue(originalOpportunity
.getType());
String newOpportunityType = getOptionValue(opportunity.getType());
createChangeLog(changeLogs, entityName, recordID,
"entity.type.label", oldOpportunityType,
newOpportunityType, loginUser);
String oldSalesStage = getOptionValue(originalOpportunity
.getSales_stage());
String newSalesStage = getOptionValue(opportunity.getSales_stage());
createChangeLog(changeLogs, entityName, recordID,
"menu.salesStage.title", oldSalesStage, newSalesStage,
loginUser);
String oldLeadSource = getOptionValue(originalOpportunity
.getLead_source());
String newLeadSource = getOptionValue(opportunity.getLead_source());
createChangeLog(changeLogs, entityName, recordID,
"menu.leadSource.title", oldLeadSource, newLeadSource,
loginUser);
String oldProbability = String.valueOf(originalOpportunity
.getProbability());
String newProbability = String
.valueOf(opportunity.getProbability());
createChangeLog(changeLogs, entityName, recordID,
"opportunity.probability.label", oldProbability,
newProbability, loginUser);
String oldCampaignName = "";
Campaign oldCampaign = originalOpportunity.getCampaign();
if (oldCampaign != null) {
oldCampaignName = CommonUtil.fromNullToEmpty(oldCampaign
.getName());
}
String newCampaignName = "";
Campaign newCampaign = opportunity.getCampaign();
if (newCampaign != null) {
newCampaignName = CommonUtil.fromNullToEmpty(newCampaign
.getName());
}
createChangeLog(changeLogs, entityName, recordID,
"entity.campaign.label", oldCampaignName, newCampaignName,
loginUser);
String oldNextStep = CommonUtil.fromNullToEmpty(originalOpportunity
.getNext_step());
String newNextStep = CommonUtil.fromNullToEmpty(opportunity
.getNext_step());
createChangeLog(changeLogs, entityName, recordID,
"opportunity.next_step.label", oldNextStep, newNextStep,
loginUser);
String oldNotes = CommonUtil.fromNullToEmpty(originalOpportunity
.getNotes());
String newNotes = CommonUtil
.fromNullToEmpty(opportunity.getNotes());
createChangeLog(changeLogs, entityName, recordID,
"entity.notes.label", oldNotes, newNotes, loginUser);
String oldAssignedToName = "";
User oldAssignedTo = originalOpportunity.getAssigned_to();
if (oldAssignedTo != null) {
oldAssignedToName = oldAssignedTo.getName();
}
String newAssignedToName = "";
User newAssignedTo = opportunity.getAssigned_to();
if (newAssignedTo != null) {
newAssignedToName = newAssignedTo.getName();
}
createChangeLog(changeLogs, entityName, recordID,
"entity.assigned_to.label",
CommonUtil.fromNullToEmpty(oldAssignedToName),
CommonUtil.fromNullToEmpty(newAssignedToName), loginUser);