use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method persistAddedAffiliations.
private void persistAddedAffiliations(String orcid, List<Affiliation> updatedAffiliationsList) {
ProfileEntity profileEntity = profileDao.find(orcid);
for (Affiliation updatedAffiliation : updatedAffiliationsList) {
OrgAffiliationRelationEntity orgAffiliationRelationEntity = jaxb2JpaAdapter.getNewOrgAffiliationRelationEntity(updatedAffiliation, profileEntity);
orgAffiliationRelationDao.persist(orgAffiliationRelationEntity);
}
orcidProfileCacheManager.remove(orcid);
}
use of org.orcid.jaxb.model.message.Affiliation 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.Affiliation in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testCreateWithAffiliations.
@Test
public void testCreateWithAffiliations() throws JAXBException {
setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = getOrcidMessage("/orcid-message-for-create-latest.xml");
Response createResponse = t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
assertNotNull(createResponse);
assertEquals(HttpStatus.SC_CREATED, createResponse.getStatus());
String location = ((URI) createResponse.getMetadata().getFirst("Location")).getPath();
assertNotNull(location);
String orcid = location.substring(1, 20);
Response readResponse = t2OrcidApiServiceDelegatorLatest.findFullDetails(orcid);
assertNotNull(readResponse);
assertEquals(HttpStatus.SC_OK, readResponse.getStatus());
OrcidMessage retrievedMessage = (OrcidMessage) readResponse.getEntity();
OrcidProfile orcidProfile = retrievedMessage.getOrcidProfile();
assertEquals(orcid, orcidProfile.getOrcidIdentifier().getPath());
Affiliations affiliations = orcidProfile.retrieveAffiliations();
assertNotNull(affiliations);
assertEquals(1, affiliations.getAffiliation().size());
Affiliation affiliation = affiliations.getAffiliation().get(0);
assertEquals(Visibility.PRIVATE, affiliation.getVisibility());
Source source = affiliation.getSource();
assertNotNull(source);
String sourceOrcid = source.retrieveSourcePath();
assertNotNull(sourceOrcid);
assertEquals("APP-5555555555555555", sourceOrcid);
}
use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method buildMessageWithAffiliation.
private OrcidMessage buildMessageWithAffiliation(AffiliationType type, String dept, String role, String orcid) {
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier(orcid));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
Affiliation affiliation = new Affiliation();
affiliation.setStartDate(new FuzzyDate(2010, 01, 01));
affiliation.setEndDate(new FuzzyDate(2015, 01, 01));
affiliation.setDepartmentName(dept);
affiliation.setRoleTitle(role);
affiliation.setType(type);
Organization organization = new Organization();
organization.setName("My Org");
OrganizationAddress add = new OrganizationAddress();
add.setCity("My City");
add.setCountry(Iso3166Country.US);
organization.setAddress(add);
DisambiguatedOrganization dorg = new DisambiguatedOrganization();
dorg.setDisambiguatedOrganizationIdentifier("disambiguated org ID");
dorg.setDisambiguationSource("THESOURCE");
organization.setDisambiguatedOrganization(dorg);
affiliation.setOrganization(organization);
affiliations.getAffiliation().add(affiliation);
orcidActivities.setAffiliations(affiliations);
return orcidMessage;
}
use of org.orcid.jaxb.model.message.Affiliation 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