use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class PublicationManagerBlImpl method updatePublication.
@Override
public Publication updatePublication(PerunSession sess, Publication publication) throws CabinetException {
if (publication.getId() == 0 || publication.getExternalId() == 0 || publication.getPublicationSystemId() == 0) {
// 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 dbPublication = getPublicationByExternalId(publication.getExternalId(), publication.getPublicationSystemId());
if (publication.getId() != (dbPublication.getId())) {
throw new CabinetException("Cannot update to duplicate publication: " + publication, ErrorCodes.PUBLICATION_ALREADY_EXISTS);
}
// save old pub
Publication oldPub = getPublicationById(publication.getId());
// update publication in DB
getPublicationManagerDao().updatePublication(sess, publication);
log.debug("{} updated.", publication);
// if updated and rank or category was changed
if ((oldPub.getRank() != publication.getRank()) || (oldPub.getCategoryId() != publication.getCategoryId())) {
synchronized (CabinetManagerBlImpl.class) {
// update coefficient for all it's authors
List<Author> authors = getAuthorshipManagerBl().getAuthorsByPublicationId(oldPub.getId());
for (Author a : authors) {
getCabinetManagerBl().updatePriorityCoefficient(sess, a.getId(), getAuthorshipManagerBl().calculateNewRank(a.getAuthorships()));
}
}
}
return publication;
}
Aggregations