use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class ICalendarEventManagementRepository method save.
@Override
public ICalendarEvent save(ICalendarEvent entity) {
User creator = entity.getCreatedBy();
if (creator == null) {
creator = AuthUtils.getUser();
}
if (entity.getOrganizer() == null && creator != null) {
if (creator.getPartner() != null && creator.getPartner().getEmailAddress() != null) {
String email = creator.getPartner().getEmailAddress().getAddress();
if (email != null) {
ICalendarUser organizer = Beans.get(ICalendarUserRepository.class).all().filter("self.email = ?1 AND self.user.id = ?2", email, creator.getId()).fetchOne();
if (organizer == null) {
organizer = new ICalendarUser();
organizer.setEmail(email);
organizer.setName(creator.getFullName());
organizer.setUser(creator);
}
entity.setOrganizer(organizer);
}
}
}
entity.setSubjectTeam(entity.getSubject());
if (entity.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
entity.setSubjectTeam(I18n.get("Available"));
if (entity.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
entity.setSubjectTeam(I18n.get("Busy"));
}
}
return super.save(entity);
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class ICalendarEventServiceImpl method addEmailGuest.
@Override
public List<ICalendarUser> addEmailGuest(EmailAddress email, ICalendarEvent event) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, MessagingException, IOException, ICalendarException, ParseException {
if (email != null) {
if (event.getAttendees() == null || !event.getAttendees().stream().anyMatch(x -> email.getAddress().equals(x.getEmail()))) {
ICalendarUser calUser = new ICalendarUser();
calUser.setEmail(email.getAddress());
calUser.setName(email.getName());
if (email.getPartner() != null) {
calUser.setUser(userRepository.all().filter("self.partner.id = ?1", email.getPartner().getId()).fetchOne());
}
event.addAttendee(calUser);
}
}
return event.getAttendees();
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class EventServiceImpl method manageFollowers.
@Override
@Transactional
public void manageFollowers(Event event) {
MailFollowerRepository mailFollowerRepo = Beans.get(MailFollowerRepository.class);
List<MailFollower> followers = mailFollowerRepo.findAll(event);
List<ICalendarUser> attendeesSet = event.getAttendees();
if (followers != null)
followers.forEach(x -> mailFollowerRepo.remove(x));
mailFollowerRepo.follow(event, event.getUser());
if (attendeesSet != null) {
for (ICalendarUser user : attendeesSet) {
if (user.getUser() != null) {
mailFollowerRepo.follow(event, user.getUser());
} else {
MailAddress mailAddress = Beans.get(MailAddressRepository.class).findOrCreate(user.getEmail(), user.getName());
mailFollowerRepo.follow(event, mailAddress);
}
}
}
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class ICalendarService method findOrCreateUser.
protected ICalendarUser findOrCreateUser(Property source, ICalendarEvent event) {
URI addr = null;
if (source instanceof Organizer) {
addr = ((Organizer) source).getCalAddress();
}
if (source instanceof Attendee) {
addr = ((Attendee) source).getCalAddress();
}
if (addr == null) {
return null;
}
String email = mailto(addr.toString(), true);
ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
ICalendarUser user = null;
if (source instanceof Organizer) {
user = repo.all().filter("self.email = ?1", email).fetchOne();
} else {
user = repo.all().filter("self.email = ?1 AND self.event.id = ?2", email, event.getId()).fetchOne();
}
if (user == null) {
user = new ICalendarUser();
user.setEmail(email);
user.setName(email);
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
user.setUser(emailAddress.getPartner().getUser());
}
}
if (source.getParameter(Parameter.CN) != null) {
user.setName(source.getParameter(Parameter.CN).getValue());
}
if (source.getParameter(Parameter.PARTSTAT) != null) {
String role = source.getParameter(Parameter.PARTSTAT).getValue();
if (role.equals("TENTATIVE")) {
user.setStatusSelect(ICalendarUserRepository.STATUS_MAYBE);
} else if (role.equals("ACCEPTED")) {
user.setStatusSelect(ICalendarUserRepository.STATUS_YES);
} else if (role.equals("DECLINED")) {
user.setStatusSelect(ICalendarUserRepository.STATUS_NO);
}
}
return user;
}
Aggregations