Search in sources :

Example 1 with XmlAgentException

use of com.hack23.cia.service.external.common.api.XmlAgentException 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 XmlAgentException

use of com.hack23.cia.service.external.common.api.XmlAgentException in project cia by Hack23.

the class XmlAgentImplITest method unmarshallXmlMissingNamespaceSuccessTest.

/**
 * Unmarshall xml missing namespace success test.
 *
 * @throws XmlAgentException
 *             the xml agent exception
 */
@Test
public void unmarshallXmlMissingNamespaceSuccessTest() throws XmlAgentException {
    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
    final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml-missing-namespace.xml").toString(), "com.hack23.cia.service.external.common.impl.test", null, null);
    assertEquals(new SimpleXml("abc123"), simpleXml);
}
Also used : SimpleXml(com.hack23.cia.service.external.common.impl.test.SimpleXml) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Test(org.junit.Test)

Example 3 with XmlAgentException

use of com.hack23.cia.service.external.common.api.XmlAgentException in project cia by Hack23.

the class XmlAgentImplITest method unmarshallXmlSuccessTest.

/**
 * Unmarshall xml success test.
 *
 * @throws XmlAgentException
 *             the xml agent exception
 */
@Test
public void unmarshallXmlSuccessTest() throws XmlAgentException {
    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
    final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml.xml").toString());
    assertEquals(new SimpleXml("abc123"), simpleXml);
}
Also used : SimpleXml(com.hack23.cia.service.external.common.impl.test.SimpleXml) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Test(org.junit.Test)

Example 4 with XmlAgentException

use of com.hack23.cia.service.external.common.api.XmlAgentException in project cia by Hack23.

the class XmlAgentImplITest method unmarshallXmlMissingNamespaceAndReplaceSuccessTest.

/**
 * Unmarshall xml missing namespace and replace success test.
 *
 * @throws XmlAgentException
 *             the xml agent exception
 */
@Test
public void unmarshallXmlMissingNamespaceAndReplaceSuccessTest() throws XmlAgentException {
    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
    final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml-missing-namespace.xml").toString(), "com.hack23.cia.service.external.common.impl.test", "abc123", "ABC123");
    assertEquals(new SimpleXml("ABC123"), simpleXml);
}
Also used : SimpleXml(com.hack23.cia.service.external.common.impl.test.SimpleXml) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Test(org.junit.Test)

Example 5 with XmlAgentException

use of com.hack23.cia.service.external.common.api.XmlAgentException in project cia by Hack23.

the class RiksdagenBallotApiImpl method getBallot.

@Override
public List<VoteData> getBallot(final String id) throws DataFailureException {
    final String url = BALLOT.replace(ID_KEY, id);
    final BallotContainer ballotContainer;
    try {
        ballotContainer = ((JAXBElement<BallotContainer>) xmlAgent.unmarshallXml(riksdagenBallotMarshaller, url, HTTP_VOTERING_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
        final List<VoteDataDto> voteDataList = ballotContainer.getBallotDocumentData().getVoteDataList();
        final Date ballotDate = tryToFindValidVoteDate(ballotContainer, voteDataList);
        final List<VoteData> result = new ArrayList<>();
        for (final VoteDataDto voteDataDto : voteDataList) {
            final VoteData voteData = new VoteData().withEmbeddedId(new VoteDataEmbeddedId().withBallotId(voteDataDto.getBallotId()).withIntressentId(voteDataDto.getIntressentId()).withIssue(voteDataDto.getIssue()).withConcern(voteDataDto.getConcern()));
            voteData.setBankNumber(voteDataDto.getBankNumber());
            voteData.setLabel(voteDataDto.getLabel());
            voteData.setLastName(voteDataDto.getLastName());
            voteData.setBornYear(voteDataDto.getBornYear());
            voteData.setFirstName(voteDataDto.getFirstName());
            voteData.setPlace(voteDataDto.getPlace());
            voteData.setGender(voteDataDto.getGender());
            voteData.setFullName(voteDataDto.getFullName());
            voteData.setParty(voteDataDto.getParty().toUpperCase(Locale.ENGLISH));
            voteData.setRm(voteDataDto.getRm());
            voteData.setVote(voteDataDto.getVote());
            voteData.setBallotType(voteDataDto.getBallotType());
            voteData.setElectoralRegionNumber(voteDataDto.getElectoralRegionNumber());
            voteData.setElectoralRegion(voteDataDto.getElectoralRegion());
            voteData.setVoteDate(ballotDate);
            result.add(voteData);
        }
        return result;
    } catch (final XmlAgentException | ParseException e) {
        LOGGER.warn(PROBLEM_GETTING_BALLOT_ID_S_FROM_DATA_RIKSDAGEN_SE, id);
        throw new DataFailureException(e);
    }
}
Also used : DataFailureException(com.hack23.cia.service.external.riksdagen.api.DataFailureException) ArrayList(java.util.ArrayList) VoteDataDto(com.hack23.cia.model.external.riksdagen.votering.impl.VoteDataDto) BallotContainer(com.hack23.cia.model.external.riksdagen.votering.impl.BallotContainer) VoteDataEmbeddedId(com.hack23.cia.model.external.riksdagen.votering.impl.VoteDataEmbeddedId) Date(java.util.Date) VoteData(com.hack23.cia.model.external.riksdagen.votering.impl.VoteData) ParseException(java.text.ParseException) XmlAgentException(com.hack23.cia.service.external.common.api.XmlAgentException)

Aggregations

XmlAgentException (com.hack23.cia.service.external.common.api.XmlAgentException)4 SimpleXml (com.hack23.cia.service.external.common.impl.test.SimpleXml)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)3 DocumentContainerElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentContainerElement)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 JAXBElement (javax.xml.bind.JAXBElement)2 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)1 BallotContainer (com.hack23.cia.model.external.riksdagen.votering.impl.BallotContainer)1 VoteData (com.hack23.cia.model.external.riksdagen.votering.impl.VoteData)1 VoteDataDto (com.hack23.cia.model.external.riksdagen.votering.impl.VoteDataDto)1 VoteDataEmbeddedId (com.hack23.cia.model.external.riksdagen.votering.impl.VoteDataEmbeddedId)1 IndicatorElement (com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement)1 IndicatorsElement (com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorsElement)1 DataFailureException (com.hack23.cia.service.external.riksdagen.api.DataFailureException)1 DataFailureException (com.hack23.cia.service.external.worldbank.api.DataFailureException)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1