Fix issues with xml import and issues with zenodo deposit

This commit is contained in:
George Kalampokis 2021-07-06 12:58:38 +03:00
parent cfff87b7d0
commit efe177f0b1
5 changed files with 57 additions and 24 deletions

View File

@ -260,7 +260,7 @@ public class DMPs extends BaseController {
if (files[0].getContentType().equals(APPLICATION_JSON.toString())) { if (files[0].getContentType().equals(APPLICATION_JSON.toString())) {
this.dataManagementPlanManager.createFromRDA(files, principal, profiles); this.dataManagementPlanManager.createFromRDA(files, principal, profiles);
} else if (files[0].getContentType().equals(APPLICATION_ATOM_XML.toString()) || files[0].getContentType().equals(TEXT_XML.toString())) { } else if (files[0].getContentType().equals(APPLICATION_ATOM_XML.toString()) || files[0].getContentType().equals(TEXT_XML.toString())) {
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal); this.dataManagementPlanManager.createDmpFromXml(files, principal, profiles);
} else { } else {
return ResponseEntity.badRequest().body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("File format is not supported")); return ResponseEntity.badRequest().body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("File format is not supported"));
} }

View File

@ -1476,7 +1476,7 @@ public class DataManagementPlanManager {
* Data Import * Data Import
* */ * */
public List<DmpImportModel> createDmpFromXml(ApiContext apiContext, MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception { public List<DmpImportModel> createDmpFromXml(MultipartFile[] files, Principal principal, String[] profiles) throws IOException, JAXBException, Exception {
List<DmpImportModel> dataManagementPlans = new ArrayList<>(); List<DmpImportModel> dataManagementPlans = new ArrayList<>();
// Jaxb approach. // Jaxb approach.
JAXBContext jaxbContext; JAXBContext jaxbContext;
@ -1532,16 +1532,26 @@ public class DataManagementPlanManager {
projectEditor.setExistProject(project); projectEditor.setExistProject(project);
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>(); List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) { if (profiles != null && profiles.length > 0) {
AssociatedProfile associatedProfile = new AssociatedProfile(); for (String profile : profiles) {
associatedProfile.setId(a.getId()); DatasetProfile exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile));
associatedProfile.setLabel(a.getLabel()); AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
associatedProfiles.add(associatedProfile); associatedProfiles.add(associatedProfile);
} }
}
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
try {
DatasetProfile exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(a.getId());
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
associatedProfiles.add(associatedProfile);
} catch (Exception ignored) {
}
}
List<eu.eudat.models.data.dmp.Organisation> organisations = new ArrayList<>(); List<eu.eudat.models.data.dmp.Organisation> organisations = new ArrayList<>();
for (OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) { for (OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
eu.eudat.models.data.dmp.Organisation organisation = new eu.eudat.models.data.dmp.Organisation(); eu.eudat.models.data.dmp.Organisation organisation = new eu.eudat.models.data.dmp.Organisation();
organisation.setLabel(org.getOrganaisationNameImport()); organisation.setName(org.getOrganaisationNameImport());
organisation.setReference(org.getOrganaisationReferenceImport()); organisation.setReference(org.getOrganaisationReferenceImport());
organisation.setKey(organisation.getReference().split(":")[0]); organisation.setKey(organisation.getReference().split(":")[0]);
organisations.add(organisation); organisations.add(organisation);
@ -1593,7 +1603,11 @@ public class DataManagementPlanManager {
for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) { for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) {
eu.eudat.data.entities.Dataset dataset = new eu.eudat.data.entities.Dataset(); eu.eudat.data.entities.Dataset dataset = new eu.eudat.data.entities.Dataset();
dataset.setLabel(das.getName()); dataset.setLabel(das.getName());
try {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile())); dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile()));
} catch (Exception ignored) {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getId()));
}
dataset.setProperties(new ObjectMapper().writeValueAsString(das.getFieldImportModels())); dataset.setProperties(new ObjectMapper().writeValueAsString(das.getFieldImportModels()));
dataset.setStatus((short) 0); dataset.setStatus((short) 0);
dataset.setRegistries(new HashSet<>()); dataset.setRegistries(new HashSet<>());
@ -1972,6 +1986,9 @@ public class DataManagementPlanManager {
i++; i++;
} }
dataBuilder.append("],\n"); dataBuilder.append("],\n");
if (dmp.getGrant().getReference() == null) {
dmp.getGrant().setReference("dmp:" + dmp.getGrant().getId());
}
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0]; String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
if (grantReferenceHead.equals("openaire")) { if (grantReferenceHead.equals("openaire")) {
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3]; String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
@ -1980,6 +1997,7 @@ public class DataManagementPlanManager {
dataBuilder.append(" \"grants\": [{\n"); dataBuilder.append(" \"grants\": [{\n");
dataBuilder.append(" \t\t\"id\": \"").append(finalId).append("\"\n}],\n"); dataBuilder.append(" \t\t\"id\": \"").append(finalId).append("\"\n}],\n");
} }
dataBuilder.append(" \"creators\": [{\n"); dataBuilder.append(" \"creators\": [{\n");
dataBuilder.append(" \t\t\"name\": \"").append(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName()).append("\",\n"); dataBuilder.append(" \t\t\"name\": \"").append(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName()).append("\",\n");
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) { if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {

View File

@ -108,7 +108,7 @@ public class DatasetRDAMapper {
for (int i = 0; i < keywordNodes.size(); i++) { for (int i = 0; i < keywordNodes.size(); i++) {
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText()); rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
} }
} else { } else if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList()); List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList());
rda.setKeyword(tags); rda.setKeyword(tags);
} }

View File

@ -6,11 +6,13 @@ import eu.eudat.data.entities.Grant;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Funding; import eu.eudat.models.rda.Funding;
import javax.transaction.Transactional;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
public class FundingRDAMapper { public class FundingRDAMapper {
@Transactional
public static Funding toRDA(Grant grant) { public static Funding toRDA(Grant grant) {
Funding rda = new Funding(); Funding rda = new Funding();
String referencePrefix; String referencePrefix;
@ -22,9 +24,13 @@ public class FundingRDAMapper {
} else { } else {
rda.setFunderId(FunderIdRDAMapper.toRDA(grant.getFunder().getId())); rda.setFunderId(FunderIdRDAMapper.toRDA(grant.getFunder().getId()));
} }
if (grant.getReference() != null) {
referencePrefix = grant.getReference().split(":")[0]; referencePrefix = grant.getReference().split(":")[0];
shortReference = grant.getReference().substring(referencePrefix.length() + 1); shortReference = grant.getReference().substring(referencePrefix.length() + 1);
rda.setGrantId(GrantIdRDAMapper.toRDA(shortReference)); rda.setGrantId(GrantIdRDAMapper.toRDA(shortReference));
} else {
rda.setGrantId(GrantIdRDAMapper.toRDA(grant.getId().toString()));
}
return rda; return rda;
} }

View File

@ -4,13 +4,19 @@ import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.Grant; import eu.eudat.data.entities.Grant;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Project; import eu.eudat.models.rda.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.transaction.Transactional;
import java.util.*; import java.util.*;
public class ProjectRDAMapper { public class ProjectRDAMapper {
private final static Logger logger = LoggerFactory.getLogger(ProjectRDAMapper.class);
@Transactional
public static Project toRDA(eu.eudat.data.entities.Project project, Grant grant) { public static Project toRDA(eu.eudat.data.entities.Project project, Grant grant) {
Project rda = new Project(); Project rda = new Project();
try {
rda.setTitle(project.getLabel()); rda.setTitle(project.getLabel());
rda.setDescription(project.getDescription()); rda.setDescription(project.getDescription());
if (project.getStartdate() != null) { if (project.getStartdate() != null) {
@ -24,6 +30,9 @@ public class ProjectRDAMapper {
if (rda.getTitle() == null) { if (rda.getTitle() == null) {
throw new IllegalArgumentException("Project Title is missing"); throw new IllegalArgumentException("Project Title is missing");
} }
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
}
return rda; return rda;
} }