Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Fix an issue with access tokens for team exercises #9802

Merged
merged 7 commits into from
Nov 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.exception.AccessForbiddenException;
import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation;
import de.tum.cit.aet.artemis.exercise.repository.TeamRepository;
import de.tum.cit.aet.artemis.programming.domain.ParticipationVCSAccessToken;
import de.tum.cit.aet.artemis.programming.repository.ParticipationVCSAccessTokenRepository;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseStudentParticipationRepository;
Expand All @@ -25,10 +26,13 @@ public class ParticipationVcsAccessTokenService {

private final ProgrammingExerciseStudentParticipationRepository programmingExerciseStudentParticipationRepository;

private final TeamRepository teamRepository;

public ParticipationVcsAccessTokenService(ParticipationVCSAccessTokenRepository participationVCSAccessTokenRepository,
ProgrammingExerciseStudentParticipationRepository programmingExerciseStudentParticipationRepository) {
ProgrammingExerciseStudentParticipationRepository programmingExerciseStudentParticipationRepository, TeamRepository teamRepository) {
this.participationVcsAccessTokenRepository = participationVCSAccessTokenRepository;
this.programmingExerciseStudentParticipationRepository = programmingExerciseStudentParticipationRepository;
this.teamRepository = teamRepository;
}

/**
Expand All @@ -55,6 +59,7 @@ public ParticipationVCSAccessToken createParticipationVCSAccessToken(User user,
*/
public ParticipationVCSAccessToken findByUserAndParticipationIdOrElseThrow(User user, long participationId) {
var participation = programmingExerciseStudentParticipationRepository.findByIdElseThrow(participationId);
loadTeamStudentsForTeamExercise(participation);
if (participation.isOwnedBy(user)) {
return participationVcsAccessTokenRepository.findByUserIdAndParticipationIdOrElseThrow(user.getId(), participationId);
}
Expand All @@ -73,6 +78,7 @@ public ParticipationVCSAccessToken findByUserAndParticipationIdOrElseThrow(User
public ParticipationVCSAccessToken createVcsAccessTokenForUserAndParticipationIdOrElseThrow(User user, long participationId) {
participationVcsAccessTokenRepository.findByUserIdAndParticipationIdAndThrowIfExists(user.getId(), participationId);
var participation = programmingExerciseStudentParticipationRepository.findByIdElseThrow(participationId);
loadTeamStudentsForTeamExercise(participation);
krusche marked this conversation as resolved.
Show resolved Hide resolved
if (participation.isOwnedBy(user)) {
return createParticipationVCSAccessToken(user, participation);
}
Expand All @@ -81,6 +87,17 @@ public ParticipationVCSAccessToken createVcsAccessTokenForUserAndParticipationId
}
}

/**
* Loads the team students of a participation's team, if it has a team
*
* @param participation the participation which team's students are not loaded yet
*/
private void loadTeamStudentsForTeamExercise(StudentParticipation participation) {
if (participation.getTeam().isPresent()) {
participation.getTeam().get().setStudents(teamRepository.findWithStudentsById(participation.getTeam().get().getId()).get().getStudents());
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Deletes the token connected to a participation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ void getAndCreateParticipationVcsAccessTokenByUser() throws Exception {
userTestService.getAndCreateParticipationVcsAccessToken();
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void getParticipationVcsAccessTokenByUserForTeamExercise() throws Exception {
userTestService.getAndCreateParticipationVcsAccessTokenForTeamExercise();
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void createAndDeleteUserVcsAccessTokenByUser() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
import de.tum.cit.aet.artemis.core.test_repository.UserTestRepository;
import de.tum.cit.aet.artemis.core.util.CourseUtilService;
import de.tum.cit.aet.artemis.core.util.RequestUtilService;
import de.tum.cit.aet.artemis.exercise.domain.ExerciseMode;
import de.tum.cit.aet.artemis.exercise.domain.SubmissionType;
import de.tum.cit.aet.artemis.exercise.domain.Team;
import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository;
import de.tum.cit.aet.artemis.exercise.team.TeamUtilService;
import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository;
import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository;
import de.tum.cit.aet.artemis.lti.service.LtiService;
Expand Down Expand Up @@ -91,6 +95,9 @@
@Autowired
private UserUtilService userUtilService;

@Autowired
private TeamUtilService teamUtilService;

@Autowired
private CourseUtilService courseUtilService;

Expand Down Expand Up @@ -128,6 +135,9 @@
@Autowired
private SubmissionTestRepository submissionRepository;

@Autowired
private ExerciseTestRepository exerciseTestRepository;

public void setup(String testPrefix, MockDelegate mockDelegate) throws Exception {
this.TEST_PREFIX = testPrefix;
this.mockDelegate = mockDelegate;
Expand All @@ -148,7 +158,7 @@
}

public void tearDown() throws IOException {
userTestRepository.deleteAll(userTestRepository.searchAllByLoginOrName(Pageable.unpaged(), TEST_PREFIX));

Check failure on line 161 in src/test/java/de/tum/cit/aet/artemis/core/user/util/UserTestService.java

View workflow job for this annotation

GitHub Actions / H2 Tests

de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest ► createAndDeleteUserVcsAccessTokenByUser()

Failed test found in: build/test-results/test/TEST-de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.xml build/test-results/test/TEST-de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.xml Error: org.springframework.dao.DataIntegrityViolationException: could not execute batch [Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
Raw output
org.springframework.dao.DataIntegrityViolationException: could not execute batch [Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]] [delete from jhi_user where id=?]; SQL [delete from jhi_user where id=?]; constraint ["FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]]
	at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:290)
	at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
	at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:566)
	at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:795)
	at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:758)
	at app//org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:663)
	at app//org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:413)
	at app//org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:165)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
	at app/jdk.proxy3/jdk.proxy3.$Proxy328.deleteAll(Unknown Source)
	at app//de.tum.cit.aet.artemis.core.user.util.UserTestService.tearDown(UserTestService.java:161)
	at app//de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.teardown(UserAccountLocalVcsIntegrationTest.java:26)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:580)
	at [email protected]/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at [email protected]/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at [email protected]/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at [email protected]/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at [email protected]/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute batch [Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]] [delete from jhi_user where id=?]
	at app//org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:97)
	at app//org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)
	at app//org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:294)
	at app//org.hibernate.engine.jdbc.mutation.internal.PreparedStatementGroupSingleTable.forEachStatement(PreparedStatementGroupSingleTable.java:59)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.performExecution(BatchImpl.java:264)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.execute(BatchImpl.java:242)
	at app//org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.executeBatch(JdbcCoordinatorImpl.java:188)
	at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:662)
	at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:499)
	at app//org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:377)
	at app//org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
	at app//org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
	at app//org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1407)
	at app//org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:488)
	at app//org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2329)
	at app//org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1986)
	at app//org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
	at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:169)
	at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:267)
	at app//org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
	at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:562)
	... 23 more
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]
	at app//org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1282)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:279)
	... 41 more
}

