public int updatePublicationById(PerunSession sess, Publication publication)
      throws CabinetException {

    if (publication.getId() == null
        || publication.getExternalId() == null
        || publication.getPublicationSystemId() == null) {
      // such publication can't exists
      throw new CabinetException(
          "Publication doesn't exists: " + publication, ErrorCodes.PUBLICATION_NOT_EXISTS);
    }

    // strip long params in new publication
    stripLongParams(publication);

    // don't create already existing publication (same id or externalId&&pubSysId)
    Publication filter = new Publication(); // for ext_id & pubSysId

    filter.setPublicationSystemId(publication.getPublicationSystemId());
    filter.setExternalId(publication.getExternalId());
    List<Publication> publications = findPublicationsByFilter(filter);

    if (publications.size() > 1) {
      throw new CabinetException(
          "Consistency error: more than one unique publications found by ExtID and PubSysID.");
    }
    if (publications.size() > 0 && !(publication.getId().equals((publications.get(0).getId())))) {
      throw new CabinetException(
          "Cannot update to duplicate publication: " + publication,
          ErrorCodes.PUBLICATION_ALREADY_EXISTS);
    }

    // save old pub (must be Rich to contain all authors)
    Publication oldPub = findPublicationById(publication.getId());

    // update publication in DB
    int result = publicationDao.updatePublicationById(publication);

    // if updated and rank or category was changed
    if (result > 0
        && ((oldPub.getRank() != publication.getRank())
            || (oldPub.getCategoryId() != publication.getCategoryId()))) {
      // update coeficient for all it's authors
      List<Author> authors = authorService.findAuthorsByPublicationId(oldPub.getId());
      for (Author a : authors) {
        perunService.updatePriorityCoeficient(
            sess, a.getId(), authorshipService.calculateNewRank(a.getAuthorships()));
      }
    }

    return result;
  }
 public boolean publicationExists(Publication p) {
   if (p.getId() != null && p.getId() != 0) {
     return publicationDao.findPublicationById(p.getId()) != null;
   }
   if (p.getExternalId() != null
       && p.getExternalId() != 0
       && p.getPublicationSystemId() != null
       && p.getPublicationSystemId() != 0) {
     Publication filter = new Publication();
     filter.setExternalId(p.getExternalId());
     filter.setPublicationSystemId(p.getPublicationSystemId());
     return publicationDao.findPublicationsByFilter(filter).size() >= 1;
   }
   if (p.getIsbn() != null && p.getIsbn() != "") {
     Publication filter = new Publication();
     filter.setIsbn(p.getIsbn());
     return publicationDao.findPublicationsByFilter(filter).size() >= 1;
   }
   return false;
 }