UniRegensburg / unsere-app-fur-die-universitat-regensburg-bib-buddy

Bib Buddy - deine App für eine konzentrierte, offene Literaturarbeit!
0 stars 0 forks source link

Import of BibTeX #114

Closed silvia-ivanova-github-rep closed 3 years ago

silvia-ivanova-github-rep commented 3 years ago

Description Closes #29 . Imports a BibTeX file into the database and the App.

Affects Mainly import of a library as BibTeX file.

Notes for Reviewer Please check if the import works and if it is okay.

An example BibTeX file that considers different possible syntaxes for BibTeX is also available here: https://drive.google.com/file/d/1dPjo_dcESc246KWD6OC13qshh9pdWaHq/view?usp=sharing

Please review & comment/approve.

silvia-ivanova-github-rep commented 3 years ago

Thanks for the review. Regarding your last comment, this is my result of the emulator:

1 2

The authors are also properly shown on a physical device. Test on API 29.

claudia3 commented 3 years ago

For testing the import of the bibtex file I exported a shelf in the BibBuddy app and imported it. As a book I added the 0123456789 ISBN as a book via online search. After import no author appeared. The problem probably lies in the parseAuthorNames() function because with and it returns an empty author list.

claudia3 commented 3 years ago

Also you should fix your bibtex export with the authors because an and appears additionally after the last author name.

claudia3 commented 3 years ago

Found a solution for the author problem. You can check if it works with this code. In ExportBibTex.java

  private String getBibAuthorNames(Long bookId, BookDao bookDao) {
    Book book = bookDao.findById(bookId);

    List<Author> authorsList = bookDao.getAllAuthorsForBook(book.getId());
    StringBuilder authorNames = new StringBuilder();

    for (int i = 0; i < authorsList.size(); i++) {
        authorNames.append(authorsList.get(i).getFirstName()).append(", ")
            .append(authorsList.get(i).getLastName());

        if (i < authorsList.size() - 1) {
          authorNames.append(" and ");
        }
    }

    if (authorsList.isEmpty()) {
      authorNames = new StringBuilder();
    }

    return "author={" + authorNames + "}," + '\n';
  }

in ImportBibTex.java for correct sequence of author names

  public List<Author> parseAuthorNames() {

    String authorNames = (String) bibTagValue.get(BibTexKeys.AUTHOR);

    List<Author> authors = new ArrayList<>();

    // if multiple authors
    if (authorNames.contains(BibTexKeys.AND_MULTIPLE_AUTHORS)) {
      String[] names = authorNames.split(BibTexKeys.AND_MULTIPLE_AUTHORS);

      for (String name : names) {
        if (name.contains(", ")) {
          String[] currAuthorsNames = name.split(", ");
          authors.add(new Author(currAuthorsNames[1], currAuthorsNames[0], ""));
        }
      }

    }

    // if one author
    if (!authorNames.contains(BibTexKeys.AND_MULTIPLE_AUTHORS)
        && authorNames.contains(",")) {

      String[] authorName = authorNames.split(", ");
      authors.add(new Author(authorName[1], authorName[0], ""));

    }

    return authors;
  }
claudia3 commented 3 years ago

Please resolve the merge conflict and fix my mistake. Afterwards I will approve your PR if the resolved merge conflict is ok.