Search in sources :

Example 41 with InvitedPosition

use of org.orcid.jaxb.model.v3.dev1.record.InvitedPosition in project ORCID-Source by ORCID.

the class AffiliationsManagerTest method testAddInvitedPositionToUnclaimedRecordPreserveInvitedPositionVisibility.

@Test
public void testAddInvitedPositionToUnclaimedRecordPreserveInvitedPositionVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    InvitedPosition element = getInvitedPosition();
    element = affiliationsManager.createInvitedPositionAffiliation(unclaimedOrcid, element, true);
    element = affiliationsManager.getInvitedPositionAffiliation(unclaimedOrcid, element.getPutCode());
    assertNotNull(element);
    assertEquals(Visibility.PUBLIC, element.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 42 with InvitedPosition

use of org.orcid.jaxb.model.v3.dev1.record.InvitedPosition in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method createInvitedPosition.

@Override
public Response createInvitedPosition(String orcid, InvitedPosition invitedPosition) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE, ScopePathType.AFFILIATIONS_UPDATE);
    clearSource(invitedPosition);
    InvitedPosition e = affiliationsManager.createInvitedPositionAffiliation(orcid, invitedPosition, true);
    sourceUtils.setSourceName(e);
    try {
        return Response.created(new URI(String.valueOf(e.getPutCode()))).build();
    } catch (URISyntaxException ex) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.createdistinction_response.exception"), ex);
    }
}
Also used : InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 43 with InvitedPosition

use of org.orcid.jaxb.model.v3.dev1.record.InvitedPosition in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method updateInvitedPosition.

@Override
public Response updateInvitedPosition(String orcid, Long putCode, InvitedPosition invitedPosition) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_UPDATE);
    if (!putCode.equals(invitedPosition.getPutCode())) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("urlPutCode", String.valueOf(putCode));
        params.put("bodyPutCode", String.valueOf(invitedPosition.getPutCode()));
        throw new MismatchedPutCodeException(params);
    }
    clearSource(invitedPosition);
    InvitedPosition e = affiliationsManager.updateInvitedPositionAffiliation(orcid, invitedPosition, true);
    sourceUtils.setSourceName(e);
    return Response.ok(e).build();
}
Also used : HashMap(java.util.HashMap) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 44 with InvitedPosition

use of org.orcid.jaxb.model.v3.dev1.record.InvitedPosition in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method testUpdateInvitedPositionWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateInvitedPositionWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    InvitedPosition invitedPosition = (InvitedPosition) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/invited-position-3.0_dev1.xml", InvitedPosition.class);
    invitedPosition.setPutCode(null);
    invitedPosition.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createInvitedPositionXml(this.getUser1OrcidId(), invitedPosition, 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/" + this.getUser1OrcidId() + "/invited-position/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    InvitedPosition gotInvitedPosition = getResponse.getEntity(InvitedPosition.class);
    assertEquals("department-name", gotInvitedPosition.getDepartmentName());
    assertEquals("role-title", gotInvitedPosition.getRoleTitle());
    gotInvitedPosition.setDepartmentName("updated dept. name");
    gotInvitedPosition.setRoleTitle("updated role title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotInvitedPosition);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    InvitedPosition gotAfterUpdateInvitedPosition = getAfterUpdateResponse.getEntity(InvitedPosition.class);
    assertEquals("department-name", gotAfterUpdateInvitedPosition.getDepartmentName());
    assertEquals("role-title", gotAfterUpdateInvitedPosition.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteInvitedPositionXml(this.getUser1OrcidId(), gotInvitedPosition.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Test(org.junit.Test)

Example 45 with InvitedPosition

use of org.orcid.jaxb.model.v3.dev1.record.InvitedPosition in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method createViewUpdateAndDeleteInvitedPosition.

@Test
public void createViewUpdateAndDeleteInvitedPosition() throws JSONException, InterruptedException, URISyntaxException {
    InvitedPosition invitedPosition = (InvitedPosition) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/invited-position-3.0_dev1.xml", InvitedPosition.class);
    invitedPosition.setPutCode(null);
    invitedPosition.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createInvitedPositionXml(this.getUser1OrcidId(), invitedPosition, 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/" + this.getUser1OrcidId() + "/invited-position/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    InvitedPosition gotInvitedPosition = getResponse.getEntity(InvitedPosition.class);
    assertEquals("department-name", gotInvitedPosition.getDepartmentName());
    assertEquals("role-title", gotInvitedPosition.getRoleTitle());
    // Save the original visibility
    Visibility originalVisibility = gotInvitedPosition.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotInvitedPosition.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotInvitedPosition);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotInvitedPosition.setVisibility(originalVisibility);
    gotInvitedPosition.setDepartmentName("updated dept. name");
    gotInvitedPosition.setRoleTitle("updated role title");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotInvitedPosition);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    InvitedPosition gotAfterUpdateInvitedPosition = getAfterUpdateResponse.getEntity(InvitedPosition.class);
    assertEquals("updated dept. name", gotAfterUpdateInvitedPosition.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateInvitedPosition.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteInvitedPositionXml(this.getUser1OrcidId(), gotInvitedPosition.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Aggregations

InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)40 Test (org.junit.Test)28 DBUnitTest (org.orcid.test.DBUnitTest)17 Response (javax.ws.rs.core.Response)16 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Education (org.orcid.jaxb.model.v3.dev1.record.Education)11 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)11 Service (org.orcid.jaxb.model.v3.dev1.record.Service)11 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)10 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)7 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)6 List (java.util.List)4 Url (org.orcid.jaxb.model.v3.dev1.common.Url)4 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)4 Work (org.orcid.jaxb.model.v3.dev1.record.Work)4 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)4 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)4