RepetitionType repetitionTypeObject = (RepetitionType) databaseSession.createCriteria(RepetitionType.class)
.add(Restrictions.eq("id", this.repetitionType))
.uniqueResult();
EventType eventTypeObject = (EventType) databaseSession.createCriteria(EventType.class)
.add(Restrictions.eq("id", this.eventType))
.uniqueResult();
Date fromDate = DateOperator.stringToDate(this.from);
Date toDate = DateOperator.stringToDate(this.to);
if( (null == fromDate) || (null == toDate) ) {
throw new IllegalArgumentException("Date has wrong format");
}
if( !DateOperator.date1IsBeforeDate2(fromDate, toDate) ) {
throw new IllegalArgumentException("From date should be before to date");
}
if( !DateOperator.isRepetitionPossible(fromDate, toDate, repetitionTypeObject) ) {
return new Response(ResponseStatus.FAIL, "Repetition is not possible. Make sure there is a sense in the repetition type you choose");
}
User oldOwner = (User) databaseSession.get(User.class, this.oldOwner);
if (oldOwner == null) {
throw new IllegalArgumentException("Couldn't locate old owner of the event");
}
EventType oldEventType = (EventType) databaseSession.get(EventType.class, this.oldEventType);
if (oldEventType == null) {
throw new IllegalArgumentException("Couldn't locate old type of the event");
}