All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.kit.kastel.sdq.artemis4j.api.artemis.assessment.LockResult Maven / Gradle / Ivy

Go to download

Artemis4J is a Java library for interacting with the Artemis teaching system.

There is a newer version: 7.5.6
Show newest version
/* Licensed under EPL-2.0 2022-2023. */
package edu.kit.kastel.sdq.artemis4j.api.artemis.assessment;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.kit.kastel.sdq.artemis4j.api.ArtemisClientException;
import edu.kit.kastel.sdq.artemis4j.api.client.IFeedbackClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * This is gotten from acquiring a lock (no matter if the lock is already held
 * by the caller or not). It is used to calculate the assessment result.
 */
public class LockResult {
	private static final Logger log = LoggerFactory.getLogger(LockResult.class);

	@Serial
	private static final long serialVersionUID = -3787474578751131899L;

	private final int submissionId;
	private final int participationId;

	private int resultId;
	private final List latestFeedback;

	@JsonCreator
	public LockResult( //
			@JsonProperty("id") int submissionId, //
			@JsonProperty("results") List previousAssessmentResults, //
			@JsonProperty("participation") Participation participation) {

		this.submissionId = submissionId;
		this.participationId = participation.getParticipationId();

		this.latestFeedback = new ArrayList<>();
		LockCallAssessmentResult latestResult = previousAssessmentResults.isEmpty() //
				? null //
				: previousAssessmentResults.get(previousAssessmentResults.size() - 1);

		if (latestResult != null) {
			resultId = latestResult.getId();
			latestResult.getFeedbacks().stream().filter(Objects::nonNull).forEach(this.latestFeedback::add);
		}
	}

	public void init(IFeedbackClient feedbackClient) throws ArtemisClientException {
		for (Feedback feedback : this.latestFeedback) {
			feedback.init(feedbackClient, resultId);
		}
	}

	/**
	 * @return the participationId this submissionId belongs to (one participation
	 *         has one or many submissions).
	 */
	public int getParticipationId() {
		return this.participationId;
	}

	/**
	 * @return all {@link Feedback Feedbacks} that are saved in Artemis. This is
	 *         used to calculate the assessment result which is sent back to
	 *         Artemis.
	 */
	public List getLatestFeedback() {
		return this.latestFeedback;
	}

	/**
	 * @return the submissionId this result belongs to (one participation has one or
	 *         many submissions).
	 */
	public int getSubmissionId() {
		return this.submissionId;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy