use of teammates.storage.entity.FeedbackSession in project teammates by TEAMMATES.
the class FeedbackSessionsDb method clearStudentRespondents.
public void clearStudentRespondents(FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString());
}
fs.getRespondingStudentList().clear();
saveEntity(fs, feedbackSession);
}
use of teammates.storage.entity.FeedbackSession in project teammates by TEAMMATES.
the class FeedbackSessionsDb method addInstructorRespondents.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addInstructorRespondents(List<String> emails, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, emails);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
try {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new RuntimeException(new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString()));
}
fs.getRespondingInstructorList().addAll(emails);
saveEntity(fs, feedbackSession);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof EntityDoesNotExistException) {
throw (EntityDoesNotExistException) e.getCause();
}
throw e;
}
}
use of teammates.storage.entity.FeedbackSession in project teammates by TEAMMATES.
the class FeedbackSessionsDb method updateInstructorRespondent.
public void updateInstructorRespondent(String oldEmail, String newEmail, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, oldEmail);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newEmail);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString());
}
if (fs.getRespondingInstructorList().contains(oldEmail)) {
fs.getRespondingInstructorList().remove(oldEmail);
fs.getRespondingInstructorList().add(newEmail);
}
saveEntity(fs, feedbackSession);
}
use of teammates.storage.entity.FeedbackSession in project teammates by TEAMMATES.
the class FeedbackSessionsDb method getAllOpenFeedbackSessions.
public List<FeedbackSessionAttributes> getAllOpenFeedbackSessions(Date startUtc, Date endUtc) {
List<FeedbackSessionAttributes> list = new LinkedList<>();
Calendar startCal = Calendar.getInstance();
startCal.setTime(startUtc);
Calendar endCal = Calendar.getInstance();
endCal.setTime(endUtc);
// To retrieve legacy data where local dates are stored instead of UTC
// TODO: remove after all legacy data has been converted
Date curStart = TimeHelper.convertToUserTimeZone(startCal, -25).getTime();
Date curEnd = TimeHelper.convertToUserTimeZone(endCal, 25).getTime();
List<FeedbackSession> endEntities = load().filter("endTime >", curStart).filter("endTime <=", curEnd).list();
List<FeedbackSession> startEntities = load().filter("startTime >=", curStart).filter("startTime <", curEnd).list();
List<FeedbackSession> endTimeEntities = new ArrayList<>(endEntities);
List<FeedbackSession> startTimeEntities = new ArrayList<>(startEntities);
endTimeEntities.removeAll(startTimeEntities);
startTimeEntities.removeAll(endTimeEntities);
endTimeEntities.addAll(startTimeEntities);
Instant start = startUtc.toInstant();
Instant end = endUtc.toInstant();
// TODO: remove after all legacy data has been converted
for (FeedbackSession feedbackSession : endTimeEntities) {
FeedbackSessionAttributes fs = makeAttributes(feedbackSession);
Instant fsStart = fs.getStartTime();
Instant fsEnd = fs.getEndTime();
boolean isStartTimeWithinRange = (fsStart.isAfter(start) || fsStart.equals(start)) && fsStart.isBefore(end);
boolean isEndTimeWithinRange = fsEnd.isAfter(start) && (fsEnd.isBefore(end) || fsEnd.equals(end));
if (isStartTimeWithinRange || isEndTimeWithinRange) {
list.add(fs);
}
}
return list;
}
use of teammates.storage.entity.FeedbackSession in project teammates by TEAMMATES.
the class FeedbackSessionsDb method updateFeedbackSession.
/**
* Updates the feedback session identified by {@code newAttributes.feedbackSesionName}
* and {@code newAttributes.courseId}.
* For the remaining parameters, the existing value is preserved
* if the parameter is null (due to 'keep existing' policy).<br>
* Preconditions: <br>
* * {@code newAttributes.feedbackSesionName} and {@code newAttributes.courseId}
* are non-null and correspond to an existing feedback session. <br>
*/
public void updateFeedbackSession(FeedbackSessionAttributes newAttributes) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newAttributes);
newAttributes.sanitizeForSaving();
if (!newAttributes.isValid()) {
throw new InvalidParametersException(newAttributes.getInvalidityInfo());
}
FeedbackSession fs = getEntity(newAttributes);
if (fs == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + newAttributes.toString());
}
fs.setInstructions(newAttributes.getInstructions());
fs.setStartTime(newAttributes.getStartTime());
fs.setEndTime(newAttributes.getEndTime());
fs.setSessionVisibleFromTime(newAttributes.getSessionVisibleFromTime());
fs.setResultsVisibleFromTime(newAttributes.getResultsVisibleFromTime());
fs.setTimeZone(newAttributes.getTimeZone().getId());
fs.setGracePeriod(newAttributes.getGracePeriodMinutes());
fs.setFeedbackSessionType(newAttributes.getFeedbackSessionType());
fs.setSentOpenEmail(newAttributes.isSentOpenEmail());
fs.setSentClosingEmail(newAttributes.isSentClosingEmail());
fs.setSentClosedEmail(newAttributes.isSentClosedEmail());
fs.setSentPublishedEmail(newAttributes.isSentPublishedEmail());
fs.setIsOpeningEmailEnabled(newAttributes.isOpeningEmailEnabled());
fs.setSendClosingEmail(newAttributes.isClosingEmailEnabled());
fs.setSendPublishedEmail(newAttributes.isPublishedEmailEnabled());
saveEntity(fs, newAttributes);
}
Aggregations