use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testCreateWithAffiliations.
@Test
public void testCreateWithAffiliations() throws JAXBException {
setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = getOrcidMessage("/orcid-message-for-create-latest.xml");
Response createResponse = t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
assertNotNull(createResponse);
assertEquals(HttpStatus.SC_CREATED, createResponse.getStatus());
String location = ((URI) createResponse.getMetadata().getFirst("Location")).getPath();
assertNotNull(location);
String orcid = location.substring(1, 20);
Response readResponse = t2OrcidApiServiceDelegatorLatest.findFullDetails(orcid);
assertNotNull(readResponse);
assertEquals(HttpStatus.SC_OK, readResponse.getStatus());
OrcidMessage retrievedMessage = (OrcidMessage) readResponse.getEntity();
OrcidProfile orcidProfile = retrievedMessage.getOrcidProfile();
assertEquals(orcid, orcidProfile.getOrcidIdentifier().getPath());
Affiliations affiliations = orcidProfile.retrieveAffiliations();
assertNotNull(affiliations);
assertEquals(1, affiliations.getAffiliation().size());
Affiliation affiliation = affiliations.getAffiliation().get(0);
assertEquals(Visibility.PRIVATE, affiliation.getVisibility());
Source source = affiliation.getSource();
assertNotNull(source);
String sourceOrcid = source.retrieveSourcePath();
assertNotNull(sourceOrcid);
assertEquals("APP-5555555555555555", sourceOrcid);
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method buildMessageWithAffiliation.
private OrcidMessage buildMessageWithAffiliation(AffiliationType type, String dept, String role, String orcid) {
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier(orcid));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
Affiliation affiliation = new Affiliation();
affiliation.setStartDate(new FuzzyDate(2010, 01, 01));
affiliation.setEndDate(new FuzzyDate(2015, 01, 01));
affiliation.setDepartmentName(dept);
affiliation.setRoleTitle(role);
affiliation.setType(type);
Organization organization = new Organization();
organization.setName("My Org");
OrganizationAddress add = new OrganizationAddress();
add.setCity("My City");
add.setCountry(Iso3166Country.US);
organization.setAddress(add);
DisambiguatedOrganization dorg = new DisambiguatedOrganization();
dorg.setDisambiguatedOrganizationIdentifier("disambiguated org ID");
dorg.setDisambiguationSource("THESOURCE");
organization.setDisambiguatedOrganization(dorg);
affiliation.setOrganization(organization);
affiliations.getAffiliation().add(affiliation);
orcidActivities.setAffiliations(affiliations);
return orcidMessage;
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testAddWorks.
@Test
public void testAddWorks() {
setUpSecurityContext();
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4441"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
OrcidWorks orcidWorks = new OrcidWorks();
orcidActivities.setOrcidWorks(orcidWorks);
Response response = t2OrcidApiServiceDelegatorLatest.addWorks(mockedUriInfo, "4444-4444-4444-4441", orcidMessage);
assertNotNull(response);
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorImpl method createProfile.
/**
* Creates a new profile and returns the saved representation of it. The
* response should include the 'location' to retrieve the newly created
* profile from.
*
* @param orcidMessage
* the message to be saved. If the message already contains an
* ORCID value a 400 Bad Request
* @return if the creation was successful, returns a 201 along with the
* location of the newly created resource otherwise returns an error
* response describing the problem
*/
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_PROFILE_CREATE)
public Response createProfile(UriInfo uriInfo, OrcidMessage orcidMessage) {
OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
try {
setSponsorFromAuthentication(orcidProfile);
orcidProfile = orcidProfileManager.createOrcidProfileAndNotify(orcidProfile);
return getCreatedResponse(uriInfo, PROFILE_GET_PATH, orcidProfile);
} catch (DataAccessException e) {
if (e.getCause() != null && ConstraintViolationException.class.isAssignableFrom(e.getCause().getClass())) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_email_exists.exception"));
}
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_createorcid.exception"), e);
}
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorImpl method addExternalIdentifiers.
/**
* Add new external identifiers to the profile. As with all calls, if the
* message contains any other elements, a 400 Bad Request will be returned.
*
* @param orcidMessage
* the message congtaining the external ids
* @return If successful, returns a 200 OK with the updated content.
*/
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE)
public Response addExternalIdentifiers(UriInfo uriInfo, String orcid, OrcidMessage orcidMessage) {
OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
try {
ExternalIdentifiers updatedExternalIdentifiers = orcidProfile.getOrcidBio().getExternalIdentifiers();
// Get the client profile information
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String clientId = null;
if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
clientId = authorizationRequest.getClientId();
}
for (ExternalIdentifier ei : updatedExternalIdentifiers.getExternalIdentifier()) {
// Set the client profile to each external identifier
if (ei.getSource() == null) {
Source source = new Source();
source.setSourceClientId(new SourceClientId(clientId));
ei.setSource(source);
} else {
// Check if the provided external orcid exists
Source source = ei.getSource();
String sourceOrcid = source.retrieveSourcePath();
if (sourceOrcid != null) {
if (StringUtils.isBlank(sourceOrcid) || (!profileEntityManager.orcidExists(sourceOrcid) && !clientDetailsManager.exists(sourceOrcid))) {
Map<String, String> params = new HashMap<String, String>();
params.put("orcid", sourceOrcid);
throw new OrcidNotFoundException(params);
}
}
}
}
orcidProfile = orcidProfileManager.addExternalIdentifiers(orcidProfile);
return getOrcidMessageResponse(orcidProfile, orcid);
} catch (DataAccessException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_createorcid.exception"));
}
}
Aggregations