public User getStudent() {
Expand Down Expand Up @@ -915,6 +925,36 @@
participationRepository.deleteById(submission.getParticipation().getId());
}

// Test
public void getAndCreateParticipationVcsAccessTokenForTeamExercise() throws Exception {
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
User user = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
var course = courseUtilService.addEmptyCourse();
var exercise = programmingExerciseUtilService.addProgrammingExerciseToCourse(course);
exercise.setMode(ExerciseMode.TEAM);
exerciseTestRepository.save(exercise);
courseRepository.save(course);
User tutor1 = userTestRepository.findOneByLogin(TEST_PREFIX + "tutor1").orElseThrow();
Team team = teamUtilService.createTeam(Set.of(user), tutor1, exercise, "team1");

var submission = (ProgrammingSubmission) new ProgrammingSubmission().commitHash("abc").type(SubmissionType.MANUAL).submitted(true);
submission = programmingExerciseUtilService.addProgrammingSubmissionToTeamExercise(exercise, submission, team);

// request existing token
request.get("/api/account/participation-vcs-access-token?participationId=" + submission.getParticipation().getId(), HttpStatus.NOT_FOUND, String.class);

var token = request.putWithResponseBody("/api/account/participation-vcs-access-token?participationId=" + submission.getParticipation().getId(), null, String.class,
HttpStatus.OK);
assertThat(token).isNotNull();

var token2 = request.get("/api/account/participation-vcs-access-token?participationId=" + submission.getParticipation().getId(), HttpStatus.OK, String.class);
assertThat(token2).isEqualTo(token);

submissionRepository.delete(submission);
participationVCSAccessTokenRepository.deleteAll();
participationRepository.deleteById(submission.getParticipation().getId());
teamUtilService.deleteAll();
}

