use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class Api12MembersTest method addUpdateWorkTest.
@Test
public void addUpdateWorkTest() throws Exception {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String accessToken = getAccessToken(userId, password, Arrays.asList("/orcid-works/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
String title = "Work " + System.currentTimeMillis();
Long putCode = null;
Api12Helper.addWork(userId, accessToken, title, t2OAuthClient_1_2);
ClientResponse response = t2OAuthClient_1_2.viewWorksDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", response.getType().toString());
OrcidMessage orcidMessageWithNewWork = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewWork);
assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
int initialSize = orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().size();
boolean found = false;
for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
if (title.equals(work.getWorkTitle().getTitle().getContent())) {
assertNotNull(work.getPutCode());
putCode = Long.valueOf(work.getPutCode());
found = true;
}
}
assertTrue(found);
// Update it
String newTitle = "Updated - " + title;
WorkType newType = WorkType.BOOK;
String newExtId = String.valueOf(System.currentTimeMillis());
Iterator<OrcidWork> it = orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().iterator();
while (it.hasNext()) {
OrcidWork work = it.next();
if (clientId.equals(work.getSource().retrieveSourcePath())) {
if (title.equals(work.getWorkTitle().getTitle().getContent())) {
assertNotNull(work.getPutCode());
// Update title
work.getWorkTitle().getTitle().setContent(newTitle);
// Update ext ids
work.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().setContent(newExtId);
// Update type
work.setWorkType(newType);
}
} else {
it.remove();
}
}
ClientResponse updateResponse = t2OAuthClient_1_2.updateWorksXml(userId, orcidMessageWithNewWork, accessToken);
assertEquals(ClientResponse.Status.OK.getStatusCode(), updateResponse.getStatus());
// Fetch them again and verify the values has been updated
response = t2OAuthClient_1_2.viewWorksDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", response.getType().toString());
OrcidMessage orcidMessageWithUpdatedWork = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithUpdatedWork);
assertNotNull(orcidMessageWithUpdatedWork.getOrcidProfile());
assertNotNull(orcidMessageWithUpdatedWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithUpdatedWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithUpdatedWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
int size = orcidMessageWithUpdatedWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().size();
assertEquals(initialSize, size);
found = false;
for (OrcidWork work : orcidMessageWithUpdatedWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
assertNotNull(work.getPutCode());
if (putCode.equals(Long.valueOf(work.getPutCode()))) {
assertEquals(newTitle, work.getWorkTitle().getTitle().getContent());
assertEquals(newType, work.getWorkType());
assertEquals(1, work.getWorkExternalIdentifiers().getWorkExternalIdentifier().size());
assertEquals(newExtId, work.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
found = true;
}
}
assertTrue(found);
// Delete it
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class FindOrcidWorkDuplicates method dedupeWorksForOrcid.
private List<OrcidWorkDeduped> dedupeWorksForOrcid(OrcidWorks orcidWorks) {
Map<OrcidWorkMatcher, List<OrcidWork>> worksSplitByDuplicates = splitWorksIntoDuplicateSets(orcidWorks);
List<OrcidWorkDeduped> orcidWorkDupes = new ArrayList<FindOrcidWorkDuplicates.OrcidWorkDeduped>();
for (Map.Entry<OrcidWorkMatcher, List<OrcidWork>> entry : worksSplitByDuplicates.entrySet()) {
List<OrcidWork> allOrcidWorks = entry.getValue();
// there may have been more than one work on a profile, but may not be duplicates
if (allOrcidWorks.size() < 2) {
continue;
}
// sort by desc put code in case we cant rely on visibility
Collections.sort(allOrcidWorks, new Comparator<OrcidWork>() {
public int compare(OrcidWork work1, OrcidWork work2) {
return Integer.valueOf(work2.getPutCode()).compareTo(Integer.valueOf(work1.getPutCode()));
}
});
// yes
// add to string
// determine which is the dupe and which the definitive XML
OrcidWork definitiveWork = null;
OrcidWork definitivePublicWork = null;
OrcidWork definitiveLimitedWork = null;
// if there are varying visibilities then the definitive is the must public level of visibility
for (OrcidWork orcidWork : allOrcidWorks) {
if (Visibility.PUBLIC.equals(orcidWork.getVisibility())) {
definitivePublicWork = orcidWork;
break;
} else // once set
if (Visibility.LIMITED.equals(orcidWork.getVisibility()) && definitiveLimitedWork == null) {
definitiveLimitedWork = orcidWork;
}
}
// fallback onto limited work and if nothing else the max put code
definitiveWork = definitivePublicWork != null ? definitivePublicWork : definitiveLimitedWork;
// if they all match the definitive is the most recent date
definitiveWork = definitiveWork != null ? definitiveWork : allOrcidWorks.get(0);
allOrcidWorks.remove(definitiveWork);
orcidWorkDupes.add(new OrcidWorkDeduped(definitiveWork, allOrcidWorks));
}
return orcidWorkDupes;
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidSearchManagerImplTest method orcidRetrievalAllDataPresentInDb.
@Test
@Rollback
public void orcidRetrievalAllDataPresentInDb() throws Exception {
when(mockSolrDao.findByOrcid("1434")).thenReturn(getOrcidSolrResult("5678", new Float(37.2)));
when(mockOrcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(getOrcidProfileAllIndexFieldsPopulated());
String orcid = "1434";
// demonstrate that the mapping from solr (profile 1234) and dao (5678)
// are truly seperate - the search results only return a subset of the
// full orcid
// because we want to keep the payload down.
OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidSearchResultsById(orcid);
assertNotNull(retrievedOrcidMessage);
assertTrue(retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
OrcidSearchResult result = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
assertTrue(new Float(37.2).compareTo(result.getRelevancyScore().getValue()) == 0);
OrcidProfile retrievedProfile = result.getOrcidProfile();
assertEquals("5678", retrievedProfile.getOrcidIdentifier().getPath());
OrcidBio orcidBio = retrievedProfile.getOrcidBio();
assertEquals("Logan", orcidBio.getPersonalDetails().getFamilyName().getContent());
assertEquals("Donald Edward", orcidBio.getPersonalDetails().getGivenNames().getContent());
assertEquals("Stanley Higgins", orcidBio.getPersonalDetails().getCreditName().getContent());
List<String> otherNames = orcidBio.getPersonalDetails().getOtherNames().getOtherNamesAsStrings();
assertTrue(otherNames.contains("Edward Bass"));
assertTrue(otherNames.contains("Gareth Dove"));
OrcidWorks orcidWorks = retrievedProfile.retrieveOrcidWorks();
OrcidWork orcidWork1 = orcidWorks.getOrcidWork().get(0);
OrcidWork orcidWork2 = orcidWorks.getOrcidWork().get(1);
assertTrue(orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 1);
assertEquals("work1-doi1", orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
assertTrue(orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 2);
assertEquals("work2-doi1", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
assertEquals("work2-doi2", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(1).getWorkExternalIdentifierId().getContent());
List<Funding> fundings = retrievedProfile.retrieveFundings().getFundings();
Funding funding1 = fundings.get(0);
Funding funding2 = fundings.get(1);
// check returns a reduced payload
assertNotNull(funding1.getTitle());
assertNotNull(funding1.getTitle().getTitle());
assertEquals("grant1", funding1.getTitle().getTitle().getContent());
assertEquals("Grant 1 - a short description", funding1.getDescription());
assertNull(funding1.getPutCode());
assertNotNull(funding2.getTitle());
assertNotNull(funding2.getTitle().getTitle());
assertEquals("grant2", funding2.getTitle().getTitle().getContent());
assertEquals("Grant 2 - a short description", funding2.getDescription());
assertNull(funding2.getPutCode());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidSearchManagerImpl method buildSearchResultsFromPublicProfile.
private List<OrcidSearchResult> buildSearchResultsFromPublicProfile(List<OrcidSolrResult> solrResults) {
List<OrcidSearchResult> orcidSearchResults = new ArrayList<OrcidSearchResult>();
for (OrcidSolrResult solrResult : solrResults) {
OrcidMessage orcidMessage = null;
String orcid = solrResult.getOrcid();
try {
orcidSecurityManager.checkProfile(orcid);
} catch (DeactivatedException | LockedException | OrcidDeprecatedException x) {
OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
RelevancyScore relevancyScore = new RelevancyScore();
relevancyScore.setValue(solrResult.getRelevancyScore());
orcidSearchResult.setRelevancyScore(relevancyScore);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
OrcidHistory history = new OrcidHistory();
Date recordLastModified = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(recordLastModified)));
orcidProfile.setOrcidHistory(history);
orcidSearchResult.setOrcidProfile(orcidProfile);
orcidSearchResults.add(orcidSearchResult);
continue;
}
if (cachingSource.equals(SOLR)) {
try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
if (reader != null) {
BufferedReader br = new BufferedReader(reader);
orcidMessage = OrcidMessage.unmarshall(br);
}
} catch (IOException e) {
throw new OrcidSearchException("Error closing record stream from solr search results for orcid: " + orcid, e);
}
}
OrcidProfile orcidProfile = null;
if (orcidMessage == null) {
// Fall back to DB
orcidProfile = orcidProfileCacheManager.retrievePublicBio(orcid);
} else {
orcidProfile = orcidMessage.getOrcidProfile();
}
if (orcidProfile != null) {
OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
RelevancyScore relevancyScore = new RelevancyScore();
relevancyScore.setValue(solrResult.getRelevancyScore());
orcidSearchResult.setRelevancyScore(relevancyScore);
OrcidWorks orcidWorksTitlesOnly = new OrcidWorks();
OrcidWorks fullOrcidWorks = orcidProfile.retrieveOrcidWorks();
if (fullOrcidWorks != null && !fullOrcidWorks.getOrcidWork().isEmpty()) {
for (OrcidWork fullOrcidWork : fullOrcidWorks.getOrcidWork()) {
OrcidWork orcidWorkSubset = new OrcidWork();
orcidWorkSubset.setVisibility(fullOrcidWork.getVisibility());
orcidWorkSubset.setWorkTitle(fullOrcidWork.getWorkTitle());
orcidWorkSubset.setWorkExternalIdentifiers(fullOrcidWork.getWorkExternalIdentifiers());
orcidWorksTitlesOnly.getOrcidWork().add(orcidWorkSubset);
}
}
FundingList reducedFundings = new FundingList();
FundingList fullOrcidFundings = orcidProfile.retrieveFundings();
if (fullOrcidFundings != null && !fullOrcidFundings.getFundings().isEmpty()) {
for (Funding fullOrcidFunding : fullOrcidFundings.getFundings()) {
Funding reducedFunding = new Funding();
reducedFunding.setVisibility(fullOrcidFunding.getVisibility());
reducedFunding.setDescription(fullOrcidFunding.getDescription());
reducedFunding.setTitle(fullOrcidFunding.getTitle());
reducedFundings.getFundings().add(reducedFunding);
}
}
orcidProfile.setOrcidWorks(orcidWorksTitlesOnly);
orcidProfile.setFundings(reducedFundings);
orcidSearchResult.setOrcidProfile(orcidProfile);
orcidSearchResults.add(orcidSearchResult);
}
}
return orcidSearchResults;
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method addOrcidWorks.
@Override
@Transactional
public void addOrcidWorks(OrcidProfile updatedOrcidProfile) {
String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
OrcidProfile existingProfile = null;
List<OrcidWork> updatedOrcidWorksList = null;
try {
synchronized (getLock(orcid)) {
existingProfile = retrieveOrcidProfile(orcid);
if (existingProfile == null) {
throw new IllegalArgumentException("No record found for " + orcid);
}
OrcidWorks existingOrcidWorks = existingProfile.retrieveOrcidWorks();
OrcidWorks updatedOrcidWorks = updatedOrcidProfile.retrieveOrcidWorks();
Visibility workVisibilityDefault = existingProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
Boolean claimed = existingProfile.getOrcidHistory().isClaimed();
setWorkPrivacy(updatedOrcidWorks, workVisibilityDefault, claimed == null ? false : claimed);
if (updatedOrcidWorks != null) {
addSourceToWorks(updatedOrcidWorks, getSource());
}
updatedOrcidWorks = dedupeWorks(updatedOrcidWorks);
updatedOrcidWorksList = updatedOrcidWorks.getOrcidWork();
checkUserCanHoldMoreElement(existingProfile.retrieveOrcidWorks(), updatedOrcidProfile.retrieveOrcidWorks());
if (compareWorksUsingScopusWay) {
checkForAlreadyExistingWorks(orcid, existingOrcidWorks, updatedOrcidWorksList);
if (existingOrcidWorks != null)
checkWorkExternalIdentifiersAreNotDuplicated(updatedOrcidWorksList, existingOrcidWorks.getOrcidWork());
else
checkWorkExternalIdentifiersAreNotDuplicated(updatedOrcidWorksList, null);
} else {
checkForAlreadyExistingWorksLegacyMode(existingOrcidWorks, updatedOrcidWorksList);
}
persistAddedWorks(orcid, updatedOrcidWorksList);
profileDao.flush();
}
} finally {
releaseLock(orcid);
}
boolean notificationsEnabled = existingProfile.getOrcidInternal().getPreferences().getNotificationsEnabled();
if (notificationsEnabled && updatedOrcidWorksList != null) {
List<Item> activities = new ArrayList<>();
for (OrcidWork updatedWork : updatedOrcidWorksList) {
Item activity = new Item();
activity.setItemName(updatedWork.getWorkTitle().getTitle().getContent());
activity.setItemType(ItemType.WORK);
activity.setPutCode(updatedWork.getPutCode());
activities.add(activity);
}
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, activities);
}
}
Aggregations