Skip to content
Snippets Groups Projects
Commit 015a8eff authored by OZGCloud's avatar OZGCloud
Browse files

use primaryid for looking for form data xml

parent b21f44ca
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
......@@ -99,11 +100,13 @@ class SemantikFormDataMapper {
}
private byte[] getXmlFormData(DepositData depositData) {
var primaryId = depositData.getPrimaryDataAttachmentId();
return depositData.getAttachments().stream()
.filter(attachment -> attachment.getName().endsWith(CONTENT_FORMDATA_FILENAME_SUFFIX))
.filter(attachment -> StringUtils.equals(attachment.getId(), primaryId))
.map(Attachment::getContent)
.findFirst()
.orElseThrow(() -> new RuntimeException("Request does not contain a file ending with " + CONTENT_FORMDATA_FILENAME_SUFFIX));
.orElseThrow(() -> new RuntimeException("Request does not contain primary data attachment"));
}
private void addFiles(Document document, List<IncomingFile> depositRequestFiles, Map<String, Object> formDataMap) {
......
......@@ -47,6 +47,7 @@ public class DepositTestFactory {
static Deposit withData(DepositData data) {
Deposit deposit = new Deposit();
data.setPrimaryDataAttachmentId(AttachmentTestFactory.XML_ID);
deposit.setData(data);
return deposit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment