use of org.orcid.jaxb.model.message.ExternalIdentifier 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"));
}
}
use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsWhenThereIsNonPublicCountry.
@Test
public void testAddDuplicatedExtIdsWhenThereIsNonPublicCountry() {
String userOrcid = "0000-0000-0000-0003";
OrcidMessage message = new OrcidMessage();
message.setMessageVersion("1.2_rc6");
message.setOrcidProfile(new OrcidProfile());
message.getOrcidProfile().setOrcidBio(new OrcidBio());
ExternalIdentifiers extIds = new ExternalIdentifiers();
ExternalIdentifier extId1 = new ExternalIdentifier();
String commonName = "common-name-1-" + System.currentTimeMillis();
extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
extIds.getExternalIdentifier().add(extId1);
message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
//Add for client 1
SecurityContextTestUtils.setUpSecurityContext(userOrcid, "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
assertNotNull(r);
OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
assertNotNull(newMessage1);
assertNotNull(newMessage1.getOrcidProfile());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(4, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(3).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(3).getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddExternalIdentifiersToDeprecatedAccount.
@Test(expected = OrcidDeprecatedException.class)
public void testAddExternalIdentifiersToDeprecatedAccount() {
SecurityContextTestUtils.setUpSecurityContext();
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
orcidMessage.setOrcidProfile(new OrcidProfile());
orcidMessage.getOrcidProfile().setOrcidBio(new OrcidBio());
ExternalIdentifiers extIds = new ExternalIdentifiers();
ExternalIdentifier extId1 = new ExternalIdentifier();
String commonName = "common-name-1-" + System.currentTimeMillis();
extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
extIds.getExternalIdentifier().add(extId1);
orcidMessage.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
t2OrcidApiServiceDelegator.addExternalIdentifiers(mockedUriInfo, "4444-4444-4444-444X", orcidMessage);
}
use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsWithDifferentClientWorks.
@Test
public void testAddDuplicatedExtIdsWithDifferentClientWorks() {
String orcid = "0000-0000-0000-0002";
OrcidMessage message = new OrcidMessage();
message.setMessageVersion("1.2_rc6");
message.setOrcidProfile(new OrcidProfile());
message.getOrcidProfile().setOrcidBio(new OrcidBio());
ExternalIdentifiers extIds = new ExternalIdentifiers();
ExternalIdentifier extId1 = new ExternalIdentifier();
String commonName = "common-name-1-" + System.currentTimeMillis();
extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
extIds.getExternalIdentifier().add(extId1);
message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
//Add for client 1
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, orcid, message);
assertNotNull(r);
OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
assertNotNull(newMessage1);
assertNotNull(newMessage1.getOrcidProfile());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
//Reset message for source # 2
message = new OrcidMessage();
message.setMessageVersion("1.2_rc6");
message.setOrcidProfile(new OrcidProfile());
message.getOrcidProfile().setOrcidBio(new OrcidBio());
extId1.setSource(null);
message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", "APP-5555555555555556", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, orcid, message);
OrcidMessage newMessage2 = (OrcidMessage) r.getEntity();
assertNotNull(newMessage2);
assertNotNull(newMessage2.getOrcidProfile());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(2, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555555", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(1).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555556", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(1).getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.
the class OrcidMessageVersionConverterImplV1_2_rc5ToV1_2_rc6 method downgradeProfile.
private void downgradeProfile(OrcidProfile orcidProfile) {
if (orcidProfile != null) {
if (orcidProfile.getOrcidBio() != null)
if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null)
for (ExternalIdentifier externalIdentifier : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
Source source = externalIdentifier.getSource();
if (source != null) {
SourceOrcid sourceOrcid = source.getSourceOrcid();
if (sourceOrcid != null) {
externalIdentifier.setSource(null);
externalIdentifier.setExternalIdSource(new ExternalIdSource(sourceOrcid));
}
}
}
if (orcidProfile.getOrcidActivities() != null) {
if (orcidProfile.getOrcidActivities().getOrcidWorks() != null) {
for (OrcidWork act : orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork()) downGradeActivity(act);
}
}
OrcidInternal orcidInternal = orcidProfile.getOrcidInternal();
if (orcidInternal != null) {
Preferences prefs = orcidInternal.getPreferences();
if (prefs != null) {
prefs.setSendEmailFrequencyDays(null);
prefs.setSendMemberUpdateRequests(null);
}
ReferredBy referredBy = orcidInternal.getReferredBy();
if (referredBy != null && !OrcidStringUtils.isValidOrcid(referredBy.getPath())) {
orcidInternal.setReferredBy(null);
}
}
}
}
Aggregations