bug fixes
This commit is contained in:
parent
e3a9e552a7
commit
62f69d2ea5
|
@ -367,7 +367,7 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
boolean hasValueInner = false;
|
boolean hasValueInner = false;
|
||||||
if (fieldSetModel.getMultiplicity() != null && fieldSetModel.getMultiplicity().getTableView()) {
|
if (fieldSetModel.getMultiplicity() != null && fieldSetModel.getMultiplicity().getTableView() && tbl != null) {
|
||||||
row = tbl.createRow();
|
row = tbl.createRow();
|
||||||
hasValueInner = createFieldsInTable(fieldSetModel, multiplicityFieldset, row, indent, createListing, hasMultiplicityItems, numOfRows, visibilityService);
|
hasValueInner = createFieldsInTable(fieldSetModel, multiplicityFieldset, row, indent, createListing, hasMultiplicityItems, numOfRows, visibilityService);
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
|
@ -385,7 +385,7 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (multiplicityItems == 1) {
|
if (multiplicityItems == 1) {
|
||||||
String text = mainDocumentPart.getLastParagraph().getRuns().get(0).getText(0);
|
String text = mainDocumentPart.getLastParagraph().getRuns().getFirst().getText(0);
|
||||||
if (text.equals("a. ")) {
|
if (text.equals("a. ")) {
|
||||||
mainDocumentPart.getLastParagraph().removeRun(0);
|
mainDocumentPart.getLastParagraph().removeRun(0);
|
||||||
}
|
}
|
||||||
|
@ -471,78 +471,49 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
} else if (fieldValueModel != null) {
|
} else if (fieldValueModel != null) {
|
||||||
this.indent = indent;
|
this.indent = indent;
|
||||||
String format = this.formatter(field, fieldValueModel);
|
|
||||||
Boolean hasMultiAutoComplete = false;
|
|
||||||
boolean isResearcher = false;
|
boolean isResearcher = false;
|
||||||
if (field.getData() instanceof LabelAndMultiplicityDataModel) {
|
|
||||||
hasMultiAutoComplete = ((LabelAndMultiplicityDataModel) field.getData()).getMultipleSelect();
|
|
||||||
}
|
|
||||||
if (field.getData() instanceof SelectDataModel) {
|
|
||||||
hasMultiAutoComplete = ((SelectDataModel) field.getData()).getMultipleSelect();
|
|
||||||
}
|
|
||||||
if (field.getData() instanceof ReferenceTypeDataModel) {
|
if (field.getData() instanceof ReferenceTypeDataModel) {
|
||||||
hasMultiAutoComplete = ((ReferenceTypeDataModel) field.getData()).getMultipleSelect();
|
|
||||||
isResearcher = ((ReferenceTypeDataModel) field.getData()).getReferenceType().getCode().equals(this.wordFileTransformerServiceProperties.getResearcherReferenceCode());
|
isResearcher = ((ReferenceTypeDataModel) field.getData()).getReferenceType().getCode().equals(this.wordFileTransformerServiceProperties.getResearcherReferenceCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format != null && !format.isEmpty()) {
|
List<String> extractValues = this.extractValues(field, fieldValueModel);
|
||||||
boolean isMultiAutoComplete = hasMultiAutoComplete != null && hasMultiAutoComplete;
|
if (!extractValues.isEmpty()){
|
||||||
boolean arrayStringFormat = format.charAt(0) == '[';
|
int numOfValuesInCell = 0;
|
||||||
if (arrayStringFormat || isMultiAutoComplete) {
|
for (String extractValue : extractValues){
|
||||||
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
boolean orcidResearcher = false;
|
||||||
if (values.size() > 1) {
|
String orcId = null;
|
||||||
boolean orcidResearcher;
|
if (isResearcher && extractValue.contains("orcid:")) {
|
||||||
int numOfValuesInCell = 0;
|
orcId = extractValue.substring(extractValue.indexOf(':') + 1, extractValue.indexOf(')'));
|
||||||
for (String val : values) {
|
extractValue = extractValue.substring(0, extractValue.indexOf(':') + 1) + " ";
|
||||||
orcidResearcher = false;
|
orcidResearcher = true;
|
||||||
String orcId = null;
|
}
|
||||||
if (isResearcher && val.contains("orcid:")) {
|
if (extractValues.size() > 1) extractValue = "• " + extractValue;
|
||||||
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
if (hasMultiplicityItems) {
|
||||||
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
XWPFParagraph paragraph = mainDocumentPart.getCell(mainDocumentPart.getTableCells().size()).addParagraph();
|
||||||
orcidResearcher = true;
|
paragraph.createRun().setText(extractValue);
|
||||||
}
|
if (orcidResearcher) {
|
||||||
format = "• " + val;
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
if (hasMultiplicityItems) {
|
run.setText(orcId);
|
||||||
XWPFParagraph paragraph = mainDocumentPart.getCell(mainDocumentPart.getTableCells().size()).addParagraph();
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
paragraph.createRun().setText(format);
|
run.setColor("0000FF");
|
||||||
if (orcidResearcher) {
|
paragraph.createRun().setText(")");
|
||||||
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
}
|
||||||
run.setText(orcId);
|
hasValue = true;
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
hasMultiplicityItems = false;
|
||||||
run.setColor("0000FF");
|
} else {
|
||||||
paragraph.createRun().setText(")");
|
XWPFParagraph paragraph = addCellContent(extractValue, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, numOfValuesInCell);
|
||||||
}
|
if (paragraph != null) {
|
||||||
hasMultiplicityItems = false;
|
numOfValuesInCell++;
|
||||||
} else {
|
if (orcidResearcher) {
|
||||||
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, numOfValuesInCell);
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
numOfValuesInCell++;
|
run.setText(orcId);
|
||||||
if (orcidResearcher) {
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
run.setColor("0000FF");
|
||||||
run.setText(orcId);
|
paragraph.createRun().setText(")");
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
}
|
||||||
run.setColor("0000FF");
|
hasValue = true;
|
||||||
paragraph.createRun().setText(")");
|
}
|
||||||
}
|
|
||||||
if (paragraph != null) {
|
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
format = null;
|
|
||||||
}
|
|
||||||
} else if (values.size() == 1) {
|
|
||||||
format = values.getFirst();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasMultiplicityItems && format != null) {
|
|
||||||
XWPFParagraph paragraph = mainDocumentPart.getCell(mainDocumentPart.getTableCells().size()).addParagraph();
|
|
||||||
paragraph.createRun().setText(format);
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
hasValue = true;
|
|
||||||
} else {
|
|
||||||
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, 0);
|
|
||||||
if (paragraph != null) {
|
|
||||||
hasValue = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,7 +588,6 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
} else if (fieldValueModel != null) {
|
} else if (fieldValueModel != null) {
|
||||||
this.indent = indent;
|
this.indent = indent;
|
||||||
String format = this.formatter(field, fieldValueModel);
|
|
||||||
boolean isMultiAutoComplete = false;
|
boolean isMultiAutoComplete = false;
|
||||||
boolean isResearcher = false;
|
boolean isResearcher = false;
|
||||||
boolean isOrganization = false;
|
boolean isOrganization = false;
|
||||||
|
@ -639,68 +609,57 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
|
|
||||||
if (isOrganization || isExternalDataset || isPublication) {
|
if (isOrganization || isExternalDataset || isPublication) {
|
||||||
if (fieldValueModel.getReferences() != null) {
|
if (fieldValueModel.getReferences() != null) {
|
||||||
for (ReferenceModel referenceModel : fieldValueModel.getReferences())
|
for (ReferenceModel referenceModel : fieldValueModel.getReferences()) {
|
||||||
createHypeLink(mainDocumentPart, format, referenceModel.getDefinition().getFields().stream().filter(x -> x.getCode().equals("pidTypeField")).map(ReferenceFieldModel::getValue).findFirst().orElse(null), referenceModel.getReference(), hasMultiplicityItems, isMultiAutoComplete && fieldValueModel.getReferences().size() > 1);
|
String label = "";
|
||||||
|
if (referenceModel.getLabel() != null && !referenceModel.getLabel().isBlank()) {
|
||||||
|
label = referenceModel.getLabel();
|
||||||
|
}
|
||||||
|
if (referenceModel.getDescription() != null && !referenceModel.getDescription().isBlank()) {
|
||||||
|
label = (label.isBlank() ? "" : " ") + referenceModel.getDescription();
|
||||||
|
}
|
||||||
|
createHypeLink(mainDocumentPart, label, referenceModel.getDefinition().getFields().stream().filter(x -> x.getCode().equals("pidTypeField")).map(ReferenceFieldModel::getValue).findFirst().orElse(null), referenceModel.getReference(), hasMultiplicityItems, isMultiAutoComplete && fieldValueModel.getReferences().size() > 1);
|
||||||
|
}
|
||||||
if (hasMultiplicityItems) hasMultiplicityItems = false;
|
if (hasMultiplicityItems) hasMultiplicityItems = false;
|
||||||
|
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (format != null && !format.isEmpty()) {
|
List<String> extractValues = this.extractValues(field, fieldValueModel);
|
||||||
boolean arrayStringFormat = format.charAt(0) == '[';
|
|
||||||
if (arrayStringFormat || isMultiAutoComplete) {
|
if (!extractValues.isEmpty()){
|
||||||
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
for (String extractValue : extractValues){
|
||||||
if (values.size() > 1) {
|
boolean orcidResearcher = false;
|
||||||
boolean orcidResearcher;
|
String orcId = null;
|
||||||
for (String val : values) {
|
if (isResearcher && extractValue.contains("orcid:")) {
|
||||||
orcidResearcher = false;
|
orcId = extractValue.substring(extractValue.indexOf(':') + 1, extractValue.indexOf(')'));
|
||||||
String orcId = null;
|
extractValue = extractValue.substring(0, extractValue.indexOf(':') + 1) + " ";
|
||||||
if (isResearcher && val.contains("orcid:")) {
|
orcidResearcher = true;
|
||||||
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
|
||||||
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
|
||||||
orcidResearcher = true;
|
|
||||||
}
|
|
||||||
format = "• " + val;
|
|
||||||
if (hasMultiplicityItems) {
|
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
|
||||||
if (orcidResearcher) {
|
|
||||||
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun("https://orcid.org/" + orcId);
|
|
||||||
run.setText(orcId);
|
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
||||||
run.setColor("0000FF");
|
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(")");
|
|
||||||
}
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
} else {
|
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
|
||||||
if (orcidResearcher) {
|
|
||||||
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
|
||||||
run.setText(orcId);
|
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
||||||
run.setColor("0000FF");
|
|
||||||
paragraph.createRun().setText(")");
|
|
||||||
}
|
|
||||||
if (paragraph != null) {
|
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
format = null;
|
|
||||||
}
|
|
||||||
} else if (values.size() == 1) {
|
|
||||||
format = values.getFirst();
|
|
||||||
}
|
}
|
||||||
}
|
if (extractValues.size() > 1) extractValue = "• " + extractValue;
|
||||||
}
|
if (hasMultiplicityItems) {
|
||||||
if (format != null) {
|
mainDocumentPart.getLastParagraph().createRun().setText(extractValue);
|
||||||
if (hasMultiplicityItems) {
|
if (orcidResearcher) {
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
hasMultiplicityItems = false;
|
run.setText(orcId);
|
||||||
hasValue = true;
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
} else {
|
run.setColor("0000FF");
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
mainDocumentPart.getLastParagraph().createRun().setText(")");
|
||||||
if (paragraph != null) {
|
}
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
} else {
|
||||||
|
XWPFParagraph paragraph = addParagraphContent(extractValue, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
||||||
|
if (paragraph != null) {
|
||||||
|
if (orcidResearcher) {
|
||||||
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
|
run.setText(orcId);
|
||||||
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
|
run.setColor("0000FF");
|
||||||
|
paragraph.createRun().setText(")");
|
||||||
|
}
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -716,32 +675,29 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
return hasValue;
|
return hasValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private XWPFParagraph addCellContent(Object content, XWPFTableRow mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent, int numOfRows, int numOfCells, int numOfValuesInCell) {
|
private XWPFParagraph addCellContent(String content, XWPFTableRow mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent, int numOfRows, int numOfCells, int numOfValuesInCell) {
|
||||||
if (content != null) {
|
if (content == null || content.isEmpty()) return null;
|
||||||
if (content instanceof String && ((String) content).isEmpty()) {
|
|
||||||
return null;
|
this.indent = indent;
|
||||||
}
|
XWPFTableCell cell;
|
||||||
this.indent = indent;
|
if (numOfRows > 0 || numOfValuesInCell > 0) {
|
||||||
XWPFTableCell cell;
|
cell = mainDocumentPart.getCell(numOfCells);
|
||||||
if (numOfRows > 0 || numOfValuesInCell > 0) {
|
} else {
|
||||||
cell = mainDocumentPart.getCell(numOfCells);
|
cell = mainDocumentPart.createCell();
|
||||||
} else {
|
}
|
||||||
cell = mainDocumentPart.createCell();
|
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
|
||||||
}
|
if (numOfValuesInCell == 0) {
|
||||||
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
|
cell.removeParagraph(0);
|
||||||
if (numOfValuesInCell == 0) {
|
}
|
||||||
cell.removeParagraph(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
XWPFParagraph paragraph = this.optionsInTable.get(style).apply(cell, content);
|
XWPFParagraph paragraph = this.optionsInTable.get(style).apply(cell, content);
|
||||||
if (paragraph != null) {
|
if (paragraph != null) {
|
||||||
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||||
paragraph.setSpacingBefore(100);
|
paragraph.setSpacingBefore(100);
|
||||||
if (numId != null) {
|
if (numId != null) {
|
||||||
paragraph.setNumID(numId);
|
paragraph.setNumID(numId);
|
||||||
}
|
|
||||||
return paragraph;
|
|
||||||
}
|
}
|
||||||
|
return paragraph;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -782,31 +738,31 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatter(FieldModel field, org.opencdmp.commonmodels.models.description.FieldModel fieldValueModel) throws InvalidApplicationException {
|
private List<String> extractValues(FieldModel field, org.opencdmp.commonmodels.models.description.FieldModel fieldValueModel) throws InvalidApplicationException {
|
||||||
|
List<String> values = new ArrayList<>();
|
||||||
if (fieldValueModel == null || field == null || field.getData() == null) {
|
if (fieldValueModel == null || field == null || field.getData() == null) {
|
||||||
return null;
|
return values;
|
||||||
}
|
}
|
||||||
switch (field.getData().getFieldType()) {
|
switch (field.getData().getFieldType()) {
|
||||||
case REFERENCE_TYPES: {
|
case REFERENCE_TYPES: {
|
||||||
List<String> values = new ArrayList<>();
|
|
||||||
if (fieldValueModel.getReferences() != null && !fieldValueModel.getReferences().isEmpty()) {
|
if (fieldValueModel.getReferences() != null && !fieldValueModel.getReferences().isEmpty()) {
|
||||||
for (ReferenceModel referenceModel : fieldValueModel.getReferences()) {
|
for (ReferenceModel referenceModel : fieldValueModel.getReferences()) {
|
||||||
if (referenceModel != null) {
|
if (referenceModel != null) {
|
||||||
|
String label = "";
|
||||||
if (referenceModel.getLabel() != null && !referenceModel.getLabel().isBlank()) {
|
if (referenceModel.getLabel() != null && !referenceModel.getLabel().isBlank()) {
|
||||||
values.add(referenceModel.getLabel());
|
label = referenceModel.getLabel();
|
||||||
}
|
}
|
||||||
if (referenceModel.getDescription() != null && !referenceModel.getDescription().isBlank()) {
|
if (referenceModel.getDescription() != null && !referenceModel.getDescription().isBlank()) {
|
||||||
values.add(referenceModel.getLabel());
|
label = (label.isBlank() ? "" : " ") + referenceModel.getDescription();
|
||||||
}
|
}
|
||||||
|
if (!label.isBlank()) values.add(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
return String.join(", ", values);
|
|
||||||
}
|
}
|
||||||
case TAGS:
|
case TAGS:
|
||||||
case SELECT: {
|
case SELECT: {
|
||||||
List<String> values = new ArrayList<>();
|
|
||||||
if (fieldValueModel.getTextListValue() != null && !fieldValueModel.getTextListValue().isEmpty()) {
|
if (fieldValueModel.getTextListValue() != null && !fieldValueModel.getTextListValue().isEmpty()) {
|
||||||
SelectDataModel selectDataModel = (SelectDataModel) field.getData();
|
SelectDataModel selectDataModel = (SelectDataModel) field.getData();
|
||||||
if (selectDataModel != null && selectDataModel.getOptions() != null && !selectDataModel.getOptions().isEmpty()) {
|
if (selectDataModel != null && selectDataModel.getOptions() != null && !selectDataModel.getOptions().isEmpty()) {
|
||||||
|
@ -815,44 +771,54 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return String.join(", ", values);
|
break;
|
||||||
}
|
}
|
||||||
case BOOLEAN_DECISION:
|
case BOOLEAN_DECISION:
|
||||||
if (fieldValueModel.getBooleanValue() != null && fieldValueModel.getBooleanValue()) return "Yes";
|
if (fieldValueModel.getBooleanValue() != null && fieldValueModel.getBooleanValue()) values.add("Yes");
|
||||||
if (fieldValueModel.getBooleanValue() != null && !fieldValueModel.getBooleanValue()) return "No";
|
if (fieldValueModel.getBooleanValue() != null && !fieldValueModel.getBooleanValue()) values.add("No");
|
||||||
return null;
|
break;
|
||||||
case RADIO_BOX:
|
case RADIO_BOX:
|
||||||
RadioBoxDataModel radioBoxDataModel = (RadioBoxDataModel) field.getData();
|
RadioBoxDataModel radioBoxDataModel = (RadioBoxDataModel) field.getData();
|
||||||
if (fieldValueModel.getTextValue() != null && radioBoxDataModel != null && radioBoxDataModel.getOptions() != null) {
|
if (fieldValueModel.getTextValue() != null && radioBoxDataModel != null && radioBoxDataModel.getOptions() != null) {
|
||||||
for (RadioBoxDataModel.RadioBoxOptionModel option : radioBoxDataModel.getOptions()) {
|
for (RadioBoxDataModel.RadioBoxOptionModel option : radioBoxDataModel.getOptions()) {
|
||||||
if (option.getValue().equals(fieldValueModel.getTextValue()) || option.getLabel().equals(fieldValueModel.getTextValue())) return option.getLabel();
|
if (option.getValue().equals(fieldValueModel.getTextValue()) || option.getLabel().equals(fieldValueModel.getTextValue())) {
|
||||||
|
values.add(option.getLabel());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
break;
|
||||||
case CHECK_BOX:
|
case CHECK_BOX: {
|
||||||
LabelDataModel checkBoxData = (LabelDataModel) field.getData();
|
LabelDataModel checkBoxData = (LabelDataModel) field.getData();
|
||||||
if (fieldValueModel.getBooleanValue() == null || !fieldValueModel.getBooleanValue()) return null;
|
if (fieldValueModel.getBooleanValue() != null && fieldValueModel.getBooleanValue() && checkBoxData != null && checkBoxData.getLabel() != null) values.add(checkBoxData.getLabel());
|
||||||
return checkBoxData != null ? checkBoxData.getLabel() : null;
|
break;
|
||||||
|
}
|
||||||
case DATE_PICKER: {
|
case DATE_PICKER: {
|
||||||
return fieldValueModel.getDateValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(fieldValueModel.getDateValue()) : "";
|
if (fieldValueModel.getDateValue() != null) values.add(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(fieldValueModel.getDateValue()));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case FREE_TEXT:
|
case FREE_TEXT:
|
||||||
case TEXT_AREA:
|
case TEXT_AREA:
|
||||||
case RICH_TEXT_AREA:
|
case RICH_TEXT_AREA: {
|
||||||
return fieldValueModel.getTextValue() != null ? fieldValueModel.getTextValue() : "";
|
if (fieldValueModel.getTextValue() != null && !fieldValueModel.getTextValue().isBlank()) values.add(fieldValueModel.getTextValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DATASET_IDENTIFIER:
|
case DATASET_IDENTIFIER:
|
||||||
case VALIDATION:
|
case VALIDATION: {
|
||||||
if (fieldValueModel.getExternalIdentifier() != null) {
|
if (fieldValueModel.getExternalIdentifier() != null) {
|
||||||
return "id: " + fieldValueModel.getExternalIdentifier().getIdentifier() + ", Type: " + fieldValueModel.getExternalIdentifier().getType();
|
values.add("id: " + fieldValueModel.getExternalIdentifier().getIdentifier() + ", Type: " + fieldValueModel.getExternalIdentifier().getType());
|
||||||
}
|
}
|
||||||
return "";
|
break;
|
||||||
|
}
|
||||||
case UPLOAD:
|
case UPLOAD:
|
||||||
case INTERNAL_ENTRIES_DESCRIPTIONS:
|
case INTERNAL_ENTRIES_DESCRIPTIONS:
|
||||||
case INTERNAL_ENTRIES_DMPS:
|
case INTERNAL_ENTRIES_DMPS:
|
||||||
return null;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidApplicationException("Invalid type " + field.getData().getFieldType());
|
throw new InvalidApplicationException("Invalid type " + field.getData().getFieldType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -908,21 +874,21 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", descriptionModel.getLabel());
|
this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", descriptionModel.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
String researchersNames = "";
|
StringBuilder researchersNames = new StringBuilder();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ReferenceModel researcher : researchers) {
|
for (ReferenceModel researcher : researchers) {
|
||||||
i++;
|
i++;
|
||||||
researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
|
researchersNames.append(researcher.getLabel()).append(i < researchers.size() ? ", " : "");
|
||||||
}
|
}
|
||||||
this.replaceTextSegment(p, "'{ARGOS.DMP.RESEARCHERS}'", researchersNames, 15);
|
this.replaceTextSegment(p, "'{ARGOS.DMP.RESEARCHERS}'", researchersNames.toString(), 15);
|
||||||
|
|
||||||
String organisationsNames = "";
|
StringBuilder organisationsNames = new StringBuilder();
|
||||||
i = 0;
|
i = 0;
|
||||||
for (ReferenceModel organisation : organizations) {
|
for (ReferenceModel organisation : organizations) {
|
||||||
i++;
|
i++;
|
||||||
organisationsNames += organisation.getLabel() + (i < organizations.size() ? ", " : "");
|
organisationsNames.append(organisation.getLabel()).append(i < organizations.size() ? ", " : "");
|
||||||
}
|
}
|
||||||
this.replaceTextSegment(p, "'{ARGOS.DMP.ORGANIZATIONS}'", organisationsNames, 15);
|
this.replaceTextSegment(p, "'{ARGOS.DMP.ORGANIZATIONS}'", organisationsNames.toString(), 15);
|
||||||
|
|
||||||
if (this.textSegmentExists(p, "'{ARGOS.DMP.DESCRIPTION}'")) {
|
if (this.textSegmentExists(p, "'{ARGOS.DMP.DESCRIPTION}'")) {
|
||||||
descrParPos = parPos;
|
descrParPos = parPos;
|
||||||
|
@ -935,27 +901,27 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
this.replaceTextSegment(p, "'{ARGOS.DATASET.DESCRIPTION}'", "");
|
this.replaceTextSegment(p, "'{ARGOS.DATASET.DESCRIPTION}'", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((descrParPos != -1) && (dmpEntity != null) && (dmpEntity.getDescription() != null) && !isDescription) {
|
if ((descrParPos != -1) && (dmpEntity.getDescription() != null) && !isDescription) {
|
||||||
XmlCursor cursor = descrPar.getCTP().newCursor();
|
XmlCursor cursor = descrPar.getCTP().newCursor();
|
||||||
cursor.toNextSibling();
|
cursor.toNextSibling();
|
||||||
Document htmlDoc = Jsoup.parse(((String) dmpEntity.getDescription()).replaceAll("\n", "<br>"));
|
Document htmlDoc = Jsoup.parse((dmpEntity.getDescription()).replaceAll("\n", "<br>"));
|
||||||
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
||||||
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
||||||
}
|
}
|
||||||
if ((descrParPos != -1) && (descriptionModel != null) && (descriptionModel.getDescription() != null) && isDescription) {
|
if ((descrParPos != -1) && (descriptionModel != null) && (descriptionModel.getDescription() != null) && isDescription) {
|
||||||
XmlCursor cursor = descrPar.getCTP().newCursor();
|
XmlCursor cursor = descrPar.getCTP().newCursor();
|
||||||
cursor.toNextSibling();
|
cursor.toNextSibling();
|
||||||
Document htmlDoc = Jsoup.parse(((String) descriptionModel.getDescription()).replaceAll("\n", "<br>"));
|
Document htmlDoc = Jsoup.parse((descriptionModel.getDescription()).replaceAll("\n", "<br>"));
|
||||||
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
||||||
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
XWPFTable tbl = document.getTables().get(0);
|
XWPFTable tbl = document.getTables().getFirst();
|
||||||
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
|
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
|
||||||
it.next(); // skip first row
|
it.next(); // skip first row
|
||||||
if (it.hasNext() && !funders.isEmpty()) {
|
if (it.hasNext() && !funders.isEmpty()) {
|
||||||
XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0);
|
XWPFParagraph p = it.next().getCell(0).getParagraphs().getFirst();
|
||||||
XWPFRun run = p.createRun();
|
XWPFRun run = p.createRun();
|
||||||
run.setText(funders.getFirst().getLabel());
|
run.setText(funders.getFirst().getLabel());
|
||||||
run.setFontSize(15);
|
run.setFontSize(15);
|
||||||
|
@ -964,7 +930,7 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
it = tbl.getRows().iterator();
|
it = tbl.getRows().iterator();
|
||||||
it.next();
|
it.next();
|
||||||
if (it.hasNext() && !grants.isEmpty()) {
|
if (it.hasNext() && !grants.isEmpty()) {
|
||||||
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
|
XWPFParagraph p = it.next().getCell(1).getParagraphs().getFirst();
|
||||||
XWPFRun run = p.createRun();
|
XWPFRun run = p.createRun();
|
||||||
String text = grants.getFirst().getLabel();
|
String text = grants.getFirst().getLabel();
|
||||||
String reference = grants.getFirst().getReference();
|
String reference = grants.getFirst().getReference();
|
||||||
|
@ -979,12 +945,8 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean textSegmentExists(XWPFParagraph paragraph, String textToFind) {
|
private boolean textSegmentExists(XWPFParagraph paragraph, String textToFind) {
|
||||||
TextSegment foundTextSegment = null;
|
|
||||||
PositionInParagraph startPos = new PositionInParagraph(0, 0, 0);
|
PositionInParagraph startPos = new PositionInParagraph(0, 0, 0);
|
||||||
while ((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) {
|
return this.searchText(paragraph, textToFind, startPos) != null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement) {
|
private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement) {
|
||||||
|
@ -992,7 +954,7 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement, Integer fontSize) {
|
private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement, Integer fontSize) {
|
||||||
TextSegment foundTextSegment = null;
|
TextSegment foundTextSegment;
|
||||||
PositionInParagraph startPos = new PositionInParagraph(0, 0, 0);
|
PositionInParagraph startPos = new PositionInParagraph(0, 0, 0);
|
||||||
while((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) { // search all text segments having text to find
|
while((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) { // search all text segments having text to find
|
||||||
|
|
||||||
|
@ -1047,56 +1009,54 @@ public class WordBuilderImpl implements WordBuilder {
|
||||||
//CTR ctRun = rArray[runPos];
|
//CTR ctRun = rArray[runPos];
|
||||||
CTR ctRun = runs.get(runPos).getCTR();
|
CTR ctRun = runs.get(runPos).getCTR();
|
||||||
XmlCursor c = ctRun.newCursor();
|
XmlCursor c = ctRun.newCursor();
|
||||||
c.selectPath("./*");
|
try (c) {
|
||||||
try {
|
c.selectPath("./*");
|
||||||
while (c.toNextSelection()) {
|
while (c.toNextSelection()) {
|
||||||
XmlObject o = c.getObject();
|
XmlObject o = c.getObject();
|
||||||
if (o instanceof CTText) {
|
if (o instanceof CTText) {
|
||||||
if (textPos >= startText) {
|
if (textPos >= startText) {
|
||||||
String candidate = ((CTText) o).getStringValue();
|
String candidate = ((CTText) o).getStringValue();
|
||||||
if (runPos == startRun) {
|
if (runPos == startRun) {
|
||||||
charPos = startChar;
|
charPos = startChar;
|
||||||
} else {
|
} else {
|
||||||
charPos = 0;
|
charPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; charPos < candidate.length(); charPos++) {
|
for (; charPos < candidate.length(); charPos++) {
|
||||||
if ((candidate.charAt(charPos) == searched.charAt(0)) && (candCharPos == 0)) {
|
if ((candidate.charAt(charPos) == searched.charAt(0)) && (candCharPos == 0)) {
|
||||||
beginTextPos = textPos;
|
beginTextPos = textPos;
|
||||||
beginCharPos = charPos;
|
beginCharPos = charPos;
|
||||||
beginRunPos = runPos;
|
beginRunPos = runPos;
|
||||||
newList = true;
|
newList = true;
|
||||||
}
|
}
|
||||||
if (candidate.charAt(charPos) == searched.charAt(candCharPos)) {
|
if (candidate.charAt(charPos) == searched.charAt(candCharPos)) {
|
||||||
if (candCharPos + 1 < searched.length()) {
|
if (candCharPos + 1 < searched.length()) {
|
||||||
candCharPos++;
|
candCharPos++;
|
||||||
} else if (newList) {
|
} else if (newList) {
|
||||||
TextSegment segment = new TextSegment();
|
TextSegment segment = new TextSegment();
|
||||||
segment.setBeginRun(beginRunPos);
|
segment.setBeginRun(beginRunPos);
|
||||||
segment.setBeginText(beginTextPos);
|
segment.setBeginText(beginTextPos);
|
||||||
segment.setBeginChar(beginCharPos);
|
segment.setBeginChar(beginCharPos);
|
||||||
segment.setEndRun(runPos);
|
segment.setEndRun(runPos);
|
||||||
segment.setEndText(textPos);
|
segment.setEndText(textPos);
|
||||||
segment.setEndChar(charPos);
|
segment.setEndChar(charPos);
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
candCharPos = 0;
|
candCharPos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
textPos++;
|
textPos++;
|
||||||
} else if (o instanceof CTProofErr) {
|
} else if (o instanceof CTProofErr) {
|
||||||
c.removeXml();
|
c.removeXml();
|
||||||
} else if (o instanceof CTRPr) {
|
} else if (o instanceof CTRPr) {
|
||||||
//do nothing
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
candCharPos = 0;
|
candCharPos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
c.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue