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

SAK-50854 Assignments: cc+ export/import not keeping model answer or private note #13316

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ private Assignment mergeAssignment(final String siteId, final Element element, f
for (String oAttachment : oAttachments) {
String fromResourcePath = attachmentNames.get(oAttachment);
String fromContext = null; // No-Op, there is no fromContext when importing from a ZIP
String nAttachId = transferAttachment(fromContext, siteId, fromResourcePath, null);
String nAttachId = transferAttachment(fromContext, siteId, fromResourcePath, attachmentNames);
assignmentFromXml.getAttachments().add(nAttachId);
}

Expand Down Expand Up @@ -1064,6 +1064,50 @@ private Assignment mergeAssignment(final String siteId, final Element element, f
results.append(result).append(LINE_SEPARATOR);
log.debug(result);
}

// After we save the assignment, we can save the private note, model answer, and attachments
NodeList nodes = element.getElementsByTagName("PrivateNote");
for (int j=0; j<nodes.getLength(); ++j) {
Element nodeElement = (Element) nodes.item(j);
String text = nodeElement.getTextContent();
String shareWith = nodeElement.getAttribute("shareWith");
AssignmentNoteItem copy = assignmentSupplementItemService.newNoteItem();
copy.setAssignmentId(assignmentFromXml.getId());
copy.setNote(text);
copy.setShareWith(Integer.parseInt(shareWith));
copy.setCreatorId(creatorId);
assignmentSupplementItemService.saveNoteItem(copy);
}

nodes = element.getElementsByTagName("ModelAnswer");
for (int j=0; j<nodes.getLength(); ++j) {
Element nodeElement = (Element) nodes.item(j);
String text = nodeElement.getTextContent();
String showTo = nodeElement.getAttribute("showTo");
AssignmentModelAnswerItem copy = assignmentSupplementItemService.newModelAnswer();
copy.setAssignmentId(assignmentFromXml.getId());
copy.setText(text);
copy.setShowTo(Integer.parseInt(showTo));

// We have to save the model answer so it exists before it can have attachments; otherwise we get a Hibernate exception
assignmentSupplementItemService.saveModelAnswer(copy);

NodeList attachments = nodeElement.getElementsByTagName("attachment");
for (int k=0; k<attachments.getLength(); ++k) {
Element attachmentElement = (Element) attachments.item(k);
String attachmentId = attachmentElement.getTextContent();
System.out.println("attachmentId="+attachmentId);
AssignmentSupplementItemAttachment attachment = assignmentSupplementItemService.newAttachment();
System.out.println("attachmentNames="+attachmentNames);
String fromContext = null; // No-Op, there is no fromContext when importing from a ZIP
String nAttachId = transferAttachment(fromContext, siteId, attachmentId, attachmentNames);
System.out.println("saved attachment="+nAttachId);
attachment.setAssignmentSupplementItemWithAttachment(copy);
attachment.setAttachmentId(nAttachId);
assignmentSupplementItemService.saveAttachment(attachment);
}
}

return assignmentFromXml;
}

Expand Down
Loading