Search in sources :

Example 96 with Visibility

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

the class ProfileKeywordManagerImpl method updateKeyword.

@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    //Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedEntity);
    adapter.toProfileKeywordEntity(keyword, updatedEntity);
    updatedEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    profileKeywordDao.merge(updatedEntity);
    return adapter.toKeyword(updatedEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 97 with Visibility

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

the class ProfileFundingManagerImpl method setIncomingWorkPrivacy.

private void setIncomingWorkPrivacy(ProfileFundingEntity profileFundingEntity, ProfileEntity profile) {
    Visibility incomingWorkVisibility = profileFundingEntity.getVisibility();
    Visibility defaultWorkVisibility = profile.getActivitiesVisibilityDefault();
    if (profile.getClaimed()) {
        profileFundingEntity.setVisibility(defaultWorkVisibility);
    } else if (incomingWorkVisibility == null) {
        profileFundingEntity.setVisibility(Visibility.PRIVATE);
    }
}
Also used : Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 98 with Visibility

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

the class OrcidSecurityManagerImpl method checkAndFilter.

/**
     * Check the permissions of a request over an element. Private
     * implementation that will also include a parameter that indicates if we
     * should check the token or, if it was already checked previously
     * 
     * @param orcid
     *            The user owner of the element
     * @param element
     *            The element to check
     * @param requiredScope
     *            The required scope to access this element
     * @param tokenAlreadyChecked
     *            Indicates if the token was already checked previously, so, we
     *            don't expend time checking it again
     * @throws OrcidUnauthorizedException
     *             In case the token used was not issued for the owner of the
     *             element
     * @throws OrcidAccessControlException
     *             In case the request doesn't have the required scopes
     * @throws OrcidVisibilityException
     *             In case the element is not visible due the visibility
     */
private void checkAndFilter(String orcid, VisibilityType element, ScopePathType requiredScope, boolean tokenAlreadyChecked) {
    if (element == null) {
        return;
    }
    // Check the token was issued for this user
    if (!tokenAlreadyChecked) {
        isMyToken(orcid);
    }
    // Check if the client is the source of the element
    if (element instanceof Filterable) {
        Filterable filterable = (Filterable) element;
        OAuth2Authentication oAuth2Authentication = getOAuth2Authentication();
        if (oAuth2Authentication != null) {
            OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
            String clientId = authorizationRequest.getClientId();
            if (clientId.equals(filterable.retrieveSourcePath())) {
                // The client doing the request is the source of the element
                return;
            }
        }
    }
    // /read-public scope
    if (Visibility.PUBLIC.equals(element.getVisibility())) {
        try {
            checkScopes(ScopePathType.READ_PUBLIC);
            // can return it
            return;
        } catch (OrcidAccessControlException e) {
        // Just continue filtering
        }
    }
    // Filter
    filter(element, requiredScope);
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) Filterable(org.orcid.jaxb.model.common_v2.Filterable) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException)

Example 99 with Visibility

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

the class ExternalIdentifierForm method toPersonExternalIdentifier.

public PersonExternalIdentifier toPersonExternalIdentifier() {
    PersonExternalIdentifier result = new PersonExternalIdentifier();
    if (putCode != null) {
        result.setPutCode(Long.valueOf(putCode));
    }
    result.setDisplayIndex(displayIndex);
    if (visibility != null && visibility.getVisibility() != null) {
        result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(visibility.getVisibility().value()));
    }
    if (url != null) {
        result.setUrl(new Url(url));
    }
    result.setType(commonName);
    result.setValue(reference);
    return result;
}
Also used : PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Url(org.orcid.jaxb.model.common_v2.Url)

Example 100 with Visibility

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

the class ProfileFundingManagerTest method getFundingSummary.

private FundingSummary getFundingSummary(String titleValue, String extIdValue, Visibility visibility) {
    FundingSummary summary = new FundingSummary();
    FundingTitle fundingTitle = new FundingTitle();
    fundingTitle.setTitle(new Title(titleValue));
    summary.setTitle(fundingTitle);
    summary.setVisibility(visibility);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    extId.setValue(extIdValue);
    extIds.getExternalIdentifier().add(extId);
    summary.setExternalIdentifiers(extIds);
    Organization org = new Organization();
    org.setName("org-name");
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("city");
    address.setCountry(Iso3166Country.US);
    org.setAddress(address);
    summary.setOrganization(org);
    return summary;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Organization(org.orcid.jaxb.model.common_v2.Organization) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Url(org.orcid.jaxb.model.common_v2.Url)

Aggregations

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 Test (org.junit.Test)37 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Url (org.orcid.jaxb.model.common_v2.Url)12 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)12 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)6 Work (org.orcid.jaxb.model.record_v2.Work)6 Education (org.orcid.jaxb.model.record_v2.Education)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)4