Search in sources :

Example 21 with CabinetException

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;
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) Author(cz.metacentrum.perun.cabinet.model.Author) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException)

Aggregations

CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)21 Publication (cz.metacentrum.perun.cabinet.model.Publication)10 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 Test (org.junit.Test)6 Author (cz.metacentrum.perun.cabinet.model.Author)4 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)4 IOException (java.io.IOException)4 XPath (javax.xml.xpath.XPath)4 XPathExpression (javax.xml.xpath.XPathExpression)4 XPathExpressionException (javax.xml.xpath.XPathExpressionException)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 Authorship (cz.metacentrum.perun.cabinet.model.Authorship)3 PublicationSystem (cz.metacentrum.perun.cabinet.model.PublicationSystem)3 Thanks (cz.metacentrum.perun.cabinet.model.Thanks)3 StringReader (java.io.StringReader)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3