Skip to content

Commit

Permalink
Contributor: Add project coordinator and principal investigator roles…
Browse files Browse the repository at this point in the history
… for contributors
  • Loading branch information
GeoffreyKarnbach committed Dec 16, 2024
1 parent f388112 commit f4935f5
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.apache.poi.xwpf.usermodel.*;
import org.damap.base.domain.*;
import org.damap.base.enums.*;
import org.damap.base.rest.dmp.domain.ContributorDO;
import org.damap.base.rest.dmp.domain.ProjectDO;
import org.damap.base.rest.dmp.mapper.ContributorDOMapper;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge;

/**
Expand All @@ -21,6 +23,7 @@ public abstract class AbstractTemplateExportScienceEuropeComponents
extends AbstractTemplateExportSetup {

protected Map<Long, String> datasetTableIDs = new HashMap<>();
private List<String> projectCoordinatorOrInvestigatorIds = new ArrayList<>();

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -194,47 +197,65 @@ private void contactPersonInformation() {
}

private void projectCoordinatorInformation() {
// mapping project coordinator information
List<String> coordinatorProperties = new ArrayList<>();
String coordinatorIdentifierId = "";
String coordinatorAffiliationIdentifierId = "";

if (projectCoordinator == null) {
addReplacement(replacements, "[coordinator]", joinWithComma(coordinatorProperties));
if (projectCoordinators == null) {
addReplacement(replacements, "[coordinator]", "");
return;
}

if (projectCoordinator.getFirstName() != null && projectCoordinator.getLastName() != null)
coordinatorProperties.add(
projectCoordinator.getFirstName() + " " + projectCoordinator.getLastName());
StringBuilder coordinatorInfos = new StringBuilder();
// mapping project coordinator information
for (ContributorDO contributor : projectCoordinators) {

List<String> coordinatorProperties = new ArrayList<>();
String coordinatorIdentifierId = "";
String coordinatorAffiliationIdentifierId = "";

if (contributor == null) {
addReplacement(replacements, "[coordinator]", joinWithComma(coordinatorProperties));
return;
}

if (projectCoordinator.getMbox() != null)
coordinatorProperties.add(projectCoordinator.getMbox());
if (contributor.getFirstName() != null && contributor.getLastName() != null)
coordinatorProperties.add(contributor.getFirstName() + " " + contributor.getLastName());

if (projectCoordinator.getPersonId() != null) {
coordinatorIdentifierId = projectCoordinator.getPersonId().getIdentifier();
if (contributor.getMbox() != null) coordinatorProperties.add(contributor.getMbox());

if (projectCoordinator.getPersonId().getType().toString().equals("orcid")) {
String coordinatorId = "ORCID iD: " + coordinatorIdentifierId;
coordinatorProperties.add(coordinatorId);
if (contributor.getPersonId() != null) {
coordinatorIdentifierId = contributor.getPersonId().getIdentifier();

if (contributor.getPersonId().getType().toString().equals("orcid")) {
String coordinatorId = "ORCID iD: " + coordinatorIdentifierId;
coordinatorProperties.add(coordinatorId);
}
}
}

if (projectCoordinator.getAffiliation() != null)
coordinatorProperties.add(projectCoordinator.getAffiliation());
if (contributor.getAffiliation() != null)
coordinatorProperties.add(contributor.getAffiliation());

if (contributor.getAffiliationId() != null) {
coordinatorAffiliationIdentifierId = contributor.getAffiliationId().getIdentifier();

if (projectCoordinator.getAffiliationId() != null) {
coordinatorAffiliationIdentifierId = projectCoordinator.getAffiliationId().getIdentifier();
if (contributor.getAffiliationId().getType().toString().equals("ror")) {
String coordinatorAffiliationIdentifierType = "ROR: ";
String coordinatorAffiliationId =
coordinatorAffiliationIdentifierType + coordinatorAffiliationIdentifierId;
coordinatorProperties.add(coordinatorAffiliationId);
}
}

if (projectCoordinator.getAffiliationId().getType().toString().equals("ror")) {
String coordinatorAffiliationIdentifierType = "ROR: ";
String coordinatorAffiliationId =
coordinatorAffiliationIdentifierType + coordinatorAffiliationIdentifierId;
coordinatorProperties.add(coordinatorAffiliationId);
if (contributor.getRole() != null) {
String coordinatorRole = contributor.getRole().toString();
coordinatorProperties.add(coordinatorRole);
}

coordinatorInfos.append(joinWithComma(coordinatorProperties));
coordinatorInfos.append(";");

this.projectCoordinatorOrInvestigatorIds.add(contributor.getUniversityId());
}

addReplacement(replacements, "[coordinator]", joinWithComma(coordinatorProperties));
addReplacement(replacements, "[coordinator]", coordinatorInfos.toString());
}

private void dmpContributorInformation() {
Expand Down Expand Up @@ -285,6 +306,14 @@ private void dmpContributorInformation() {
contributorProperties.add(contributorRole);
}

if ((contributor.getContributorRole() != null
&& (contributor.getContributorRole().equals(EContributorRole.PRINCIPAL_INVESTIGATOR)
|| contributor.getContributorRole().equals(EContributorRole.PROJECT_LEADER)
|| contributor.getContributorRole().equals(EContributorRole.PROJECT_COORDINATOR)))
|| this.projectCoordinatorOrInvestigatorIds.contains(contributor.getUniversityId())) {
continue;
}

contributorPerson = joinWithComma(contributorProperties);
contributorList.add(contributorPerson);
}
Expand Down Expand Up @@ -363,13 +392,70 @@ public void datasetsInformation() {

/** storageIntroInformation */
public void storageIntroInformation() {
String coordinatorFullName;
String coordinatorFullName = null;

if (projectCoordinator != null) {
coordinatorFullName =
projectCoordinator.getFirstName() + " " + projectCoordinator.getLastName();
} else {
coordinatorFullName = "Coordinator";
List<Contributor> contributorPool = dmp.getContributorList();
for (ContributorDO contributorDO : projectCoordinators) {
contributorPool.add(ContributorDOMapper.mapDOtoEntity(contributorDO, new Contributor()));
}

// Data Manager
for (Contributor contributor : contributorPool) {
if (contributor != null
&& contributor.getContributorRole() != null
&& contributor.getContributorRole().equals(EContributorRole.DATA_MANAGER)) {
coordinatorFullName = contributor.getFirstName() + " " + contributor.getLastName();
break;
}
}

if (coordinatorFullName == null) {
// Project Leader
for (Contributor contributor : contributorPool) {
if (contributor != null
&& contributor.getContributorRole() != null
&& contributor.getContributorRole().equals(EContributorRole.PROJECT_LEADER)) {
coordinatorFullName = contributor.getFirstName() + " " + contributor.getLastName();
break;
}
}
}

if (coordinatorFullName == null) {
// Principal Investigator
for (Contributor contributor : contributorPool) {
if (contributor != null
&& contributor.getContributorRole() != null
&& contributor.getContributorRole().equals(EContributorRole.PRINCIPAL_INVESTIGATOR)) {
coordinatorFullName = contributor.getFirstName() + " " + contributor.getLastName();
break;
}
}
}

if (coordinatorFullName == null) {
// Project Coordinator
for (Contributor contributor : contributorPool) {
if (contributor != null
&& contributor.getContributorRole() != null
&& contributor.getContributorRole().equals(EContributorRole.PROJECT_COORDINATOR)) {
coordinatorFullName = contributor.getFirstName() + " " + contributor.getLastName();
break;
}
}
}

if (coordinatorFullName == null) {
// Contact person as fallback option 1
if (dmp.getContact() != null) {
coordinatorFullName =
dmp.getContact().getFirstName() + " " + dmp.getContact().getLastName();
}
}

if (coordinatorFullName == null) {
// Generic string as fallback option 2
coordinatorFullName = "the project leader ";
}

boolean usesExternalStorage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class AbstractTemplateExportSetup extends AbstractTemplateExport
protected Properties prop = null;
protected List<XWPFParagraph> xwpfParagraphs = null;
protected List<XWPFTable> xwpfTables = null;
protected ContributorDO projectCoordinator = null;
protected List<ContributorDO> projectCoordinators = new ArrayList<>();

/**
* exportSetup.
Expand All @@ -53,21 +53,31 @@ protected void exportSetup(long dmpId) {
costList = dmp.getCosts();

// determine project leader/coordinator/principal investigator
Optional<Contributor> projectLeaderOpt =
projectCoordinators =
dmp.getContributorList().stream()
.filter(
contributor -> contributor.getContributorRole() == EContributorRole.PROJECT_LEADER)
.findFirst();
if (projectLeaderOpt.isPresent())
projectCoordinator =
ContributorDOMapper.mapEntityToDO(projectLeaderOpt.get(), new ContributorDO());
else
contributor ->
contributor.getContributorRole() == EContributorRole.PROJECT_LEADER
|| contributor.getContributorRole() == EContributorRole.PROJECT_COORDINATOR
|| contributor.getContributorRole()
== EContributorRole.PRINCIPAL_INVESTIGATOR)
.map(contributor -> ContributorDOMapper.mapEntityToDO(contributor, new ContributorDO()))
.toList();

if (projectCoordinators.isEmpty()) {
try {
if (dmp.getProject() != null && dmp.getProject().getUniversityId() != null)
projectCoordinator = projectService.getProjectLeader(dmp.getProject().getUniversityId());
if (dmp.getProject() != null && dmp.getProject().getUniversityId() != null) {
ContributorDO projectLeader =
projectService.getProjectLeader(dmp.getProject().getUniversityId());
if (projectLeader.getRole() == null) {
projectLeader.setRole(EContributorRole.PROJECT_LEADER);
}
projectCoordinators = List.of(projectLeader);
}
} catch (Exception e) {
log.error("Project API not functioning");
}
}
}

private List<Dataset> getDeletedDatasets(List<Dataset> datasets) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/damap/base/enums/EContributorRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum EContributorRole {
SPONSOR("Sponsor"),
SUPERVISOR("Supervisor"),
WORK_PACKAGE_LEADER("Work Package Leader"),
PRINCIPAL_INVESTIGATOR("Principal Investigator"),
PROJECT_COORDINATOR("Project Coordinator"),
OTHER("Other");

private final String role;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
databaseChangeLog:
- changeSet:
id: 16
author: Geoffrey Karnbach
changes:
- insert:
tableName: e_contributor_role
columns:
- column:
name: role
value: PRINCIPAL_INVESTIGATOR
- insert:
tableName: e_contributor_role
columns:
- column:
name: role
value: PROJECT_COORDINATOR

rollback:
- delete:
tableName: e_contributor_role
where: "role IN ('PRINCIPAL_INVESTIGATOR', 'PROJECT_COORDINATOR')"
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ databaseChangeLog:
- include:
file: org/damap/base/db/changeLog-4.x/changeLog-4.0.3_3.yaml
- include:
file: org/damap/base/db/changeLog-4.x/changeLog-4.3.0_1.yaml
file: org/damap/base/db/changeLog-4.x/changeLog-4.3.0_1.yaml
- include:
file: org/damap/base/db/changeLog-4.x/changeLog-4.3.0_2.yaml

0 comments on commit f4935f5

Please sign in to comment.