Search in sources :

Example 1 with Visibility

use of org.orcid.jaxb.model.message.Visibility in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method copyUpdatedExternalIdentifiersToExistingPreservingVisibility.

@Override
public void copyUpdatedExternalIdentifiersToExistingPreservingVisibility(OrcidBio existing, OrcidBio updated) {
    if (updated.getExternalIdentifiers() == null) {
        return;
    }
    ExternalIdentifiers existingExternalIdentifiers = existing.getExternalIdentifiers();
    ExternalIdentifiers updatedExternalIdentifiers = updated.getExternalIdentifiers();
    Visibility existingExternalIdentifiersVisibility = existingExternalIdentifiers != null ? existingExternalIdentifiers.getVisibility() : null;
    Visibility updatedExternalIdentifiersVisibility = updatedExternalIdentifiers.getVisibility();
    if (updatedExternalIdentifiersVisibility == null && existingExternalIdentifiersVisibility == null) {
        updatedExternalIdentifiers.setVisibility(OrcidVisibilityDefaults.EXTERNAL_IDENTIFIER_DEFAULT.getVisibility());
    } else if (updatedExternalIdentifiersVisibility == null && existingExternalIdentifiersVisibility != null) {
        updatedExternalIdentifiers.setVisibility(existingExternalIdentifiersVisibility);
    }
    existing.setExternalIdentifiers(updatedExternalIdentifiers);
}
Also used : Visibility(org.orcid.jaxb.model.message.Visibility) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers)

Example 2 with Visibility

use of org.orcid.jaxb.model.message.Visibility in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method copyUpdatedShortDescriptionToExistingPreservingVisibility.

@Override
public void copyUpdatedShortDescriptionToExistingPreservingVisibility(OrcidBio existing, OrcidBio updated) {
    if (updated.getBiography() == null) {
        return;
    }
    Biography existingShortDescription = existing.getBiography();
    Biography updatedShortDescription = updated.getBiography();
    Visibility existingShortDescriptionVisibility = existingShortDescription != null ? existingShortDescription.getVisibility() : OrcidVisibilityDefaults.SHORT_DESCRIPTION_DEFAULT.getVisibility();
    Visibility updatedShortDescriptionVisibility = updatedShortDescription != null ? updatedShortDescription.getVisibility() : existingShortDescriptionVisibility;
    if (updatedShortDescriptionVisibility == null && existingShortDescriptionVisibility == null) {
        updatedShortDescription.setVisibility(OrcidVisibilityDefaults.SHORT_DESCRIPTION_DEFAULT.getVisibility());
    } else if (updatedShortDescriptionVisibility == null && existingShortDescriptionVisibility != null) {
        updatedShortDescription.setVisibility(existingShortDescriptionVisibility);
    }
    if (existingShortDescription != null) {
        if (existingShortDescription.getVisibility() != null && !existingShortDescription.getVisibility().equals(Visibility.PRIVATE)) {
            existing.setBiography(updatedShortDescription);
        }
    } else {
        existing.setBiography(updatedShortDescription);
    }
}
Also used : Biography(org.orcid.jaxb.model.message.Biography) Visibility(org.orcid.jaxb.model.message.Visibility)

Example 3 with Visibility

use of org.orcid.jaxb.model.message.Visibility in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method copyUpdatedResearcherUrlPreservingVisbility.

@Override
public void copyUpdatedResearcherUrlPreservingVisbility(OrcidBio existing, OrcidBio updated) {
    if (updated.getResearcherUrls() == null) {
        return;
    }
    ResearcherUrls existingResearcherUrls = existing.getResearcherUrls();
    ResearcherUrls updatedResearcherUrls = updated.getResearcherUrls();
    Visibility existingVisibility = (existingResearcherUrls != null && existingResearcherUrls.getVisibility() != null) ? existingResearcherUrls.getVisibility() : OrcidVisibilityDefaults.RESEARCHER_URLS_DEFAULT.getVisibility();
    Visibility updatedVisibility = (updatedResearcherUrls != null && updatedResearcherUrls.getVisibility() != null) ? updatedResearcherUrls.getVisibility() : existingVisibility;
    // now visibility has been preserved, overwrite the content
    updatedResearcherUrls.setVisibility(updatedVisibility);
    existing.setResearcherUrls(updatedResearcherUrls);
}
Also used : ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) Visibility(org.orcid.jaxb.model.message.Visibility)

