map dmp schematics to zenodo metadata
This commit is contained in:
parent
61849a5abf
commit
cbcefea3bd
|
@ -1,8 +1,11 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.mapper;
|
||||
|
||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||
import eu.eudat.depositinterface.models.OrganisationDepositModel;
|
||||
import eu.eudat.depositinterface.models.UserDMPDepositModel;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.depositinterface.models.*;
|
||||
import eu.eudat.depositinterface.zenodorepository.config.DOIFunder;
|
||||
import eu.eudat.depositinterface.zenodorepository.models.*;
|
||||
|
||||
|
@ -12,10 +15,146 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class DMPToZenodoMapper {
|
||||
|
||||
public static ZenodoDeposit fromDMP(DMPDepositModel dmp, String zenodoCommunity, String zenodoAffiliation, String domain, List<DOIFunder> doiFunders) {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public static ZenodoDeposit fromDMP(DMPDepositModel dmp, String zenodoCommunity, String zenodoAffiliation, String domain, List<DOIFunder> doiFunders) throws JsonProcessingException {
|
||||
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
|
||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||
deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
Map<String, Object> schematicsMap = new HashMap<>();
|
||||
|
||||
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
|
||||
List<ZenodoComunity> communities = new ArrayList<>();
|
||||
List<ZenodoContributor> contributors = new ArrayList<>();
|
||||
List<ZenodoCreator> creators = new ArrayList<>();
|
||||
List<ZenodoGrant> grants = new ArrayList<>();
|
||||
List<String> keywords = new ArrayList<>();
|
||||
List<String> references = new ArrayList<>();
|
||||
|
||||
//objectMapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
|
||||
for(DatasetDepositModel dataset: dmp.getDatasets()){
|
||||
for(DatasetFieldsDepositModel field: dataset.getFields()){
|
||||
for(String schematic: field.getSchematics()){
|
||||
if(schematic.contains("zenodo.")){
|
||||
if(field.getValue() != null && !field.getValue().isEmpty()){
|
||||
if(schematic.contains("related_identifiers")){
|
||||
if(schematic.endsWith("relation")){
|
||||
Optional<ZenodoRelator> relatorOptional = relatedIdentifiers.stream().filter(r -> r.getRelation() == null).findAny();
|
||||
if(relatorOptional.isPresent()){
|
||||
relatorOptional.get().setRelation(field.getValue());
|
||||
}
|
||||
else{
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setRelation(field.getValue());
|
||||
relatedIdentifiers.add(relator);
|
||||
}
|
||||
}
|
||||
else if(schematic.endsWith("identifier")){
|
||||
Optional<ZenodoRelator> relatorOptional = relatedIdentifiers.stream().filter(r -> r.getIdentifier() == null).findAny();
|
||||
if(relatorOptional.isPresent()){
|
||||
relatorOptional.get().setIdentifier(field.getValue());
|
||||
}
|
||||
else{
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setIdentifier(field.getValue());
|
||||
relatedIdentifiers.add(relator);
|
||||
}
|
||||
}
|
||||
else{
|
||||
JsonNode relatorNodes = objectMapper.readTree(field.getValue());
|
||||
if(relatorNodes.isArray()){
|
||||
List<ZenodoRelator> relators = objectMapper.readValue(field.getValue(), new TypeReference<List<ZenodoRelator>>(){});
|
||||
relatedIdentifiers.addAll(relators);
|
||||
}
|
||||
else{
|
||||
ZenodoRelator relator = objectMapper.readValue(field.getValue(), ZenodoRelator.class);
|
||||
relatedIdentifiers.add(relator);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("communities")){
|
||||
JsonNode communitiesNodes = objectMapper.readTree(field.getValue());
|
||||
if(communitiesNodes.isArray()){
|
||||
List<ZenodoComunity> communitiesList = objectMapper.readValue(field.getValue(), new TypeReference<List<ZenodoComunity>>(){});
|
||||
communities.addAll(communitiesList);
|
||||
}
|
||||
else{
|
||||
ZenodoComunity community = objectMapper.readValue(field.getValue(), ZenodoComunity.class);
|
||||
communities.add(community);
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("contributors")){
|
||||
JsonNode contributorsNodes = objectMapper.readTree(field.getValue());
|
||||
if(contributorsNodes.isArray()){
|
||||
List<ZenodoContributor> contributorsList = objectMapper.readValue(field.getValue(), new TypeReference<List<ZenodoContributor>>(){});
|
||||
contributors.addAll(contributorsList);
|
||||
}
|
||||
else{
|
||||
ZenodoContributor contributor = objectMapper.readValue(field.getValue(), ZenodoContributor.class);
|
||||
contributors.add(contributor);
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("creators")){
|
||||
JsonNode creatorsNodes = objectMapper.readTree(field.getValue());
|
||||
if(creatorsNodes.isArray()){
|
||||
List<ZenodoCreator> creatorsList = objectMapper.readValue(field.getValue(), new TypeReference<List<ZenodoCreator>>(){});
|
||||
creators.addAll(creatorsList);
|
||||
}
|
||||
else{
|
||||
ZenodoCreator creator = objectMapper.readValue(field.getValue(), ZenodoCreator.class);
|
||||
creators.add(creator);
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("grants")){
|
||||
JsonNode grantsNodes = objectMapper.readTree(field.getValue());
|
||||
if(grantsNodes.isArray()){
|
||||
List<ZenodoGrant> grantsList = objectMapper.readValue(field.getValue(), new TypeReference<List<ZenodoGrant>>(){});
|
||||
grants.addAll(grantsList);
|
||||
}
|
||||
else{
|
||||
ZenodoGrant grant = objectMapper.readValue(field.getValue(), ZenodoGrant.class);
|
||||
grants.add(grant);
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("keywords")){
|
||||
if(field.getValue().startsWith("[")){
|
||||
List<String> keywordsList = objectMapper.readValue(field.getValue(), new TypeReference<List<String>>(){});
|
||||
keywords.addAll(keywordsList);
|
||||
}
|
||||
else{
|
||||
keywords.add(field.getValue());
|
||||
}
|
||||
}
|
||||
else if(schematic.contains("references")){
|
||||
if(field.getValue().startsWith("[")){
|
||||
List<String> referencesList = objectMapper.readValue(field.getValue(), new TypeReference<List<String>>(){});
|
||||
references.addAll(referencesList);
|
||||
}
|
||||
else{
|
||||
references.add(field.getValue());
|
||||
}
|
||||
}
|
||||
else{
|
||||
schematicsMap.put(schematic.replace("zenodo.", ""), field.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
schematicsMap.put("related_identifiers", relatedIdentifiers);
|
||||
schematicsMap.put("communities", communities);
|
||||
schematicsMap.put("contributors", contributors);
|
||||
schematicsMap.put("creators", creators);
|
||||
schematicsMap.put("grants", grants);
|
||||
schematicsMap.put("keywords", keywords);
|
||||
schematicsMap.put("references", references);
|
||||
|
||||
String schematicsString = objectMapper.writeValueAsString(schematicsMap);
|
||||
objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
|
||||
ZenodoDepositMetadata metadata = objectMapper.readValue(schematicsString, new TypeReference<ZenodoDepositMetadata>(){});
|
||||
|
||||
deposit.setMetadata(metadata);
|
||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
||||
deposit.getMetadata().setUploadType("publication");
|
||||
deposit.getMetadata().setPublicationType("datamanagementplan");
|
||||
|
@ -24,7 +163,7 @@ public class DMPToZenodoMapper {
|
|||
if(zenodoCommunity != null && !zenodoAffiliation.isEmpty()) {
|
||||
ZenodoComunity community = new ZenodoComunity();
|
||||
community.setIdentifier(zenodoCommunity);
|
||||
deposit.getMetadata().setCommunities(Collections.singletonList(community));
|
||||
deposit.getMetadata().getCommunities().add(community);
|
||||
}
|
||||
if (extraProperties.get("visible") == null) {
|
||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||
|
@ -51,10 +190,9 @@ public class DMPToZenodoMapper {
|
|||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setIdentifier(domain + "/external/zenodo/" + dmp.getId().toString());
|
||||
relator.setRelation("isIdenticalTo");
|
||||
deposit.getMetadata().setRelatedIdentifiers(Collections.singletonList(relator));
|
||||
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
||||
}
|
||||
deposit.getMetadata().setContributors(new LinkedList<>());
|
||||
List<ZenodoContributor> contributors = dmp.getUsers().stream().map(userDMP -> {
|
||||
List<ZenodoContributor> contributors1 = dmp.getUsers().stream().map(userDMP -> {
|
||||
ZenodoContributor contributor = new ZenodoContributor();
|
||||
contributor.setName(userDMP.getUser().getName());
|
||||
contributor.setType("ProjectMember");
|
||||
|
@ -82,7 +220,7 @@ public class DMPToZenodoMapper {
|
|||
return contributor;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
deposit.getMetadata().getContributors().addAll(contributors);
|
||||
deposit.getMetadata().getContributors().addAll(contributors1);
|
||||
deposit.getMetadata().getContributors().addAll(researchers);
|
||||
|
||||
if (dmp.getGrant().getReference() == null) {
|
||||
|
@ -98,10 +236,10 @@ public class DMPToZenodoMapper {
|
|||
String finalId = doiFunder.getDOI() + "::" + grantReferenceTail;
|
||||
ZenodoGrant grant = new ZenodoGrant();
|
||||
grant.setId(finalId);
|
||||
deposit.getMetadata().setGrants(Collections.singletonList(grant));
|
||||
deposit.getMetadata().getGrants().add(grant);
|
||||
}
|
||||
}
|
||||
ZenodoContributor creator = new ZenodoContributor();
|
||||
ZenodoCreator creator = new ZenodoCreator();
|
||||
creator.setName(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMPDepositModel.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName());
|
||||
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
|
||||
creator.setAffiliation(dmp.getOrganisations()
|
||||
|
@ -111,7 +249,7 @@ public class DMPToZenodoMapper {
|
|||
creator.setAffiliation(zenodoAffiliation);
|
||||
}
|
||||
}
|
||||
deposit.getMetadata().setCreators(Collections.singletonList(creator));
|
||||
deposit.getMetadata().getCreators().add(creator);
|
||||
|
||||
return deposit;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoCreator {
|
||||
private String name;
|
||||
private String affiliation;
|
||||
private String orcid;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
public void setAffiliation(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
}
|
||||
|
||||
public String getOrcid() {
|
||||
return orcid;
|
||||
}
|
||||
|
||||
public void setOrcid(String orcid) {
|
||||
this.orcid = orcid;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,15 @@ public class ZenodoDepositMetadata {
|
|||
|
||||
private String version;
|
||||
|
||||
@JsonProperty("publication_date")
|
||||
private String publicationDate;
|
||||
|
||||
private List<String> keywords;
|
||||
|
||||
private String notes;
|
||||
|
||||
private List<String> references;
|
||||
|
||||
private List<ZenodoComunity> communities;
|
||||
|
||||
@JsonProperty("access_right")
|
||||
|
@ -42,7 +51,7 @@ public class ZenodoDepositMetadata {
|
|||
|
||||
private List<ZenodoGrant> grants;
|
||||
|
||||
private List<ZenodoContributor> creators;
|
||||
private List<ZenodoCreator> creators;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
|
@ -68,6 +77,38 @@ public class ZenodoDepositMetadata {
|
|||
this.publicationType = publicationType;
|
||||
}
|
||||
|
||||
public String getPublicationDate() {
|
||||
return publicationDate;
|
||||
}
|
||||
|
||||
public void setPublicationDate(String publicationDate) {
|
||||
this.publicationDate = publicationDate;
|
||||
}
|
||||
|
||||
public List<String> getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public void setKeywords(List<String> keywords) {
|
||||
this.keywords = keywords;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public List<String> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<String> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -148,11 +189,11 @@ public class ZenodoDepositMetadata {
|
|||
this.grants = grants;
|
||||
}
|
||||
|
||||
public List<ZenodoContributor> getCreators() {
|
||||
public List<ZenodoCreator> getCreators() {
|
||||
return creators;
|
||||
}
|
||||
|
||||
public void setCreators(List<ZenodoContributor> creators) {
|
||||
public void setCreators(List<ZenodoCreator> creators) {
|
||||
this.creators = creators;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue