Skip to content

Commit d5f2795

Browse files
authored
Merge pull request #6673 from ORCID/IgnoreRecordOwnerInBibtex
If the work was created through bibtex we dont care if it contains th…
2 parents 43740ed + 16fff7e commit d5f2795

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

orcid-web/src/main/java/org/orcid/frontend/web/controllers/WorksController.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import org.orcid.pojo.grouping.WorkGroupingSuggestion;
5656
import org.orcid.pojo.grouping.WorkGroupingSuggestions;
5757
import org.orcid.pojo.grouping.WorkGroupingSuggestionsCount;
58+
import org.slf4j.Logger;
59+
import org.slf4j.LoggerFactory;
5860
import org.springframework.beans.factory.annotation.Value;
5961
import org.springframework.stereotype.Controller;
6062
import org.springframework.web.bind.annotation.PathVariable;
@@ -71,6 +73,8 @@
7173
@RequestMapping(value = { "/works" })
7274
public class WorksController extends BaseWorkspaceController {
7375

76+
private static final Logger LOGGER = LoggerFactory.getLogger(WorksController.class);
77+
7478
private static final Pattern LANGUAGE_CODE = Pattern.compile("([a-zA-Z]{2})(_[a-zA-Z]{2}){0,2}");
7579
private static final String PAGE_SIZE_DEFAULT = "50";
7680

@@ -534,21 +538,30 @@ private void initializePublicationDate(WorkForm w) {
534538
}
535539

536540
return null;
537-
}
541+
}
542+
538543
/**
539544
* Creates a new work
540545
*
541546
* @throws Exception
542547
*/
543548
@RequestMapping(value = "/work.json", method = RequestMethod.POST)
544-
public @ResponseBody WorkForm postWork(HttpServletRequest request, @RequestBody WorkForm workForm) throws Exception {
549+
public @ResponseBody WorkForm postWork(HttpServletRequest request, @RequestBody WorkForm workForm,
550+
@RequestParam(value = "isBibtex", required = false, defaultValue = "false") Boolean isBibtex) throws Exception {
545551
validateWork(workForm);
546552
if (workForm.getErrors().size() == 0) {
547553
removeEmptyExternalIdentifiers(workForm);
548554
if (isRecordHolderNotInContributors(workForm)) {
549-
List<String> errors = workForm.getErrors();
550-
errors.add(getMessage("web.orcid.record_holder_not_contributor.exception"));
551-
return workForm;
555+
if (Boolean.TRUE.equals(isBibtex)) {
556+
// For now, if the request comes from bibtex, we just need
557+
// to ignore the record owner, we can't validate if it is
558+
// already in one of the provided contributors
559+
} else {
560+
LOGGER.error("Record owner is not in contributors list, orcid id: " + getCurrentUserOrcid());
561+
List<String> errors = workForm.getErrors();
562+
errors.add(getMessage("web.orcid.record_holder_not_contributor.exception"));
563+
return workForm;
564+
}
552565
}
553566
if (workForm.getPutCode() != null)
554567
updateWork(workForm);

orcid-web/src/test/java/org/orcid/frontend/web/controllers/WorksControllerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void testAddWork() throws Exception {
318318
work.getCitation().setCitationType(Text.valueOf("formatted-unspecified"));
319319
}
320320

321-
work = worksController.postWork(null, work);
321+
work = worksController.postWork(null, work, false);
322322
assertNotNull(work);
323323
assertFalse(PojoUtil.isEmpty(work.getPutCode()));
324324
assertEquals(1, work.getWorkExternalIdentifiers().size());
@@ -336,7 +336,7 @@ public void testEditOtherSourceThrowsError() throws Exception {
336336
WorkForm work = worksController.getWorkInfo(Long.valueOf("7"));
337337
boolean throwsError = false;
338338
try {
339-
worksController.postWork(null, work);
339+
worksController.postWork(null, work, false);
340340
} catch (Exception e) {
341341
throwsError = true;
342342
}
@@ -383,7 +383,7 @@ public void testUpdateWork() throws Exception {
383383
work.getErrors().forEach(n -> System.out.println(n));
384384
fail("invalid work update");
385385
}
386-
worksController.postWork(null, work);
386+
worksController.postWork(null, work, false);
387387

388388
WorkForm updatedWork = worksController.getWorkInfo(Long.valueOf("6"));
389389
assertNotNull(updatedWork);

0 commit comments

Comments
 (0)