// Test
public void createAndDeleteUserVcsAccessToken() throws Exception {
User user = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,11 @@
team.setExercise(exercise);
return teamRepo.saveAndFlush(team);
}

/**
* Deletes all teams
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
*/
public void deleteAll() {
teamRepo.deleteAll();

Check failure on line 252 in src/test/java/de/tum/cit/aet/artemis/exercise/team/TeamUtilService.java

View workflow job for this annotation

GitHub Actions / H2 Tests

de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest ► getParticipationVcsAccessTokenByUserForTeamExercise()

Failed test found in: build/test-results/test/TEST-de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.xml Error: org.springframework.dao.DataIntegrityViolationException: could not execute batch [Referential integrity constraint violation: "FK_PARTICIPANT_SCORE_TEAM_ID: PUBLIC.PARTICIPANT_SCORE FOREIGN KEY(TEAM_ID) REFERENCES PUBLIC.TEAM(ID) (CAST(1 AS BIGINT))"; SQL statement:
Raw output
org.springframework.dao.DataIntegrityViolationException: could not execute batch [Referential integrity constraint violation: "FK_PARTICIPANT_SCORE_TEAM_ID: PUBLIC.PARTICIPANT_SCORE FOREIGN KEY(TEAM_ID) REFERENCES PUBLIC.TEAM(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from team where id=? [23503-224]] [delete from team where id=?]; SQL [delete from team where id=?]; constraint ["FK_PARTICIPANT_SCORE_TEAM_ID: PUBLIC.PARTICIPANT_SCORE FOREIGN KEY(TEAM_ID) REFERENCES PUBLIC.TEAM(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from team where id=? [23503-224]]
	at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:290)
	at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
	at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:566)
	at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:795)
	at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:758)
	at app//org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:663)
	at app//org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:413)
	at app//org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:165)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
	at app/jdk.proxy3/jdk.proxy3.$Proxy377.deleteAll(Unknown Source)
	at app//de.tum.cit.aet.artemis.exercise.team.TeamUtilService.deleteAll(TeamUtilService.java:252)
	at app//de.tum.cit.aet.artemis.core.user.util.UserTestService.getAndCreateParticipationVcsAccessTokenForTeamExercise(UserTestService.java:955)
	at app//de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.getParticipationVcsAccessTokenByUserForTeamExercise(UserAccountLocalVcsIntegrationTest.java:44)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:580)
	at [email protected]/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at [email protected]/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at [email protected]/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at [email protected]/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at [email protected]/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
	Suppressed: org.springframework.dao.DataIntegrityViolationException: could not execute batch [Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]] [delete from jhi_user where id=?]; SQL [delete from jhi_user where id=?]; constraint ["FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]]
		at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:290)
		at app//org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
		at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:566)
		at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:795)
		at app//org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:758)
		at app//org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:663)
		at app//org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:413)
		at app//org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
		at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at app//org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
		at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at app//org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:165)
		at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at app//org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
		at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
		at app/jdk.proxy3/jdk.proxy3.$Proxy328.deleteAll(Unknown Source)
		at app//de.tum.cit.aet.artemis.core.user.util.UserTestService.tearDown(UserTestService.java:161)
		at app//de.tum.cit.aet.artemis.core.authentication.UserAccountLocalVcsIntegrationTest.teardown(UserAccountLocalVcsIntegrationTest.java:26)
		... 7 more
	Caused by: org.hibernate.exception.ConstraintViolationException: could not execute batch [Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]] [delete from jhi_user where id=?]
		at app//org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:97)
		at app//org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)
		at app//org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
		at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:294)
		at app//org.hibernate.engine.jdbc.mutation.internal.PreparedStatementGroupSingleTable.forEachStatement(PreparedStatementGroupSingleTable.java:59)
		at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.performExecution(BatchImpl.java:264)
		at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.execute(BatchImpl.java:242)
		at app//org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.executeBatch(JdbcCoordinatorImpl.java:188)
		at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:662)
		at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:499)
		at app//org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:377)
		at app//org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
		at app//org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
		at app//org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1407)
		at app//org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:488)
		at app//org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2329)
		at app//org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1986)
		at app//org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
		at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:169)
		at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:267)
		at app//org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
		at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:562)
		... 23 more
	Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: "FK_TEAM_STUDENT_STUDENT_ID: PUBLIC.TEAM_STUDENT FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.JHI_USER(ID) (CAST(28 AS BIGINT))"; SQL statement:
