Search in sources :

Example 56 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword.

@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.Keyword newKeyword = new org.orcid.jaxb.model.v3.dev1.record.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV3Dev1ApiClient.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV3Dev1ApiClient.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.Keywords keywords = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.v3.dev1.record.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV3Dev1ApiClient.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.v3.dev1.common.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.v3.dev1.common.Visibility updatedVisibility = org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClient.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.error.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.v3.dev1.error.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV3Dev1ApiClient.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV3Dev1ApiClient.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.v3.dev1.record.Keyword updatedKeyword = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV3Dev1ApiClient.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 57 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class OtherNamesTest method testCreateGetUpdateAndDeleteOtherName.

@SuppressWarnings({ "rawtypes", "deprecation" })
@Test
public void testCreateGetUpdateAndDeleteOtherName() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    changeCurrentOtherNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.OtherName newOtherName = new org.orcid.jaxb.model.v3.dev1.record.OtherName();
    newOtherName.setContent("other-name-3" + System.currentTimeMillis());
    newOtherName.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    // Create
    ClientResponse response = memberV3Dev1ApiClient.createOtherName(getUser1OrcidId(), newOtherName, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get and verify
    response = memberV3Dev1ApiClient.viewOtherNames(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.OtherNames otherNames = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherNames.class);
    assertNotNull(otherNames);
    assertNotNull(otherNames.getOtherNames());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.v3.dev1.record.OtherName existingOtherName : otherNames.getOtherNames()) {
        if (otherName1.equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingOtherName.getVisibility());
            found1 = true;
        } else if (otherName2.equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingOtherName.getVisibility());
            found2 = true;
        } else if (newOtherName.getContent().equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, existingOtherName.getVisibility());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV3Dev1ApiClient.viewOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.v3.dev1.record.OtherName otherName = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherName.class);
    assertNotNull(otherName);
    assertEquals(newOtherName.getContent(), otherName.getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
    assertEquals(putCode, otherName.getPutCode());
    assertNotNull(otherName.getDisplayIndex());
    Long originalDisplayIndex = otherName.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.v3.dev1.common.Visibility originalVisibility = otherName.getVisibility();
    org.orcid.jaxb.model.v3.dev1.common.Visibility updatedVisibility = org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC;
    // Verify you cant update the visibility
    otherName.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClient.updateOtherName(this.getUser1OrcidId(), otherName, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.error.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.v3.dev1.error.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    otherName.setVisibility(originalVisibility);
    // Update it
    otherName.setContent("Other Name #1 - Updated");
    response = memberV3Dev1ApiClient.updateOtherName(this.getUser1OrcidId(), otherName, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV3Dev1ApiClient.viewOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    otherName = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherName.class);
    assertNotNull(otherName);
    assertEquals("Other Name #1 - Updated", otherName.getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
    assertEquals(putCode, otherName.getPutCode());
    assertEquals(originalDisplayIndex, otherName.getDisplayIndex());
    // Delete
    response = memberV3Dev1ApiClient.deleteOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 58 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class ResearcherUrlsTest method testCreateGetUpdateAndDeleteResearcherUrl.

@Test
public void testCreateGetUpdateAndDeleteResearcherUrl() throws InterruptedException, JSONException, URISyntaxException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl rUrlToCreate = new org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl();
    long time = System.currentTimeMillis();
    String url = "http://test.orcid.org/test/" + time;
    rUrlToCreate.setUrl(new org.orcid.jaxb.model.v3.dev1.common.Url(url));
    rUrlToCreate.setUrlName(url);
    // Create
    ClientResponse postResponse = memberV3Dev1ApiClient.createResearcherUrls(getUser1OrcidId(), rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + getUser1OrcidId() + "/researcher-urls/\\d+"));
    // Read
    ClientResponse getResponse = memberV3Dev1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl gotResearcherUrl = getResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl.class);
    assertNotNull(gotResearcherUrl);
    assertNotNull(gotResearcherUrl.getPutCode());
    assertNotNull(gotResearcherUrl.getSource());
    assertNotNull(gotResearcherUrl.getCreatedDate());
    assertNotNull(gotResearcherUrl.getLastModifiedDate());
    assertEquals(getClient1ClientId(), gotResearcherUrl.getSource().retrieveSourcePath());
    assertEquals("http://test.orcid.org/test/" + time, gotResearcherUrl.getUrl().getValue());
    assertEquals("http://test.orcid.org/test/" + time, gotResearcherUrl.getUrlName());
    assertEquals("public", gotResearcherUrl.getVisibility().value());
    assertNotNull(gotResearcherUrl.getDisplayIndex());
    Long originalDisplayIndex = gotResearcherUrl.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.v3.dev1.common.Visibility originalVisibility = gotResearcherUrl.getVisibility();
    org.orcid.jaxb.model.v3.dev1.common.Visibility updatedVisibility = org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.equals(originalVisibility) ? org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED : org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotResearcherUrl.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotResearcherUrl);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_v2.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_v2.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotResearcherUrl.setVisibility(originalVisibility);
    // Update
    org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate initialLastModified = gotResearcherUrl.getLastModifiedDate();
    Long currentTime = System.currentTimeMillis();
    gotResearcherUrl.setUrlName(gotResearcherUrl.getUrlName() + " - " + currentTime);
    gotResearcherUrl.getUrl().setValue(gotResearcherUrl.getUrl().getValue() + currentTime);
    ClientResponse updatedResearcherUrlResponse = memberV3Dev1ApiClient.updateResearcherUrls(getUser1OrcidId(), gotResearcherUrl, accessToken);
    assertNotNull(updatedResearcherUrlResponse);
    assertEquals(Response.Status.OK.getStatusCode(), updatedResearcherUrlResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl updatedResearcherUrl = updatedResearcherUrlResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl.class);
    assertNotNull(updatedResearcherUrl);
    assertEquals("http://test.orcid.org/test/" + time + currentTime, updatedResearcherUrl.getUrl().getValue());
    assertEquals("http://test.orcid.org/test/" + time + " - " + currentTime, updatedResearcherUrl.getUrlName());
    assertEquals(originalDisplayIndex, updatedResearcherUrl.getDisplayIndex());
    // Keep it public, since it is more restrictive than the user visibility
    // default
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, updatedResearcherUrl.getVisibility());
    assertFalse(initialLastModified.equals(updatedResearcherUrl.getLastModifiedDate()));
    // Delete
    ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteResearcherUrl(getUser1OrcidId(), gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 59 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class ContributorUtils method filterContributorPrivateData.

public void filterContributorPrivateData(Work work) {
    if (work.getWorkContributors() != null && work.getWorkContributors().getContributor() != null) {
        for (Contributor contributor : work.getWorkContributors().getContributor()) {
            contributor.setContributorEmail(null);
            if (!PojoUtil.isEmpty(contributor.getContributorOrcid())) {
                String contributorOrcid = contributor.getContributorOrcid().getPath();
                if (profileEntityManager.orcidExists(contributorOrcid)) {
                    // contributor is an ORCID user - visibility of user's
                    // name in record must be taken into account
                    ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                    String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                    CreditName creditName = new CreditName(publicContributorCreditName != null ? publicContributorCreditName : "");
                    contributor.setCreditName(creditName);
                }
            }
        }
    }
}
Also used : CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 60 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.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.v3.dev1.common.Filterable) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException)

Aggregations

Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)44 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 Test (org.junit.Test)17 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Url (org.orcid.jaxb.model.v3.dev1.common.Url)11 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)11 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 HashMap (java.util.HashMap)10 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Name (org.orcid.jaxb.model.v3.dev1.record.Name)7 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)6 Date (java.util.Date)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5