+ "where c.hash LIKE :hashCode "
+ "AND c.deleted = :deleted";
TypedQuery<Invitations> query = em.createQuery(hql, Invitations.class);
query.setParameter("hashCode", hashCode);
query.setParameter("deleted", false);
Invitations invitation = null;
try {
invitation = query.getSingleResult();
} catch (NoResultException ex) {
}
if (invitation == null) {
// already deleted or does not exist
return new Long(-31);
} else {
if (invitation.getCanBeUsedOnlyOneTime()) {
// do this only if the user tries to get the Invitation, not
// while checking the PWD
if (hidePass) {
// one-time invitation
if (invitation.getInvitationWasUsed()) {
// Invitation is of type *only-one-time* and was
// already used
return new Long(-32);
} else {
// set to true if this is the first time / a normal
// getInvitation-Query
invitation.setInvitationWasUsed(true);
this.updateInvitation(invitation);
// invitation.setInvitationpass(null);
invitation.setAllowEntry(true);
return invitation;
}
} else {
invitation.setAllowEntry(true);
return invitation;
}
} else if (invitation.getIsValidByTime()) {
OmTimeZone tz = invitation.getOmTimeZone() == null
? omTimeZoneDaoImpl.getOmTimeZone(configurationDao.getConfValue("default.timezone", String.class, "Europe/Berlin"))
: invitation.getOmTimeZone();
Calendar now = Calendar.getInstance(TimeZone.getTimeZone(tz.getIcal()));
Calendar start = Calendar.getInstance(TimeZone.getTimeZone(tz.getIcal()));
start.setTime(invitation.getValidFrom());
Calendar end = Calendar.getInstance(TimeZone.getTimeZone(tz.getIcal()));
end.setTime(invitation.getValidTo());
if (now.after(start) && now.before(end)) {
this.updateInvitation(invitation);
// invitation.setInvitationpass(null);
invitation.setAllowEntry(true);
return invitation;
} else {
// Invitation is of type *period* and is not valid
// anymore, this is an extra hook to display the time
// correctly
// in the method where it shows that the hash code does
// not work anymore
invitation.setAllowEntry(false);
return invitation;
}
} else {
// Invitation is not limited, neither time nor single-usage
this.updateInvitation(invitation);
invitation.setAllowEntry(true);
// invitation.setInvitationpass(null);
return invitation;
}
}