check for grant, since it is not a mandatory field

This commit is contained in:
Aldo Mihasi 2023-10-05 09:31:56 +03:00
parent ace8cf6189
commit 591ed6fcd9
1 changed files with 24 additions and 20 deletions

View File

@ -234,27 +234,31 @@ public class DMPToZenodoMapper {
deposit.getMetadata().getContributors().addAll(contributors1);
deposit.getMetadata().getContributors().addAll(researchers);
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];
List<DOIFunder> doiFunders = new ArrayList<>();
try {
List<Map<String, Object>> tempdoiFunders = objectMapper.readValue(configLoader.getStreamFromPath(zenodoConfig.getDoiFunder()), List.class);
doiFunders = tempdoiFunders.stream().map(map -> objectMapper.convertValue(map, DOIFunder.class) ).collect(Collectors.toList());
} catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
if (dmp.getGrant() != null) {
if (dmp.getGrant().getReference() == null) {
dmp.getGrant().setReference("dmp:" + dmp.getGrant().getId());
}
DOIFunder doiFunder = doiFunders.stream()
.filter(doiFunder1 -> dmp.getGrant().getFunder().getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(dmp.getGrant().getFunder().getLabel()))
.findFirst().orElse(null);
if (doiFunder != null) {
String finalId = doiFunder.getDOI() + "::" + grantReferenceTail;
ZenodoGrant grant = new ZenodoGrant();
grant.setId(finalId);
deposit.getMetadata().getGrants().add(grant);
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
if (grantReferenceHead.equals("openaire")) {
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
List<DOIFunder> doiFunders = new ArrayList<>();
try {
List<Map<String, Object>> tempdoiFunders = objectMapper.readValue(configLoader.getStreamFromPath(zenodoConfig.getDoiFunder()), List.class);
doiFunders = tempdoiFunders.stream().map(map -> objectMapper.convertValue(map, DOIFunder.class)).collect(Collectors.toList());
} catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
}
if (dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getLabel() != null) {
DOIFunder doiFunder = doiFunders.stream()
.filter(doiFunder1 -> dmp.getGrant().getFunder().getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(dmp.getGrant().getFunder().getLabel()))
.findFirst().orElse(null);
if (doiFunder != null) {
String finalId = doiFunder.getDOI() + "::" + grantReferenceTail;
ZenodoGrant grant = new ZenodoGrant();
grant.setId(finalId);
deposit.getMetadata().getGrants().add(grant);
}
}
}
}
ZenodoCreator creator = new ZenodoCreator();