package eu.eudat.models.rda.mapper; import eu.eudat.data.entities.Researcher; import eu.eudat.data.entities.UserDMP; import eu.eudat.models.rda.Contributor; import eu.eudat.models.rda.ContributorId; import java.util.Arrays; import java.util.HashSet; public class ContributorRDAMapper { public static Contributor toRDA(UserDMP userDMP) { Contributor rda = new Contributor(); rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser().getId())); rda.setName(userDMP.getUser().getName()); rda.setMbox(userDMP.getUser().getEmail()); rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name()))); return rda; } public static Contributor toRDA(Researcher researcher) { Contributor rda = new Contributor(); rda.setContributorId(ContributorIdRDAMapper.toRDA(researcher.getReference())); rda.setName(researcher.getLabel()); rda.setMbox(researcher.getPrimaryEmail()); // rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name()))); return rda; } public static Researcher toEntity(Contributor rda) { Researcher entity = new Researcher(); String reference; if (rda.getContributorId().getType() == ContributorId.Type.ORCID) { String id = rda.getContributorId().getIdentifier().replace("http://orcid.org/", ""); reference = "orcid:" + id; } else { String idParts[] = rda.getContributorId().getIdentifier().split(":"); if (idParts.length == 1) { reference = "dmp:" + rda.getContributorId().getIdentifier(); } else { reference = rda.getContributorId().getIdentifier(); } } entity.setReference(reference); entity.setLabel(rda.getName()); entity.setPrimaryEmail(rda.getMbox()); return entity; } }