Fix issues with xml import and issues with zenodo deposit

(cherry picked from commit efe177f0b1)
This commit is contained in:
George Kalampokis 2021-07-06 12:58:38 +03:00 committed by Diamantis Tziotzios
parent d1fc10854c
commit e5a929f259
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())) {
this.dataManagementPlanManager.createFromRDA(files, principal, profiles);
} 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 {
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
* */
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<>();
// Jaxb approach.
JAXBContext jaxbContext;
@ -1532,16 +1532,26 @@ public class DataManagementPlanManager {
projectEditor.setExistProject(project);
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
if (profiles != null && profiles.length > 0) {
for (String profile : profiles) {
DatasetProfile exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile));
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
associatedProfiles.add(associatedProfile);
}
}
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
AssociatedProfile associatedProfile = new AssociatedProfile();
associatedProfile.setId(a.getId());
associatedProfile.setLabel(a.getLabel());
associatedProfiles.add(associatedProfile);
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<>();
for (OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
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.setKey(organisation.getReference().split(":")[0]);
organisations.add(organisation);
@ -1593,7 +1603,11 @@ public class DataManagementPlanManager {
for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) {
eu.eudat.data.entities.Dataset dataset = new eu.eudat.data.entities.Dataset();
dataset.setLabel(das.getName());
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile()));
try {
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.setStatus((short) 0);
dataset.setRegistries(new HashSet<>());
@ -1972,6 +1986,9 @@ public class DataManagementPlanManager {
i++;
}
dataBuilder.append("],\n");
if (dmp.getGrant().getReference() == null) {
dmp.getGrant().setReference("dmp:" + dmp.getGrant().getId());
}
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
if (grantReferenceHead.equals("openaire")) {
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
@ -1980,6 +1997,7 @@ public class DataManagementPlanManager {
dataBuilder.append(" \"grants\": [{\n");
dataBuilder.append(" \t\t\"id\": \"").append(finalId).append("\"\n}],\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");
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {

View File

@ -108,7 +108,7 @@ public class DatasetRDAMapper {
for (int i = 0; i < keywordNodes.size(); i++) {
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());
rda.setKeyword(tags);
}

View File

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

View File

@ -4,25 +4,34 @@ import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.Grant;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.transaction.Transactional;
import java.util.*;
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) {
Project rda = new Project();
rda.setTitle(project.getLabel());
rda.setDescription(project.getDescription());
if (project.getStartdate() != null) {
rda.setStart(project.getStartdate().toString());
}
if (project.getEnddate() != null) {
rda.setEnd(project.getEnddate().toString());
}
rda.setFunding(Collections.singletonList(FundingRDAMapper.toRDA(grant)));
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Project Title is missing");
try {
rda.setTitle(project.getLabel());
rda.setDescription(project.getDescription());
if (project.getStartdate() != null) {
rda.setStart(project.getStartdate().toString());
}
if (project.getEnddate() != null) {
rda.setEnd(project.getEnddate().toString());
}
rda.setFunding(Collections.singletonList(FundingRDAMapper.toRDA(grant)));
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Project Title is missing");
}
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
}
return rda;