Search in sources :

Example 1 with DocumentContainerElement

use of com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement in project cia by Hack23.

the class RiksdagenDocumentApiImpl method loadAndProcessDocumentList.

/**
 * Load and process document list.
 *
 * @param url
 *            the url
 * @param processStrategy
 *            the process strategy
 * @throws Exception
 *             the exception
 */
private void loadAndProcessDocumentList(final String url, final ProcessDataStrategy<DocumentElement> processStrategy) throws XmlAgentException {
    final DocumentContainerElement dokumentLista = ((JAXBElement<DocumentContainerElement>) xmlAgent.unmarshallXml(riksdagenDocumentListMarshaller, url, HTTP_DOKUMENTLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
    int resultSize = dokumentLista.getDokument().size();
    processAll(dokumentLista.getDokument(), processStrategy);
    final BigInteger pages = dokumentLista.getTotalPages();
    for (int i = 1; i < pages.intValue(); i++) {
        final DocumentContainerElement otherPagesdokumentLista = ((JAXBElement<DocumentContainerElement>) xmlAgent.unmarshallXml(riksdagenDocumentListMarshaller, url + PAGE_PROPERTY + i, HTTP_DOKUMENTLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
        resultSize = resultSize + otherPagesdokumentLista.getDokument().size();
        processAll(otherPagesdokumentLista.getDokument(), processStrategy);
        LOGGER.info(LOADING_DOCUMENTS, resultSize, dokumentLista.getHits());
    }
}
Also used : BigInteger(java.math.BigInteger) DocumentContainerElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with DocumentContainerElement

use of com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement in project cia by Hack23.

the class RiksdagenDocumentApiImpl method loadDocumentList.

/**
 * Load document list.
 *
 * @param url
 *            the url
 * @param maxNumberPages
 *            the max number pages
 * @return the list
 * @throws Exception
 *             the exception
 */
private List<DocumentElement> loadDocumentList(final String url, final int maxNumberPages) throws XmlAgentException {
    final List<DocumentElement> result = new ArrayList<>();
    DocumentContainerElement dokumentLista = ((JAXBElement<DocumentContainerElement>) xmlAgent.unmarshallXml(riksdagenDocumentListMarshaller, url, HTTP_DOKUMENTLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
    result.addAll(dokumentLista.getDokument());
    final BigInteger pages = dokumentLista.getTotalPages();
    for (int i = 1; i < pages.intValue() && i < maxNumberPages; i++) {
        dokumentLista = ((JAXBElement<DocumentContainerElement>) xmlAgent.unmarshallXml(riksdagenDocumentListMarshaller, fixBrokenUrl(dokumentLista.getNextPage()), HTTP_DOKUMENTLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
        result.addAll(dokumentLista.getDokument());
        LOGGER.info(LOADING_DOCUMENTS, result.size(), dokumentLista.getHits());
    }
    return result;
}
Also used : DocumentElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) DocumentContainerElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

DocumentContainerElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement)2 BigInteger (java.math.BigInteger)2 JAXBElement (javax.xml.bind.JAXBElement)2 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)1 ArrayList (java.util.ArrayList)1