ethical_issues added to DatasetRDAMapper, minor fixes to dmp docx export

This commit is contained in:
DESKTOP-4ES9U2E\aldom 2022-01-12 14:10:00 +02:00
parent 16c124cc3d
commit 9d5d685ad6
5 changed files with 98 additions and 33 deletions

View File

@ -193,18 +193,26 @@ public class WordBuilder {
boolean hasValue = false; boolean hasValue = false;
for (FieldSet compositeField: compositeFields) { for (FieldSet compositeField: compositeFields) {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) { if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
char c = 'a';
int paragraphPos = -1; int paragraphPos = -1;
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) { if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId); XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph); paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId);
}
} }
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) { if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList()); List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
for (FieldSet multiplicityFieldset : list) { for (FieldSet multiplicityFieldset : list) {
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); if(!createListing){
c++;
addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId);
}
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
} }
} }
if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) { if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
@ -224,6 +232,15 @@ public class WordBuilder {
if (createListing) this.addListing(mainDocumentPart, indent, false, false); if (createListing) this.addListing(mainDocumentPart, indent, false, false);
boolean hasValue = false; boolean hasValue = false;
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList()); List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
List<Field> formats = tempFields.stream().filter(f -> {
try {
String fTemp = this.formatter(f);
return fTemp != null && !fTemp.isEmpty();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return false;
}).collect(Collectors.toList());
for (Field field: tempFields) { for (Field field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId())) { if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) { if (!createListing) {
@ -231,8 +248,13 @@ public class WordBuilder {
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
this.indent = indent; this.indent = indent;
String format = this.formatter(field); String format = this.formatter(field);
if(format != null && format.charAt(0) == '['){ if(format != null){
format = format.substring(1, format.length() - 1).replaceAll(",", ", "); if(format.charAt(0) == '['){
format = format.substring(1, format.length() - 1).replaceAll(",", ", ");
}
if(formats.size() > 1){
format = "\t• " + format;
}
} }
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId); XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
if (paragraph != null) { if (paragraph != null) {

View File

@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.net.URI;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -40,7 +41,7 @@ public class DatasetRDAMapper {
} }
@Transactional @Transactional
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors, List<Cost> costs) { public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, eu.eudat.models.rda.Dmp dmp) {
Dataset rda = new Dataset(); Dataset rda = new Dataset();
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId())); // rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
if (dataset.getLabel() == null) { if (dataset.getLabel() == null) {
@ -125,7 +126,11 @@ public class DatasetRDAMapper {
} }
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data"); List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
if (!personalDataNodes.isEmpty()) { if (!personalDataNodes.isEmpty()) {
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get()); try{
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
}
} else { } else {
rda.setPersonalData(Dataset.PersonalData.UNKNOWN); rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
} }
@ -137,7 +142,11 @@ public class DatasetRDAMapper {
} }
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data"); List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
if (!sensitiveDataNodes.isEmpty()) { if (!sensitiveDataNodes.isEmpty()) {
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get()); try{
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
}
} else { } else {
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN); rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
} }
@ -153,7 +162,7 @@ public class DatasetRDAMapper {
} }
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor"); List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
if (!contributorNodes.isEmpty()) { if (!contributorNodes.isEmpty()) {
contributors.addAll(contributorNodes.stream().map(contributorNode -> { dmp.getContributor().addAll(contributorNodes.stream().map(contributorNode -> {
JsonNode value = contributorNode.get("value"); JsonNode value = contributorNode.get("value");
if (value.isArray()) { if (value.isArray()) {
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList()); return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
@ -164,7 +173,46 @@ public class DatasetRDAMapper {
} }
List<JsonNode> costNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.cost"); List<JsonNode> costNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.cost");
if (!costNodes.isEmpty()) { if (!costNodes.isEmpty()) {
costs.addAll(CostRDAMapper.toRDAList(costNodes)); dmp.getCost().addAll(CostRDAMapper.toRDAList(costNodes));
}
List<JsonNode> ethicsNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.ethical_issues");
if (!ethicsNodes.isEmpty()) {
for(JsonNode node: ethicsNodes){
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue == null || rdaValue.isEmpty()){
continue;
}
if(rdaProperty.contains("exist")){
try {
Dmp.EthicalIssuesExist exists = dmp.getEthicalIssuesExist();
if(exists == null
|| ((exists == Dmp.EthicalIssuesExist.NO || exists == Dmp.EthicalIssuesExist.UNKNOWN) && rdaValue.equals("yes"))
|| (exists == Dmp.EthicalIssuesExist.YES && !(rdaValue.equals("no") || rdaValue.equals("unknown")))
|| (exists == Dmp.EthicalIssuesExist.UNKNOWN && rdaValue.equals("no"))){
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(rdaValue));
}
}catch(IllegalArgumentException e){
logger.warn(e.getLocalizedMessage() + ". Setting ethical_issues_exist to unknown");
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
}
}
else if(rdaProperty.contains("description")){
if(dmp.getEthicalIssuesDescription() == null){
dmp.setEthicalIssuesDescription(rdaValue);
}
else{
dmp.setEthicalIssuesDescription(dmp.getEthicalIssuesDescription() + ", " + rdaValue);
}
}
else if(rdaProperty.contains("report")){
try {
dmp.setEthicalIssuesReport(URI.create(rdaValue));
} catch (IllegalArgumentException e) {
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
}
}
} }
List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes, List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes,
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList()); keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());

View File

@ -68,7 +68,7 @@ public class DmpRDAMapper {
if (!extraProperties.isEmpty()) { if (!extraProperties.isEmpty()) {
if (extraProperties.get("ethicalIssues") != null) { if (extraProperties.get("ethicalIssues") != null) {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIsses").toString())); rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString()));
} else { } else {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN); rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
} }
@ -95,7 +95,7 @@ public class DmpRDAMapper {
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
} }
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); // rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda.getContributor(), rda.getCost())).collect(Collectors.toList())); rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray()); rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
return rda; return rda;

View File

@ -67,15 +67,14 @@ public class HostRDAMapper {
while(iter.hasNext()) { while(iter.hasNext()) {
pList.add(iter.next().asText()); pList.add(iter.next().asText());
} }
// List<PidSystem> pidList; List<PidSystem> pidList;
// if(pList.size() == 0){ if(pList.size() == 0){
// pidList = Arrays.stream(rdaValue.replaceAll("[\\[\"\\]]","").split(",")) pidList = Arrays.stream(rdaValue.replaceAll("[\\[\"\\]]","").split(","))
// .map(PidSystem::fromValue).collect(Collectors.toList()); .map(PidSystem::fromValue).collect(Collectors.toList());
// } }
// else{ else{
// pidList = pList.stream().map(PidSystem::fromValue).collect(Collectors.toList()); pidList = pList.stream().map(PidSystem::fromValue).collect(Collectors.toList());
// } }
List<PidSystem> pidList = pList.stream().map(PidSystem::fromValue).collect(Collectors.toList());
rda.setPidSystem(pidList); rda.setPidSystem(pidList);
rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText()); rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText());
} }

View File

@ -15,21 +15,17 @@ public class KeywordRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class); private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
public static List<String> toRDA(String value) { public static List<String> toRDA(String value) {
ObjectMapper mapper = new ObjectMapper(); if (!value.isEmpty()) {
value = JavaToJson.objectStringToJson(value); try {
if (!value.isEmpty()) { ObjectMapper mapper = new ObjectMapper();
try { String valueJson = JavaToJson.objectStringToJson(value);
List<Tag> tags = Arrays.asList(mapper.readValue(value, Tag[].class)); List<Tag> tags = Arrays.asList(mapper.readValue(valueJson, Tag[].class));
List<String> keywordNames = tags.stream().map(Tag::getName).collect(Collectors.toList()); return tags.stream().map(Tag::getName).collect(Collectors.toList());
return keywordNames; } catch (JsonProcessingException e) {
} catch (JsonProcessingException e) { logger.warn(e.getMessage() + ". Attempting to parse it as a String list.");
logger.warn(e.getMessage() + ". Attempting to parse it as a String list."); return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
if(!value.isEmpty()) {
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
}
}
} }
}
return new ArrayList<>(); return new ArrayList<>();
} }