Search in sources :

Example 1 with BookDetails

use of org.olat.modules.edubase.BookDetails in project OpenOLAT by OpenOLAT.

the class EdubaseBookSectionListController method setBookIdsAndCovers.

private void setBookIdsAndCovers() {
    for (BookSectionWrapper wrapper : bookSectionWrappers) {
        String bookId = setParsedBookId(wrapper);
        BookDetails bookDetails = edubaseManager.fetchBookDetails(bookId);
        setCoverUrl(wrapper, bookDetails);
    }
}
Also used : BookDetails(org.olat.modules.edubase.BookDetails)

Example 2 with BookDetails

use of org.olat.modules.edubase.BookDetails in project openolat by klemens.

the class EdubaseBookSectionListController method setBookIdsAndCovers.

private void setBookIdsAndCovers() {
    for (BookSectionWrapper wrapper : bookSectionWrappers) {
        String bookId = setParsedBookId(wrapper);
        BookDetails bookDetails = edubaseManager.fetchBookDetails(bookId);
        setCoverUrl(wrapper, bookDetails);
    }
}
Also used : BookDetails(org.olat.modules.edubase.BookDetails)

Example 3 with BookDetails

use of org.olat.modules.edubase.BookDetails in project openolat by klemens.

the class EdubaseManagerImpl method fetchBookDetails.

@Override
public BookDetails fetchBookDetails(String bookId) {
    BookDetails infoReponse = new BookDetailsImpl();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
    String url = String.format(edubaseModule.getInfoverUrl(), bookId);
    HttpGet request = new HttpGet(url);
    request.setConfig(requestConfig);
    try (CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse httpResponse = httpClient.execute(request)) {
        String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
    } catch (SocketTimeoutException socketTimeoutException) {
        log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
    } catch (JsonParseException | EOFException noesNotExitsException) {
        log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
    } catch (Exception e) {
        log.error("", e);
    }
    return infoReponse;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) JsonParseException(org.codehaus.jackson.JsonParseException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) JsonParseException(org.codehaus.jackson.JsonParseException) BookDetails(org.olat.modules.edubase.BookDetails) BookDetailsImpl(org.olat.modules.edubase.model.BookDetailsImpl) SocketTimeoutException(java.net.SocketTimeoutException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) EOFException(java.io.EOFException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with BookDetails

use of org.olat.modules.edubase.BookDetails in project OpenOLAT by OpenOLAT.

the class EdubaseBookSectionListController method showDetails.

private void showDetails(UserRequest ureq, BookSectionWrapper wrapper) {
    String bookId = setParsedBookId(wrapper);
    BookDetails bookDetails = edubaseManager.fetchBookDetails(bookId);
    setCoverUrl(wrapper, bookDetails);
    detailsController = new EdubaseBookSectionDetailsController(ureq, getWindowControl(), wrapper, bookDetails);
    listenTo(detailsController);
    closeableModalController = new CloseableModalController(getWindowControl(), translate("close"), detailsController.getInitialComponent(), true, translate("edubase.book.section.details.form.title"));
    listenTo(closeableModalController);
    closeableModalController.activate();
}
Also used : BookDetails(org.olat.modules.edubase.BookDetails) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 5 with BookDetails

use of org.olat.modules.edubase.BookDetails in project OpenOLAT by OpenOLAT.

the class EdubaseManagerImpl method fetchBookDetails.

@Override
public BookDetails fetchBookDetails(String bookId) {
    BookDetails infoReponse = new BookDetailsImpl();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
    String url = String.format(edubaseModule.getInfoverUrl(), bookId);
    HttpGet request = new HttpGet(url);
    request.setConfig(requestConfig);
    try (CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse httpResponse = httpClient.execute(request)) {
        String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
    } catch (SocketTimeoutException socketTimeoutException) {
        log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
    } catch (JsonParseException | EOFException noesNotExitsException) {
        log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
    } catch (Exception e) {
        log.error("", e);
    }
    return infoReponse;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) JsonParseException(org.codehaus.jackson.JsonParseException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) JsonParseException(org.codehaus.jackson.JsonParseException) BookDetails(org.olat.modules.edubase.BookDetails) BookDetailsImpl(org.olat.modules.edubase.model.BookDetailsImpl) SocketTimeoutException(java.net.SocketTimeoutException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) EOFException(java.io.EOFException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

BookDetails (org.olat.modules.edubase.BookDetails)6 EOFException (java.io.EOFException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 RequestConfig (org.apache.http.client.config.RequestConfig)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 BookDetailsImpl (org.olat.modules.edubase.model.BookDetailsImpl)2