Search in sources :

Example 6 with Author

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

the class AuthorshipManagerBlImpl method getAuthorsByAuthorshipId.

@Override
public List<Author> getAuthorsByAuthorshipId(PerunSession sess, int id) throws CabinetException {
    List<Author> result = new ArrayList<Author>();
    Authorship report = getAuthorshipManagerDao().getAuthorshipById(id);
    if (report == null) {
        throw new CabinetException("Authorship with ID: " + id + " doesn't exists!", ErrorCodes.AUTHORSHIP_NOT_EXISTS);
    }
    List<Authorship> publicationReports = getAuthorshipManagerDao().getAuthorshipsByPublicationId(report.getPublicationId());
    for (Authorship r : publicationReports) {
        result.add(getAuthorshipManagerDao().getAuthorById(r.getUserId()));
    }
    return convertAuthorsToAuthorsWithAttributes(result);
}
Also used : Authorship(cz.metacentrum.perun.cabinet.model.Authorship) ArrayList(java.util.ArrayList) Author(cz.metacentrum.perun.cabinet.model.Author) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException)

Example 7 with Author

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

the class OBD30Strategy method convertNodeToPublication.

/**
 * Convert node of response to Publication
 *
 * @param node XML node to convert
 * @return Publication instance
 * @throws InternalErrorException
 */
