make grant funder not mandatory for the creation/new version/clone of dmp

This commit is contained in:
Bernaldo Mihasi 2023-09-18 17:48:54 +03:00
parent bfa310a074
commit 93c5918251
16 changed files with 294 additions and 130 deletions

View File

@ -46,9 +46,9 @@ public class QuickWizardController extends BaseController {
Funder funderEntity; Funder funderEntity;
//Create Funder //Create Funder
if (quickWizard.getFunder() == null) { if (quickWizard.getFunder() == null) {
throw new Exception("Funder is a mandatory entity"); funderEntity = null;
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) { } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
throw new Exception("Funder is a mandatory entity"); funderEntity = null;
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) { } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal); funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
} else { } else {
@ -58,9 +58,9 @@ public class QuickWizardController extends BaseController {
eu.eudat.data.entities.Grant grantEntity; eu.eudat.data.entities.Grant grantEntity;
//Create Grant //Create Grant
if (quickWizard.getGrant() == null) { if (quickWizard.getGrant() == null) {
throw new Exception("Grant is a mandatory entity"); grantEntity = null;
} else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) { } else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) {
throw new Exception("Grant is a mandatory entity"); grantEntity = null;
} else if (quickWizard.getGrant().getExistGrant() == null) { } else if (quickWizard.getGrant().getExistGrant() == null) {
grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal); grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal);
} else { } else {

View File

@ -91,7 +91,9 @@ public class DashBoardManager {
for (DMP dmp : dmps) { for (DMP dmp : dmps) {
numberOfDatasets = numberOfDatasets + dmp.getDataset().stream() numberOfDatasets = numberOfDatasets + dmp.getDataset().stream()
.filter(item -> item.getStatus() == Dataset.Status.FINALISED.getValue()).count(); .filter(item -> item.getStatus() == Dataset.Status.FINALISED.getValue()).count();
grants.add(dmp.getGrant()); if (dmp.getGrant() != null) {
grants.add(dmp.getGrant());
}
} }
statistics.setTotalDataManagementPlanCount((long) dmps.size()); statistics.setTotalDataManagementPlanCount((long) dmps.size());

View File

@ -53,6 +53,7 @@ import eu.eudat.models.data.doi.Doi;
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue; import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.*; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.*;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.FieldCategory; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.FieldCategory;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.SystemFieldType;
import eu.eudat.models.data.funder.FunderDMPEditorModel; import eu.eudat.models.data.funder.FunderDMPEditorModel;
import eu.eudat.models.data.grant.GrantDMPEditorModel; import eu.eudat.models.data.grant.GrantDMPEditorModel;
import eu.eudat.models.data.helpermodels.Tuple; import eu.eudat.models.data.helpermodels.Tuple;
@ -110,6 +111,7 @@ public class DataManagementPlanManager {
private ApiContext apiContext; private ApiContext apiContext;
private DatasetManager datasetManager; private DatasetManager datasetManager;
private DataManagementProfileManager dataManagementProfileManager;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
private Environment environment; private Environment environment;
private RDAManager rdaManager; private RDAManager rdaManager;
@ -119,10 +121,11 @@ public class DataManagementPlanManager {
private List<RepositoryDeposit> repositoriesDeposit; private List<RepositoryDeposit> repositoriesDeposit;
@Autowired @Autowired
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager, public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, DataManagementProfileManager dataManagementProfileManager, Environment environment, RDAManager rdaManager, UserManager userManager,
MetricsManager metricsManager, ConfigLoader configLoader, List<RepositoryDeposit> repositoriesDeposit) { MetricsManager metricsManager, ConfigLoader configLoader, List<RepositoryDeposit> repositoriesDeposit) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.datasetManager = datasetManager; this.datasetManager = datasetManager;
this.dataManagementProfileManager = dataManagementProfileManager;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.environment = environment; this.environment = environment;
this.rdaManager = rdaManager; this.rdaManager = rdaManager;
@ -486,14 +489,24 @@ public class DataManagementPlanManager {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
newDmp.setCreator(user); newDmp.setCreator(user);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) {
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); }
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.RESEARCHERS, principal)) {
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) { createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
}
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
}
} }
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
DMP dmp; DMP dmp;
if (dataManagementPlan.getId() != null) { if (dataManagementPlan.getId() != null) {
@ -513,12 +526,18 @@ public class DataManagementPlanManager {
} }
} }
if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
checkIfUserCanEditGrant(newDmp, user); if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
checkIfUserCanEditGrant(newDmp, user);
}
assignGrandUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
assignFunderUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
assignProjectUserIfInternal(newDmp, user);
} }
assignGrandUserIfInternal(newDmp, user);
assignFunderUserIfInternal(newDmp, user);
assignProjectUserIfInternal(newDmp, user);
if(newDmp.getId() != null){ if(newDmp.getId() != null){
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
@ -526,7 +545,9 @@ public class DataManagementPlanManager {
} }
} }
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
}
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
@ -622,10 +643,18 @@ public class DataManagementPlanManager {
checkDmpValidationRules(tempDMP); checkDmpValidationRules(tempDMP);
} }
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) {
createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); }
createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), SystemFieldType.RESEARCHERS, principal)) {
createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), SystemFieldType.FUNDER, principal)) {
createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
}
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), SystemFieldType.GRANT, principal)) {
createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
}
DMP result = createOrUpdate(dataManagementPlan, principal); DMP result = createOrUpdate(dataManagementPlan, principal);
@ -660,31 +689,50 @@ public class DataManagementPlanManager {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
newDmp.setCreator(user); newDmp.setCreator(user);
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) {
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
}
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.RESEARCHERS, principal)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) { }
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
}
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
}
} }
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
newDmp.setGroupId(oldDmp.getGroupId()); newDmp.setGroupId(oldDmp.getGroupId());
newDmp.setVersion(oldDmp.getVersion() + 1); newDmp.setVersion(oldDmp.getVersion() + 1);
newDmp.setId(null); newDmp.setId(null);
checkIfUserCanEditGrant(newDmp, user); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
assignGrandUserIfInternal(newDmp, user); if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
assignFunderUserIfInternal(newDmp, user); checkIfUserCanEditGrant(newDmp, user);
assignProjectUserIfInternal(newDmp, user); }
if (newDmp.getGrant().getStartdate() == null) { assignGrandUserIfInternal(newDmp, user);
newDmp.getGrant().setStartdate(new Date());
} }
if (newDmp.getGrant().getEnddate() == null) { if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); assignFunderUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
assignProjectUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
if (newDmp.getGrant().getStartdate() == null) {
newDmp.getGrant().setStartdate(new Date());
}
if (newDmp.getGrant().getEnddate() == null) {
newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS)));
}
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
} }
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
newDmp.setId(tempDmp.getId()); newDmp.setId(tempDmp.getId());
@ -721,25 +769,44 @@ public class DataManagementPlanManager {
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
newDmp.setCreator(user); newDmp.setCreator(user);
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) {
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
}
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.RESEARCHERS, principal)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) { }
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
}
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
}
} }
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
newDmp.setGroupId(UUID.randomUUID()); newDmp.setGroupId(UUID.randomUUID());
newDmp.setVersion(0); newDmp.setVersion(0);
newDmp.setId(null); newDmp.setId(null);
checkIfUserCanEditGrant(newDmp, user); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
assignGrandUserIfInternal(newDmp, user); if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
assignFunderUserIfInternal(newDmp, user); checkIfUserCanEditGrant(newDmp, user);
assignProjectUserIfInternal(newDmp, user); }
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); assignGrandUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.FUNDER, principal)) {
assignFunderUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.PROJECT, principal)) {
assignProjectUserIfInternal(newDmp, user);
}
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) {
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
}
DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
newDmp.setId(tempDmp.getId()); newDmp.setId(tempDmp.getId());
@ -882,7 +949,7 @@ public class DataManagementPlanManager {
} }
private void createFunderIfItDoesntExist(DMP newDmp, FunderDao funderDao) { private void createFunderIfItDoesntExist(DMP newDmp, FunderDao funderDao) {
if (newDmp.getGrant().getFunder() != null) { if (newDmp.getGrant() != null && newDmp.getGrant().getFunder() != null) {
Funder funder = newDmp.getGrant().getFunder(); Funder funder = newDmp.getGrant().getFunder();
FunderCriteria criteria = new FunderCriteria(); FunderCriteria criteria = new FunderCriteria();
if (funder.getReference() != null) { if (funder.getReference() != null) {
@ -1005,7 +1072,9 @@ public class DataManagementPlanManager {
datasetElastic.setStatus(dataset1.getStatus()); datasetElastic.setStatus(dataset1.getStatus());
datasetElastic.setDmp(dataset1.getDmp().getId()); datasetElastic.setDmp(dataset1.getDmp().getId());
datasetElastic.setGroup(dataset1.getDmp().getGroupId()); datasetElastic.setGroup(dataset1.getDmp().getGroupId());
datasetElastic.setGrant(dataset1.getDmp().getGrant().getId()); if(this.dataManagementProfileManager.fieldInBlueprint(dataset1.getDmp().getProfile(), SystemFieldType.GRANT, null)) {
datasetElastic.setGrant(dataset1.getDmp().getGrant().getId());
}
if (dataset1.getDmp().getUsers() != null) { if (dataset1.getDmp().getUsers() != null) {
datasetElastic.setCollaborators(dataset1.getDmp().getUsers().stream().map(user -> { datasetElastic.setCollaborators(dataset1.getDmp().getUsers().stream().map(user -> {
Collaborator collaborator = new Collaborator(); Collaborator collaborator = new Collaborator();
@ -1026,7 +1095,9 @@ public class DataManagementPlanManager {
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
datasetElastic.setPublic(dataset1.getDmp().isPublic()); datasetElastic.setPublic(dataset1.getDmp().isPublic());
datasetElastic.setGrantStatus(dataset1.getDmp().getGrant().getStatus()); if(this.dataManagementProfileManager.fieldInBlueprint(dataset1.getDmp().getProfile(), SystemFieldType.GRANT, null)) {
datasetElastic.setGrantStatus(dataset1.getDmp().getGrant().getStatus());
}
try { try {
eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()); eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
@ -1660,53 +1731,59 @@ public class DataManagementPlanManager {
// Funder. // Funder.
Element funder = xmlDoc.createElement("funder"); Element funder = xmlDoc.createElement("funder");
Element funderLabel = xmlDoc.createElement("label"); if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), SystemFieldType.GRANT, principal) && this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), SystemFieldType.FUNDER, principal)) {
Element funderId = xmlDoc.createElement("id"); Element funderLabel = xmlDoc.createElement("label");
funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel()); Element funderId = xmlDoc.createElement("id");
funderId.setTextContent(dmp.getGrant().getFunder().getId().toString()); funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel());
funder.appendChild(funderLabel); funderId.setTextContent(dmp.getGrant().getFunder().getId().toString());
funder.appendChild(funderId); funder.appendChild(funderLabel);
if(dmp.getGrant().getFunder().getReference() != null){ funder.appendChild(funderId);
String referencePrefix = dmp.getGrant().getFunder().getReference().split(":")[0]; if (dmp.getGrant().getFunder().getReference() != null) {
String shortReference = dmp.getGrant().getFunder().getReference().substring(referencePrefix.length() + 1); String referencePrefix = dmp.getGrant().getFunder().getReference().split(":")[0];
Element funderReference = xmlDoc.createElement("reference"); String shortReference = dmp.getGrant().getFunder().getReference().substring(referencePrefix.length() + 1);
funderReference.setTextContent(shortReference); Element funderReference = xmlDoc.createElement("reference");
funder.appendChild(funderReference); funderReference.setTextContent(shortReference);
funder.appendChild(funderReference);
}
} }
dmpElement.appendChild(funder); dmpElement.appendChild(funder);
// Grant. // Grant.
Element grant = xmlDoc.createElement("grant"); Element grant = xmlDoc.createElement("grant");
Element grantLabel = xmlDoc.createElement("label"); if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), SystemFieldType.GRANT, principal)) {
Element grantId = xmlDoc.createElement("id"); Element grantLabel = xmlDoc.createElement("label");
grantLabel.setTextContent(dmp.getGrant().getLabel()); Element grantId = xmlDoc.createElement("id");
grantId.setTextContent(dmp.getGrant().getId().toString()); grantLabel.setTextContent(dmp.getGrant().getLabel());
grant.appendChild(grantLabel); grantId.setTextContent(dmp.getGrant().getId().toString());
grant.appendChild(grantId); grant.appendChild(grantLabel);
if(dmp.getGrant().getReference() != null) { grant.appendChild(grantId);
String referencePrefix = dmp.getGrant().getReference().split(":")[0]; if (dmp.getGrant().getReference() != null) {
String shortReference = dmp.getGrant().getReference().substring(referencePrefix.length() + 1); String referencePrefix = dmp.getGrant().getReference().split(":")[0];
Element grantReference = xmlDoc.createElement("reference"); String shortReference = dmp.getGrant().getReference().substring(referencePrefix.length() + 1);
grantReference.setTextContent(shortReference); Element grantReference = xmlDoc.createElement("reference");
grant.appendChild(grantReference); grantReference.setTextContent(shortReference);
grant.appendChild(grantReference);
}
} }
dmpElement.appendChild(grant); dmpElement.appendChild(grant);
// Project. // Project.
Element project = xmlDoc.createElement("project"); Element project = xmlDoc.createElement("project");
Element projectId = xmlDoc.createElement("id"); if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), SystemFieldType.PROJECT, principal)) {
Element projectLabel = xmlDoc.createElement("label"); Element projectId = xmlDoc.createElement("id");
Element projectDescription = xmlDoc.createElement("description"); Element projectLabel = xmlDoc.createElement("label");
Element projectStartDate = xmlDoc.createElement("start"); Element projectDescription = xmlDoc.createElement("description");
Element projectEndDate = xmlDoc.createElement("end"); Element projectStartDate = xmlDoc.createElement("start");
projectId.setTextContent(dmp.getProject().getId().toString()); Element projectEndDate = xmlDoc.createElement("end");
projectLabel.setTextContent(dmp.getProject().getLabel()); projectId.setTextContent(dmp.getProject().getId().toString());
projectDescription.setTextContent(dmp.getProject().getDescription()); projectLabel.setTextContent(dmp.getProject().getLabel());
projectStartDate.setTextContent(dmp.getProject().getStartdate().toString()); projectDescription.setTextContent(dmp.getProject().getDescription());
projectEndDate.setTextContent(dmp.getProject().getEnddate().toString()); projectStartDate.setTextContent(dmp.getProject().getStartdate().toString());
project.appendChild(projectId); projectEndDate.setTextContent(dmp.getProject().getEnddate().toString());
project.appendChild(projectLabel); project.appendChild(projectId);
project.appendChild(projectDescription); project.appendChild(projectLabel);
project.appendChild(projectStartDate); project.appendChild(projectDescription);
project.appendChild(projectEndDate); project.appendChild(projectStartDate);
project.appendChild(projectEndDate);
}
dmpElement.appendChild(project); dmpElement.appendChild(project);
Element organisationsElement = xmlDoc.createElement("organisations"); Element organisationsElement = xmlDoc.createElement("organisations");

View File

@ -13,8 +13,9 @@ import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ExportXmlBuilderDmpProfile; import eu.eudat.logic.utilities.documents.xml.dmpXml.ExportXmlBuilderDmpProfile;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ImportXmlBuilderDmpProfile; import eu.eudat.logic.utilities.documents.xml.dmpXml.ImportXmlBuilderDmpProfile;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DmpProfileExternalAutoComplete; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.*;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.FieldCategory;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.SystemFieldType;
import eu.eudat.models.data.helpermodels.Tuple; import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem; import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
@ -101,13 +102,29 @@ public class DataManagementProfileManager {
return dataManagementPlanProfileListingModel; return dataManagementPlanProfileListingModel;
} }
public DataManagementPlanBlueprintListingModel getSingleBlueprint(String id, Principal principal) throws InstantiationException, IllegalAccessException { public DataManagementPlanBlueprintListingModel getSingleBlueprint(String id, Principal principal) {
DMPProfile dmpProfile = databaseRepository.getDmpProfileDao().find(UUID.fromString(id)); DMPProfile dmpProfile = databaseRepository.getDmpProfileDao().find(UUID.fromString(id));
DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = new DataManagementPlanBlueprintListingModel(); DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = new DataManagementPlanBlueprintListingModel();
dataManagementPlanBlueprintListingModel.fromDataModel(dmpProfile); dataManagementPlanBlueprintListingModel.fromDataModel(dmpProfile);
return dataManagementPlanBlueprintListingModel; return dataManagementPlanBlueprintListingModel;
} }
public boolean fieldInBlueprint(DMPProfile dmpProfile, SystemFieldType type, Principal principal) {
DataManagementPlanBlueprintListingModel dmpBlueprint = new DataManagementPlanBlueprintListingModel();
dmpBlueprint.fromDataModel(dmpProfile);
for(Section section: dmpBlueprint.getDefinition().getSections()){
for(FieldModel field: section.getFields()){
if(field.getCategory().equals(FieldCategory.SYSTEM)){
SystemField systemField = field.toSystemField();
if(systemField.getType().equals(type)){
return true;
}
}
}
}
return false;
}
public List<DataManagementPlanProfileListingModel> getWithCriteria(DataManagementPlanProfileCriteriaRequest dataManagementPlanProfileCriteriaRequest) throws IllegalAccessException, InstantiationException { public List<DataManagementPlanProfileListingModel> getWithCriteria(DataManagementPlanProfileCriteriaRequest dataManagementPlanProfileCriteriaRequest) throws IllegalAccessException, InstantiationException {
QueryableList<DMPProfile> items = databaseRepository.getDmpProfileDao().getWithCriteria(dataManagementPlanProfileCriteriaRequest.getCriteria()); QueryableList<DMPProfile> items = databaseRepository.getDmpProfileDao().getWithCriteria(dataManagementPlanProfileCriteriaRequest.getCriteria());
List<DataManagementPlanProfileListingModel> datamanagementPlans = items.select(item -> new DataManagementPlanProfileListingModel().fromDataModel(item)); List<DataManagementPlanProfileListingModel> datamanagementPlans = items.select(item -> new DataManagementPlanProfileListingModel().fromDataModel(item));

View File

@ -50,7 +50,9 @@ public class DatasetMapper {
elastic.setStatus(dataset.getStatus()); elastic.setStatus(dataset.getStatus());
elastic.setDmp(dataset.getDmp().getId()); elastic.setDmp(dataset.getDmp().getId());
elastic.setGroup(dataset.getDmp().getGroupId()); elastic.setGroup(dataset.getDmp().getGroupId());
elastic.setGrant(dataset.getDmp().getGrant().getId()); if (dataset.getDmp().getGrant() != null) {
elastic.setGrant(dataset.getDmp().getGrant().getId());
}
elastic.setCreated(dataset.getCreated()); elastic.setCreated(dataset.getCreated());
elastic.setModified(dataset.getModified()); elastic.setModified(dataset.getModified());
elastic.setFinalizedAt(dataset.getFinalizedAt()); elastic.setFinalizedAt(dataset.getFinalizedAt());
@ -74,7 +76,9 @@ public class DatasetMapper {
elastic.setOrganizations(dataset.getDmp().getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList())); elastic.setOrganizations(dataset.getDmp().getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList()));
} }
elastic.setPublic(dataset.getDmp().isPublic()); elastic.setPublic(dataset.getDmp().isPublic());
elastic.setGrantStatus(dataset.getDmp().getGrant().getStatus()); if (dataset.getDmp().getGrant() != null) {
elastic.setGrantStatus(dataset.getDmp().getGrant().getStatus());
}
elastic.setFormData(datasetManager.getWordDocumentText(dataset)); elastic.setFormData(datasetManager.getWordDocumentText(dataset));
return elastic; return elastic;

View File

@ -37,7 +37,9 @@ public class DmpMapper {
elastic.setCollaborators(dmp.getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList())); elastic.setCollaborators(dmp.getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList()));
} }
elastic.setDescription(dmp.getDescription()); elastic.setDescription(dmp.getDescription());
elastic.setGrant(dmp.getGrant().getId()); if (dmp.getGrant() != null) {
elastic.setGrant(dmp.getGrant().getId());
}
elastic.setLabel(dmp.getLabel()); elastic.setLabel(dmp.getLabel());
elastic.setPublic(dmp.isPublic()); elastic.setPublic(dmp.isPublic());
elastic.setStatus(dmp.getStatus()); elastic.setStatus(dmp.getStatus());

View File

@ -37,7 +37,9 @@ public class DMPToDepositMapper {
deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet())); deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet())); deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet())); deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
deposit.setGrant(fromGrant(entity.getGrant())); if (entity.getGrant() != null) {
deposit.setGrant(fromGrant(entity.getGrant()));
}
deposit.setPdfFile(pdfFile); deposit.setPdfFile(pdfFile);
deposit.setRdaJsonFile(jsonFile); deposit.setRdaJsonFile(jsonFile);

