Search in sources :

Example 1 with PublicationSystemStrategy

use of cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy in project perun by CESNET.

the class PublicationSystemManagerIntegrationTest method getPublicationSystemByNamespace.

@Test
public void getPublicationSystemByNamespace() throws Exception {
    System.out.println("PublicationSystemManagerIntegrationTest.getPublicationSystemByNamespace");
    PublicationSystem publicationSystem = getCabinetManager().getPublicationSystemByNamespace("mu");
    assertNotNull(publicationSystem);
    assertTrue(Objects.equals(publicationSystem, pubSysMu));
    PublicationSystemStrategy ps = (PublicationSystemStrategy) Class.forName(publicationSystem.getType()).newInstance();
    assertNotNull(ps);
}
Also used : PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) PublicationSystemStrategy(cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy) Test(org.junit.Test)

Example 2 with PublicationSystemStrategy

use of cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy in project perun by CESNET.

the class PublicationSystemManagerIntegrationTest method getPublicationSystemById.

@Test
public void getPublicationSystemById() throws Exception {
    System.out.println("PublicationSystemManagerIntegrationTest.getPublicationSystemById");
    PublicationSystem publicationSystem = getCabinetManager().getPublicationSystemById(pubSysZcu.getId());
    assertNotNull(publicationSystem);
    assertTrue(Objects.equals(publicationSystem, pubSysZcu));
    PublicationSystemStrategy ps = (PublicationSystemStrategy) Class.forName(publicationSystem.getType()).newInstance();
    assertNotNull(ps);
}
Also used : PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) PublicationSystemStrategy(cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy) Test(org.junit.Test)

Example 3 with PublicationSystemStrategy

use of cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy in project perun by CESNET.

the class PublicationSystemManagerIntegrationTest method getPublicationSystemByName.

@Test
public void getPublicationSystemByName() throws Exception {
    System.out.println("PublicationSystemManagerIntegrationTest.getPublicationSystemByName");
    PublicationSystem publicationSystem = getCabinetManager().getPublicationSystemByName(pubSysZcu.getFriendlyName());
    assertNotNull(publicationSystem);
    assertTrue(Objects.equals(publicationSystem, pubSysZcu));
    PublicationSystemStrategy ps = (PublicationSystemStrategy) Class.forName(publicationSystem.getType()).newInstance();
    assertNotNull(ps);
}
Also used : PublicationSystem(cz.metacentrum.perun.cabinet.model.PublicationSystem) PublicationSystemStrategy(cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy) Test(org.junit.Test)

Example 4 with PublicationSystemStrategy

use of cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy in project perun by CESNET.

the class CabinetManagerBlImpl method findPublicationsInPubSys.

// methods --------------------------------------
public List<Publication> findPublicationsInPubSys(String authorId, int yearSince, int yearTill, PublicationSystem ps) throws CabinetException {
    if (StringUtils.isBlank(authorId))
        throw new CabinetException("AuthorId cannot be empty while searching for publications");
    if (ps == null)
        throw new CabinetException("Publication system cannot be null while searching for publications");
    // authorId must be an publication system internal id i.e. UCO! not memberId, userId etc.
    PublicationSystemStrategy prezentator = null;
    try {
        log.debug("Attempting to instantiate class [{}]...", ps.getType());
        prezentator = (PublicationSystemStrategy) Class.forName(ps.getType()).newInstance();
        log.debug("Class [{}] successfully created.", ps.getType());
    } catch (Exception e) {
        throw new CabinetException(e);
    }
    HttpUriRequest request = prezentator.getHttpRequest(authorId, yearSince, yearTill, ps);
    HttpResponse response = prezentator.execute(request);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new CabinetException("Can't contact publication system. HTTP error code: " + response.getStatusLine().getStatusCode(), ErrorCodes.HTTP_IO_EXCEPTION);
    }
    List<Publication> publications = prezentator.parseHttpResponse(response);
    for (Publication p : publications) {
        // set pub system for founded publications
        p.setPublicationSystemId(ps.getId());
    }
    return publications;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse) Publication(cz.metacentrum.perun.cabinet.model.Publication) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) PublicationSystemStrategy(cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException)

Aggregations

PublicationSystemStrategy (cz.metacentrum.perun.cabinet.strategy.PublicationSystemStrategy)4 PublicationSystem (cz.metacentrum.perun.cabinet.model.PublicationSystem)3 Test (org.junit.Test)3 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)1 Publication (cz.metacentrum.perun.cabinet.model.Publication)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1