Skip to content

Commit

Permalink
Delete SubmissionEvent for test submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Apr 26, 2024
1 parent bb70c7d commit 2c11ca7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.pass.support.client.model.PassEntity;
import org.eclipse.pass.support.client.model.Policy;
import org.eclipse.pass.support.client.model.Submission;
import org.eclipse.pass.support.client.model.SubmissionEvent;
import org.eclipse.pass.support.client.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -92,6 +93,10 @@ private void deleteTestSubmissions(Grant testGrant) throws IOException {
testFileSelector.setFilter(RSQL.equals("submission.id", testSubmission.getId()));
List<File> testFiles = passClient.streamObjects(testFileSelector).toList();
testFiles.forEach(this::deleteFile);
PassClientSelector<SubmissionEvent> subEventSelector = new PassClientSelector<>(SubmissionEvent.class);
subEventSelector.setFilter(RSQL.equals("submission.id", testSubmission.getId()));
List<SubmissionEvent> testSubmissionEvents = passClient.streamObjects(subEventSelector).toList();
testSubmissionEvents.forEach(this::deleteObject);
deleteObject(testSubmission);
deleteObject(testSubmission.getPublication());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.pass.support.client.model.AwardStatus;
import org.eclipse.pass.support.client.model.Deposit;
import org.eclipse.pass.support.client.model.DepositStatus;
import org.eclipse.pass.support.client.model.EventType;
import org.eclipse.pass.support.client.model.File;
import org.eclipse.pass.support.client.model.Grant;
import org.eclipse.pass.support.client.model.PassEntity;
Expand All @@ -42,6 +43,7 @@
import org.eclipse.pass.support.client.model.Repository;
import org.eclipse.pass.support.client.model.RepositoryCopy;
import org.eclipse.pass.support.client.model.Submission;
import org.eclipse.pass.support.client.model.SubmissionEvent;
import org.eclipse.pass.support.client.model.User;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -93,6 +95,9 @@ public void cleanUp() throws IOException {
PassClientSelector<File> fileSelector = new PassClientSelector<>(File.class);
List<File> testFiles = passClient.streamObjects(fileSelector).toList();
testFiles.forEach(this::deleteFile);
PassClientSelector<SubmissionEvent> subEventSelector = new PassClientSelector<>(SubmissionEvent.class);
List<SubmissionEvent> testSubEvents = passClient.streamObjects(subEventSelector).toList();
testSubEvents.forEach(this::deleteObject);
PassClientSelector<Submission> submissionSelector = new PassClientSelector<>(Submission.class);
List<Submission> testSubmissions = passClient.streamObjects(submissionSelector).toList();
testSubmissions.forEach(this::deleteObject);
Expand Down Expand Up @@ -195,6 +200,9 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception
PassClientSelector<File> fileSelector = new PassClientSelector<>(File.class);
List<File> testFiles = passClient.streamObjects(fileSelector).toList();
assertTrue(testFiles.isEmpty());
PassClientSelector<SubmissionEvent> subEventSelector = new PassClientSelector<>(SubmissionEvent.class);
List<SubmissionEvent> testSubEvents = passClient.streamObjects(subEventSelector).toList();
assertTrue(testSubEvents.isEmpty());
}

@Test
Expand Down Expand Up @@ -255,6 +263,12 @@ public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws E
assertEquals(1, testFiles.size());
File actualFile = testFiles.get(0);
assertEquals(actualSubmission.getId(), actualFile.getSubmission().getId());

PassClientSelector<SubmissionEvent> subEventSelector = new PassClientSelector<>(SubmissionEvent.class);
List<SubmissionEvent> testSubEvents = passClient.streamObjects(subEventSelector).toList();
assertEquals(1, testSubEvents.size());
SubmissionEvent actualSubEvent = testSubEvents.get(0);
assertEquals(actualSubmission.getId(), actualSubEvent.getSubmission().getId());
}

private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception {
Expand Down Expand Up @@ -294,6 +308,16 @@ private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception {
file.setSubmission(submission);
passClient.createObject(file);

PassClientSelector<User> selectorUser = new PassClientSelector<>(User.class);
selectorUser.setFilter(RSQL.equals("email", "test-user-email@foo"));
User testUser = passClient.streamObjects(selectorUser).toList().get(0);

SubmissionEvent submissionEvent = new SubmissionEvent();
submissionEvent.setSubmission(submission);
submissionEvent.setEventType(EventType.SUBMITTED);
submissionEvent.setPerformedBy(testUser);
passClient.createObject(submissionEvent);

return submission;
}

Expand Down

0 comments on commit 2c11ca7

Please sign in to comment.