Search in sources :

Example 11 with Author

use of cz.metacentrum.perun.cabinet.model.Author in project perun by CESNET.

the class ThanksManagerBlImpl method deleteThanks.

@Override
public void deleteThanks(PerunSession sess, Thanks thanks) throws CabinetException {
    getThanksManagerDao().deleteThanks(sess, thanks);
    log.debug("{} deleted.", thanks);
    // recalculate thanks for all publication's authors
    List<Author> authors = getAuthorshipManagerBl().getAuthorsByPublicationId(thanks.getPublicationId());
    synchronized (ThanksManagerBlImpl.class) {
        for (Author a : authors) {
            getCabinetManagerBl().setThanksAttribute(a.getId());
        }
    }
}
Also used : Author(cz.metacentrum.perun.cabinet.model.Author)

Example 12 with Author

use of cz.metacentrum.perun.cabinet.model.Author in project perun by CESNET.

the class CabinetManagerImpl method getAuthorsByPublicationId.

@Override
public List<Author> getAuthorsByPublicationId(PerunSession session, int id) throws PrivilegeException, CabinetException {
    List<Author> authors = getAuthorshipManagerBl().getAuthorsByPublicationId(id);
    boolean oneOfAuthors = false;
    for (Author author : authors) {
        if (author.getId() == session.getPerunPrincipal().getUserId()) {
            oneOfAuthors = true;
            break;
        }
    }
    // Authorization
    if (AuthzResolver.authorizedInternal(session, "getAuthorsByPublicationId_int_policy")) {
        oneOfAuthors = true;
    }
    if (!oneOfAuthors) {
        // not author, but check if user created publication, then he can list current authors
        Publication publication = getPublicationManagerBl().getPublicationById(id);
        if ((publication.getCreatedByUid() != session.getPerunPrincipal().getUserId()) && !(Objects.equals(publication.getCreatedBy(), session.getPerunPrincipal().getActor()))) {
            throw new PrivilegeException("getAuthorsByPublicationId");
        }
    }
    return authors;
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Author(cz.metacentrum.perun.cabinet.model.Author) Publication(cz.metacentrum.perun.cabinet.model.Publication)

Aggregations

Author (cz.metacentrum.perun.cabinet.model.Author)12 Publication (cz.metacentrum.perun.cabinet.model.Publication)7 ArrayList (java.util.ArrayList)6 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Authorship (cz.metacentrum.perun.cabinet.model.Authorship)1 Category (cz.metacentrum.perun.cabinet.model.Category)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPath (javax.xml.xpath.XPath)1