use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class Api12MembersTest method viewOwnPrivateWorksTest.
@Test
public void viewOwnPrivateWorksTest() throws InterruptedException, JSONException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
String client1Id = getClient1ClientId();
String client1RedirectUri = getClient1RedirectUri();
String client1Secret = getClient1ClientSecret();
String client2Id = getClient2ClientId();
String client2RedirectUri = getClient2RedirectUri();
String client2Secret = getClient2ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String client1AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client1Id, client1Secret, client1RedirectUri, true);
String client2AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client2Id, client2Secret, client2RedirectUri, true);
String title1 = "Client 1 - Work " + System.currentTimeMillis();
String title2 = "Client 2 - Work " + System.currentTimeMillis();
Api12Helper.addWork(userId, client1AccessToken, title1, t2OAuthClient_1_2);
Api12Helper.addWork(userId, client2AccessToken, title2, t2OAuthClient_1_2);
Long putCode1 = 0L;
Long putCode2 = 0L;
// Fetch with client 1 and verify it can only see his private work
ClientResponse client1Response = t2OAuthClient_1_2.viewWorksDetailsXml(userId, client1AccessToken);
assertNotNull(client1Response);
assertEquals(200, client1Response.getStatus());
OrcidMessage orcidMessageWithNewWork = client1Response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewWork);
assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
boolean found = false;
for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
if (title2.equals(work.getWorkTitle().getTitle().getContent())) {
fail("I found work for client # 2, which is wrong since it is private");
}
if (title1.equals(work.getWorkTitle().getTitle().getContent())) {
assertEquals(Visibility.PRIVATE, work.getVisibility());
putCode1 = Long.valueOf(work.getPutCode());
found = true;
}
}
assertTrue(found);
// Fetch with client 2 and verify it can only see his private work
ClientResponse client2Response = t2OAuthClient_1_2.viewWorksDetailsXml(userId, client2AccessToken);
assertNotNull(client2Response);
assertEquals(200, client2Response.getStatus());
orcidMessageWithNewWork = client2Response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewWork);
assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
found = false;
for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
if (title1.equals(work.getWorkTitle().getTitle().getContent())) {
fail("I found work for client # 1, which is wrong since it is private");
}
if (title2.equals(work.getWorkTitle().getTitle().getContent())) {
assertEquals(Visibility.PRIVATE, work.getVisibility());
putCode2 = Long.valueOf(work.getPutCode());
found = true;
}
}
assertTrue(found);
// Delete both works before finishing
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, client1AccessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, client2AccessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class Api12MembersTest method activitiesReadLimitedTest.
@Test
public void activitiesReadLimitedTest() throws InterruptedException, JSONException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String workTitle = "Work " + System.currentTimeMillis();
String fundingTitle = "Funding " + System.currentTimeMillis();
String orgName = "Org_" + System.currentTimeMillis();
String accessToken = getAccessToken(userId, password, Arrays.asList("/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
Long workPutCode = null;
Api12Helper.addWork(userId, accessToken, workTitle, t2OAuthClient_1_2);
Long fundingPutCode = null;
Api12Helper.addFunding(userId, accessToken, fundingTitle, t2OAuthClient_1_2);
Long affiliationPutCode = null;
Api12Helper.addAffiliation(userId, accessToken, orgName, t2OAuthClient_1_2);
ClientResponse worksResponse = t2OAuthClient_1_2.viewWorksDetailsXml(userId, accessToken);
assertNotNull(worksResponse);
assertEquals(200, worksResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", worksResponse.getType().toString());
OrcidMessage orcidMessageWithNewWork = worksResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewWork);
assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
assertTrue(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().size() > 0);
boolean workFound = false;
for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
if (workTitle.equals(work.getWorkTitle().getTitle().getContent())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, work.getVisibility());
assertNotNull(work.getPutCode());
workPutCode = Long.valueOf(work.getPutCode());
workFound = true;
}
}
assertTrue(workFound);
ClientResponse fundingResponse = t2OAuthClient_1_2.viewFundingDetailsXml(userId, accessToken);
assertNotNull(fundingResponse);
assertEquals(200, fundingResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", fundingResponse.getType().toString());
OrcidMessage orcidMessageWithNewFunding = fundingResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewFunding);
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
assertTrue(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings().size() > 0);
boolean fundingFound = false;
for (Funding funding : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
if (fundingTitle.equals(funding.getTitle().getTitle().getContent())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, funding.getVisibility());
assertNotNull(funding.getPutCode());
fundingPutCode = Long.valueOf(funding.getPutCode());
fundingFound = true;
}
}
assertTrue(fundingFound);
ClientResponse affiliationResponse = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, accessToken);
assertNotNull(affiliationResponse);
assertEquals(200, affiliationResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", affiliationResponse.getType().toString());
OrcidMessage orcidMessageWithNewAffiliation = affiliationResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewAffiliation);
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
assertTrue(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation().size() > 0);
boolean affiliationFound = false;
for (Affiliation affiliation : orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
if (orgName.equals(affiliation.getOrganization().getName())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, affiliation.getVisibility());
assertNotNull(affiliation.getPutCode());
affiliationPutCode = Long.valueOf(affiliation.getPutCode());
affiliationFound = true;
}
}
assertTrue(affiliationFound);
// Delete work
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), workPutCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
// Delete funding
deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), fundingPutCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
// Delete affiliation
deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), affiliationPutCode, 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 Api12Helper method addWork.
protected static void addWork(String userOrcid, String token, String title, T2OAuthAPIService<ClientResponse> oauthT2Client) {
String id = String.valueOf(System.currentTimeMillis());
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
OrcidWorks orcidWorks = new OrcidWorks();
orcidActivities.setOrcidWorks(orcidWorks);
OrcidWork orcidWork = new OrcidWork();
orcidWorks.getOrcidWork().add(orcidWork);
orcidWork.setWorkType(WorkType.JOURNAL_ARTICLE);
orcidWork.setVisibility(Visibility.LIMITED);
WorkTitle workTitle = new WorkTitle();
orcidWork.setWorkTitle(workTitle);
WorkExternalIdentifier wei = new WorkExternalIdentifier();
wei.setWorkExternalIdentifierId(new WorkExternalIdentifierId(id));
wei.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
extIds.getWorkExternalIdentifier().add(wei);
orcidWork.setWorkExternalIdentifiers(extIds);
workTitle.setTitle(new Title(title));
ClientResponse clientResponse = oauthT2Client.addWorksXml(userOrcid, orcidMessage, token);
assertEquals(201, clientResponse.getStatus());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testUpdateExistingNonPrivateWork.
@Test
public void testUpdateExistingNonPrivateWork() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.ORCID_WORKS_UPDATE);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4446"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
OrcidWorks orcidWorks = new OrcidWorks();
orcidActivities.setOrcidWorks(orcidWorks);
OrcidWork orcidWork = new OrcidWork();
orcidWorks.getOrcidWork().add(orcidWork);
orcidWork.setPutCode("5");
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title("Updated by works update"));
orcidWork.setWorkTitle(workTitle);
orcidWork.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
WorkExternalIdentifiers workExternalIdentifiers = new WorkExternalIdentifiers();
WorkExternalIdentifier wei = new WorkExternalIdentifier();
wei.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
wei.setWorkExternalIdentifierId(new WorkExternalIdentifierId("abc123"));
workExternalIdentifiers.getWorkExternalIdentifier().add(wei);
orcidWork.setWorkExternalIdentifiers(workExternalIdentifiers);
Response response = t2OrcidApiServiceDelegator.updateWorks(mockedUriInfo, "4444-4444-4444-4446", orcidMessage);
assertNotNull(response);
OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4446");
List<OrcidWork> retreivedWorksList = retrievedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork();
assertEquals(4, retreivedWorksList.size());
boolean foundWorkFromAnotherSource = false;
boolean foundUpdated = false;
boolean foundExisting = false;
boolean foundExistingPrivate = false;
for (OrcidWork retrievedWork : retreivedWorksList) {
if ("5".equals(retrievedWork.getPutCode())) {
// The updated work
assertEquals("Updated by works update", retrievedWork.getWorkTitle().getTitle().getContent());
assertEquals(Visibility.PUBLIC, retrievedWork.getVisibility());
assertEquals("APP-5555555555555555", retrievedWork.getSource().retrieveSourcePath());
foundUpdated = true;
} else if ("6".equals(retrievedWork.getPutCode())) {
assertEquals("Journal article B", retrievedWork.getWorkTitle().getTitle().getContent());
assertEquals(Visibility.LIMITED, retrievedWork.getVisibility());
assertEquals("4444-4444-4444-4446", retrievedWork.getSource().retrieveSourcePath());
foundWorkFromAnotherSource = true;
} else if ("7".equals(retrievedWork.getPutCode())) {
// Existing private work
assertEquals("Journal article C", retrievedWork.getWorkTitle().getTitle().getContent());
assertEquals(Visibility.PRIVATE, retrievedWork.getVisibility());
assertEquals("APP-5555555555555555", retrievedWork.getSource().retrieveSourcePath());
foundExisting = true;
} else if ("8".equals(retrievedWork.getPutCode())) {
// Existing private work added by the user
assertEquals("Journal article D", retrievedWork.getWorkTitle().getTitle().getContent());
assertEquals(Visibility.PRIVATE, retrievedWork.getVisibility());
assertEquals("4444-4444-4444-4446", retrievedWork.getSource().retrieveSourcePath());
foundExistingPrivate = true;
}
}
assertTrue("Work from other source should be there", foundWorkFromAnotherSource);
assertTrue("Updated work should be there", foundUpdated);
assertTrue("Existing private work should be there", foundExisting);
assertTrue("Existing private work added by the user should be there", foundExistingPrivate);
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class VisibilityFilterImpl method filter.
/**
* Remove the elements that are not present in the list of set of
* {@link org.orcid.jaxb.model.message .Visibility}s present in the array
* passed in.
*
* @param messageToBeFiltered
* the {@link org.orcid.jaxb.model.message.OrcidMessage} that
* will be traversed looking for
* {@link org .orcid.jaxb.model.message.VisibilityType} elements.
* @param source
* The orcid source that is executing the request
* @param removeAttribute
* should all {@link org.orcid.jaxb.model.message.Visibility}
* elements be removed from the object graph. This has the effect
* that they will not be present in the resulting JAXB
* serialisation.
* @param visibilities
* What {@link org.orcid.jaxb.model.message.Visibility} elements
* should be allowed.
* @return the cleansed {@link org.orcid.jaxb.model.message.OrcidMessage}
*/
@Override
public OrcidMessage filter(OrcidMessage messageToBeFiltered, final String sourceId, final boolean allowPrivateWorks, final boolean allowPrivateFunding, final boolean allowPrivateAffiliations, Visibility... visibilities) {
if (messageToBeFiltered == null || visibilities == null || visibilities.length == 0) {
return null;
}
String messageIdForLog = getMessageIdForLog(messageToBeFiltered);
LOGGER.debug("About to filter message: " + messageIdForLog);
final Set<Visibility> visibilitySet = new HashSet<Visibility>(Arrays.asList(visibilities));
if (visibilitySet.contains(Visibility.SYSTEM)) {
return messageToBeFiltered;
} else {
TreeCleaner treeCleaner = new TreeCleaner();
treeCleaner.clean(messageToBeFiltered, new TreeCleaningStrategy() {
public TreeCleaningDecision needsStripping(Object obj) {
TreeCleaningDecision decision = TreeCleaningDecision.DEFAULT;
if (obj != null) {
Class<?> clazz = obj.getClass();
if (!PojoUtil.isEmpty(sourceId)) {
if (allowPrivateAffiliations && Affiliation.class.isAssignableFrom(clazz)) {
Affiliation affiliation = (Affiliation) obj;
Source source = affiliation.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateFunding && Funding.class.isAssignableFrom(clazz)) {
Funding funding = (Funding) obj;
Source source = funding.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateWorks && OrcidWork.class.isAssignableFrom(clazz)) {
OrcidWork work = (OrcidWork) obj;
Source source = work.getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
}
// fields are inside the country element
if (Address.class.isAssignableFrom(clazz)) {
Address address = (Address) obj;
// Remove empty addresses
if (address.getCountry() == null) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
} else {
Country country = address.getCountry();
// Allow public addresses
if (Visibility.PUBLIC.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else if (visibilitySet.contains(Visibility.LIMITED)) {
// Allow limited visibility when possible
if (Visibility.LIMITED.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else {
// As last resource, check the source
Source source = country.getSource();
if (source != null && sourceId != null && sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
} else {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
}
if (Email.class.isAssignableFrom(clazz)) {
// include all emails if present
try {
Authentication authentication = getAuthentication();
if (authentication != null && messageToBeFiltered.getOrcidProfile() != null) {
permissionChecker.checkPermissions(getAuthentication(), ScopePathType.EMAIL_READ_PRIVATE, messageToBeFiltered.getOrcidProfile().retrieveOrcidPath());
decision = TreeCleaningDecision.IGNORE;
}
} catch (AccessControlException e) {
// private email can't be read, do nothing here
}
}
// that implements PrivateVisibleToSource
if (sourceId != null)
if (PrivateVisibleToSource.class.isAssignableFrom(clazz) && visibilitySet.contains(Visibility.LIMITED)) {
Source source = ((PrivateVisibleToSource) obj).getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
if (TreeCleaningDecision.DEFAULT.equals(decision)) {
if (WorkContributors.class.isAssignableFrom(clazz)) {
decision = TreeCleaningDecision.IGNORE;
} else if (VisibilityType.class.isAssignableFrom(clazz)) {
VisibilityType visibilityType = (VisibilityType) obj;
if ((visibilityType.getVisibility() == null || !visibilitySet.contains(visibilityType.getVisibility()))) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
return decision;
}
});
OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile();
if (orcidProfile != null) {
orcidProfile.setOrcidInternal(null);
}
LOGGER.debug("Finished filtering message: " + messageIdForLog);
return messageToBeFiltered;
}
}
Aggregations