use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project Artemis by ls1intum.
the class ResultResource method getParticipationWithResults.
@Nullable
private ProgrammingExerciseParticipation getParticipationWithResults(String planKey) {
// we have to support template, solution and student build plans here
if (planKey.endsWith("-" + BuildPlanType.TEMPLATE.getName())) {
return templateProgrammingExerciseParticipationRepository.findByBuildPlanIdWithResults(planKey).orElse(null);
} else if (planKey.endsWith("-" + BuildPlanType.SOLUTION.getName())) {
return solutionProgrammingExerciseParticipationRepository.findByBuildPlanIdWithResults(planKey).orElse(null);
}
List<ProgrammingExerciseStudentParticipation> participations = programmingExerciseStudentParticipationRepository.findByBuildPlanId(planKey);
ProgrammingExerciseStudentParticipation participation = null;
if (!participations.isEmpty()) {
participation = participations.get(0);
if (participations.size() > 1) {
// in the rare case of multiple participations, take the latest one.
for (ProgrammingExerciseStudentParticipation otherParticipation : participations) {
if (otherParticipation.getInitializationDate().isAfter(participation.getInitializationDate())) {
participation = otherParticipation;
}
}
}
}
return participation;
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ResultResource method getParticipationWithResults.
@Nullable
private ProgrammingExerciseParticipation getParticipationWithResults(String planKey) {
// we have to support template, solution and student build plans here
if (planKey.endsWith("-" + BuildPlanType.TEMPLATE.getName())) {
return templateProgrammingExerciseParticipationRepository.findByBuildPlanIdWithResults(planKey).orElse(null);
} else if (planKey.endsWith("-" + BuildPlanType.SOLUTION.getName())) {
return solutionProgrammingExerciseParticipationRepository.findByBuildPlanIdWithResults(planKey).orElse(null);
}
List<ProgrammingExerciseStudentParticipation> participations = programmingExerciseStudentParticipationRepository.findByBuildPlanId(planKey);
ProgrammingExerciseStudentParticipation participation = null;
if (!participations.isEmpty()) {
participation = participations.get(0);
if (participations.size() > 1) {
// in the rare case of multiple participations, take the latest one.
for (ProgrammingExerciseStudentParticipation otherParticipation : participations) {
if (otherParticipation.getInitializationDate().isAfter(participation.getInitializationDate())) {
participation = otherParticipation;
}
}
}
}
return participation;
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ResultResource method getResultDetails.
/**
* GET /participations/:participationId/results/:resultId/details : get the build result details from CI service for the "id" result.
* This method is only invoked if the result actually includes details (e.g. feedback or build errors)
*
* @param participationId the id of the participation to the result
* @param resultId the id of the result to retrieve. If the participation related to the result is not a StudentParticipation or ProgrammingExerciseParticipation, the endpoint will return forbidden!
* @return the ResponseEntity with status 200 (OK) and with body the result, status 404 (Not Found) if the result does not exist or 403 (forbidden) if the user does not have permissions to access the participation.
*/
@GetMapping("participations/{participationId}/results/{resultId}/details")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<Feedback>> getResultDetails(@PathVariable Long participationId, @PathVariable Long resultId) {
log.debug("REST request to get Result : {}", resultId);
Result result = resultRepository.findByIdWithEagerFeedbacksElseThrow(resultId);
Participation participation = result.getParticipation();
if (!participation.getId().equals(participationId)) {
throw new BadRequestAlertException("participationId of the path doesnt match the participationId of the participation corresponding to the result " + resultId + " !", "participationId", "400");
}
// The permission check depends on the participation type (normal participations vs. programming exercise participations).
if (participation instanceof StudentParticipation) {
if (!authCheckService.canAccessParticipation((StudentParticipation) participation)) {
throw new AccessForbiddenException("participation", participationId);
}
} else if (participation instanceof ProgrammingExerciseParticipation) {
if (!programmingExerciseParticipationService.canAccessParticipation((ProgrammingExerciseParticipation) participation)) {
throw new AccessForbiddenException("participation", participationId);
}
} else {
// This would be the case that a new participation type is introduced, without this the user would have access to it regardless of the permissions.
throw new AccessForbiddenException("participation", participationId);
}
return new ResponseEntity<>(resultService.getFeedbacksForResult(result), HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class BitbucketService method getPushDate.
@Override
public ZonedDateTime getPushDate(ProgrammingExerciseParticipation participation, String commitHash, Object eventObject) {
// If the event object is supplied we try to retrieve the push date from there to save one call
if (eventObject != null) {
JsonNode node = new ObjectMapper().convertValue(eventObject, JsonNode.class);
String dateString = node.get("date").asText(null);
if (dateString != null) {
try {
return ZonedDateTime.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
} catch (DateTimeParseException e) {
// If parsing fails for some reason we ignore the exception and try to get it via the direct request.
}
}
}
boolean isLastPage = false;
final int perPage = 40;
int start = 0;
while (!isLastPage) {
try {
UriComponents builder = UriComponentsBuilder.fromUri(bitbucketServerUrl.toURI()).pathSegment("rest", "api", "latest", "projects", participation.getProgrammingExercise().getProjectKey(), "repos", urlService.getRepositorySlugFromRepositoryUrl(participation.getVcsRepositoryUrl()), "ref-change-activities").queryParam("start", start).queryParam("limit", perPage).queryParam("ref", "refs/heads/" + defaultBranch).build();
final var response = restTemplate.exchange(builder.toUri(), HttpMethod.GET, null, BitbucketChangeActivitiesDTO.class);
if (response.getStatusCode() != HttpStatus.OK || response.getBody() == null) {
throw new BitbucketException("Unable to get push date for participation " + participation.getId() + "\n" + response.getBody());
}
final var changeActivities = response.getBody().getValues();
final var activityOfPush = changeActivities.stream().filter(activity -> commitHash.equals(activity.getRefChange().getToHash())).findFirst();
if (activityOfPush.isPresent()) {
return Instant.ofEpochMilli(activityOfPush.get().getCreatedDate()).atZone(ZoneOffset.UTC);
}
isLastPage = response.getBody().getLastPage();
start += perPage;
} catch (URISyntaxException e) {
throw new BitbucketException("Unable to get push date for participation " + participation.getId(), e);
}
}
throw new BitbucketException("Unable to find push date result for participation " + participation.getId() + " and hash " + commitHash);
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerFailedBuildEmptyLatestPendingSubmission.
@Test
@WithMockUser(username = "student1", roles = "USER")
void triggerFailedBuildEmptyLatestPendingSubmission() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
doReturn(Optional.empty()).when(programmingSubmissionService).getLatestPendingSubmission(anyLong(), anyBoolean());
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-failed-build";
request.postWithoutLocation(url, null, HttpStatus.NOT_FOUND, new HttpHeaders());
}
Aggregations