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;
}
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;
}
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;
}
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));
}
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;
}
Aggregations