use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class BatchEventReminder method generateMessageProcess.
protected void generateMessageProcess() {
MessageRepository messageRepo = Beans.get(MessageRepository.class);
if (!stop) {
int i = 0;
Query q = JPA.em().createQuery(" SELECT er FROM EventReminder as er WHERE er.isReminded = true and ?1 MEMBER OF er.batchSet");
q.setParameter(1, batch);
@SuppressWarnings("unchecked") List<EventReminder> eventReminderList = q.getResultList();
for (EventReminder eventReminder : eventReminderList) {
try {
eventReminder = eventReminderRepo.find(eventReminder.getId());
Message message = messageServiceCrmImpl.createMessage(eventReminder.getEvent());
// Send reminder to owner of the reminder in any case
if (eventReminder.getUser().getPartner() != null && eventReminder.getUser().getPartner().getEmailAddress() != null) {
message.addToEmailAddressSetItem(eventReminder.getUser().getPartner().getEmailAddress());
} else if (eventReminder.getUser().getEmail() != null) {
message.addToEmailAddressSetItem(findOrCreateEmailAddress(eventReminder.getUser().getEmail(), "[" + eventReminder.getUser().getEmail() + "]"));
} else {
messageRepo.remove(message);
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CRM_CONFIG_USER_EMAIL), eventReminder.getUser().getName());
}
// Also send to attendees if needed
if (EventReminderRepository.ASSIGN_TO_ALL.equals(eventReminder.getAssignToSelect()) && eventReminder.getEvent().getAttendees() != null) {
for (ICalendarUser iCalUser : eventReminder.getEvent().getAttendees()) {
if (iCalUser.getUser() != null && iCalUser.getUser().getPartner() != null) {
message.addToEmailAddressSetItem(iCalUser.getUser().getPartner().getEmailAddress());
} else {
message.addToEmailAddressSetItem(findOrCreateEmailAddress(iCalUser.getEmail(), iCalUser.getName()));
}
}
}
message = Beans.get(MessageService.class).sendByEmail(message);
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("Event") + " %s", eventRepo.find(eventReminder.getEvent().getId()).getSubject()), e), ExceptionOriginRepository.CRM, batch.getId());
incrementAnomaly();
LOG.error("Bug(Anomalie) généré(e) pour l'évènement {}", eventRepo.find(eventReminder.getEvent().getId()).getSubject());
} finally {
if (i % 1 == 0) {
JPA.clear();
}
}
}
}
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class EventManagementRepository method save.
@Override
public Event save(Event entity) {
if (entity.getTypeSelect() == EventRepository.TYPE_MEETING) {
super.save(entity);
Beans.get(EventService.class).manageFollowers(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 (!Strings.isNullOrEmpty(email)) {
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 ICalendarService method findOrCreateEvent.
@Transactional
protected ICalendarEvent findOrCreateEvent(VEvent vEvent, ICalendar calendar) {
String uid = vEvent.getUid().getValue();
DtStart dtStart = vEvent.getStartDate();
DtEnd dtEnd = vEvent.getEndDate();
ICalendarEvent event = iEventRepo.findByUid(uid);
if (event == null) {
event = ICalendarEventFactory.getNewIcalEvent(calendar);
event.setUid(uid);
event.setCalendar(calendar);
}
ZoneId zoneId = OffsetDateTime.now().getOffset();
if (dtStart.getDate() != null) {
if (dtStart.getTimeZone() != null) {
zoneId = dtStart.getTimeZone().toZoneId();
}
event.setStartDateTime(LocalDateTime.ofInstant(dtStart.getDate().toInstant(), zoneId));
}
if (dtEnd.getDate() != null) {
if (dtEnd.getTimeZone() != null) {
zoneId = dtEnd.getTimeZone().toZoneId();
}
event.setEndDateTime(LocalDateTime.ofInstant(dtEnd.getDate().toInstant(), zoneId));
}
event.setAllDay(!(dtStart.getDate() instanceof DateTime));
event.setSubject(getValue(vEvent, Property.SUMMARY));
event.setDescription(getValue(vEvent, Property.DESCRIPTION));
event.setLocation(getValue(vEvent, Property.LOCATION));
event.setGeo(getValue(vEvent, Property.GEO));
event.setUrl(getValue(vEvent, Property.URL));
event.setSubjectTeam(event.getSubject());
if (Clazz.PRIVATE.getValue().equals(getValue(vEvent, Property.CLASS))) {
event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PRIVATE);
} else {
event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PUBLIC);
}
if (Transp.TRANSPARENT.getValue().equals(getValue(vEvent, Property.TRANSP))) {
event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_AVAILABLE);
} else {
event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_BUSY);
}
if (event.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
event.setSubjectTeam(I18n.get("Available"));
if (event.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
event.setSubjectTeam(I18n.get("Busy"));
}
}
ICalendarUser organizer = findOrCreateUser(vEvent.getOrganizer(), event);
if (organizer != null) {
event.setOrganizer(organizer);
iCalendarUserRepository.save(organizer);
}
for (Object item : vEvent.getProperties(Property.ATTENDEE)) {
ICalendarUser attendee = findOrCreateUser((Property) item, event);
if (attendee != null) {
event.addAttendee(attendee);
iCalendarUserRepository.save(attendee);
}
}
iEventRepo.save(event);
return event;
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class ICalendarService method findOrCreateUser.
public ICalendarUser findOrCreateUser(User user) {
String email = null;
if (user.getPartner() != null && user.getPartner().getEmailAddress() != null && !Strings.isNullOrEmpty(user.getPartner().getEmailAddress().getAddress())) {
email = user.getPartner().getEmailAddress().getAddress();
} else if (!Strings.isNullOrEmpty(user.getEmail())) {
email = user.getEmail();
} else {
return null;
}
ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
ICalendarUser icalUser = null;
icalUser = repo.all().filter("self.email = ?1 AND self.user.id = ?2", email, user.getId()).fetchOne();
if (icalUser == null) {
icalUser = repo.all().filter("self.user.id = ?1", user.getId()).fetchOne();
}
if (icalUser == null) {
icalUser = repo.all().filter("self.email = ?1", email).fetchOne();
}
if (icalUser == null) {
icalUser = new ICalendarUser();
icalUser.setEmail(email);
icalUser.setName(user.getFullName());
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
icalUser.setUser(emailAddress.getPartner().getUser());
}
}
return icalUser;
}
use of com.axelor.apps.base.db.ICalendarUser in project axelor-open-suite by axelor.
the class ICalendarService method createVEvent.
protected VEvent createVEvent(ICalendarEvent event) throws SocketException, ParseException {
boolean allDay = event.getAllDay() == Boolean.TRUE;
Date start = toDate(event.getStartDateTime(), allDay);
Date end = toDate(event.getEndDateTime(), allDay);
VEvent vevent = new VEvent();
PropertyList<Property> items = vevent.getProperties();
items.add(new DtStart(start));
if (end != null) {
items.add(new DtEnd(end));
}
if (event.getSubject() != null) {
items.add(new Summary(event.getSubject()));
}
if (event.getDescription() != null) {
items.add(new Description(event.getDescription()));
}
if (event.getStatus() != null) {
items.add(new Status(event.getStatus()));
}
if (event.getLocation() != null) {
items.add(new Location(event.getLocation()));
}
if (StringUtils.notEmpty(event.getGeo()) && event.getGeo().contains(";")) {
// new Geo() object seperate the longitude and latitude using ; char
items.add(new Geo(event.getGeo()));
}
if (event.getUid() == null) {
items.add(nextUid());
} else {
items.add(new Uid(event.getUid()));
}
if (event.getUrl() != null) {
items.add(new Url(createUri(event.getUrl())));
}
if (event.getUpdatedOn() != null) {
DateTime date = new DateTime(java.util.Date.from(event.getUpdatedOn().toInstant(OffsetDateTime.now().getOffset())));
date.setUtc(true);
LastModified lastModified = new LastModified(date);
items.add(lastModified);
} else {
DateTime date = new DateTime(java.util.Date.from(event.getCreatedOn().toInstant(OffsetDateTime.now().getOffset())));
date.setUtc(true);
LastModified lastModified = new LastModified(date);
items.add(lastModified);
}
Organizer organizer = updateUser(new Organizer(), event.getOrganizer());
if (organizer != null) {
items.add(organizer);
}
if (event.getAttendees() != null) {
for (ICalendarUser user : event.getAttendees()) {
Attendee attendee = updateUser(new Attendee(), user);
if (attendee != null) {
items.add(attendee);
}
}
}
return vevent;
}
Aggregations