private Publication convertNodeToPublication(Node node) {
    Publication publication = new Publication();
    publication.setExternalId(Integer.valueOf(node.getAttributes().getNamedItem("id").getNodeValue()));
    NodeList titleList = (NodeList) getValueFromXpath(node, "./titul_list/titul", XPathConstants.NODESET);
    for (int i = 0; i < titleList.getLength(); i++) {
        Node singleNode = titleList.item(i);
        String original = (String) getValueFromXpath(singleNode, "./original/text()", XPathConstants.STRING);
        // use original name (language) of publication
        if ("ano".equalsIgnoreCase(original)) {
            String title = (String) getValueFromXpath(singleNode, "./nazev/text()", XPathConstants.STRING);
            publication.setTitle((title != null) ? title : "");
        }
    }
    String isbn = (String) getValueFromXpath(node, "./isbn/text()", XPathConstants.STRING);
    isbn = (isbn != null) ? isbn : "";
    String issn = (String) getValueFromXpath(node, "./issn/text()", XPathConstants.STRING);
    issn = (issn != null) ? issn : "";
    if (!issn.isEmpty())
        publication.setIsbn(issn);
    if (!isbn.isEmpty())
        publication.setIsbn(isbn);
    int year = ((Double) getValueFromXpath(node, "./rok/text()", XPathConstants.NUMBER)).intValue();
    publication.setYear(year);
    String source = (String) getValueFromXpath(node, "./zdroj_nazev/text()", XPathConstants.STRING);
    source = (source != null) ? source : "";
    String source_year = (String) getValueFromXpath(node, "./rocnik/text()", XPathConstants.STRING);
    source_year = (source_year != null) ? source_year : "";
    String pages = (String) getValueFromXpath(node, "./strany/text()", XPathConstants.STRING);
    pages = (pages != null) ? pages : "";
    String issue = (String) getValueFromXpath(node, "./cislo/text()", XPathConstants.STRING);
    issue = (issue != null) ? issue : "";
    // parse authors
    List<Author> authors = new ArrayList<Author>();
    NodeList authorList = (NodeList) getValueFromXpath(node, "./autor_list/autor", XPathConstants.NODESET);
    for (int i = 0; i < authorList.getLength(); i++) {
        Node singleNode = authorList.item(i);
        Author author = new Author();
        author.setTitleBefore((String) getValueFromXpath(singleNode, "./titul_pred/text()", XPathConstants.STRING));
        author.setTitleAfter((String) getValueFromXpath(singleNode, "./titul_za/text()", XPathConstants.STRING));
        author.setFirstName((String) getValueFromXpath(singleNode, "./jmeno/text()", XPathConstants.STRING));
        author.setLastName((String) getValueFromXpath(singleNode, "./prijmeni/text()", XPathConstants.STRING));
        authors.add(author);
    }
    publication.setAuthors(authors);
    // create main entry
    String main = "";
    for (int i = 0; i < authors.size(); i++) {
        if (i == 0) {
            main += authors.get(i).getLastName().toUpperCase() + " " + authors.get(i).getFirstName();
        } else {
            main += authors.get(i).getFirstName() + " " + authors.get(i).getLastName().toUpperCase();
        }
        main += " a ";
    }
    if (main.length() > 3) {
        main = main.substring(0, main.length() - 3) + ". ";
    }
    main += publication.getTitle() + ". ";
    main += (publication.getYear() != 0) ? publication.getYear() + ". " : "";
    main += (!source.isEmpty()) ? source + "," : "";
    main += (!source_year.isEmpty()) ? " roč. " + source_year + "," : "";
    main += (!issue.isEmpty()) ? " č. " + issue + "," : "";
    main += (!pages.isEmpty()) ? " s. " + pages + "," : "";
    main += (!isbn.isEmpty()) ? " ISBN: " + isbn + "." : "";
    main += (!issn.isEmpty()) ? " ISSN: " + issn + "." : "";
    publication.setMain(main);
    return publication;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Publication(cz.metacentrum.perun.cabinet.model.Publication) Author(cz.metacentrum.perun.cabinet.model.Author)

Example 8 with Author

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

the class MUStrategy method convertNodeToPublication.

/**
 * Convert node of response to Publication
 *
 * @param node XML node to convert
 * @return Publication instance
 * @throws InternalErrorException
 */
private Publication convertNodeToPublication(Node node) {
    Publication publication = new Publication();
    publication.setExternalId(((Double) getValueFromXpath(node, "./id/text()", XPathConstants.NUMBER)).intValue());
    publication.setMain(((String) getValueFromXpath(node, "./main/text()", XPathConstants.STRING)));
    // optional properties
    String isbn = (String) getValueFromXpath(node, "./isbn/text()", XPathConstants.STRING);
    publication.setIsbn((isbn != null) ? isbn : "");
    String title = (String) getValueFromXpath(node, "./title/text()", XPathConstants.STRING);
    publication.setTitle((title != null) ? title : "");
    String doi = (String) getValueFromXpath(node, "./doi/text()", XPathConstants.STRING);
    publication.setDoi((doi != null) ? doi : "");
    int year = ((Double) getValueFromXpath(node, "./year/text()", XPathConstants.NUMBER)).intValue();
    publication.setYear(year);
    // parse authors
    List<Author> authors = new ArrayList<Author>();
    String[] names = ((String) getValueFromXpath(node, "./authors/names/text()", XPathConstants.STRING)).split("#");
    for (String name : names) {
        try {
            Author author = new Author();
            Map<String, String> commonName = Utils.parseCommonName(name);
            author.setFirstName(commonName.get("firstName"));
            author.setLastName(WordUtils.capitalize(commonName.get("lastName")));
            authors.add(author);
        } catch (Exception ex) {
            log.error("Exception [{}] caught while processing authors of response: [{}]", ex, node);
        }
    }
    publication.setAuthors(authors);
    return publication;
}
Also used : ArrayList(java.util.ArrayList) Publication(cz.metacentrum.perun.cabinet.model.Publication) Author(cz.metacentrum.perun.cabinet.model.Author) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 9 with Author

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

the class MUStrategyUnitTest method parseResponse.

@Test
public void parseResponse() throws Exception {
    System.out.println("MUStrategyUnitTest.parseResponse");
    List<Publication> publications = muStrategy.parseResponse(muPublicationsResponse);
    assertNotNull(publications);
    assertEquals(4, publications.size());
    Publication p = publications.get(0);
    final String title = "Network Identity Manager Providers.";
    final Integer year = 2009;
    assertTrue(p.getMain().contains(title));
    assertEquals(title, p.getTitle());
    assertEquals("missing isbn should be default (=empty string)", "", p.getIsbn());
    assertTrue(year == p.getYear());
    assertNotNull(p.getExternalId());
    assertTrue(p.getExternalId() > 0);
    List<Author> authors = p.getAuthors();
    assertEquals(5, authors.size());
    assertTrue(authors.get(0) != null);
    assertTrue(authors.get(1) != null);
    assertTrue(authors.get(2) != null);
    assertTrue(authors.get(3) != null);
    assertTrue(authors.get(4) != null);
    final String firstName = "Michal";
    final String lastName = "Procházka";
    Author a = authors.get(1);
    assertEquals(firstName, a.getFirstName());
    assertEquals(lastName, a.getLastName());
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) Author(cz.metacentrum.perun.cabinet.model.Author) Test(org.junit.Test)

Example 10 with Author

use of cz.metacentrum.perun.cabinet.model.Author 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

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