2984 PO 8) Save final thesis rejection comment

This commit is contained in:
Andreas Svanberg 2023-10-24 10:44:34 +02:00
parent 8fba4d4451
commit 2b14fd0ede
11 changed files with 65 additions and 11 deletions
core/src
main
test/java/se/su/dsv/scipro/finalthesis
daisy-integration/src/main/java/se/su/dsv/scipro/integration/daisy/workers
view/src

@ -62,6 +62,9 @@ public class FinalThesis extends DomainObject {
private String swedishTitle;
@Column(name = "rejection_comment")
private String rejectionComment;
@PrePersist
@PreUpdate
void cleanTitle() {
@ -153,6 +156,14 @@ public class FinalThesis extends DomainObject {
this.textMatchingAnalysis = textMatchingAnalysis;
}
public String getRejectionComment() {
return rejectionComment;
}
public void setRejectionComment(String rejectionComment) {
this.rejectionComment = rejectionComment;
}
@Override
public String toString() {
return "FinalThesis(id=" + this.getId() + ", fileDescription=" + this.getDocument() + ", textMatchingDocument=" + this.getTextMatchingDocument() + ", project=" + this.getProject() + ", status=" + this.getStatus() + ", dateApproved=" + this.getDateApproved() + ", dateRejected=" + this.getDateRejected() + ", englishTitle=" + this.getEnglishTitle() + ", swedishTitle=" + this.getSwedishTitle() + ")";

@ -16,7 +16,7 @@ public interface FinalThesisService extends GenericService<FinalThesis, Long>,
boolean hasFinalThesis(Project project);
FileDescription getFinalThesisFileDescription(Project project);
void approve(Project project, final String englishTitle, final String swedishTitle);
void reject(Project project);
void reject(Project project, String comment);
boolean isUploadAllowed(Project project);
FinalThesis findByProject(Project project);
Date getRejectedDate(Project project);

@ -151,8 +151,10 @@ public class FinalThesisServiceImpl extends AbstractServiceImpl<FinalThesis, Lon
@Override
@Transactional
public void reject(Project project) {
public void reject(Project project, String comment) {
FinalThesis finalThesis = setStatus(project, FinalThesis.Status.REJECTED);
finalThesis.setRejectionComment(comment);
save(finalThesis);
removePlagiarismAnalysis(finalThesis);
eventBus.post(new FinalThesisRejectedEvent(project));
}

@ -0,0 +1,30 @@
alter table FinalThesis
add column rejection_comment TEXT NULL;
update FinalThesis
set rejection_comment = (
select content
from forum_post
inner join thread on forum_post.thread = thread.id
inner join project_thread on thread.id = project_thread.thread_id
where thread.subject = 'Final thesis revision needed'
and project_thread.project_id = FinalThesis.project_id
-- only get threads that were for this (or earlier) rejections
and thread.dateCreated <= date_add(FinalThesis.dateRejected, interval 1 day)
-- get the newest thread, and the oldest post (first one in the thread)
order by thread.id desc, forum_post.dateCreated asc
limit 1)
where dateRejected is not null;
update FinalThesis
set rejection_comment = (
select right(content, length(content) - 169)
from forum_post
inner join thread on forum_post.thread = thread.id
inner join project_thread on thread.id = project_thread.thread_id
where thread.subject = 'Thesis rejected by examiner'
and project_thread.project_id = FinalThesis.project_id
and thread.dateCreated <= date_add(FinalThesis.dateRejected, interval 1 day)
order by thread.id desc, forum_post.dateCreated asc
limit 1)
where dateRejected is not null and rejection_comment is null;

@ -111,10 +111,12 @@ public class FinalThesisServiceImplTest extends IntegrationTest {
public void reject_final_thesis() {
uploadThesis();
finalThesisService.reject(project);
String comment = "Does not follow report template";
finalThesisService.reject(project, comment);
FinalThesis finalThesis = finalThesisService.findByProject(project);
assertEquals(finalThesis.getStatus(), FinalThesis.Status.REJECTED);
assertEquals(FinalThesis.Status.REJECTED, finalThesis.getStatus());
assertEquals(comment, finalThesis.getRejectionComment());
assertNotNull(finalThesis.getDateRejected());
}
@ -128,7 +130,7 @@ public class FinalThesisServiceImplTest extends IntegrationTest {
finalThesis.setTextMatchingAnalysis("analysis");
finalThesis.setTextMatchingDocument(fileReference);
finalThesisService.reject(project);
finalThesisService.reject(project, "Does not follow the report template");
assertNull(finalThesis.getTextMatchingAnalysis());
assertNull(finalThesis.getTextMatchingDocument());
@ -150,7 +152,7 @@ public class FinalThesisServiceImplTest extends IntegrationTest {
@Test
public void uploading_is_allowed_if_latest_final_thesis_is_rejected() {
uploadThesis();
finalThesisService.reject(project);
finalThesisService.reject(project, "Does not follow the report template");
assertTrue(finalThesisService.isUploadAllowed(project));
}

@ -61,7 +61,7 @@ public class RejectedThesisWorker extends AbstractWorker {
}
final FinalThesis finalThesis = finalThesisService.findByProject(project);
if (finalThesis != null && finalThesis.getStatus() != FinalThesis.Status.REJECTED && finalThesis.getLastModified().before(rejectedDate)) {
finalThesisService.reject(project);
finalThesisService.reject(project, thesisRejection.getMessage());
}
// Check dates here since the API call is only date-based rather than time as well.
if (thesisRejection.isVisibleToAuthors() && rejectedDate.after(getLastSuccessfulRun())) {

@ -50,6 +50,7 @@
<div class="help-box">
<wicket:enclosure><span wicket:id="rejectedDateLabel"></span><br></wicket:enclosure>
<span wicket:id="rejectedInfoLabel"></span>
<wicket:enclosure><br>Reason: <span wicket:id="rejection_comment"></span><br></wicket:enclosure>
Please note that you also have the option to upload the file if needed.
</div>

@ -124,6 +124,14 @@ public class ApproveFinalThesisPanel extends GenericPanel<Project> {
}
});
add(new Label("rejection_comment", getFinalThesis().map(FinalThesis::getRejectionComment)) {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(thesisHasStatus(REJECTED));
}
});
add(new Label(REJECTED_INFO_LABEL, new ResourceModel("thesis.rejected.info.label")) {
@Override
protected void onConfigure() {

@ -106,7 +106,7 @@ public class RejectFinalThesisPanel extends GenericPanel<Project> {
projectForumService.createThread(project.getObject(), user,
REJECTED_SUBJECT, contentArea.getInput(), uploads);
finalThesisService.reject(getModelObject());
finalThesisService.reject(getModelObject(), contentArea.getInput());
onRejection();
setResponsePage(getPage());
}

@ -183,8 +183,9 @@ public class UploadTextMatchingPanel extends GenericPanel<Project> {
}
private void minorPlagiarismDetected() {
String content = commentField.getModelObject();
Project project = UploadTextMatchingPanel.this.getModelObject();
finalThesisService.reject(project);
finalThesisService.reject(project, content);
HashSet<Attachment> attachments = new HashSet<>();
attachments.add(Attachment.existing(getModelObject().getDocument().getFileDescription()));
@ -193,7 +194,6 @@ public class UploadTextMatchingPanel extends GenericPanel<Project> {
}
String subject = getString("minor_plagiarism_forum_subject");
String content = commentField.getModelObject();
projectForumService.createThread(project, SciProSession.get().getUser(), subject, content, attachments);
}
}

@ -118,7 +118,7 @@ public class ApproveFinalThesisPanelTest extends SciProTest {
formTester.setValue(path(RejectFinalThesisPanel.CONTENT), SOME_CONTENT);
formTester.submit();
Mockito.verify(finalThesisService).reject(eq(SOME_PROJECT));
Mockito.verify(finalThesisService).reject(eq(SOME_PROJECT), eq(SOME_CONTENT));
Mockito.verify(projectForumService).createThread(SOME_PROJECT,
SciProSession.get().getUser(),
RejectFinalThesisPanel.REJECTED_SUBJECT,