Example 4 with Visibility

use of org.orcid.jaxb.model.message.Visibility in project ORCID-Source by ORCID.

the class DefaultOAuthClientVisibilityTest method testCheckClientPermissionsAllowOnlyPublicAndLimitedVisibility.

@Test
@Transactional
@Rollback
public void testCheckClientPermissionsAllowOnlyPublicAndLimitedVisibility() throws Exception {
    Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
    HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
    AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4446", Arrays.asList("/orcid-bio/external-identifiers/create"));
    request.setAuthorities(grantedAuthorities);
    request.setResourceIds(resourceIds);
    ProfileEntity entity = new ProfileEntity("4444-4444-4444-4446");
    OrcidOauth2UserAuthentication oauth2UserAuthentication = new OrcidOauth2UserAuthentication(entity, true);
    // we care only that an OAuth client request results in the correct
    // visibilities
    OrcidOAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, oauth2UserAuthentication, "made-up-token");
    OrcidOauth2TokenDetail tokenDetail = new OrcidOauth2TokenDetail();
    tokenDetail.setScope("/orcid-bio/external-identifiers/create");
    tokenDetail.setDateCreated(new Date());
    when(orcidOauth2TokenDetailService.findNonDisabledByTokenValue(any(String.class))).thenReturn(tokenDetail);
    ScopePathType scopePathType = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE;
    Set<Visibility> visibilitiesForClient = permissionChecker.obtainVisibilitiesForAuthentication(oAuth2Authentication, scopePathType, getOrcidMessage());
    assertTrue(visibilitiesForClient.size() == 3);
    assertTrue(visibilitiesForClient.contains(Visibility.LIMITED));
    assertTrue(visibilitiesForClient.contains(Visibility.REGISTERED_ONLY));
    assertTrue(visibilitiesForClient.contains(Visibility.PUBLIC));
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2UserAuthentication(org.orcid.core.oauth.OrcidOauth2UserAuthentication) Visibility(org.orcid.jaxb.model.message.Visibility) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Visibility

use of org.orcid.jaxb.model.message.Visibility in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method copyCreditNamePreservingVisibility.

private void copyCreditNamePreservingVisibility(PersonalDetails existingPersonalDetails, PersonalDetails updatedPersonalDetails) {
    CreditName existingCreditName = existingPersonalDetails.getCreditName();
    CreditName updatedCreditName = updatedPersonalDetails.getCreditName();
    // if no update, nothing to do
    if (updatedCreditName == null) {
        return;
    }
    // otherwise take into account the visibility of updated and existing
    Visibility existingVisibility = (existingCreditName != null && existingCreditName.getVisibility() != null) ? existingCreditName.getVisibility() : OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility();
    // If it is private, ignore the request
    if (!existingVisibility.equals(Visibility.PRIVATE)) {
        Visibility updatedVisibility = (updatedCreditName != null && updatedCreditName.getVisibility() != null) ? updatedCreditName.getVisibility() : existingVisibility;
        updatedCreditName.setVisibility(updatedVisibility);
        // now visibility has been preserved, overwrite the content
        existingPersonalDetails.setCreditName(updatedCreditName);
    }
}
Also used : CreditName(org.orcid.jaxb.model.message.CreditName) Visibility(org.orcid.jaxb.model.message.Visibility)

Aggregations

Visibility (org.orcid.jaxb.model.message.Visibility)17 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)6 Transactional (org.springframework.transaction.annotation.Transactional)5 HashSet (java.util.HashSet)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 AccessControlException (java.security.AccessControlException)2 Date (java.util.Date)2 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)2 Affiliation (org.orcid.jaxb.model.message.Affiliation)2 Country (org.orcid.jaxb.model.message.Country)2 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)2 Funding (org.orcid.jaxb.model.message.Funding)2 Keywords (org.orcid.jaxb.model.message.Keywords)2 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)2 OtherNames (org.orcid.jaxb.model.message.OtherNames)2 ResearcherUrls (org.orcid.jaxb.model.message.ResearcherUrls)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1