Search in sources :

Example 1 with Category

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

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

the class AuthorshipManagerBlImpl method calculateNewRank.

@Override
public synchronized double calculateNewRank(List<Authorship> authorships) throws CabinetException {
    double rank = DEFAULT_RANK;
    for (Authorship r : authorships) {
        Publication p = getPublicationManagerBl().getPublicationById(r.getPublicationId());
        rank += p.getRank();
        Category c = getCategoryManagerBl().getCategoryById(p.getCategoryId());
        rank += c.getRank();
    }
    return rank;
}
Also used : Category(cz.metacentrum.perun.cabinet.model.Category) Authorship(cz.metacentrum.perun.cabinet.model.Authorship) Publication(cz.metacentrum.perun.cabinet.model.Publication)

Example 3 with Category

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

the class CategoryManagerIntegrationTest method createCategoryTest.

@Test
public void createCategoryTest() throws Exception {
    System.out.println("CategoryManagerIntegrationTest.createCategoryTest");
    Category c = new Category(0, "Patent3", 7.0);
    c = getCabinetManager().createCategory(sess, c);
    Category retrievedCategory = getCabinetManager().getCategoryById(c.getId());
    assertTrue(Objects.equals(c, retrievedCategory));
}
Also used : Category(cz.metacentrum.perun.cabinet.model.Category) Test(org.junit.Test)

Example 4 with Category

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

the class CategoryManagerIntegrationTest method deleteCategoryTest.

@Test
public void deleteCategoryTest() throws Exception {
    System.out.println("CategoryManagerIntegrationTest.deleteCategoryTest");
    Category c = new Category(0, "Patent4", 1.0);
    c = getCabinetManager().createCategory(sess, c);
    getCabinetManager().deleteCategory(sess, c);
    List<Category> categories = getCabinetManager().getCategories();
    assertTrue(categories != null);
    assertTrue(!categories.isEmpty());
    assertTrue(!categories.contains(c));
}
Also used : Category(cz.metacentrum.perun.cabinet.model.Category) Test(org.junit.Test)

Example 5 with Category

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

the class CabinetBaseIntegrationTest method beforeClass.

// test -------------------------------
@Before
public void beforeClass() throws Exception {
    // do only once for all tests
    if (init)
        return;
    // principal
    PerunPrincipal pp = new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
    sess = perun.getPerunSession(pp, new PerunClient());
    // setup world
    User user = new User();
    user.setLastName("cabinetTestUser");
    user.setServiceUser(false);
    user = perun.getUsersManagerBl().createUser(sess, user);
    USER_ID = user.getId();
    User user2 = new User();
    user2.setLastName("cabinetTestUser2");
    user2.setServiceUser(false);
    user2 = perun.getUsersManagerBl().createUser(sess, user2);
    USER_ID_2 = user2.getId();
    // owner
    Owner owner = new Owner();
    owner.setName("PubOwner");
    owner.setContact("Call me");
    owner.setType(OwnerType.administrative);
    this.owner = perun.getOwnersManagerBl().createOwner(sess, owner);
    // category
    c1 = new Category(0, "patent", 3.9);
    c1 = getCabinetManager().createCategory(sess, c1);
    // publication systems
    PublicationSystem ps = new PublicationSystem();
    ps.setFriendlyName("OBD");
    ps.setLoginNamespace("zcu");
    ps.setUrl("http://obd.zcu.cz:6443/fcgi/verso.fpl?");
    ps.setType("cz.metacentrum.perun.cabinet.strategy.impl.OBD30Strategy");
    pubSysZcu = getCabinetManager().createPublicationSystem(sess, ps);
    assertTrue(pubSysZcu.getId() > 0);
    PublicationSystem ps2 = new PublicationSystem();
    ps2.setFriendlyName("Masarykova Univerzita - Prezentátor");
    ps2.setLoginNamespace("mu");
    ps2.setUrl("https://is.muni.cz/auth/prezentator/index.pl");
    ps2.setUsername(cabinetProperties.getProperty("perun.cabinet.mu.login"));
    ps2.setPassword(cabinetProperties.getProperty("perun.cabinet.mu.password"));
    ps2.setType("cz.metacentrum.perun.cabinet.strategy.impl.MUStrategy");
    pubSysMu = getCabinetManager().createPublicationSystem(sess, ps2);
    assertTrue(pubSysMu.getId() > 0);
    PublicationSystem ps3 = new PublicationSystem();
    ps3.setFriendlyName("Europe PMC");
    ps3.setLoginNamespace("europepmc");
    ps3.setUrl("https://www.ebi.ac.uk/europepmc/webservices/rest/search?");
    ps3.setType("cz.metacentrum.perun.cabinet.strategy.impl.EuropePMCStrategy");
    pubSysEuropePMC = getCabinetManager().createPublicationSystem(sess, ps3);
    assertTrue(pubSysEuropePMC.getId() > 0);
    // create publication
    Publication p1 = new Publication();
    p1.setCategoryId(c1.getId());
    p1.setExternalId(666);
    p1.setPublicationSystemId(ps.getId());
    p1.setCreatedBy(sess.getPerunPrincipal().getActor());
    p1.setCreatedDate(new Date());
    p1.setTitle("Some title");
    p1.setIsbn("ISBN");
    p1.setMain("MAIN");
    p1.setYear(2020);
    p1.setRank(0.0);
    p1.setLocked(false);
    p1.setDoi("DOI1");
    Publication p2 = new Publication();
    p2.setCategoryId(c1.getId());
    p2.setExternalId(333);
    p2.setPublicationSystemId(ps.getId());
    p2.setCreatedBy(sess.getPerunPrincipal().getActor());
    p2.setCreatedDate(new Date());
    p2.setTitle("Some title vol. 2");
    p2.setIsbn("ISBN2");
    p2.setMain("MAIN2");
    p2.setYear(2025);
    p2.setRank(0.0);
    p2.setLocked(false);
    p2.setDoi("DOI2");
    publicationOne = getCabinetManager().createPublication(sess, p1);
    publicationTwo = getCabinetManager().createPublication(sess, p2);
    Authorship a1 = new Authorship();
    a1.setCreatedBy(sess.getPerunPrincipal().getActor());
    a1.setCreatedDate(new Date());
    // for PUB 1
    a1.setPublicationId(p1.getId());
    a1.setUserId(USER_ID);
    Authorship a2 = new Authorship();
    a2.setCreatedBy(sess.getPerunPrincipal().getActor());
    a2.setCreatedDate(new Date());
    // for PUB 1
    a2.setPublicationId(p1.getId());
    a2.setUserId(USER_ID_2);
    a1 = getCabinetManager().createAuthorship(sess, a1);
    a2 = getCabinetManager().createAuthorship(sess, a2);
    authorshipOne = a1;
    authorshipTwo = a2;
    init = true;
}
Also used : Category(cz.metacentrum.perun.cabinet.model.Category) Authorship(cz.metacentrum.perun.cabinet.model.Authorship) Publication(cz.metacentrum.perun.cabinet.model.Publication) PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) Date(java.util.Date) Before(org.junit.Before)

Aggregations

Category (cz.metacentrum.perun.cabinet.model.Category)8 Test (org.junit.Test)4 Publication (cz.metacentrum.perun.cabinet.model.Publication)3 Authorship (cz.metacentrum.perun.cabinet.model.Authorship)2 Author (cz.metacentrum.perun.cabinet.model.Author)1 PublicationSystem (cz.metacentrum.perun.cabinet.model.PublicationSystem)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1