use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.
the class MemberV2Test method testUpdateEmploymentWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdateEmploymentWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
Employment employment = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
employment.setPutCode(null);
employment.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(this.getUser1OrcidId(), employment, 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(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/employment/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Employment gotEmployment = getResponse.getEntity(Employment.class);
assertEquals("affiliation:department-name", gotEmployment.getDepartmentName());
assertEquals("affiliation:role-title", gotEmployment.getRoleTitle());
gotEmployment.setDepartmentName("updated dept. name");
gotEmployment.setRoleTitle("updated role title");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotEmployment);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Employment gotAfterUpdateEmployment = getAfterUpdateResponse.getEntity(Employment.class);
assertEquals("affiliation:department-name", gotAfterUpdateEmployment.getDepartmentName());
assertEquals("affiliation:role-title", gotAfterUpdateEmployment.getRoleTitle());
ClientResponse deleteResponse = memberV2ApiClient.deleteEmploymentXml(this.getUser1OrcidId(), gotEmployment.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method createEmployment.
@Override
public Response createEmployment(String orcid, Employment employment) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE);
clearSource(employment);
Employment e = affiliationsManager.createEmploymentAffiliation(orcid, employment, true);
sourceUtils.setSourceName(e);
try {
return Response.created(new URI(String.valueOf(e.getPutCode()))).build();
} catch (URISyntaxException ex) {
throw new RuntimeException(localeManager.resolveMessage("apiError.createemployment_response.exception"), ex);
}
}
use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewEmployment.
@Override
public Response viewEmployment(String orcid, Long putCode) {
Employment e = affiliationsManagerReadOnly.getEmploymentAffiliation(orcid, putCode);
orcidSecurityManager.checkAndFilter(orcid, e, ScopePathType.AFFILIATIONS_READ_LIMITED);
ActivityUtils.setPathToActivity(e, orcid);
sourceUtils.setSourceName(e);
return Response.ok(e).build();
}
use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.
the class AffiliationsManagerTest method testAddEmploymentToUnclaimedRecordPreserveEmploymentVisibility.
@Test
public void testAddEmploymentToUnclaimedRecordPreserveEmploymentVisibility() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Employment employment = getEmployment();
employment = affiliationsManager.createEmploymentAffiliation(unclaimedOrcid, employment, true);
employment = affiliationsManager.getEmploymentAffiliation(unclaimedOrcid, employment.getPutCode());
assertNotNull(employment);
assertEquals(Visibility.PUBLIC, employment.getVisibility());
}
use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.
the class BlackBoxBaseRC3 method unmarshallFromPath.
public Object unmarshallFromPath(String path, Class<?> type) {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type);
Object result = null;
if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Education.class.equals(type)) {
result = (Education) obj;
} else if (Employment.class.equals(type)) {
result = (Employment) obj;
} else if (Funding.class.equals(type)) {
result = (Funding) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Work.class.equals(type)) {
result = (Work) obj;
} else if (PeerReview.class.equals(type)) {
result = (PeerReview) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
Aggregations