Search in sources :

Example 1 with FeedbackResponse

use of teammates.storage.entity.FeedbackResponse in project teammates by TEAMMATES.

the class FeedbackResponsesLogic method updateFeedbackResponseForChangingSection.

public void updateFeedbackResponseForChangingSection(StudentEnrollDetails enrollment, FeedbackResponseAttributes response) throws InvalidParametersException, EntityDoesNotExistException {
    FeedbackResponse feedbackResponse = frDb.getFeedbackResponseEntityOptimized(response);
    boolean isGiverSameForResponseAndEnrollment = feedbackResponse.getGiverEmail().equals(enrollment.email);
    boolean isReceiverSameForResponseAndEnrollment = feedbackResponse.getRecipientEmail().equals(enrollment.email);
    if (isGiverSameForResponseAndEnrollment) {
        feedbackResponse.setGiverSection(enrollment.newSection);
    }
    if (isReceiverSameForResponseAndEnrollment) {
        feedbackResponse.setRecipientSection(enrollment.newSection);
    }
    frDb.saveEntity(feedbackResponse);
    if (isGiverSameForResponseAndEnrollment || isReceiverSameForResponseAndEnrollment) {
        frcLogic.updateFeedbackResponseCommentsForResponse(response.getId());
    }
}
Also used : FeedbackResponse(teammates.storage.entity.FeedbackResponse)

Example 2 with FeedbackResponse

use of teammates.storage.entity.FeedbackResponse in project teammates by TEAMMATES.

the class FeedbackResponsesLogic method updateFeedbackResponse.

/**
 * Updates a {@link FeedbackResponse} based on it's {@code id}.<br>
 * If the giver/recipient field is changed, the {@link FeedbackResponse} is
 * updated by recreating the response<br>
 * in order to prevent an id clash if the previous email is reused later on.
 */
public void updateFeedbackResponse(FeedbackResponseAttributes responseToUpdate) throws InvalidParametersException, EntityDoesNotExistException, EntityAlreadyExistsException {
    // Create a copy.
    FeedbackResponseAttributes newResponse = new FeedbackResponseAttributes(responseToUpdate);
    FeedbackResponse oldResponseEntity = null;
    if (newResponse.getId() == null) {
        oldResponseEntity = frDb.getFeedbackResponseEntityWithCheck(newResponse.feedbackQuestionId, newResponse.giver, newResponse.recipient);
    } else {
        oldResponseEntity = frDb.getFeedbackResponseEntityWithCheck(newResponse.getId());
    }
    FeedbackResponseAttributes oldResponse = null;
    if (oldResponseEntity != null) {
        oldResponse = new FeedbackResponseAttributes(oldResponseEntity);
    }
    if (oldResponse == null) {
        throw new EntityDoesNotExistException("Trying to update a feedback response that does not exist.");
    }
    updateFeedbackResponse(newResponse, oldResponseEntity);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponse(teammates.storage.entity.FeedbackResponse) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with FeedbackResponse

use of teammates.storage.entity.FeedbackResponse in project teammates by TEAMMATES.

the class FeedbackResponsesLogic method recreateResponse.

private void recreateResponse(FeedbackResponseAttributes newResponse, FeedbackResponseAttributes oldResponse) throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException {
    try {
        newResponse.setId(null);
        FeedbackResponse createdResponseEntity = frDb.createEntity(newResponse);
        frDb.deleteEntity(oldResponse);
        frcLogic.updateFeedbackResponseCommentsForChangingResponseId(oldResponse.getId(), createdResponseEntity.getId());
    } catch (EntityAlreadyExistsException e) {
        log.warning("Trying to update an existing response to one that already exists.");
        throw e;
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) FeedbackResponse(teammates.storage.entity.FeedbackResponse)

Example 4 with FeedbackResponse

use of teammates.storage.entity.FeedbackResponse in project teammates by TEAMMATES.

the class FeedbackResponsesDb method getFeedbackResponseEntityWithCheck.

/**
 * Preconditions: <br>
 * * All parameters are non-null.
 * @return Null if not found.
 */
public FeedbackResponse getFeedbackResponseEntityWithCheck(String feedbackResponseId) {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackResponseId);
    FeedbackResponse fr = getFeedbackResponseEntity(feedbackResponseId);
    if (fr == null) {
        log.info("Trying to get non-existent response: " + feedbackResponseId + ".");
        return null;
    }
    return fr;
}
Also used : FeedbackResponse(teammates.storage.entity.FeedbackResponse)

Example 5 with FeedbackResponse

use of teammates.storage.entity.FeedbackResponse in project teammates by TEAMMATES.

the class FeedbackResponsesDb method getFeedbackResponseEntitiesForReceiverForQuestionInSection.

private Collection<FeedbackResponse> getFeedbackResponseEntitiesForReceiverForQuestionInSection(String feedbackQuestionId, String receiver, String section) {
    Map<String, FeedbackResponse> feedbackResponses = new HashMap<>();
    List<FeedbackResponse> firstQueryResponses = load().filter("feedbackQuestionId =", feedbackQuestionId).filter("receiver =", receiver).filter("giverSection =", section).list();
    for (FeedbackResponse response : firstQueryResponses) {
        feedbackResponses.put(response.getId(), response);
    }
    List<FeedbackResponse> secondQueryResponses = load().filter("feedbackQuestionId =", feedbackQuestionId).filter("receiver =", receiver).filter("receiverSection =", section).list();
    for (FeedbackResponse response : secondQueryResponses) {
        feedbackResponses.put(response.getId(), response);
    }
    return feedbackResponses.values();
}
Also used : HashMap(java.util.HashMap) FeedbackResponse(teammates.storage.entity.FeedbackResponse)

Aggregations

FeedbackResponse (teammates.storage.entity.FeedbackResponse)6 HashMap (java.util.HashMap)2 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1