Search in sources :

Example 1 with Author

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

the class AuthorshipManagerBlImpl method findNewAuthors.

@Override
public List<Author> findNewAuthors(PerunSession sess, String searchString) throws CabinetException {
    List<String> attrs = Arrays.asList(AttributesManager.NS_USER_ATTR_DEF + ":preferredMail", AttributesManager.NS_USER_ATTR_DEF + ":organization");
    // AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:einfra"
    List<Author> authors = new ArrayList<>();
    try {
        List<RichUser> users = perun.getUsersManagerBl().findRichUsersWithAttributes(sess, searchString, attrs);
        for (RichUser user : users) {
            Author author = new Author(user.getId(), user.getFirstName(), user.getLastName(), user.getMiddleName(), user.getTitleBefore(), user.getTitleAfter());
            for (Attribute a : user.getUserAttributes()) {
                if (a.getName().equals(AttributesManager.NS_USER_ATTR_DEF + ":preferredMail")) {
                    if (a.getValue() != null && !((String) a.getValue()).isEmpty()) {
                        String safeMail = ((String) a.getValue()).split("@")[0];
                        if (safeMail.length() > 2) {
                            safeMail = safeMail.substring(0, 1) + "****" + safeMail.substring(safeMail.length() - 1, safeMail.length());
                        }
                        safeMail += "@" + ((String) a.getValue()).split("@")[1];
                        a.setValue(safeMail);
                    }
                }
            }
            author.setAttributes(user.getUserAttributes());
            authors.add(author);
        }
    } catch (UserNotExistsException e) {
        log.error("Shouldn't really happen.");
    }
    return authors;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) Author(cz.metacentrum.perun.cabinet.model.Author)

Example 2 with Author

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

the class CategoryManagerBlImpl method updateCategory.

@Override
public Category updateCategory(PerunSession sess, Category category) throws CabinetException {
    // save original category
    Category cat = getCategoryManagerDao().getCategoryById(category.getId());
    // update
    Category result = getCategoryManagerDao().updateCategory(sess, category);
    // was rank changed ?
    if (!Objects.equals(cat.getRank(), category.getRank())) {
        synchronized (CabinetManagerBlImpl.class) {
            // yes
            List<Publication> pubs = getPublicationManagerBl().getPublicationsByCategoryId(category.getId());
            // update coef for all authors of all publications in updated category
            Set<Author> authors = new HashSet<Author>();
            for (Publication p : pubs) {
                authors.addAll(getAuthorshipManagerBl().getAuthorsByPublicationId(p.getId()));
            }
            for (Author a : authors) {
                getCabinetManagerBl().updatePriorityCoefficient(sess, a.getId(), getAuthorshipManagerBl().calculateNewRank(a.getAuthorships()));
            }
        }
        log.debug("Category: [{}] updated to Category: [{}]", cat, category);
    }
    return result;
}
Also used : Category(cz.metacentrum.perun.cabinet.model.Category) Publication(cz.metacentrum.perun.cabinet.model.Publication) Author(cz.metacentrum.perun.cabinet.model.Author) HashSet(java.util.HashSet)

Example 3 with Author

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

the class ThanksManagerBlImpl method createThanks.

// methods -------------------------
public Thanks createThanks(PerunSession sess, Thanks t) throws CabinetException {
    if (t.getCreatedDate() == null) {
        t.setCreatedDate(new Date());
    }
    if (thanksExist(t)) {
        throw new CabinetException("Can't create duplicate thanks.", ErrorCodes.THANKS_ALREADY_EXISTS);
    }
    t = getThanksManagerDao().createThanks(sess, t);
    log.debug("{} created.", t);
    // recalculate thanks for all publication's authors
    List<Author> authors = new ArrayList<Author>();
    authors = getAuthorshipManagerBl().getAuthorsByPublicationId(t.getPublicationId());
    // sort to prevent locking
    synchronized (ThanksManagerBlImpl.class) {
        for (Author a : authors) {
            getCabinetManagerBl().setThanksAttribute(a.getId());
        }
    }
    return t;
}
Also used : ArrayList(java.util.ArrayList) Author(cz.metacentrum.perun.cabinet.model.Author) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) Date(java.util.Date)

Example 4 with Author

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

the class AuthorshipManagerIntegrationTest method getAuthorsByAuthorshipIdTest.

@Test
public void getAuthorsByAuthorshipIdTest() throws Exception {
    System.out.println("AuthorshipManagerIntegrationTest.getAuthorsByAuthorshipIdTest");
    // store existing author of authorship one
    Author a = getCabinetManager().getAuthorById(USER_ID);
    List<Author> result = getCabinetManager().getAuthorsByAuthorshipId(sess, authorshipOne.getId());
    assertTrue("No authors found by authorship ID when there should be.", (result != null && result.size() > 0));
    assertTrue("Original author should be between returned authors.", result.contains(a));
}
Also used : Author(cz.metacentrum.perun.cabinet.model.Author) Test(org.junit.Test)

Example 5 with Author

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

the class EuropePMCStrategy method convertNodeToPublication.

/**
 * Convert node of response to Publication
 *
 * @param node XML node to convert
 * @return Publication instance
 * @throws InternalErrorException
 */
private Publication convertNodeToPublication(Node node, XPathFactory xPathFactory) throws CabinetException {
    Publication publication = new Publication();
    publication.setExternalId(((Double) getValueFromXpath(node, "./id/text()", XPathConstants.NUMBER)).intValue());
    String title = (String) getValueFromXpath(node, "./title/text()", XPathConstants.STRING);
    publication.setTitle((title != null) ? title : "");
    // optional properties
    String issn = (String) getValueFromXpath(node, "./journalInfo/journal/ISSN/text()", XPathConstants.STRING);
    publication.setIsbn((issn != null) ? issn : "");
    String isbn = (String) getValueFromXpath(node, "./bookOrReportDetails/isbn13/text()", XPathConstants.STRING);
    if (publication.getIsbn() == null) {
        publication.setIsbn((isbn != null) ? isbn : "");
    }
    String doi = (String) getValueFromXpath(node, "./doi/text()", XPathConstants.STRING);
    publication.setDoi((doi != null) ? doi : "");
    int year = ((Double) getValueFromXpath(node, "./pubYear/text()", XPathConstants.NUMBER)).intValue();
    publication.setYear(year);
    XPath xpath = xPathFactory.newXPath();
    XPathExpression authorsQuery;
    try {
        authorsQuery = xpath.compile("./authorList/author");
    } catch (XPathExpressionException ex) {
        throw new CabinetException("Error when compiling xpath query.", ex);
    }
    NodeList nodeList;
    try {
        nodeList = (NodeList) authorsQuery.evaluate(node, XPathConstants.NODESET);
    } catch (XPathExpressionException ex) {
        throw new CabinetException("Error when evaluate xpath query on document.", ex);
    }
    if (nodeList.getLength() == 0) {
        // There are no authors !! Which is weird, return rest of publication
        return publication;
    } else {
        List<Author> authors = new ArrayList<Author>();
        // Iterate through nodes and convert them to Map<String,String>
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node singleNode = nodeList.item(i);
            // remove node from original structure in order to keep access time constant (otherwise is exp.)
            singleNode.getParentNode().removeChild(singleNode);
            try {
                String firstName = ((String) getValueFromXpath(singleNode, "./firstName/text()", XPathConstants.STRING));
                String lastName = ((String) getValueFromXpath(singleNode, "./lastName/text()", XPathConstants.STRING));
                String initials = ((String) getValueFromXpath(singleNode, "./initials/text()", XPathConstants.STRING));
                Author author = new Author();
                if (firstName == null || firstName.isEmpty()) {
                    author.setFirstName(initials.trim());
                } else {
                    author.setFirstName(firstName.trim());
                }
                author.setLastName(WordUtils.capitalize(lastName.trim()));
                authors.add(author);
            } catch (InternalErrorException ex) {
                log.error("Exception [{}] caught while processing authors of response: [{}]", ex, node);
            }
        }
        publication.setAuthors(authors);
    }
    // Make up citation
    List<Author> authors = publication.getAuthors();
    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 = main.replaceAll("\\s{2,}", " ");
    main += publication.getTitle() + ((publication.getTitle().endsWith(".")) ? " " : ". ");
    main += (publication.getYear() != 0) ? publication.getYear() + ". " : "";
    String journalTitle = (String) getValueFromXpath(node, "./journalInfo/journal/title/text()", XPathConstants.STRING);
    String journalYear = (String) getValueFromXpath(node, "./journalInfo/yearOfPublication/text()", XPathConstants.STRING);
    String journalIssue = (String) getValueFromXpath(node, "./journalInfo/volume/text()", XPathConstants.STRING);
    String pages = (String) getValueFromXpath(node, "./bookOrReportDetails/numberOfPages/text()", XPathConstants.STRING);
    main += (!journalTitle.isEmpty()) ? journalTitle + ", " : "";
    main += (!journalYear.isEmpty()) ? " roč. " + journalYear + ", " : "";
    main += (!journalIssue.isEmpty()) ? " č. " + journalIssue + ", " : "";
    main += (!pages.isEmpty()) ? "s. " + pages + "," : "";
    main += (isbn != null && !isbn.isEmpty()) ? " ISBN: " + isbn + "." : "";
    main += (issn != null && !issn.isEmpty()) ? " ISSN: " + issn + "." : "";
    main += (doi != null && !doi.isEmpty()) ? " DOI: " + doi + "." : "";
    publication.setMain(main);
    return publication;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Publication(cz.metacentrum.perun.cabinet.model.Publication) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) 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