/** * Saves the entity. * * @return the SUCCESS result */ public String save() throws Exception { Call originalCall = saveEntity(); final Collection<ChangeLog> changeLogs = changeLog(originalCall, call); // Validate Reminder Email Template if (call.isReminder_email() && reminderTemplateID == null) { String errorMessage = getText("error.reminderEamilTemplate"); super.addActionError(errorMessage); return INPUT; } call = getbaseService().makePersistent(call); this.setId(call.getId()); this.setSaveFlag("true"); if (changeLogs != null) { taskExecutor.execute( new Runnable() { public void run() { batchInserChangeLogs(changeLogs); } }); } return SUCCESS; }
/** * Saves entity field * * @return original call record * @throws ParseException */ private Call saveEntity() throws Exception { Call originalCall = null; if (call.getId() == null) { UserUtil.permissionCheck("create_call"); } else { UserUtil.permissionCheck("update_call"); originalCall = baseService.getEntityById(Call.class, call.getId()); call.setContacts(originalCall.getContacts()); call.setLeads(originalCall.getLeads()); call.setUsers(originalCall.getUsers()); } CallDirection direction = null; if (directionID != null) { direction = callDirectionService.getEntityById(CallDirection.class, directionID); } call.setDirection(direction); CallStatus status = null; if (statusID != null) { status = callStatusService.getEntityById(CallStatus.class, statusID); } call.setStatus(status); ReminderOption reminderOptionEmail = null; if (reminderOptionEmailID != null) { reminderOptionEmail = reminderOptionService.getEntityById(ReminderOption.class, reminderOptionEmailID); } call.setReminder_option_email(reminderOptionEmail); EmailTemplate reminderTemplate = null; if (reminderTemplateID != null) { reminderTemplate = emailTemplateService.getEntityById(EmailTemplate.class, reminderTemplateID); } call.setReminder_template(reminderTemplate); User user = null; if (this.getAssignedToID() != null) { user = userService.getEntityById(User.class, this.getAssignedToID()); } call.setAssigned_to(user); User owner = null; if (this.getOwnerID() != null) { owner = userService.getEntityById(User.class, this.getOwnerID()); } call.setOwner(owner); SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT); Date start_date = null; if (!CommonUtil.isNullOrEmpty(startDate)) { start_date = dateFormat.parse(startDate); } call.setStart_date(start_date); String relatedObject = call.getRelated_object(); if ("Account".equals(relatedObject)) { call.setRelated_record(relatedAccountID); } else if ("CaseInstance".equals(relatedObject)) { call.setRelated_record(relatedCaseID); } else if ("Contact".equals(relatedObject)) { call.setRelated_record(relatedContactID); } else if ("Lead".equals(relatedObject)) { call.setRelated_record(relatedLeadID); } else if ("Opportunity".equals(relatedObject)) { call.setRelated_record(relatedOpportunityID); } else if ("Target".equals(relatedObject)) { call.setRelated_record(relatedTargetID); } else if ("Task".equals(relatedObject)) { call.setRelated_record(relatedTaskID); } super.updateBaseInfo(call); return originalCall; }
/** * Sends invitation mail to all participants. * * @return the SUCCESS result */ public String sendInvites() throws Exception { UserUtil.permissionCheck("update_call"); call = baseService.getEntityById(Call.class, call.getId()); Date start_date = call.getStart_date(); SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT); startDate = ""; if (start_date != null) { startDate = dateFormat.format(start_date); } this.setId(call.getId()); ActionContext context = ActionContext.getContext(); Map<String, Object> session = context.getSession(); User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER); StringBuilder targetEmails = new StringBuilder(""); Set<Contact> contacts = call.getContacts(); if (contacts != null) { for (Contact contact : contacts) { String email = contact.getEmail(); if (CommonUtil.isNullOrEmpty(email)) { continue; } if (targetEmails.length() > 0) { targetEmails.append(","); } targetEmails.append(email); } } Set<Lead> leads = call.getLeads(); if (leads != null) { for (Lead lead : leads) { String email = lead.getEmail(); if (CommonUtil.isNullOrEmpty(email)) { continue; } if (targetEmails.length() > 0) { targetEmails.append(","); } targetEmails.append(email); } } from = loginUser.getEmail(); if (from == null) { from = ""; } Set<User> users = call.getUsers(); if (users != null) { for (User user : users) { String email = user.getEmail(); if (CommonUtil.isNullOrEmpty(email) || (from != null && email.endsWith(from))) { continue; } if (targetEmails.length() > 0) { targetEmails.append(","); } targetEmails.append(email); } } if (targetEmails.length() > 0) { to = targetEmails.toString(); } // Gets email template list String hql = "select new EmailTemplate(id,name) from EmailTemplate where type = 'callInvite' order by created_on"; emailTemplates = emailTemplateService.findByHQL(hql); return SUCCESS; }
private Collection<ChangeLog> changeLog(Call originalCall, Call call) { Collection<ChangeLog> changeLogs = null; if (originalCall != null) { ActionContext context = ActionContext.getContext(); Map<String, Object> session = context.getSession(); String entityName = Call.class.getSimpleName(); Integer recordID = call.getId(); User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER); changeLogs = new ArrayList<ChangeLog>(); String oldSubject = CommonUtil.fromNullToEmpty(originalCall.getSubject()); String newSubject = CommonUtil.fromNullToEmpty(call.getSubject()); if (!oldSubject.equals(newSubject)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.subject.label", oldSubject, newSubject, loginUser); changeLogs.add(changeLog); } String oldStatus = getOptionValue(originalCall.getStatus()); String newStatus = getOptionValue(call.getStatus()); if (!oldStatus.equals(newStatus)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.status.label", oldStatus, newStatus, loginUser); changeLogs.add(changeLog); } SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_EDIT_FORMAT); String oldStartDateValue = ""; Date oldStartDate = originalCall.getStart_date(); if (oldStartDate != null) { oldStartDateValue = dateFormat.format(oldStartDate); } String newStartDateValue = ""; Date newStartDate = call.getStart_date(); if (newStartDate != null) { newStartDateValue = dateFormat.format(newStartDate); } if (!oldStartDateValue.equals(newStartDateValue)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.start_date.label", oldStartDateValue, newStartDateValue, loginUser); changeLogs.add(changeLog); } String oldRelatedObject = CommonUtil.fromNullToEmpty(originalCall.getRelated_object()); String newRelatedObject = CommonUtil.fromNullToEmpty(call.getRelated_object()); if (!oldRelatedObject.equals(newRelatedObject)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.related_object.label", oldRelatedObject, newRelatedObject, loginUser); changeLogs.add(changeLog); } String oldRelatedRecord = String.valueOf(originalCall.getRelated_record()); String newRelatedRecord = String.valueOf(call.getRelated_record()); if (!oldRelatedRecord.equals(newRelatedRecord)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.related_record.label", oldRelatedRecord, newRelatedRecord, loginUser); changeLogs.add(changeLog); } boolean oldReminderEmail = originalCall.isReminder_email(); boolean newReminderEmail = call.isReminder_email(); if (oldReminderEmail != newReminderEmail) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.reminder.label", String.valueOf(oldReminderEmail), String.valueOf(newReminderEmail), loginUser); changeLogs.add(changeLog); } String oldReminderOption = getOptionValue(originalCall.getReminder_option_email()); String newReminderOption = getOptionValue(call.getReminder_option_email()); if (!oldReminderOption.equals(newReminderOption)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.reminder_option_email_name.label", oldReminderOption, newReminderOption, loginUser); changeLogs.add(changeLog); } String oldReminderTemplateName = ""; EmailTemplate oldReminderTemplate = originalCall.getReminder_template(); if (oldReminderTemplate != null) { oldReminderTemplateName = CommonUtil.fromNullToEmpty(oldReminderTemplate.getName()); } String newReminderTemplateName = ""; EmailTemplate newReminderTemplate = call.getReminder_template(); if (newReminderTemplate != null) { newReminderTemplateName = CommonUtil.fromNullToEmpty(newReminderTemplate.getName()); } if (oldReminderTemplateName != newReminderTemplateName) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.reminder_template.label", oldReminderTemplateName, newReminderTemplateName, loginUser); changeLogs.add(changeLog); } String oldDescription = CommonUtil.fromNullToEmpty(originalCall.getDescription()); String newDescription = CommonUtil.fromNullToEmpty(call.getDescription()); if (!oldDescription.equals(newDescription)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.description.label", oldDescription, newDescription, loginUser); changeLogs.add(changeLog); } String oldNotes = CommonUtil.fromNullToEmpty(originalCall.getNotes()); String newNotes = CommonUtil.fromNullToEmpty(call.getNotes()); if (!oldNotes.equals(newNotes)) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.notes.label", oldNotes, newNotes, loginUser); changeLogs.add(changeLog); } String oldAssignedToName = ""; User oldAssignedTo = originalCall.getAssigned_to(); if (oldAssignedTo != null) { oldAssignedToName = oldAssignedTo.getName(); } String newAssignedToName = ""; User newAssignedTo = call.getAssigned_to(); if (newAssignedTo != null) { newAssignedToName = newAssignedTo.getName(); } if (oldAssignedToName != newAssignedToName) { ChangeLog changeLog = saveChangeLog( entityName, recordID, "entity.assigned_to.label", CommonUtil.fromNullToEmpty(oldAssignedToName), CommonUtil.fromNullToEmpty(newAssignedToName), loginUser); changeLogs.add(changeLog); } } return changeLogs; }