Search in sources :

Example 1 with VoteDataEmbeddedId

use of com.hack23.cia.model.external.riksdagen.votering.impl.VoteDataEmbeddedId 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

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 XmlAgentException (com.hack23.cia.service.external.common.api.XmlAgentException)1 DataFailureException (com.hack23.cia.service.external.riksdagen.api.DataFailureException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1