diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 7726e9200..a7c7b6042 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1537,7 +1537,7 @@ public class DataManagementPlanManager { .sorted(Comparator.comparing(Dataset::getCreated)).collect(Collectors.toList()); if (datasets.size() > 0) - wordBuilder.addParagraphContent("Section descriptions", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0); + wordBuilder.addParagraphContent("Descriptions", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0); for (Dataset datasetEntity : datasets) { @@ -1559,7 +1559,7 @@ public class DataManagementPlanManager { datasetDescriptionParagraph.setStyle("Heading4"); datasetDescriptionParagraph.setSpacingBetween(1.5); XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun(); - datasetDescriptionRun.setText("Description"); + datasetDescriptionRun.setText(datasetEntity.getLabel()); //datasetDescriptionRun.setColor("2E75B6"); //datasetDescriptionRun.setBold(true); datasetDescriptionRun.setFontSize(15); @@ -1567,24 +1567,24 @@ public class DataManagementPlanManager { // Custom style for the Dataset title. //wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO); - XWPFParagraph datasetLabelParagraph = document.createParagraph(); -// datasetLabelParagraph.setStyle("Heading2"); - datasetLabelParagraph.setSpacingBetween(1.0); - XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun(); - runDatasetTitle1.setText("Title: "); - runDatasetTitle1.setColor("000000"); - //runDatasetTitle1.setBold(true); - //runDatasetTitle1.setFontSize(12); - XWPFRun runDatasetTitle = datasetLabelParagraph.createRun(); - runDatasetTitle.setText(datasetEntity.getLabel()); - runDatasetTitle.setColor("116a78"); +// XWPFParagraph datasetLabelParagraph = document.createParagraph(); +//// datasetLabelParagraph.setStyle("Heading2"); +// datasetLabelParagraph.setSpacingBetween(1.0); +// XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun(); +// runDatasetTitle1.setText("Title: "); +// runDatasetTitle1.setColor("000000"); +// //runDatasetTitle1.setBold(true); +// //runDatasetTitle1.setFontSize(12); +// XWPFRun runDatasetTitle = datasetLabelParagraph.createRun(); +// runDatasetTitle.setText(datasetEntity.getLabel()); +// runDatasetTitle.setColor("116a78"); //runDatasetTitle.setBold(true); //runDatasetTitle.setFontSize(12); XWPFParagraph descriptionParagraph = document.createParagraph(); - XWPFRun descriptionParagraphRun = descriptionParagraph.createRun(); - descriptionParagraphRun.setText("Description: "); - descriptionParagraphRun.setColor("000000"); +// XWPFRun descriptionParagraphRun = descriptionParagraph.createRun(); +// descriptionParagraphRun.setText("Description: "); +// descriptionParagraphRun.setColor("000000"); wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0); XWPFParagraph datasetTemplateParagraph = document.createParagraph(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index dea584ddd..15e724c1f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -24,6 +24,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.util.Units; import org.apache.poi.xwpf.usermodel.*; import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; import org.json.JSONArray; import org.json.JSONException; import org.jsoup.Jsoup; @@ -1019,60 +1020,46 @@ public class WordBuilder { int descrParPos = -1; XWPFParagraph descrPar = null; for(XWPFParagraph p: document.getParagraphs()){ - List runs = p.getRuns(); - if(runs != null){ - for(XWPFRun r : runs){ - String text = r.getText(0); - if(text != null){ - if(text.contains("{ARGOS.DMP.TITLE}")) { - text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel()); - r.setText(text, 0); - } else if(text.contains("{ARGOS.DMP.VERSION}")) { - text = text.replace("{ARGOS.DMP.VERSION}", "Version " + dmpEntity.getVersion()); - r.setText(text, 0); - } else if(datasetEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) { - text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel()); - r.setText(text, 0); -// } else if(text.equals("Description") && ((!isDataset && (dmpEntity == null || dmpEntity.getDescription() != null)) || (isDataset && (datasetEntity == null || datasetEntity.getDescription() == null)))) { -// r.setText("", 0); - } else if((dmpEntity != null && text.contains("{ARGOS.DMP.DESCRIPTION}") && !isDataset) || (datasetEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}") && isDataset)) { - descrParPos = parPos; - descrPar = p; - if(dmpEntity != null && !isDataset) { - text = text.replace("{ARGOS.DMP.DESCRIPTION}", ""); - } else if(datasetEntity != null && isDataset) { - text = text.replace("{ARGOS.DATASET.DESCRIPTION}", ""); - } - r.setText(text, 0); - } else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) { - String researchersNames = ""; - Set researchers = dmpEntity.getResearchers(); - int i = 0; - for(Researcher researcher : researchers){ - i++; - researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : ""); - } - text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames); - r.setText(text, 0); - r.setFontSize(17); - } else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) { - String organisationsNames = ""; - Set organisations = dmpEntity.getOrganisations(); - int i = 0; - for(Organisation organisation : organisations){ - i++; - organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : ""); - } - text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames); - r.setText(text, 0); - r.setFontSize(17); - } - } - } - } - parPos++; - } + if( dmpEntity != null) { + this.replaceTextSegment(p, "'{ARGOS.DMP.TITLE}'", dmpEntity.getLabel()); + this.replaceTextSegment(p, "'{ARGOS.DMP.VERSION}'", "Version " + dmpEntity.getVersion()); + } + if( datasetEntity != null) { + this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", datasetEntity.getLabel()); + } + + String researchersNames = ""; + Set researchers = dmpEntity.getResearchers(); + int i = 0; + for(Researcher researcher : researchers){ + i++; + researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : ""); + } + this.replaceTextSegment(p, "'{ARGOS.DMP.RESEARCHERS}'", researchersNames, 15); + + String organisationsNames = ""; + Set organisations = dmpEntity.getOrganisations(); + i = 0; + for(Organisation organisation : organisations){ + i++; + organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : ""); + } + this.replaceTextSegment(p, "'{ARGOS.DMP.ORGANIZATIONS}'", organisationsNames, 15); + + this.replaceTextSegment(p, "'{ARGOS.DMP.DESCRIPTION}'", "dfdsfsdf"); + + if(this.textSegmentExists(p,"'{ARGOS.DMP.DESCRIPTION}'")) { + descrParPos = parPos; + descrPar = p; + this.replaceTextSegment(p, "'{ARGOS.DMP.DESCRIPTION}'", ""); + } + if(this.textSegmentExists(p,"'{ARGOS.DATASET.DESCRIPTION}'")) { + descrParPos = parPos; + descrPar = p; + this.replaceTextSegment(p, "'{ARGOS.DATASET.DESCRIPTION}'", ""); + } + } if((descrParPos != -1) && (dmpEntity!=null) && (dmpEntity.getDescription() != null) && !isDataset) { XmlCursor cursor = descrPar.getCTP().newCursor(); cursor.toNextSibling(); @@ -1096,7 +1083,7 @@ public class WordBuilder { XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0); XWPFRun run = p.createRun(); run.setText(dmpEntity.getGrant().getFunder().getLabel()); - run.setFontSize(17); + run.setFontSize(15); p.setAlignment(ParagraphAlignment.CENTER); } it = tbl.getRows().iterator(); @@ -1111,7 +1098,7 @@ public class WordBuilder { text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : ""; } run.setText(text); - run.setFontSize(17); + run.setFontSize(15); p.setAlignment(ParagraphAlignment.CENTER); } } @@ -1119,43 +1106,165 @@ public class WordBuilder { public void fillFooter(DMP dmpEntity, Dataset datasetEntity, XWPFDocument document, boolean isDataset) { document.getFooterList().forEach(xwpfFooter -> { List runs = xwpfFooter.getParagraphs().get(0).getRuns(); - if(runs != null){ - for(XWPFRun r : runs){ - String text = r.getText(0); - if(text != null){ - if(text.contains("{ARGOS.DMP.TITLE}")){ - text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel()); - r.setText(text, 0); - } - if(text.contains("{ARGOS.DATASET.TITLE}") && datasetEntity != null){ - text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel()); - r.setText(text, 0); - } - if(text.contains("{ARGOS.DMP.LICENSE}")){ - try{ - Map license = ((Map) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license")); - text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid")); - } - catch (JsonProcessingException | NullPointerException e){ - text = text.replace("{ARGOS.DMP.LICENSE}", "License: -"); - } - r.setText(text, 0); - } - if(text.contains("{ARGOS.DMP.DOI}")){ - if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty()) - text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi()); - else - text = text.replace("{ARGOS.DMP.DOI}", "-"); - r.setText(text, 0); - } - if(text.contains("{ARGOS.DMP.LAST_MODIFIED}")){ - DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); - text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getModified())); - r.setText(text, 0); - } + for(XWPFParagraph p : xwpfFooter.getParagraphs()){ + if(p != null){ + if( dmpEntity != null) { + this.replaceTextSegment(p, "'{ARGOS.DMP.TITLE}'", dmpEntity.getLabel()); } + if( datasetEntity != null) { + this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", datasetEntity.getLabel()); + } + Map license = null; + try { + license = ((Map) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license")); + if (license != null && license.get("pid") != null) { + this.replaceTextSegment(p, "'{ARGOS.DMP.LICENSE}'", license.get("pid")); + } else { + this.replaceTextSegment(p, "'{ARGOS.DMP.LICENSE}'", "License: -"); + } + } catch (JsonProcessingException e) { + this.replaceTextSegment(p, "'{ARGOS.DMP.LICENSE}'", "License: -"); + } + if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty()) { + this.replaceTextSegment(p, "'{ARGOS.DMP.DOI}'", dmpEntity.getDois().iterator().next().getDoi()); + } else { + this.replaceTextSegment(p, "'{ARGOS.DMP.DOI}'", "-"); + } + DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + this.replaceTextSegment(p, "'{ARGOS.DMP.LAST_MODIFIED}'", formatter.format(dmpEntity.getModified())); } } }); } + + private boolean textSegmentExists(XWPFParagraph paragraph, String textToFind) { + TextSegment foundTextSegment = null; + PositionInParagraph startPos = new PositionInParagraph(0, 0, 0); + while((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) { + return true; + } + return false; + } + + private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement) { + this.replaceTextSegment(paragraph, textToFind, replacement, null); + } + + private void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement, Integer fontSize) { + TextSegment foundTextSegment = null; + PositionInParagraph startPos = new PositionInParagraph(0, 0, 0); + while((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) { // search all text segments having text to find + + System.out.println(foundTextSegment.getBeginRun()+":"+foundTextSegment.getBeginText()+":"+foundTextSegment.getBeginChar()); + System.out.println(foundTextSegment.getEndRun()+":"+foundTextSegment.getEndText()+":"+foundTextSegment.getEndChar()); + + // maybe there is text before textToFind in begin run + XWPFRun beginRun = paragraph.getRuns().get(foundTextSegment.getBeginRun()); + String textInBeginRun = beginRun.getText(foundTextSegment.getBeginText()); + String textBefore = textInBeginRun.substring(0, foundTextSegment.getBeginChar()); // we only need the text before + + // maybe there is text after textToFind in end run + XWPFRun endRun = paragraph.getRuns().get(foundTextSegment.getEndRun()); + String textInEndRun = endRun.getText(foundTextSegment.getEndText()); + String textAfter = textInEndRun.substring(foundTextSegment.getEndChar() + 1); // we only need the text after + + if (foundTextSegment.getEndRun() == foundTextSegment.getBeginRun()) { + textInBeginRun = textBefore + replacement + textAfter; // if we have only one run, we need the text before, then the replacement, then the text after in that run + } else { + textInBeginRun = textBefore + replacement; // else we need the text before followed by the replacement in begin run + endRun.setText(textAfter, foundTextSegment.getEndText()); // and the text after in end run + } + + beginRun.setText(textInBeginRun, foundTextSegment.getBeginText()); + if (fontSize != null) { + beginRun.setFontSize(fontSize); + } + // runs between begin run and end run needs to be removed + for (int runBetween = foundTextSegment.getEndRun() - 1; runBetween > foundTextSegment.getBeginRun(); runBetween--) { + paragraph.removeRun(runBetween); // remove not needed runs + } + + } + } + + /** + * this methods parse the paragraph and search for the string searched. + * If it finds the string, it will return true and the position of the String + * will be saved in the parameter startPos. + * + * @param searched + * @param startPos + */ + private TextSegment searchText(XWPFParagraph paragraph, String searched, PositionInParagraph startPos) { + int startRun = startPos.getRun(), + startText = startPos.getText(), + startChar = startPos.getChar(); + int beginRunPos = 0, candCharPos = 0; + boolean newList = false; + + //CTR[] rArray = paragraph.getRArray(); //This does not contain all runs. It lacks hyperlink runs for ex. + java.util.List runs = paragraph.getRuns(); + + int beginTextPos = 0, beginCharPos = 0; //must be outside the for loop + + //for (int runPos = startRun; runPos < rArray.length; runPos++) { + for (int runPos = startRun; runPos < runs.size(); runPos++) { + //int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos; //int beginTextPos = 0, beginCharPos = 0 must be outside the for loop + int textPos = 0, charPos; + //CTR ctRun = rArray[runPos]; + CTR ctRun = runs.get(runPos).getCTR(); + XmlCursor c = ctRun.newCursor(); + c.selectPath("./*"); + try { + while (c.toNextSelection()) { + XmlObject o = c.getObject(); + if (o instanceof CTText) { + if (textPos >= startText) { + String candidate = ((CTText) o).getStringValue(); + if (runPos == startRun) { + charPos = startChar; + } else { + charPos = 0; + } + + for (; charPos < candidate.length(); charPos++) { + if ((candidate.charAt(charPos) == searched.charAt(0)) && (candCharPos == 0)) { + beginTextPos = textPos; + beginCharPos = charPos; + beginRunPos = runPos; + newList = true; + } + if (candidate.charAt(charPos) == searched.charAt(candCharPos)) { + if (candCharPos + 1 < searched.length()) { + candCharPos++; + } else if (newList) { + TextSegment segment = new TextSegment(); + segment.setBeginRun(beginRunPos); + segment.setBeginText(beginTextPos); + segment.setBeginChar(beginCharPos); + segment.setEndRun(runPos); + segment.setEndText(textPos); + segment.setEndChar(charPos); + return segment; + } + } else { + candCharPos = 0; + } + } + } + textPos++; + } else if (o instanceof CTProofErr) { + c.removeXml(); + } else if (o instanceof CTRPr) { + //do nothing + } else { + candCharPos = 0; + } + } + } finally { + c.dispose(); + } + } + return null; + } } diff --git a/dmp-backend/web/src/main/resources/documents/h2020.docx b/dmp-backend/web/src/main/resources/documents/h2020.docx index defd937d3..ff728d3ab 100644 Binary files a/dmp-backend/web/src/main/resources/documents/h2020.docx and b/dmp-backend/web/src/main/resources/documents/h2020.docx differ diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index a4c17050f..4997a57bc 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -364,7 +364,6 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); - this.dmpSectionIndex = this.datasetWizardModel.dmpSectionIndex; this.datasetWizardModel.status = 0; this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup.get('id').setValue(null); @@ -375,6 +374,10 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.datasetWizardModel.dmp = data; this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp); this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue())); + const descipptionTemplateiNNewDmp:DmpDatasetProfile = this.datasetWizardModel.dmp?.profiles?.find(x => x.descriptionTemplateId === this.datasetWizardModel.profile.id); + + this.dmpSectionIndex = descipptionTemplateiNNewDmp?.data?.dmpSectionIndex?.length > 0 ? descipptionTemplateiNNewDmp?.data?.dmpSectionIndex[0] : 0; + this.formGroup.get('dmpSectionIndex').setValue(this.dmpSectionIndex); this.loadDatasetProfiles(); this.breadCrumbs = observableOf([ diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.html b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.html index f60d38f2c..2566b9527 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.html +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.html @@ -142,7 +142,7 @@
- + {{formGroup.get('label').getError('backendError').message}} @@ -151,7 +151,7 @@
+ [placeholder]="field?.placeholder?.length > 0 ? field.placeholder : 'DMP-EDITOR.PLACEHOLDER.DESCRIPTION'" [required]="field.required">
@@ -191,7 +191,7 @@
- + {{ lang.name }} @@ -205,7 +205,7 @@
- + {{vis.name | translate}} @@ -218,17 +218,17 @@
- +
- +
- +
- + {{formGroup.get('extraProperties').get('license').getError('backendError').message}} @@ -238,7 +238,7 @@
- + {{vis.name | translate}} @@ -309,7 +309,7 @@
Description templates
{{'DMP-EDITOR.FIELDS.SELECT-TEMPLATE' | translate}} - + {{formGroup.get('profiles').getError('backendError').message}} diff --git a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html index 723d4a39d..cf6383007 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html @@ -16,7 +16,7 @@
- +
@@ -66,7 +66,7 @@
- +
@@ -122,7 +122,7 @@
- +
diff --git a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts index 8559eda7f..f3d9e9fda 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts @@ -14,6 +14,7 @@ import { FunderCriteria } from '@app/core/query/funder/funder-criteria'; import { debounceTime, filter, map, switchMap, takeUntil, tap } from 'rxjs/operators'; import { isNullOrUndefined } from '@swimlane/ngx-datatable'; +import { FieldInSection } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; @Component({ selector: 'funding-info', templateUrl: './funding-info.component.html', @@ -30,6 +31,7 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { @Input() isRequired: boolean; @Input() type: number; + @Input() field: FieldInSection; @Input() formGroup: FormGroup; @Input() grantformGroup: FormGroup;