Search in sources :

Example 6 with Authorship

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

the class AuthorshipManagerIntegrationTest method createAuthorshipTest.

@Test
public void createAuthorshipTest() throws Exception {
    System.out.println("AuthorshipManagerIntegrationTest.createAuthorshipTest");
    Authorship authorship = new Authorship();
    authorship.setPublicationId(publicationTwo.getId());
    authorship.setUserId(USER_ID);
    authorship.setCreatedDate(new Date());
    authorship.setCreatedBy(sess.getPerunPrincipal().getActor());
    authorship = getCabinetManager().createAuthorship(sess, authorship);
    assertTrue(authorship != null);
    assertTrue("New Authorship ID shouldn't be 0.", authorship.getId() > 0);
    Authorship retrievedAuthorship = getCabinetManager().getAuthorshipById(authorship.getId());
    assertEquals(authorship, retrievedAuthorship);
}
Also used : Authorship(cz.metacentrum.perun.cabinet.model.Authorship) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Authorship

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

the class AuthorshipManagerBlImpl method getAuthorsByAuthorshipId.

@Override
public List<Author> getAuthorsByAuthorshipId(PerunSession sess, int id) throws CabinetException, InternalErrorException {
    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 8 with Authorship

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

the class AuthorshipManagerIntegrationTest method authorshipExistsTest.

@Test
public void authorshipExistsTest() throws Exception {
    System.out.println("AuthorshipManagerIntegrationTest.authorshipExistsTest");
    // authorshipOne always exists
    boolean result = getCabinetManager().authorshipExists(authorshipOne);
    assertTrue("Existing Authorship doesn't exists by checkMethod (by ID).", result);
    // new authorship shouldn't exists by ID
    Authorship a = new Authorship();
    a.setId(0);
    boolean result1 = getCabinetManager().authorshipExists(a);
    assertFalse("Authorship with ID: 0 shouldn't exists by checkMethod (by ID).", result1);
    // authorship with USER_ID for publicationOne should always exists
    Authorship a2 = new Authorship();
    a2.setPublicationId(publicationOne.getId());
    a2.setUserId(USER_ID);
    boolean result2 = getCabinetManager().authorshipExists(a2);
    assertTrue("Existing Authorship doesn't exists by checkMethod (by USER_ID, PUB_ID).", result2);
    // authorship with USER_ID for publication with ID=0 shouldn't exists
    a2.setPublicationId(0);
    boolean result3 = getCabinetManager().authorshipExists(a2);
    assertFalse("Authorship with PUB_ID: 0 shouldn't exists by checkMethod (by USER_ID, PUB_ID).", result3);
}
Also used : Authorship(cz.metacentrum.perun.cabinet.model.Authorship) Test(org.junit.Test)

Example 9 with Authorship

use of cz.metacentrum.perun.cabinet.model.Authorship 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);
    // 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

Authorship (cz.metacentrum.perun.cabinet.model.Authorship)9 Date (java.util.Date)5 Test (org.junit.Test)4 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)3 Category (cz.metacentrum.perun.cabinet.model.Category)2 Publication (cz.metacentrum.perun.cabinet.model.Publication)2 ArrayList (java.util.ArrayList)2 Author (cz.metacentrum.perun.cabinet.model.Author)1 PublicationSystem (cz.metacentrum.perun.cabinet.model.PublicationSystem)1 Thanks (cz.metacentrum.perun.cabinet.model.Thanks)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)1 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)1 TaskResult (cz.metacentrum.perun.taskslib.model.TaskResult)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Before (org.junit.Before)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1