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());
}
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);
}
}
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();
}
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());
}
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());
}
Aggregations