use of org.apache.openmeetings.db.entity.room.Invitation in project openmeetings by apache.
the class InvitationDao method getByHash.
public Invitation getByHash(String hash, boolean hidePass, boolean markUsed) {
List<Invitation> list = em.createNamedQuery("getInvitationByHashCode", Invitation.class).setParameter("hashCode", hash).getResultList();
Invitation i = list != null && list.size() == 1 ? list.get(0) : null;
if (i != null) {
switch(i.getValid()) {
case OneTime:
// one-time invitation
i.setAllowEntry(!i.isUsed());
if (markUsed) {
i.setUsed(true);
update(i);
// flash is required to eliminate 'detach' effect
em.flush();
}
break;
case Period:
String tzId = i.getInvitee().getTimeZoneId();
if (Strings.isEmpty(tzId) && i.getAppointment() != null) {
log.warn("User with NO timezone found: {}", i.getInvitee().getId());
tzId = i.getAppointment().getOwner().getTimeZoneId();
}
if (Strings.isEmpty(tzId)) {
log.warn("Unable to obtain valid timezone, setting SYSTEM TZ");
tzId = TimeZone.getDefault().getID();
}
LocalDateTime now = ZonedDateTime.now(getZoneId(tzId)).toLocalDateTime();
LocalDateTime from = CalendarHelper.getDateTime(i.getValidFrom(), tzId);
LocalDateTime to = CalendarHelper.getDateTime(i.getValidTo(), tzId);
i.setAllowEntry(now.isAfter(from) && now.isBefore(to));
break;
case Endless:
default:
i.setAllowEntry(true);
break;
}
// required to disable password update
em.detach(i);
if (hidePass) {
i.setPassword(null);
}
}
return i;
}
use of org.apache.openmeetings.db.entity.room.Invitation in project openmeetings by apache.
the class InvitationDTO method get.
public Invitation get(Long userId, UserDao userDao, RoomDao roomDao) {
Invitation i = new Invitation();
i.setHash(UUID.randomUUID().toString());
i.setPasswordProtected(passwordProtected);
if (passwordProtected) {
i.setPassword(CryptProvider.get().hash(password));
}
i.setUsed(false);
i.setValid(valid);
try {
// valid period of Invitation
switch(valid) {
case Period:
i.setValidFrom(new Date(SDF.parse(validFrom).getTime() - (5 * 60 * 1000)));
i.setValidTo(SDF.parse(validTo));
break;
case Endless:
case OneTime:
default:
break;
}
} catch (ParseException e) {
log.error("Unexpected error while creating invitation", e);
throw new RuntimeException(e);
}
i.setDeleted(false);
i.setInvitedBy(userDao.get(userId));
i.setInvitee(userDao.getContact(email, firstname, lastname, userId));
if (Type.contact == i.getInvitee().getType()) {
i.getInvitee().setLanguageId(languageId);
}
i.setRoom(roomDao.get(roomId));
i.setInserted(new Date());
i.setAppointment(null);
return i;
}
use of org.apache.openmeetings.db.entity.room.Invitation in project openmeetings by apache.
the class MessageDialog method onSubmit.
@Override
protected void onSubmit(AjaxRequestTarget target) {
PrivateMessage m = getModelObject();
m.setInserted(new Date());
User owner = userDao.get(getUserId());
if (m.isBookedRoom()) {
Room r = m.getRoom();
r.setName(m.getSubject());
r.setComment("");
r.setCapacity(100L);
r.setAppointment(true);
r.setAllowUserQuestions(true);
r = roomDao.update(r, getUserId());
Appointment a = new Appointment();
a.setTitle(m.getSubject());
a.setDescription(m.getMessage());
a.setRoom(r);
a.setStart(CalendarWebHelper.getDate(start.getModelObject()));
a.setEnd(CalendarWebHelper.getDate(end.getModelObject()));
List<MeetingMember> attendees = new ArrayList<>();
for (User to : modelTo.getObject()) {
MeetingMember mm = new MeetingMember();
mm.setUser(to);
mm.setDeleted(false);
mm.setInserted(a.getInserted());
mm.setUpdated(a.getUpdated());
mm.setAppointment(a);
attendees.add(mm);
}
a.setOwner(owner);
a.setMeetingMembers(attendees);
apptDao.update(a, getUserId(), false);
m.setRoom(r);
} else {
m.setRoom(null);
}
for (User to : modelTo.getObject()) {
if (to.getId() == null) {
userDao.update(to, getUserId());
}
// to send
PrivateMessage p = new PrivateMessage(m);
p.setTo(to);
p.setFolderId(SENT_FOLDER_ID);
msgDao.update(p, getUserId());
// to inbox
p = new PrivateMessage(m);
p.setOwner(to);
p.setFolderId(INBOX_FOLDER_ID);
msgDao.update(p, getUserId());
if (to.getAddress() != null) {
String aLinkHTML = (isPrivate && to.getType() == Type.user) ? "<br/><br/>" + "<a href='" + getContactsLink() + "'>" + Application.getString("1302", to.getLanguageId()) + "</a><br/>" : "";
String invitationLink = "";
if (p.isBookedRoom()) {
Invitation i = inviteManager.getInvitation(to, p.getRoom(), false, null, Valid.Period, owner, to.getLanguageId(), CalendarHelper.getDate(start.getModelObject(), to.getTimeZoneId()), CalendarHelper.getDate(end.getModelObject(), to.getTimeZoneId()), null);
invitationLink = getInvitationLink(i, WebSession.get().getExtendedProperties().getBaseUrl());
if (invitationLink == null) {
invitationLink = "";
} else {
invitationLink = //
"<br/>" + Application.getString("503", to.getLanguageId()) + "<br/><a href='" + invitationLink + "'>" + Application.getString("504", to.getLanguageId()) + "</a><br/>";
}
}
String subj = p.getSubject() == null ? "" : p.getSubject();
handler.send(to.getAddress().getEmail(), Application.getString("1301", to.getLanguageId()) + subj, (p.getMessage() == null ? "" : p.getMessage().replaceAll("\\<.*?>", "")) + aLinkHTML + invitationLink);
}
}
}
use of org.apache.openmeetings.db.entity.room.Invitation in project openmeetings by apache.
the class RoomInvitationForm method updateModel.
@Override
public void updateModel(AjaxRequestTarget target) {
super.updateModel(target);
Invitation i = getModelObject();
i.setRoom(roomDao.get(roomId));
if (i.getRoom() != null) {
target.add(sipContainer.replace(new Label("room.confno", i.getRoom().getConfno())).setVisible(i.getRoom().isSipEnabled()));
}
groups.setModelObject(new ArrayList<Group>());
groups.setEnabled(false);
rdi.setModelObject(InviteeType.user);
}
use of org.apache.openmeetings.db.entity.room.Invitation in project openmeetings by apache.
the class InvitationForm method updateModel.
public void updateModel(AjaxRequestTarget target) {
Invitation i = new Invitation();
User u = userDao.get(getUserId());
i.setInvitedBy(u);
i.setRoom(null);
from.setModelObject(LocalDateTime.now());
to.setModelObject(LocalDateTime.now().plusDays(1));
i.setPassword(null);
i.setHash(null);
subject.setModelObject(null);
message.setModelObject(null);
timeZoneId.setModelObject(u.getTimeZoneId());
lang.setModelObject(u.getLanguageId());
url.setModelObject(null);
setModelObject(i);
recipients.setModelObject(new ArrayList<User>());
recipients.setEnabled(true);
passwd.setEnabled(false);
final boolean isPeriod = i.getValid() == Valid.Period;
from.setEnabled(isPeriod);
to.setEnabled(isPeriod);
timeZoneId.setEnabled(isPeriod);
target.add(this);
}
Aggregations