Search in sources :

Example 51 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class GenerateMessageController method generateMessage.

public Map<String, Object> generateMessage(long objectId, String model, String tag, Template template) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException {
    LOG.debug("template : {} ", template);
    LOG.debug("object id : {} ", objectId);
    LOG.debug("model : {} ", model);
    LOG.debug("tag : {} ", tag);
    Message message = null;
    if (template != null) {
        message = Beans.get(TemplateMessageService.class).generateMessage(objectId, model, tag, template);
    } else {
        message = Beans.get(MessageService.class).createMessage(model, Math.toIntExact(objectId), null, null, null, null, null, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, null, null);
    }
    return ActionView.define(I18n.get(IExceptionMessage.MESSAGE_3)).model(Message.class.getName()).add("form", "message-form").param("forceEdit", "true").context("_showRecord", message.getId().toString()).map();
}
Also used : Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage)

Example 52 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class TimesheetController method valid.

/**
 * Action called when validating a timesheet. Changing status + Sending mail to Applicant
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void valid(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
        TimesheetService timesheetService = Beans.get(TimesheetService.class);
        timesheetService.checkEmptyPeriod(timesheet);
        computeTimeSpent(request, response);
        Message message = timesheetService.validateAndSendValidationEmail(timesheet);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
        Beans.get(PeriodService.class).checkPeriod(timesheet.getCompany(), timesheet.getToDate(), timesheet.getFromDate());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) PeriodService(com.axelor.apps.base.service.PeriodService) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Example 53 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class TimesheetReportController method sendTimesheetReminder.

public void sendTimesheetReminder(ActionRequest request, ActionResponse response) throws AxelorException {
    TimesheetReport timesheetReport = request.getContext().asType(TimesheetReport.class);
    if (ObjectUtils.isEmpty(timesheetReport.getReminderUserSet())) {
        return;
    }
    List<Message> messages = Beans.get(TimesheetReportService.class).sendReminders(timesheetReport);
    List<Long> messageIds = new ArrayList<Long>();
    messageIds.add(0L);
    for (Message message : messages) {
        messageIds.add(message.getId());
    }
    response.setView(ActionView.define(I18n.get("Messages")).model(Message.class.getName()).add("grid", "message-timesheet-reminder-grid").add("form", "message-form").domain("self.id in (:messageIds)").context("messageIds", messageIds).map());
}
Also used : Message(com.axelor.apps.message.db.Message) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) TimesheetReportService(com.axelor.apps.hr.service.timesheet.TimesheetReportService) ArrayList(java.util.ArrayList)

Example 54 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class CampaignServiceImpl method generateAndSendMessage.

@Transactional(rollbackOn = { Exception.class })
protected void generateAndSendMessage(Campaign campaign, Model model, Template template) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException, JSONException {
    Message message = templateMessageMarketingService.generateAndSendMessage(model, template);
    message.setRelatedTo1Select(Campaign.class.getCanonicalName());
    message.setRelatedTo1SelectId(campaign.getId());
}
Also used : Campaign(com.axelor.apps.marketing.db.Campaign) Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.marketing.exception.IExceptionMessage) Transactional(com.google.inject.persist.Transactional)

Aggregations

Message (com.axelor.apps.message.db.Message)54 AxelorException (com.axelor.exception.AxelorException)25 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)16 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)14 Transactional (com.google.inject.persist.Transactional)13 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)11 Template (com.axelor.apps.message.db.Template)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 ArrayList (java.util.ArrayList)6 Employee (com.axelor.apps.hr.db.Employee)5 EmailAddress (com.axelor.apps.message.db.EmailAddress)5 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)4 Expense (com.axelor.apps.hr.db.Expense)4 ExtraHours (com.axelor.apps.hr.db.ExtraHours)4 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)4 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)4 ExtraHoursService (com.axelor.apps.hr.service.extra.hours.ExtraHoursService)4 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)4 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)4 User (com.axelor.auth.db.User)4