Skip to content
Snippets Groups Projects

fix(contributors): [AoU-507] simplify contributors list synchronization and...

Merged Nicolas.Rod requested to merge rodn-507-remove-orcid-from-contributor-table into master
10 files
+ 73
296
Compare changes
  • Side-by-side
  • Inline
Files
10
@@ -714,6 +714,14 @@ class PublicationAsUserIT extends PublicationIT {
/************************
* Remove cnIndividu from first UNIGE contributor
*/
//check that the first contributor can be found
this.restClientTool.sudoRoot();
Contributor previousContributor = this.contributorService.findOne(contributor1.getResId());
this.restClientTool.exitSudo();
assertNotNull(previousContributor);
assertEquals(contributor1.getResId(), previousContributor.getResId());
contributorDTOs.get(0).setCnIndividu(null);
xmlMetadata = this.getMetadata(properties);
@@ -743,6 +751,12 @@ class PublicationAsUserIT extends PublicationIT {
assertEquals(this.CONTRIBUTOR2_FIRSTNAME, updatedContributor2.getFirstName());
assertEquals(this.CONTRIBUTOR2_LASTNAME, updatedContributor2.getLastName());
//check that the first contributor can not be found anymore: he has been deleted as he was not linked to any other publication
this.restClientTool.sudoRoot();
previousContributor = this.contributorService.findOne(contributor1.getResId());
this.restClientTool.exitSudo();
assertNull(previousContributor);
/************************
* Make first contributor UNIGE member again --> must use the same existing contributor
*/
@@ -766,9 +780,7 @@ class PublicationAsUserIT extends PublicationIT {
assertEquals(this.CONTRIBUTOR1_CN_INDIVIDU, updatedAgainContributor1.getCnIndividu());
assertEquals(this.CONTRIBUTOR1_FIRSTNAME, updatedAgainContributor1.getFirstName());
assertEquals(this.CONTRIBUTOR1_LASTNAME, updatedAgainContributor1.getLastName());
// check that the same UNIGE contributor has been used in database
assertEquals(contributor1.getResId(), updatedAgainContributor1.getResId());
assertTrue(updatedAgainContributorOptional2.isPresent());
Contributor updatedAgainContributor2 = updatedAgainContributorOptional2.get();
assertEquals(this.CONTRIBUTOR2_CN_INDIVIDU, updatedAgainContributor2.getCnIndividu());
@@ -982,7 +994,7 @@ class PublicationAsUserIT extends PublicationIT {
}
@Test
void contributorsCreateWithOrcidThenCnIndividuTest() {
void contributorsCreateWithoutCnIndividuThenWithCnIndividuTest() {
/**
* First create a publication with a contributor without ORCID nor cnIndividu
@@ -1021,110 +1033,6 @@ class PublicationAsUserIT extends PublicationIT {
assertEquals(this.CONTRIBUTOR1_FIRSTNAME, contributor1.getFirstName());
assertEquals(this.CONTRIBUTOR1_LASTNAME, contributor1.getLastName());
assertNull(contributor1.getCnIndividu());
assertNull(contributor1.getOrcid());
this.restClientTool.exitSudo();
/**
* Then create another publication with a contributor with ORCID
* Check that it creates another contributor with the same name, but with ORCID
*/
formDataJsonObject = new JSONObject(formData);
formDataJsonObject.getJSONObject("contributors").getJSONArray("contributors").getJSONObject(0).getJSONObject("contributor")
.put("orcid", this.ORCID_TEST);
formData = formDataJsonObject.toString();
this.createNewTemporaryPublication(formData);
myPublications = this.publicationService.listMyPublications(myPublicationsParams);
assertNotNull(myPublications);
assertEquals(2, myPublications.size());
this.restClientTool.sudoRoot();
contributorList = this.contributorService.searchByProperties(contributorsParams);
assertNotNull(contributorList);
assertEquals(2, contributorList.size());
Optional<Contributor> contributorNoId = contributorList.stream().filter(c -> c.getCnIndividu() == null && c.getOrcid() == null)
.findFirst();
assertTrue(contributorNoId.isPresent());
Optional<Contributor> contributorid = contributorList.stream()
.filter(c -> c.getCnIndividu() == null && this.ORCID_TEST.equals(c.getOrcid()))
.findFirst();
assertTrue(contributorid.isPresent());
this.restClientTool.exitSudo();
/**
* Finally create another publication with a contributor with both ORCID and cnIndividu
* The contributor with ORCID created above must be updated with the cnIndividu and reused
* The contributor name is updated along with the cnIndividu.
*/
formDataJsonObject = new JSONObject(formData);
JSONObject contributorObj = formDataJsonObject.getJSONObject("contributors").getJSONArray("contributors").getJSONObject(0)
.getJSONObject("contributor");
contributorObj.put("cnIndividu", this.CONTRIBUTOR1_CN_INDIVIDU);
String newFirstName = this.getTemporaryTestLabel("Harry");
String newLastName = this.getTemporaryTestLabel("Cow");
contributorObj.put("firstname", newFirstName);
contributorObj.put("lastname", newLastName);
formData = formDataJsonObject.toString();
this.createNewTemporaryPublication(formData);
myPublications = this.publicationService.listMyPublications(myPublicationsParams);
assertNotNull(myPublications);
assertEquals(3, myPublications.size());
this.restClientTool.sudoRoot();
contributorList = this.contributorService.searchByProperties(contributorsParams);
assertNotNull(contributorList);
assertEquals(2, contributorList.size());
contributorNoId = contributorList.stream().filter(c -> c.getCnIndividu() == null && c.getOrcid() == null).findFirst();
assertTrue(contributorNoId.isPresent());
contributorid = contributorList.stream()
.filter(c -> this.CONTRIBUTOR1_CN_INDIVIDU.equals(c.getCnIndividu()) && this.ORCID_TEST.equals(c.getOrcid()))
.findFirst();
assertTrue(contributorid.isPresent());
assertEquals(newFirstName, contributorid.get().getFirstName());
assertEquals(newLastName, contributorid.get().getLastName());
this.restClientTool.exitSudo();
}
@Test
void contributorsCreateWithCnIndividuThenOrcidTest() {
/**
* First create a publication with a contributor without ORCID nor cnIndividu
*/
String title = this.getTemporaryTestLabel("test publication contributors");
String formData = this.getTestFormData(title);
JSONObject formDataJsonObject = new JSONObject(formData);
JSONArray contributorsArray = new JSONArray();
JSONObject contributor = new JSONObject();
contributor.put("firstname", this.CONTRIBUTOR1_FIRSTNAME);
contributor.put("lastname", this.CONTRIBUTOR1_LASTNAME);
contributor.put("role", "author");
JSONObject contributorContainer = new JSONObject();
contributorContainer.put("contributor", contributor);
contributorsArray.put(contributorContainer);
formDataJsonObject.getJSONObject("contributors").put("contributors", contributorsArray);
formData = formDataJsonObject.toString();
this.createNewTemporaryPublication(formData);
Map<String, String> myPublicationsParams = new HashMap<>();
myPublicationsParams.put("title", this.getTemporaryTestLabel(""));
myPublicationsParams.put("sort", "title");
List<Publication> myPublications = this.publicationService.listMyPublications(myPublicationsParams);
assertNotNull(myPublications);
assertEquals(1, myPublications.size());
this.restClientTool.sudoRoot();
Map<String, String> contributorsParams = new HashMap<>();
contributorsParams.put("firstName", this.getTemporaryTestLabel(""));
List<Contributor> contributorList = this.contributorService.searchByProperties(contributorsParams);
assertNotNull(contributorList);
assertEquals(1, contributorList.size());
Contributor contributor1 = contributorList.get(0);
assertEquals(this.CONTRIBUTOR1_FIRSTNAME, contributor1.getFirstName());
assertEquals(this.CONTRIBUTOR1_LASTNAME, contributor1.getLastName());
assertNull(contributor1.getCnIndividu());
assertNull(contributor1.getOrcid());
this.restClientTool.exitSudo();
/**
@@ -1144,46 +1052,11 @@ class PublicationAsUserIT extends PublicationIT {
contributorList = this.contributorService.searchByProperties(contributorsParams);
assertNotNull(contributorList);
assertEquals(2, contributorList.size());
Optional<Contributor> contributorNoId = contributorList.stream().filter(c -> c.getCnIndividu() == null && c.getOrcid() == null)
.findFirst();
assertTrue(contributorNoId.isPresent());
Optional<Contributor> contributorid = contributorList.stream()
.filter(c -> this.CONTRIBUTOR1_CN_INDIVIDU.equals(c.getCnIndividu()) && c.getOrcid() == null)
.findFirst();
assertTrue(contributorid.isPresent());
this.restClientTool.exitSudo();
/**
* Finally create another publication with a contributor with both ORCID and cnIndividu
* The contributor with ORCID created above must be updated with the cnIndividu and reused
* The contributor name is not updated along with the ORCID.
*/
formDataJsonObject = new JSONObject(formData);
JSONObject contributorObj = formDataJsonObject.getJSONObject("contributors").getJSONArray("contributors").getJSONObject(0)
.getJSONObject("contributor");
contributorObj.put("orcid", this.ORCID_TEST);
String newFirstName = this.getTemporaryTestLabel("Harry");
String newLastName = this.getTemporaryTestLabel("Cow");
contributorObj.put("firstname", newFirstName);
contributorObj.put("lastname", newLastName);
formData = formDataJsonObject.toString();
this.createNewTemporaryPublication(formData);
myPublications = this.publicationService.listMyPublications(myPublicationsParams);
assertNotNull(myPublications);
assertEquals(3, myPublications.size());
this.restClientTool.sudoRoot();
contributorList = this.contributorService.searchByProperties(contributorsParams);
assertNotNull(contributorList);
assertEquals(2, contributorList.size());
contributorNoId = contributorList.stream().filter(c -> c.getCnIndividu() == null && c.getOrcid() == null).findFirst();
Optional<Contributor> contributorNoId = contributorList.stream().filter(c -> c.getCnIndividu() == null).findFirst();
assertTrue(contributorNoId.isPresent());
contributorid = contributorList.stream()
.filter(c -> this.CONTRIBUTOR1_CN_INDIVIDU.equals(c.getCnIndividu()) && this.ORCID_TEST.equals(c.getOrcid()))
Optional<Contributor> contributorid = contributorList.stream().filter(c -> this.CONTRIBUTOR1_CN_INDIVIDU.equals(c.getCnIndividu()))
.findFirst();
assertTrue(contributorid.isPresent());
assertEquals(this.CONTRIBUTOR1_FIRSTNAME, contributorid.get().getFirstName());
assertEquals(this.CONTRIBUTOR1_LASTNAME, contributorid.get().getLastName());
this.restClientTool.exitSudo();
}
Loading