add send meeting details to guests
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
|
||||
<many-to-one name="accountCreationTemplate" ref="com.axelor.apps.message.db.Template" title="Template for account creation"/>
|
||||
|
||||
<many-to-one name="sendMailToInvitedPersonInMeetingTemplate" ref="com.axelor.apps.message.db.Template" title="Template for changed password"/>
|
||||
<many-to-one name="sendMailToInvitedPersonInMeetingTemplate" ref="com.axelor.apps.message.db.Template" title="Template for Meeting Invitation"/>
|
||||
|
||||
<integer name="limitNumberTasksGenerated" title="Number of tasks generated at most at once" min="1" default="100"/>
|
||||
|
||||
|
||||
@@ -58,6 +58,12 @@ public interface IExceptionMessage {
|
||||
static final String EVENT_SAVED = /*$$(*/
|
||||
"Please save the event before setting the recurrence" /*)*/;
|
||||
|
||||
static final String EVENT_MEETING_INVITATION_1 = /*$$(*/
|
||||
"No PERSON IS INVITED TO THIS MEETING" /*)*/;
|
||||
|
||||
static final String USER_EMAIL_1 = /*$$(*/
|
||||
"No email address associated to %s" /*)*/;
|
||||
|
||||
/** Lead controller */
|
||||
static final String LEAD_1 = /*$$(*/ "Please select the Lead(s) to print." /*)*/;
|
||||
|
||||
|
||||
@@ -23,10 +23,14 @@ import com.axelor.apps.crm.db.RecurrenceConfiguration;
|
||||
import com.axelor.apps.message.db.EmailAddress;
|
||||
import com.axelor.auth.db.User;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import java.io.IOException;
|
||||
import javax.mail.MessagingException;
|
||||
import com.axelor.meta.CallMethod;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface EventService {
|
||||
|
||||
@@ -74,4 +78,19 @@ public interface EventService {
|
||||
void generateRecurrentEvents(Event event, RecurrenceConfiguration conf) throws AxelorException;
|
||||
|
||||
public EmailAddress getEmailAddress(Event event);
|
||||
|
||||
/**
|
||||
* Processs changed user password.
|
||||
*
|
||||
* @param Set<user>
|
||||
* @throws ClassNotFoundException
|
||||
* @throws InstantiationException
|
||||
* @throws IllegalAccessException
|
||||
* @throws MessagingException
|
||||
* @throws IOException
|
||||
* @throws AxelorException
|
||||
*/
|
||||
|
||||
void sendEmailMeetingInvitation(Event event,Set<User> users) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
MessagingException, IOException, AxelorException;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
*/
|
||||
package com.axelor.apps.crm.service;
|
||||
|
||||
|
||||
import com.axelor.apps.base.db.AppBase;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
import com.axelor.apps.base.db.Address;
|
||||
import com.axelor.apps.base.db.ICalendarUser;
|
||||
import com.axelor.apps.base.db.Partner;
|
||||
@@ -34,8 +37,11 @@ import com.axelor.apps.message.db.EmailAddress;
|
||||
import com.axelor.apps.message.db.repo.EmailAddressRepository;
|
||||
import com.axelor.apps.message.service.MessageService;
|
||||
import com.axelor.apps.message.service.TemplateMessageService;
|
||||
import com.axelor.apps.message.db.Template;
|
||||
import com.axelor.auth.db.User;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.IOException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
@@ -54,6 +60,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -655,4 +662,32 @@ public class EventServiceImpl implements EventService {
|
||||
}
|
||||
return emailAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEmailMeetingInvitation(Event event, Set<User> users) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
MessagingException, IOException, AxelorException {
|
||||
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
|
||||
Template template = appBase.getSendMailToInvitedPersonInMeetingTemplate();
|
||||
|
||||
if (template == null) {
|
||||
throw new AxelorException(
|
||||
appBase,
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Template for sending meeting invitation is missing.")
|
||||
);
|
||||
}
|
||||
|
||||
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
|
||||
|
||||
try {
|
||||
templateMessageService.generateAndSendMessageToBulkUsers(event, template, users);
|
||||
} catch (MessagingException e) {
|
||||
throw new AxelorException(
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Failed to send meeting invitation email."),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.math3.ode.events.EventState;
|
||||
@@ -604,4 +605,37 @@ public class EventController {
|
||||
response.setView(ActionView.define(eventName).add("html", fileLink).map());
|
||||
}
|
||||
|
||||
public void sendMailToGuests(ActionRequest request, ActionResponse response) throws AxelorException {
|
||||
|
||||
Event event = request.getContext().asType(Event.class);
|
||||
event = Beans.get(EventRepository.class).find(event.getId());
|
||||
|
||||
Set<User> users = event.getGuestList();
|
||||
if (event.getUser() != null)
|
||||
users.add(event.getUser());
|
||||
users.add(event.getCreatedBy());
|
||||
|
||||
if (!users.isEmpty()) {
|
||||
// Check if all users have an email address
|
||||
for (User user : users) {
|
||||
if (user.getEmail() == null) {
|
||||
response.setFlash(I18n.get(String.format(IExceptionMessage.USER_EMAIL_1, user.getName())));
|
||||
return; // Exit the method if any user lacks an email
|
||||
}
|
||||
}
|
||||
|
||||
// All users have emails; proceed to send emails
|
||||
try {
|
||||
Beans.get(EventService.class).sendEmailMeetingInvitation(event,users);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage());
|
||||
return; // Exit if any email fails to send
|
||||
}
|
||||
|
||||
response.setFlash(I18n.get("Emails successfully sent to all guests."));
|
||||
|
||||
} else {
|
||||
response.setFlash(I18n.get(IExceptionMessage.EVENT_MEETING_INVITATION_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.axelor.tool.template.TemplateMaker;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import javax.mail.MessagingException;
|
||||
import com.axelor.auth.db.User;
|
||||
import java.util.List;
|
||||
|
||||
public interface TemplateMessageService {
|
||||
|
||||
@@ -41,6 +43,10 @@ public interface TemplateMessageService {
|
||||
throws MessagingException, IOException, AxelorException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException;
|
||||
|
||||
public Message generateAndSendMessageToBulkUsers(Model model, Template template, Set<User> users)
|
||||
throws MessagingException, IOException, AxelorException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException;
|
||||
|
||||
public Set<MetaFile> getMetaFiles(Template template) throws AxelorException, IOException;
|
||||
|
||||
public TemplateMaker initMaker(long objectId, String model, String tag, boolean isJson)
|
||||
|
||||
@@ -53,10 +53,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import javax.mail.MessagingException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.axelor.auth.db.User;
|
||||
|
||||
public class TemplateMessageServiceImpl implements TemplateMessageService {
|
||||
|
||||
@@ -197,7 +200,10 @@ public class TemplateMessageServiceImpl implements TemplateMessageService {
|
||||
|
||||
message.setTemplate(Beans.get(TemplateRepository.class).find(template.getId()));
|
||||
|
||||
message = Beans.get(MessageRepository.class).save(message);
|
||||
// Save message if it's not related to the USER model
|
||||
if (!"com.axelor.auth.db.User".equals(model)) {
|
||||
message = Beans.get(MessageRepository.class).save(message);
|
||||
}
|
||||
|
||||
messageService.attachMetaFiles(message, getMetaFiles(template));
|
||||
|
||||
@@ -215,6 +221,26 @@ public class TemplateMessageServiceImpl implements TemplateMessageService {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message generateAndSendMessageToBulkUsers(Model model, Template template, Set<User> users)
|
||||
throws MessagingException, IOException, AxelorException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException {
|
||||
|
||||
Message message = this.generateMessage(model, template);
|
||||
Set<EmailAddress> emailAddresses = new HashSet<>();
|
||||
for (User user : users) {
|
||||
emailAddresses.add(getEmailAddress(user.getEmail()));
|
||||
}
|
||||
|
||||
// Set recipients as sets
|
||||
message.setToEmailAddressSet(emailAddresses);
|
||||
message.setCcEmailAddressSet(emailAddresses);
|
||||
|
||||
messageService.sendMessage(message);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<MetaFile> getMetaFiles(Template template) throws AxelorException, IOException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user