Search in sources :

Example 1 with DataFailureException

use of com.hack23.cia.service.external.worldbank.api.DataFailureException in project cia by Hack23.

the class RiksdagenPersonsWorkGeneratorImpl method generateWorkOrders.

@Override
public void generateWorkOrders() {
    try {
        final List<PersonElement> personList = riksdagenApi.getPersonList().getPerson();
        final Map<String, String> currentSaved = getImportService().getPersonMap();
        for (final PersonElement personElement : personList) {
            if (!currentSaved.containsKey(personElement.getId())) {
                LOGGER.info("Send Load Order:{}", personElement.getPersonUrlXml());
                getJmsSender().send(personElementWorkdestination, personElement);
                currentSaved.put(personElement.getId(), personElement.getId());
            }
        }
        for (final String personId : readMissingPersonList()) {
            if (!currentSaved.containsKey(personId)) {
                LOGGER.info("Send Load Order:{}{}", "https://data.riksdagen.se/person/", personId);
                getJmsSender().send(personElementWorkdestination, new PersonElement().withId(personId));
            }
        }
    } catch (final DataFailureException exception) {
        LOGGER.warn("Problem during generate work orders", exception);
    }
}
Also used : PersonElement(com.hack23.cia.model.external.riksdagen.personlista.impl.PersonElement) DataFailureException(com.hack23.cia.service.external.riksdagen.api.DataFailureException)

Example 2 with DataFailureException

use of com.hack23.cia.service.external.worldbank.api.DataFailureException in project cia by Hack23.

the class WorldBankCountryWorkGeneratorImpl method generateWorkOrders.

@Override
public void generateWorkOrders() {
    try {
        final List<CountryElement> countryList = worldbankCountryApi.getCountries();
        final Map<String, String> currentSaved = getImportService().getWorldBankCountryMap();
        for (final CountryElement countryElement : countryList) {
            if (countryElement.getCapitalCity() != null && countryElement.getCapitalCity().length() > 0 && !currentSaved.containsKey(countryElement.getIso2Code())) {
                getJmsSender().send(countryElementWorkdestination, countryElement);
            }
        }
    } catch (final DataFailureException exception) {
        LOGGER.warn("jms", exception);
    }
}
Also used : DataFailureException(com.hack23.cia.service.external.worldbank.api.DataFailureException) CountryElement(com.hack23.cia.model.external.worldbank.countries.impl.CountryElement)

Example 3 with DataFailureException

use of com.hack23.cia.service.external.worldbank.api.DataFailureException in project cia by Hack23.

the class WorldBankIndicatorWorkGeneratorImpl method generateWorkOrders.

@Override
public void generateWorkOrders() {
    try {
        final List<IndicatorElement> list = worldbankIndicatorApi.getIndicators();
        final Map<String, String> currentSaved = getImportService().getWorldBankIndicatorElementMap();
        for (final IndicatorElement element : list) {
            if (!currentSaved.containsKey(element.getId())) {
                getJmsSender().send(indicatorElementWorkdestination, element);
            }
        }
    } catch (final DataFailureException exception) {
        LOGGER.warn("jms", exception);
    }
}
Also used : DataFailureException(com.hack23.cia.service.external.worldbank.api.DataFailureException) IndicatorElement(com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement)

Example 4 with DataFailureException

use of com.hack23.cia.service.external.worldbank.api.DataFailureException in project cia by Hack23.

the class RiksdagenBallotListWorkGeneratorImpl method generateWorkOrders.

@Override
public void generateWorkOrders() {
    try {
        final List<BallotDocumentElement> ballotList = riksdagenApi.getBallotList();
        final Map<String, String> alreadySavedIdMap = getImportService().getLoadedBallotIdMap();
        for (final BallotDocumentElement ballotDocument : ballotList) {
            if (!alreadySavedIdMap.containsKey(ballotDocument.getBallotId())) {
                getJmsSender().send(voteDataWorkdestination, ballotDocument.getBallotId());
                LOGGER.info("Load : https://data.riksdagen.se/votering/{}", ballotDocument.getBallotId());
            }
        }
    } catch (final DataFailureException e) {
        LOGGER.warn("Loadin ballots", e);
    }
}
Also used : DataFailureException(com.hack23.cia.service.external.riksdagen.api.DataFailureException) BallotDocumentElement(com.hack23.cia.model.external.riksdagen.voteringlista.impl.BallotDocumentElement)

Example 5 with DataFailureException

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

DataFailureException (com.hack23.cia.service.external.riksdagen.api.DataFailureException)3 DataFailureException (com.hack23.cia.service.external.worldbank.api.DataFailureException)3 IndicatorElement (com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement)2 XmlAgentException (com.hack23.cia.service.external.common.api.XmlAgentException)2 ArrayList (java.util.ArrayList)2 PersonElement (com.hack23.cia.model.external.riksdagen.personlista.impl.PersonElement)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 BallotDocumentElement (com.hack23.cia.model.external.riksdagen.voteringlista.impl.BallotDocumentElement)1 CountryElement (com.hack23.cia.model.external.worldbank.countries.impl.CountryElement)1 IndicatorsElement (com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorsElement)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1