delete from jhi_user where id=? [23503-224]
		at app//org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1282)
		at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:279)
		... 41 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute batch [Referential integrity constraint violation: "FK_PARTICIPANT_SCORE_TEAM_ID: PUBLIC.PARTICIPANT_SCORE FOREIGN KEY(TEAM_ID) REFERENCES PUBLIC.TEAM(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from team where id=? [23503-224]] [delete from team where id=?]
	at app//org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:97)
	at app//org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)
	at app//org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:294)
	at app//org.hibernate.engine.jdbc.mutation.internal.PreparedStatementGroupSingleTable.forEachStatement(PreparedStatementGroupSingleTable.java:59)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.performExecution(BatchImpl.java:264)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.addToBatch(BatchImpl.java:153)
	at app//org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleBatched.performBatchedOperations(MutationExecutorSingleBatched.java:60)
	at app//org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:54)
	at app//org.hibernate.persister.entity.mutation.AbstractDeleteCoordinator.doStaticDelete(AbstractDeleteCoordinator.java:279)
	at app//org.hibernate.persister.entity.mutation.AbstractDeleteCoordinator.coordinateDelete(AbstractDeleteCoordinator.java:87)
	at app//org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2973)
	at app//org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:131)
	at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:632)
	at app//org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:499)
	at app//org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:377)
	at app//org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
	at app//org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
	at app//org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1407)
	at app//org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:488)
	at app//org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2329)
	at app//org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1986)
	at app//org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
	at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:169)
	at app//org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:267)
	at app//org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
	at app//org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:562)
	... 24 more
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: "FK_PARTICIPANT_SCORE_TEAM_ID: PUBLIC.PARTICIPANT_SCORE FOREIGN KEY(TEAM_ID) REFERENCES PUBLIC.TEAM(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from team where id=? [23503-224]
	at app//org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1282)
	at app//org.hibernate.engine.jdbc.batch.internal.BatchImpl.lambda$performExecution$2(BatchImpl.java:279)
	... 47 more
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import de.tum.cit.aet.artemis.exam.util.ExamUtilService;
import de.tum.cit.aet.artemis.exercise.domain.InitializationState;
import de.tum.cit.aet.artemis.exercise.domain.SubmissionType;
import de.tum.cit.aet.artemis.exercise.domain.Team;
import de.tum.cit.aet.artemis.exercise.domain.participation.Participation;
import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory;
Expand Down Expand Up @@ -741,6 +742,21 @@ public ProgrammingSubmission addProgrammingSubmission(ProgrammingExercise exerci
return submission;
}

/**
* Adds programming submission to provided programming exercise. The provided login is used to access or create a participation.
*
* @param exercise The exercise to which the submission should be added.
* @param submission The submission which should be added to the programming exercise.
* @param team The login of the user used to access or create an exercise participation.
* @return The created programming submission.
*/
public ProgrammingSubmission addProgrammingSubmissionToTeamExercise(ProgrammingExercise exercise, ProgrammingSubmission submission, Team team) {
StudentParticipation participation = participationUtilService.addTeamParticipationForProgrammingExercise(exercise, team);
submission.setParticipation(participation);
submission = programmingSubmissionRepo.save(submission);
return submission;
}

/**
* Adds a submission with a result to the given programming exercise. The submission will be assigned to the corresponding participation of the given login (if exists or
* create a new participation).
Expand Down
Loading