Skip to content

Commit

Permalink
Conversion: Make template autoselection overridable and add HE
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinFutterer committed Mar 7, 2024
1 parent f512200 commit efd7db9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CUSTOMISING.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,7 @@ The new filepath will look into the local resource folder and take the file plac
This .docx file needs to contain the placeholder keywords found in the sample template provided in the generic project,
in order to replace the text at those specific places.
By replacing the resource file instead, the default texts used to compose the document can be adapted.

The template is selected automatically when exporting, if the project has a funder. You may want to override this functionality,
if you have custom templates for example. To override this, write a class that extends [TemplateSelectorServiceImpl](src/main/java/at/ac/tuwien/damap/conversion/TemplateSelectorServiceImpl.java)
and have it override the methods that determine the template.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public class ExportTemplateBroker {
private final ExportFWFTemplate exportFWFTemplate;
private final ExportHorizonEuropeTemplate exportHorizonEuropeTemplate;

private final TemplateSelectorServiceImpl templateSelectorService;

@Inject
public ExportTemplateBroker(DmpService dmpService, ExportScienceEuropeTemplate exportScienceEuropeTemplate,
ExportFWFTemplate exportFWFTemplate, ExportHorizonEuropeTemplate exportHorizonEuropeTemplate) {
ExportFWFTemplate exportFWFTemplate, ExportHorizonEuropeTemplate exportHorizonEuropeTemplate,
TemplateSelectorServiceImpl templateSelectorService) {
this.dmpService = dmpService;
this.exportScienceEuropeTemplate = exportScienceEuropeTemplate;
this.exportFWFTemplate = exportFWFTemplate;
this.exportHorizonEuropeTemplate = exportHorizonEuropeTemplate;
this.templateSelectorService = templateSelectorService;
}

/**
Expand All @@ -37,21 +41,7 @@ public ExportTemplateBroker(DmpService dmpService, ExportScienceEuropeTemplate e
* @return
*/
public XWPFDocument exportTemplate(long dmpId) {
DmpDO dmpDO = dmpService.getDmpById(dmpId);
if (dmpDO.getProject() != null)
if (dmpDO.getProject().getFunding() != null)
if (dmpDO.getProject().getFunding().getFunderId() != null) {
IdentifierDO funderIdentifier = dmpDO.getProject().getFunding().getFunderId();
if (funderIdentifier.getType() != null)
if (funderIdentifier.getType().equals(EIdentifierType.FUNDREF))
// FWF FUNDREF Identifier 501100002428
if (funderIdentifier.getIdentifier() != null)
if (funderIdentifier.getIdentifier().equals("501100002428"))
return exportFWFTemplate.exportTemplate(dmpId);
}

// default export science europe template
return exportScienceEuropeTemplate.exportTemplate(dmpId);
return exportTemplateByType(dmpId, templateSelectorService.selectTemplate(dmpService.getDmpById(dmpId)));
}

public XWPFDocument exportTemplateByType(long dmpId, ETemplateType type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package at.ac.tuwien.damap.conversion;

import at.ac.tuwien.damap.enums.ETemplateType;
import at.ac.tuwien.damap.rest.dmp.domain.DmpDO;
import at.ac.tuwien.damap.rest.dmp.domain.IdentifierDO;

public interface TemplateSelectorService {

ETemplateType selectTemplate(DmpDO dmpDO);

boolean isHorizonEuropeTemplate(IdentifierDO identifierDO);

boolean isFWFTemplate(IdentifierDO identifierDO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package at.ac.tuwien.damap.conversion;

import at.ac.tuwien.damap.enums.EFunderIds;
import at.ac.tuwien.damap.enums.EIdentifierType;
import at.ac.tuwien.damap.enums.ETemplateType;
import at.ac.tuwien.damap.rest.dmp.domain.DmpDO;
import at.ac.tuwien.damap.rest.dmp.domain.IdentifierDO;
import io.quarkus.arc.DefaultBean;
import lombok.extern.jbosslog.JBossLog;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
@DefaultBean
@JBossLog
public class TemplateSelectorServiceImpl implements TemplateSelectorService{
@Override
public ETemplateType selectTemplate(DmpDO dmpDO) {
if (dmpDO.getProject() != null && dmpDO.getProject().getFunding() != null) {
IdentifierDO funderIdentifier = dmpDO.getProject().getFunding().getFunderId();
if (funderIdentifier != null && EIdentifierType.getFunderIdentifierTypeList().contains(funderIdentifier.getType())) {
if (isHorizonEuropeTemplate(funderIdentifier)) {
return ETemplateType.HORIZON_EUROPE;
}
if (isFWFTemplate(funderIdentifier)) {
return ETemplateType.FWF;
}
}
}
// default export science europe template
return ETemplateType.SCIENCE_EUROPE;
}

@Override
public boolean isHorizonEuropeTemplate(IdentifierDO identifierDO) {
return (EFunderIds.getEUFunderIds().contains(identifierDO.getIdentifier()));
}

@Override
public boolean isFWFTemplate(IdentifierDO identifierDO) {
return (EFunderIds.getFWFFunderIds().contains(identifierDO.getIdentifier()));
}
}
42 changes: 42 additions & 0 deletions src/main/java/at/ac/tuwien/damap/enums/EFunderIds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package at.ac.tuwien.damap.enums;

import java.util.ArrayList;
import java.util.List;

public enum EFunderIds {

EU_FUNDREF_ID("501100000780"),
EU_ROR_ID("https://ror.org/032s10s29"),
EU_ISNI_ID("0000 0004 6090 9785"),

FWF_FUNDREF_ID("501100002428"),
FWF_ROR_ID("https://ror.org/013tf3c58"),
FWF_ISNI_ID("0000 0001 1091 8438");


private final String funderId;

private static final List<String> EUFunderIds = new ArrayList<>();
private static final List<String> FWFFunderIds = new ArrayList<>();

static {
EUFunderIds.add(EU_FUNDREF_ID.funderId);
EUFunderIds.add(EU_ROR_ID.funderId);
EUFunderIds.add(EU_ISNI_ID.funderId);

FWFFunderIds.add(FWF_FUNDREF_ID.funderId);
FWFFunderIds.add(FWF_ROR_ID.funderId);
FWFFunderIds.add(FWF_ISNI_ID.funderId);
}

EFunderIds(String funderId) {
this.funderId = funderId;
}

public static List<String> getEUFunderIds() {return EUFunderIds;}
public static List<String> getFWFFunderIds() {return FWFFunderIds;}
@Override
public String toString() {
return funderId;
}
}
10 changes: 6 additions & 4 deletions src/main/java/at/ac/tuwien/damap/enums/EIdentifierType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public enum EIdentifierType {

funderIdentifierType.add(EIdentifierType.FUNDREF);
funderIdentifierType.add(EIdentifierType.URL);
funderIdentifierType.add(EIdentifierType.ROR);
funderIdentifierType.add(EIdentifierType.ISNI);
funderIdentifierType.add(EIdentifierType.OTHER);

grantIdentifierType.add(EIdentifierType.URL);
Expand All @@ -55,19 +57,19 @@ public List<EIdentifierType> getPersonIdentifierTypeList() {
return personIdentifierType;
}

public List<EIdentifierType> getDatasetIdentifierTypeList() {
public static List<EIdentifierType> getDatasetIdentifierTypeList() {
return datasetIdentifierType;
}

public List<EIdentifierType> getFunderIdentifierTypeList() {
public static List<EIdentifierType> getFunderIdentifierTypeList() {
return funderIdentifierType;
}

public List<EIdentifierType> getGrantIdentifierTypeList() {
public static List<EIdentifierType> getGrantIdentifierTypeList() {
return grantIdentifierType;
}

public List<EIdentifierType> getMetadataIdentifierTypeList() {
public static List<EIdentifierType> getMetadataIdentifierTypeList() {
return metadataIdentifierType;
}

Expand Down

0 comments on commit efd7db9

Please sign in to comment.