Search in sources :

Example 1 with FeedbackSession

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);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 2 with 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;
    }
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) VoidWork(com.googlecode.objectify.VoidWork) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with FeedbackSession

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);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 4 with 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;
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackSession(teammates.storage.entity.FeedbackSession) Calendar(java.util.Calendar) Instant(java.time.Instant) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 5 with FeedbackSession

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);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

FeedbackSession (teammates.storage.entity.FeedbackSession)10 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)9 InvalidParametersException (teammates.common.exception.InvalidParametersException)9 VoidWork (com.googlecode.objectify.VoidWork)4 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1