View File

@ -242,9 +242,14 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.version = entity.getVersion(); this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : entity.getGroupId(); this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.grant = new Grant();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
this.grant.fromDataModel(entity.getGrant()); if(entity.getGrant() != null) {
this.grant = new Grant();
this.grant.fromDataModel(entity.getGrant());
}
else {
this.grant = null;
}
this.creator = new eu.eudat.models.data.userinfo.UserInfo(); this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId(); this.groupId = entity.getGroupId();
this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
@ -296,7 +301,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.project = new Project().fromDataModel(entity.getProject()); this.project = new Project().fromDataModel(entity.getProject());
} }
if (entity.getGrant().getFunder() != null) { if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
this.funder = new Funder(); this.funder = new Funder();
this.funder.fromDataModel(entity.getGrant().getFunder()); this.funder.fromDataModel(entity.getGrant().getFunder());
} }
@ -362,7 +367,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.version = entity.getVersion(); this.version = entity.getVersion();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.grant = new Grant();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
this.creator = new eu.eudat.models.data.userinfo.UserInfo(); this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId(); this.groupId = entity.getGroupId();
@ -398,13 +402,19 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
this.grant.fromDataModel(entity.getGrant()); if(entity.getGrant() != null) {
this.grant = new Grant();
this.grant.fromDataModel(entity.getGrant());
}
else {
this.grant = null;
}
if (entity.getProject() != null) { if (entity.getProject() != null) {
this.project = new Project(); this.project = new Project();
this.project = new Project().fromDataModel(entity.getProject()); this.project = new Project().fromDataModel(entity.getProject());
} }
if (entity.getGrant().getFunder() != null) { if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
this.funder = new Funder(); this.funder = new Funder();
this.funder.fromDataModel(entity.getGrant().getFunder()); this.funder.fromDataModel(entity.getGrant().getFunder());
} }

