use of org.orcid.jaxb.model.message.Title in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testUpdatePersonalInformationRemovesOrcidIndexFields.
@Test
@Transactional
@Rollback(true)
public void testUpdatePersonalInformationRemovesOrcidIndexFields() throws Exception {
// re-use the createFull method but add some extra criteria so we can
// use our specific orcidAllSolrFieldsPopulatedForSave matcher
OrcidProfile profile = createFullOrcidProfile();
OtherNames otherNames = new OtherNames();
otherNames.getOtherName().add(new OtherName("Stan", null));
otherNames.getOtherName().add(new OtherName("Willis", null));
profile.getOrcidBio().getPersonalDetails().setOtherNames(otherNames);
OrcidWorks orcidWorks = new OrcidWorks();
profile.setOrcidWorks(orcidWorks);
WorkTitle singleWorkTitle = new WorkTitle();
singleWorkTitle.setTitle(new Title("Single works"));
singleWorkTitle.setSubtitle(new Subtitle("Single works"));
OrcidWork orcidWork = createWork1(singleWorkTitle);
// TODO JB some doi testing here?
// orcidWork.getElectronicResourceNum().add(new
// ElectronicResourceNum("10.1016/S0021-8502(00)90373-2",
// ElectronicResourceNumType.DOI));
orcidWorks.getOrcidWork().add(orcidWork);
orcidProfileManager.createOrcidProfile(profile, false, false);
// now negate all fields that form part of a solr query, leaving only
// the orcid itself
// we do this by passing through an orcid missing the fields from an
// OrcidSolrDocument
OrcidProfile negatedProfile = createBasicProfile();
negatedProfile.getOrcidBio().getPersonalDetails().setFamilyName(null);
negatedProfile.getOrcidBio().getPersonalDetails().setGivenNames(null);
negatedProfile.getOrcidBio().getPersonalDetails().setCreditName(null);
negatedProfile.getOrcidBio().getPersonalDetails().setOtherNames(null);
negatedProfile.getOrcidActivities().setAffiliations(null);
orcidProfileManager.updateOrcidBio(negatedProfile);
assertEquals(IndexingStatus.PENDING, profileDao.find(TEST_ORCID).getIndexingStatus());
}
use of org.orcid.jaxb.model.message.Title in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testAddOrcidWorksWhenDefaultVisibilityIsLimited.
@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorksWhenDefaultVisibilityIsLimited() {
OrcidProfile profile1 = createBasicProfile();
OrcidHistory history = new OrcidHistory();
history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
profile1.setOrcidHistory(history);
history.setClaimed(new Claimed(true));
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
orcidProfileManager.createOrcidProfile(profile1, false, false);
OrcidProfile profile2 = new OrcidProfile();
profile2.setOrcidIdentifier(TEST_ORCID);
OrcidWorks orcidWorks = new OrcidWorks();
profile2.setOrcidWorks(orcidWorks);
WorkTitle workTitle1 = new WorkTitle();
workTitle1.setTitle(new Title("Another Title"));
workTitle1.setSubtitle(new Subtitle("Journal of Cloud Spotting"));
OrcidWork work1 = createWork1(workTitle1);
Source source = new Source(TEST_ORCID);
work1.setSource(source);
orcidWorks.getOrcidWork().add(work1);
WorkTitle workTitle2 = new WorkTitle();
workTitle2.setTitle(new Title("New Title"));
workTitle2.setSubtitle(new Subtitle("Another New subtitle"));
OrcidWork work2 = createWork2(workTitle2);
orcidWorks.getOrcidWork().add(work2);
// Try to add a duplicate
WorkTitle workTitle3 = new WorkTitle();
workTitle3.setTitle(new Title("Further Title"));
workTitle3.setSubtitle(new Subtitle("Further subtitle"));
OrcidWork work3 = createWork3(workTitle3);
work3.setVisibility(Visibility.LIMITED);
orcidWorks.getOrcidWork().add(work3);
orcidProfileManager.addOrcidWorks(profile2);
OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
List<OrcidWork> works = resultProfile.retrieveOrcidWorks().getOrcidWork();
assertEquals(4, works.size());
assertEquals("Another Title", works.get(0).getWorkTitle().getTitle().getContent());
assertEquals("Journal of Cloud Spotting", works.get(0).getWorkTitle().getSubtitle().getContent());
for (OrcidWork work : works) {
if ("Test Title".equals(work.getWorkTitle().getTitle().getContent()))
assertEquals(Visibility.PRIVATE, work.getVisibility());
else
assertEquals(Visibility.LIMITED, work.getVisibility());
}
}
use of org.orcid.jaxb.model.message.Title 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.Title 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