45 lines
1.2 KiB
Java
45 lines
1.2 KiB
Java
package org.opencdmp.filetransformer.rda.model.rda.mapper;
|
|
|
|
|
|
import org.opencdmp.filetransformer.rda.model.rda.ContributorId;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.Map;
|
|
|
|
@Component
|
|
public class ContributorIdRDAMapper{
|
|
|
|
public ContributorId toRDA(String id) {
|
|
if (id == null || id.isBlank()) return null;
|
|
ContributorId rda = new ContributorId();
|
|
String[] idParts = id.split(":");
|
|
String prefix = idParts.length > 1 ? idParts[0] : id;
|
|
if (prefix.equals("orcid")) {
|
|
String finalId = id.replace(prefix + ":", "");
|
|
rda.setIdentifier("http://orcid.org/" + finalId);
|
|
rda.setType(ContributorId.Type.ORCID);
|
|
} else {
|
|
rda.setIdentifier(id);
|
|
rda.setType(ContributorId.Type.OTHER);
|
|
}
|
|
return rda;
|
|
}
|
|
|
|
public String toEntity(ContributorId rda) {
|
|
if (rda.getIdentifier() != null) return null;
|
|
String referenceString;
|
|
if (rda.getType() == ContributorId.Type.ORCID) {
|
|
String id = rda.getIdentifier().replace("http://orcid.org/", "");
|
|
referenceString = "orcid:" + id;
|
|
} else {
|
|
String[] idParts = rda.getIdentifier().split(":");
|
|
if (idParts.length == 1) {
|
|
referenceString = "dmp:" + rda.getIdentifier();
|
|
} else {
|
|
referenceString = rda.getIdentifier();
|
|
}
|
|
}
|
|
return referenceString;
|
|
}
|
|
}
|