use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testUpdateAffiliationWhenNotSource.
@Test(expected = WrongSourceException.class)
@Transactional
public void testUpdateAffiliationWhenNotSource() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.AFFILIATIONS_UPDATE);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4443"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
orcidActivities.setAffiliations(affiliations);
Affiliation affiliation1 = new Affiliation();
affiliations.getAffiliation().add(affiliation1);
affiliation1.setPutCode("2");
affiliation1.setType(AffiliationType.EDUCATION);
Organization organization1 = new Organization();
affiliation1.setOrganization(organization1);
organization1.setName("Different org");
OrganizationAddress organizationAddress = new OrganizationAddress();
organization1.setAddress(organizationAddress);
organizationAddress.setCity("Edinburgh");
organizationAddress.setCountry(Iso3166Country.GB);
t2OrcidApiServiceDelegator.updateAffiliations(mockedUriInfo, "4444-4444-4444-4443", orcidMessage);
}
use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddAffilliations.
@Test
public void testAddAffilliations() {
SecurityContextTestUtils.setUpSecurityContext(ScopePathType.AFFILIATIONS_CREATE);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4441"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
orcidActivities.setAffiliations(affiliations);
Affiliation affiliation1 = new Affiliation();
affiliations.getAffiliation().add(affiliation1);
affiliation1.setType(AffiliationType.EDUCATION);
Organization organization1 = new Organization();
affiliation1.setOrganization(organization1);
organization1.setName("A new affiliation");
OrganizationAddress organizationAddress = new OrganizationAddress();
organization1.setAddress(organizationAddress);
organizationAddress.setCity("Edinburgh");
organizationAddress.setCountry(Iso3166Country.GB);
Response response = t2OrcidApiServiceDelegator.addAffiliations(mockedUriInfo, "4444-4444-4444-4441", orcidMessage);
assertNotNull(response);
assertEquals(HttpStatus.SC_CREATED, response.getStatus());
String location = ((URI) response.getMetadata().getFirst("Location")).getPath();
assertNotNull(location);
OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4441");
List<Affiliation> affiliationsList = retrievedProfile.getOrcidActivities().getAffiliations().getAffiliation();
assertEquals(1, affiliationsList.size());
Affiliation affiliation = affiliationsList.get(0);
assertEquals("A new affiliation", affiliation.getOrganization().getName());
assertEquals("APP-5555555555555555", affiliation.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testUpdateWithNewAffiliation.
@Test
@Transactional
public void testUpdateWithNewAffiliation() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.AFFILIATIONS_UPDATE);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4443"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
orcidActivities.setAffiliations(affiliations);
Affiliation affiliation1 = new Affiliation();
affiliations.getAffiliation().add(affiliation1);
affiliation1.setType(AffiliationType.EDUCATION);
Organization organization1 = new Organization();
affiliation1.setOrganization(organization1);
organization1.setName("A new affiliation");
OrganizationAddress organizationAddress = new OrganizationAddress();
organization1.setAddress(organizationAddress);
organizationAddress.setCity("Edinburgh");
organizationAddress.setCountry(Iso3166Country.GB);
Response response = t2OrcidApiServiceDelegator.updateAffiliations(mockedUriInfo, "4444-4444-4444-4443", orcidMessage);
assertNotNull(response);
OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4443");
List<Affiliation> retreivedAffiliationsList = retrievedProfile.getOrcidActivities().getAffiliations().getAffiliation();
assertEquals(3, retreivedAffiliationsList.size());
Affiliation newAffiliation = retreivedAffiliationsList.get(0);
assertEquals("A new affiliation", newAffiliation.getOrganization().getName());
assertEquals("APP-5555555555555555", newAffiliation.getSource().retrieveSourcePath());
Affiliation existingAffiliation = retreivedAffiliationsList.get(1);
assertEquals(Visibility.PRIVATE, existingAffiliation.getVisibility());
assertEquals("Eine Institution", existingAffiliation.getOrganization().getName());
}
use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class OrcidIndexManagerImplTest method orcidProfileLimitedVisiblityAffiliations.
private OrcidProfile orcidProfileLimitedVisiblityAffiliations() {
OrcidProfile limitedOrcid = getStandardOrcid();
List<Affiliation> affiliations = limitedOrcid.getOrcidActivities().getAffiliations().getAffiliation();
for (Affiliation affiliation : affiliations) {
affiliation.setVisibility(Visibility.LIMITED);
}
return limitedOrcid;
}
use of org.orcid.jaxb.model.message.Affiliation in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setOrgAffiliationRelations.
private void setOrgAffiliationRelations(ProfileEntity profileEntity, Affiliations affiliations) {
SortedSet<OrgAffiliationRelationEntity> existingOrgAffiliationEntities = profileEntity.getOrgAffiliationRelations();
if (existingOrgAffiliationEntities == null) {
existingOrgAffiliationEntities = new TreeSet<>();
}
Map<String, OrgAffiliationRelationEntity> existingOrgAffiliationsEntitiesMap = createOrgAffiliationEntitiesMap(existingOrgAffiliationEntities);
SortedSet<OrgAffiliationRelationEntity> updatedOrgAffiliationEntities = new TreeSet<>();
if (affiliations != null && !affiliations.getAffiliation().isEmpty()) {
for (Affiliation affiliation : affiliations.getAffiliation()) {
OrgAffiliationRelationEntity orgRelationEntity = getOrgAffiliationRelationEntity(affiliation, existingOrgAffiliationsEntitiesMap.get(affiliation.getPutCode()));
orgRelationEntity.setProfile(profileEntity);
updatedOrgAffiliationEntities.add(orgRelationEntity);
}
}
Map<String, OrgAffiliationRelationEntity> updatedOrgAffiliationEntitiesMap = createOrgAffiliationEntitiesMap(updatedOrgAffiliationEntities);
// Remove orphans
for (Iterator<OrgAffiliationRelationEntity> iterator = existingOrgAffiliationEntities.iterator(); iterator.hasNext(); ) {
OrgAffiliationRelationEntity existingEntity = iterator.next();
if (!updatedOrgAffiliationEntitiesMap.containsKey(String.valueOf(existingEntity.getId()))) {
iterator.remove();
}
}
// Add new
for (OrgAffiliationRelationEntity updatedEntity : updatedOrgAffiliationEntities) {
if (updatedEntity.getId() == null) {
existingOrgAffiliationEntities.add(updatedEntity);
}
}
profileEntity.setOrgAffiliationRelations(existingOrgAffiliationEntities);
}
Aggregations