use of org.orcid.jaxb.model.message.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method getWorkInsideOrcidProfile.
private OrcidProfile getWorkInsideOrcidProfile(String defaultTitle, String orcid) {
OrcidWork orcidWork = new OrcidWork();
//Set title
WorkTitle title = new WorkTitle();
if (defaultTitle != null)
title.setTitle(new Title(defaultTitle));
else
title.setTitle(new Title("Title"));
orcidWork.setWorkTitle(title);
//Set external identifiers
WorkExternalIdentifier extId1 = new WorkExternalIdentifier();
extId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("doi-" + defaultTitle));
extId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
WorkExternalIdentifier extId2 = new WorkExternalIdentifier();
if (defaultTitle != null)
extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + defaultTitle));
else
extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + System.currentTimeMillis()));
extId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.ISSN);
WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
extIds.getWorkExternalIdentifier().add(extId1);
extIds.getWorkExternalIdentifier().add(extId2);
orcidWork.setWorkExternalIdentifiers(extIds);
orcidWork.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
OrcidProfile profile = new OrcidProfile();
profile.setOrcidIdentifier(orcid);
List<OrcidWork> workList = new ArrayList<OrcidWork>();
workList.add(orcidWork);
OrcidWorks orcidWorks = new OrcidWorks();
orcidWorks.setOrcidWork(workList);
profile.setOrcidWorks(orcidWorks);
return profile;
}
use of org.orcid.jaxb.model.message.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method checkWorkExternalIdentifiersAreNotDuplicated.
/**
* Checks if the list of updated works contains any duplicated external
* identifier, if so, it will throw an exception The newOrcidWorksList MUST
* be deduped before getting into this method
*
* @param updatedOrcidWorksList
* the deduped list of works
* @throws IllegalArgumentException
* if there is a duplicated external identifier
* */
public void checkWorkExternalIdentifiersAreNotDuplicated(List<OrcidWork> newOrcidWorksList, List<OrcidWork> existingWorkList) {
// from the same source, so, we can skip the work source comparison
if (newOrcidWorksList != null) {
for (int i = 0; i < newOrcidWorksList.size(); i++) {
OrcidWork newWork = newOrcidWorksList.get(i);
for (int j = 0; j < newOrcidWorksList.size(); j++) {
// If they are not the same work
if (i != j) {
OrcidWork newWorkToCompare = newOrcidWorksList.get(j);
// If newWork have external identifiers
if (newWork.getWorkExternalIdentifiers() != null && newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// For each external id on the outer work
for (WorkExternalIdentifier workExtId : newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
if (newWorkToCompare.getWorkExternalIdentifiers() != null && newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// the inner work
for (WorkExternalIdentifier workExtIdToCompare : newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
// If the ext ids are the same
if (workExtId.equals(workExtIdToCompare)) {
Title title = (newWork.getWorkTitle() == null || newWork.getWorkTitle().getTitle() == null) ? null : newWork.getWorkTitle().getTitle();
Title titleToCompare = (newWorkToCompare.getWorkTitle() == null || newWorkToCompare.getWorkTitle().getTitle() == null) ? null : newWorkToCompare.getWorkTitle().getTitle();
if (!isTheSameTitle(title, titleToCompare) && !areBothExtIdsPartOf(newWork.getWorkType(), workExtId, workExtIdToCompare)) {
String extIdContent = (workExtId.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(workExtId.getWorkExternalIdentifierId().getContent())) ? "" : workExtId.getWorkExternalIdentifierId().getContent();
String title1 = (title == null) ? "" : title.getContent();
String title2 = (titleToCompare == null) ? "" : titleToCompare.getContent();
String errorMessage = String.format("Works \"%s\" and \"%s\" have the same external id \"%s\"", title1, title2, extIdContent);
throw new IllegalArgumentException(errorMessage);
}
}
}
}
}
}
}
}
}
}
// Then, if it already have works
if (existingWorkList != null && existingWorkList.size() > 0) {
// Check for duplicates in existing works, if any is found, log it
for (int i = 0; i < existingWorkList.size(); i++) {
OrcidWork existingWork = existingWorkList.get(i);
Source workSource = existingWork.getSource();
for (int j = 0; j < existingWorkList.size(); j++) {
// If it is not the same index
if (i != j) {
OrcidWork existingWorkToCompare = existingWorkList.get(j);
Source workSourceToCompare = existingWorkToCompare.getSource();
// If both works have the same source
if (isTheSameSource(workSource, workSourceToCompare)) {
// If the work have external identifiers
if (existingWork.getWorkExternalIdentifiers() != null && existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// Compare each external identifier
for (WorkExternalIdentifier workExtId : existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
// If the workToCompare have ext ids
if (existingWorkToCompare.getWorkExternalIdentifiers() != null && existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// rules:
for (WorkExternalIdentifier workToCompareExtId : existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
// If the ext ids are the same
if (workExtId.equals(workToCompareExtId)) {
// Compare the titles, if they
// are different, set it as
// duplicated
Title title = (existingWork.getWorkTitle() == null || existingWork.getWorkTitle().getTitle() == null) ? null : existingWork.getWorkTitle().getTitle();
Title titleToCompare = (existingWorkToCompare.getWorkTitle() == null || existingWorkToCompare.getWorkTitle().getTitle() == null) ? null : existingWorkToCompare.getWorkTitle().getTitle();
if (!isTheSameTitle(title, titleToCompare)) {
String extIdContent = (workExtId.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(workExtId.getWorkExternalIdentifierId().getContent())) ? "" : workExtId.getWorkExternalIdentifierId().getContent();
LOG.error("Works {} and {} have the same external identifier {}", new Object[] { existingWork.getPutCode(), existingWorkToCompare.getPutCode(), extIdContent });
}
}
}
}
}
}
}
}
}
}
// Check for duplicates between the existing works and the new works
if (newOrcidWorksList != null) {
for (OrcidWork orcidWork : newOrcidWorksList) {
Source workSource = orcidWork.getSource();
for (OrcidWork existingWork : existingWorkList) {
Source existingWorkSource = existingWork.getSource();
// If both works have the same source
if (isTheSameSource(workSource, existingWorkSource)) {
// If the new work have external identifiers
if (orcidWork.getWorkExternalIdentifiers() != null && orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// For each external identifier in the new work
for (WorkExternalIdentifier newExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
if (existingWork.getWorkExternalIdentifiers() != null && existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
// identifiers
for (WorkExternalIdentifier existingExternalIdentifier : existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
// If the ext ids are the same
if (newExternalIdentifier.equals(existingExternalIdentifier)) {
// Compare the titles, if they
// are different, set it as
// duplicated
Title title = (orcidWork.getWorkTitle() == null || orcidWork.getWorkTitle().getTitle() == null) ? null : orcidWork.getWorkTitle().getTitle();
Title titleToCompare = (existingWork.getWorkTitle() == null || existingWork.getWorkTitle().getTitle() == null) ? null : existingWork.getWorkTitle().getTitle();
if (!isTheSameTitle(title, titleToCompare) && !areBothExtIdsPartOf(orcidWork.getWorkType(), existingExternalIdentifier, newExternalIdentifier)) {
String extIdContent = (existingExternalIdentifier.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(existingExternalIdentifier.getWorkExternalIdentifierId().getContent())) ? "" : existingExternalIdentifier.getWorkExternalIdentifierId().getContent();
String title1 = (title == null) ? "" : title.getContent();
String title2 = (titleToCompare == null) ? "" : titleToCompare.getContent();
String errorMessage = String.format("Works \"%s\" and \"%s\"(put-code '%s') have the same external id \"%s\"", title1, title2, existingWork.getPutCode(), extIdContent);
throw new IllegalArgumentException(errorMessage);
}
}
}
}
}
}
}
}
}
}
}
}
Aggregations