use of com.axelor.apps.base.db.repo.ICalendarUserRepository 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.repo.ICalendarUserRepository 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