View File

@ -314,13 +314,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
} }
} }
if (this.funder == null) { if (this.funder != null) {
// dataManagementPlanEntity.getGrant().setFunder(null);
throw new Exception("Funder is a mandatory entity");
} else if (this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
// dataManagementPlanEntity.getGrant().setFunder(null);
throw new Exception("Funder is a mandatory entity");
} else {
if (this.funder.getLabel() != null) { if (this.funder.getLabel() != null) {
Funder funder = new Funder(); Funder funder = new Funder();
funder.setId(UUID.randomUUID()); funder.setId(UUID.randomUUID());

View File

@ -214,13 +214,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
} }
} }
if (this.funder == null) { if (this.funder != null) {
// dataManagementPlanEntity.getGrant().setFunder(null);
throw new Exception("Funder is a mandatory entity");
} else if (this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
// dataManagementPlanEntity.getGrant().setFunder(null);
throw new Exception("Funder is a mandatory entity");
} else {
if (this.funder.getLabel() != null) { if (this.funder.getLabel() != null) {
Funder funder = new Funder(); Funder funder = new Funder();
funder.setId(UUID.randomUUID()); funder.setId(UUID.randomUUID());

View File

@ -147,7 +147,7 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.fromDataModel(entity); this.fromDataModel(entity);
this.status = entity.getStatus(); this.status = entity.getStatus();
this.version = entity.getVersion(); this.version = entity.getVersion();
this.grant = entity.getGrant().getLabel(); this.grant = (entity.getGrant() != null) ? entity.getGrant().getLabel() : null;
this.creationTime = entity.getCreated(); this.creationTime = entity.getCreated();
this.modifiedTime = entity.getModified(); this.modifiedTime = entity.getModified();
this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList());

View File

@ -104,7 +104,9 @@ public class DmpRDAMapper {
} }
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); // rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList())); rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); if (dmp.getProject() != null) {
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
}
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray()); rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
return rda; return rda;
} }

