Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vf/165 trigger the automatic selection for horizon europe #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
60 changes: 52 additions & 8 deletions docker/api-mock/data/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,64 @@
"dmpExists": false
},
{
"acronym": "RP.20230313.0",
"universityId": "uniProjectIdRecommended0",
"description": "Recommended project description text.",
"title": "Recommended Project Numero Uno",
"acronym": "PROJ.NO-FUNDING",
"universityId": "uniProjectIdNoFunding0",
"description": "This project has no funding and is recommended.",
"title": "No Funding Sample Project",
"funding": null,
"start": "2022-01-01T00:00:00.000Z",
"end": "2024-12-31T00:00:00.000Z",
"dmpExists": false
},
{
"acronym": "PROJ.FUNDER",
"universityId": "uniProjectIdFunderInfo",
"description": "Funder supported Project description text.",
"title": "Project Title - Funder Supported",
"acronym": "PROJ.HORIZON-EUROPE",
"universityId": "uniProjectIdHorizonEurope0",
"description": "This project is funded by the EU and is recommended.",
"title": "Horizon Europe Sample Project",
"funding": {
"fundingName": null,
"fundingProgram": null,
"funderId": {
"identifier": "501100000780",
"type": "FUNDREF"
},
"grantId": {
"identifier": null,
"type": null
},
"fundingStatus": "GRANTED"
},
"start": "2022-01-01T00:00:00.000Z",
"end": "2024-12-31T00:00:00.000Z",
"dmpExists": false
},
{
"acronym": "PROJ.FWF",
"universityId": "uniProjectIdFWF0",
"description": "This project is funded by the FWF and is recommended.",
"title": "FWF Sample Project",
"funding": {
"fundingName": null,
"fundingProgram": null,
"funderId": {
"identifier": "501100002428",
"type": "FUNDREF"
},
"grantId": {
"identifier": null,
"type": null
},
"fundingStatus": "GRANTED"
},
"start": "2022-01-01T00:00:00.000Z",
"end": "2024-12-31T00:00:00.000Z",
"dmpExists": false
},
{
"acronym": "PROJ.UNKNOWN-FUNDING",
"universityId": "uniProjectIdUnknownFunder0",
"description": "This project is funded by an unknown entity and is recommended.",
"title": "Unknown Funder Sample Project",
"funding": {
"fundingName": null,
"fundingProgram": null,
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface MockProjectRestService {

@GET
@Path("/projects")
List<ProjectDO> getRecommended(@QueryParam("title_like") @DefaultValue("recommend") String title);
List<ProjectDO> getRecommended(@QueryParam("description_like") @DefaultValue("recommend") String description);

@GET
@Path("/project-supplement")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package at.ac.tuwien.damap.conversion;

import at.ac.tuwien.damap.TestSetup;
import at.ac.tuwien.damap.enums.ETemplateType;
import at.ac.tuwien.damap.rest.dmp.domain.DmpDO;
import at.ac.tuwien.damap.rest.dmp.domain.FundingDO;
import at.ac.tuwien.damap.rest.dmp.domain.ProjectDO;
import at.ac.tuwien.damap.util.MockDmpService;
import at.ac.tuwien.damap.util.TestDOFactory;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.security.TestSecurity;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

@QuarkusTest
class TemplateSelectorServiceImplTest extends TestSetup {

@Inject
TestDOFactory testDOFactory;

@Inject
MockDmpService dmpService;

@Inject
TemplateSelectorServiceImpl templateSelectorService;

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasUnknownFunding_whenTemplateIsSelected_thenShouldReturnScienceEurope() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456UnknwonFunder");
project.setDescription("Test unknown funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100004955");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.SCIENCE_EUROPE, templateSelectorService.selectTemplate(updatedDMP));
}

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasFWFFunding_whenTemplateIsSelected_thenShouldReturnFWF() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456FWFFunder");
project.setDescription("Test FWF funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100002428");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.FWF, templateSelectorService.selectTemplate(updatedDMP));
}

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasUnknownFunding_whenTemplateIsSelected_thenShouldReturnHorizonEurope() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456HEFunder");
project.setDescription("Test HE funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100000780");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.HORIZON_EUROPE, templateSelectorService.selectTemplate(updatedDMP));
}
}
Loading