View File

@ -94,7 +94,7 @@ CREATE TABLE public."DMP" (
"GroupId" uuid, "GroupId" uuid,
"Label" character varying(250) NOT NULL, "Label" character varying(250) NOT NULL,
"Version" integer NOT NULL, "Version" integer NOT NULL,
"Grant" uuid NOT NULL, "Grant" uuid,
"AssociatedDmps" xml, "AssociatedDmps" xml,
"Profile" uuid, "Profile" uuid,
"Status" smallint DEFAULT 0 NOT NULL, "Status" smallint DEFAULT 0 NOT NULL,
@ -130,7 +130,7 @@ CREATE TABLE public."DMPDatasetProfile" (
"ID" uuid DEFAULT public.uuid_generate_v4() NOT NULL, "ID" uuid DEFAULT public.uuid_generate_v4() NOT NULL,
dmp uuid NOT NULL, dmp uuid NOT NULL,
datasetprofile uuid NOT NULL, datasetprofile uuid NOT NULL,
"data" text "data" text NOT NULL
); );
@ -236,7 +236,7 @@ CREATE TABLE public."Dataset" (
"ID" uuid DEFAULT public.uuid_generate_v4() NOT NULL, "ID" uuid DEFAULT public.uuid_generate_v4() NOT NULL,
"Label" character varying(250) NOT NULL, "Label" character varying(250) NOT NULL,
"DMP" uuid, "DMP" uuid,
"DmpSectionIndex" integer, "DmpSectionIndex" integer NOT NULL,
"Uri" character varying(250), "Uri" character varying(250),
"Properties" text, "Properties" text,
"Profile" uuid, "Profile" uuid,

View File

@ -0,0 +1,12 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.00.017';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."DMP"
ALTER COLUMN "Grant" DROP NOT NULL;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.017', '2023-09-18 12:00:00.000000+02', now(), 'Make grant column of dmp table not null.');
END$$;

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms'; import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request'; import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; import { DmpBlueprintDefinition, FieldCategory, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
import { DmpBlueprintCriteria } from '@app/core/query/dmp/dmp-blueprint-criteria'; import { DmpBlueprintCriteria } from '@app/core/query/dmp/dmp-blueprint-criteria';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
@ -178,6 +178,9 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(result => { .subscribe(result => {
this.selectedDmpBlueprintDefinition = result.definition; this.selectedDmpBlueprintDefinition = result.definition;
this.checkForGrant();
this.checkForFunder();
this.checkForProject();
this.formGroup.get('profile').setValue(result); this.formGroup.get('profile').setValue(result);
this.maxStep = this.selectedDmpBlueprintDefinition.sections.length; this.maxStep = this.selectedDmpBlueprintDefinition.sections.length;
this.step = 1; this.step = 1;
@ -784,6 +787,9 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
.subscribe(Option => { .subscribe(Option => {
if (Option instanceof Object) { if (Option instanceof Object) {
this.selectedDmpBlueprintDefinition = Option.definition; this.selectedDmpBlueprintDefinition = Option.definition;
this.checkForGrant();
this.checkForFunder();
this.checkForProject();
this.addProfiles(); this.addProfiles();
} }
else { else {
@ -792,6 +798,48 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
}) })
} }
private checkForGrant() {
let hasGrant = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder() {
let hasFunder = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject() {
let hasProject = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
private addProfiles(profiles?: DmpDatasetProfile[]) { private addProfiles(profiles?: DmpDatasetProfile[]) {
for(let i = 0; i < this.selectedDmpBlueprintDefinition.sections.length; i++){ for(let i = 0; i < this.selectedDmpBlueprintDefinition.sections.length; i++){
this.sectionTemplates.push(new Array<DatasetProfileModel>()); this.sectionTemplates.push(new Array<DatasetProfileModel>());

View File

@ -134,9 +134,9 @@ export class DmpEditorModel {
baseContext.validation.push({ key: 'version', validators: [BackendErrorValidator(this.validationErrorModel, 'version')] }); baseContext.validation.push({ key: 'version', validators: [BackendErrorValidator(this.validationErrorModel, 'version')] });
baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] }); baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] });
baseContext.validation.push({ key: 'description', validators: [BackendErrorValidator(this.validationErrorModel, 'description')] }); baseContext.validation.push({ key: 'description', validators: [BackendErrorValidator(this.validationErrorModel, 'description')] });
baseContext.validation.push({ key: 'grant', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'grant')] }); baseContext.validation.push({ key: 'grant', validators: [BackendErrorValidator(this.validationErrorModel, 'grant')] });
baseContext.validation.push({ key: 'project', validators: [BackendErrorValidator(this.validationErrorModel, 'project')] }); baseContext.validation.push({ key: 'project', validators: [BackendErrorValidator(this.validationErrorModel, 'project')] });
baseContext.validation.push({ key: 'funder', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'funder')] }); baseContext.validation.push({ key: 'funder', validators: [BackendErrorValidator(this.validationErrorModel, 'funder')] });
baseContext.validation.push({ key: 'organisations', validators: [BackendErrorValidator(this.validationErrorModel, 'organisations')] }); baseContext.validation.push({ key: 'organisations', validators: [BackendErrorValidator(this.validationErrorModel, 'organisations')] });
baseContext.validation.push({ key: 'researchers', validators: [BackendErrorValidator(this.validationErrorModel, 'researchers')] }); baseContext.validation.push({ key: 'researchers', validators: [BackendErrorValidator(this.validationErrorModel, 'researchers')] });
baseContext.validation.push({ key: 'profiles', validators: [Validators.required, ValidJsonValidator, BackendErrorValidator(this.validationErrorModel, 'profiles')] }); baseContext.validation.push({ key: 'profiles', validators: [Validators.required, ValidJsonValidator, BackendErrorValidator(this.validationErrorModel, 'profiles')] });