<commit_before>package eu.nimble.core.infrastructure.identity.controller.ubl;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import eu.nimble.core.infrastructure.identity.service.IdentityUtils;
import eu.nimble.core.infrastructure.identity.repository.PartyRepository;
import eu.nimble.core.infrastructure.identity.repository.PersonRepository;
import eu.nimble.core.infrastructure.identity.repository.QualifyingPartyRepository;
import eu.nimble.core.infrastructure.identity.uaa.OAuthClient;
import eu.nimble.core.infrastructure.identity.utils.UblUtils;
import eu.nimble.service.model.ubl.commonaggregatecomponents.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * Created by <NAME> on 26/04/17.
 * Controller for retrieving party data.
 */
@Controller
@Api(value = "party", description = "API for handling parties on the platform.")
public class PartyController {

    private static final Logger logger = LoggerFactory.getLogger(PartyController.class);

    @Autowired
    private PartyRepository partyRepository;

    @Autowired
    private PersonRepository personRepository;

    @Autowired
    private QualifyingPartyRepository qualifyingPartyRepository;

    @Autowired
    private IdentityUtils identityUtils;

    @SuppressWarnings("PointlessBooleanExpression")
    @ApiOperation(value = "", notes = "Get Party for Id.", response = PartyType.class, tags = {})
    @RequestMapping(value = "/party/{partyId}", method = RequestMethod.GET)
    ResponseEntity<PartyType> getParty(
            @ApiParam(value = "Id of party to retrieve.", required = true) @PathVariable Long partyId,
            @RequestHeader(value = "Authorization") String bearer) throws IOException {

        // search relevant parties
        List<PartyType> parties = partyRepository.findByHjid(partyId);

        // check if party was found
        if (parties.isEmpty()) {
            logger.info("Requested party with Id {} not found", partyId);
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        PartyType party = parties.get(0);

        // remove person depending on access rights
        if (identityUtils.hasRole(bearer, OAuthClient.Role.LEGAL_REPRESENTATIVE) == false)
            party.setPerson(new ArrayList<>());

        UblUtils.removeBinaries(party);

        logger.debug("Returning requested party with Id {}", party.getHjid());
        return new ResponseEntity<>(party, HttpStatus.OK);
    }


    @ApiOperation(value = "getAllParties", notes = "Get all parties in a paginated manner", response = Page.class)
    @RequestMapping(value = "/parties/all", method = RequestMethod.GET)
    ResponseEntity<Page<PartyType>> getAllParties(@RequestParam(value = "page", required = false, defaultValue = "1") int pageNumber,
                                                  @RequestParam(value = "size", required = false, defaultValue = "10") int pageSize) {

        logger.debug("Requesting all parties page {}", pageNumber);

        Page<PartyType> partyPage = partyRepository.findAll(new PageRequest(pageNumber - 1, pageSize, new Sort(Sort.Direction.ASC, "name")));

        // remove binaries for response
        partyPage.getContent().forEach(UblUtils::removeBinaries);

        return new ResponseEntity<>(partyPage, HttpStatus.OK);
    }

    @SuppressWarnings("PointlessBooleanExpression")
    @ApiOperation(value = "getParties", notes = "Get multiple parties for Ids.", response = Iterable.class)
    @RequestMapping(value = "/parties/{partyIds}", method = RequestMethod.GET)
    ResponseEntity<?> getParty(
            @ApiParam(value = "Ids of parties to retrieve.", required = true) @PathVariable List<Long> partyIds) {

        logger.debug("Requesting parties with Ids {}", partyIds);

        // search relevant parties
        List<PartyType> parties = new ArrayList<>();
        for (Long partyId : partyIds) {<commit_msg>Tested transaction repository<commit_after>package eu.nimble.core.infrastructure.identity.controller.ubl;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import eu.nimble.core.infrastructure.identity.service.IdentityUtils;
import eu.nimble.core.infrastructure.identity.repository.PartyRepository;
import eu.nimble.core.infrastructure.identity.repository.PersonRepository;
import eu.nimble.core.infrastructure.identity.repository.QualifyingPartyRepository;
import eu.nimble.core.infrastructure.identity.uaa.OAuthClient;
import eu.nimble.core.infrastructure.identity.utils.UblUtils;
import eu.nimble.service.model.ubl.commonaggregatecomponents.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * Created by <NAME> on 26/04/17.
 * Controller for retrieving party data.
 */
@Controller
@Api(value = "party", description = "API for handling parties on the platform.")
public class PartyController {

    private static final Logger logger = LoggerFactory.getLogger(PartyController.class);

    @Autowired
    private PartyRepository partyRepository;

    @Autowired
    private PersonRepository personRepository;

    @Autowired
    private QualifyingPartyRepository qualifyingPartyRepository;

    @Autowired
    private IdentityUtils identityUtils;

    @SuppressWarnings("PointlessBooleanExpression")
    @ApiOperation(value = "", notes = "Get Party for Id.", response = PartyType.class, tags = {})
    @RequestMapping(value = "/party/{partyId}", method = RequestMethod.GET)
    ResponseEntity<PartyType> getParty(
            @ApiParam(value = "Id of party to retrieve.", required = true) @PathVariable Long partyId,
            @RequestHeader(value = "Authorization") String bearer) throws IOException {

        // search relevant parties
        List<PartyType> parties = partyRepository.findByHjid(partyId);

        // check if party was found
        if (parties.isEmpty()) {
            logger.info("Requested party with Id {} not found", partyId);
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        PartyType party = parties.get(0);

        // remove person depending on access rights
        if (identityUtils.hasRole(bearer, OAuthClient.Role.LEGAL_REPRESENTATIVE) == false)
            party.setPerson(new ArrayList<>());

        UblUtils.removeBinaries(party);

        logger.debug("Returning requested party with Id {}", party.getHjid());
        return new ResponseEntity<>(party, HttpStatus.OK);
    }


    @ApiOperation(value = "getAllParties", notes = "Get all parties in a paginated manner", response = Page.class)
    @RequestMapping(value = "/parties/all", method = RequestMethod.GET)
    ResponseEntity<Page<PartyType>> getAllParties(@RequestParam(value = "page", required = false, defaultValue = "1") int pageNumber,
                                                  @RequestParam(value = "size", required = false, defaultValue = "10") int pageSize) {

        logger.debug("Requesting all parties page {}", pageNumber);

        Page<PartyType> partyPage = partyRepository.findAll(new PageRequest(pageNumber, pageSize, new Sort(Sort.Direction.ASC, "name")));

        // remove binaries for response
        partyPage.getContent().forEach(UblUtils::removeBinaries);

        return new ResponseEntity<>(partyPage, HttpStatus.OK);
    }

    @SuppressWarnings("PointlessBooleanExpression")
    @ApiOperation(value = "getParties", notes = "Get multiple parties for Ids.", response = Iterable.class)
    @RequestMapping(value = "/parties/{partyIds}", method = RequestMethod.GET)
    ResponseEntity<?> getParty(
            @ApiParam(value = "Ids of parties to retrieve.", required = true) @PathVariable List<Long> partyIds) {

        logger.debug("Requesting parties with Ids {}", partyIds);

        // search relevant parties
        List<PartyType> parties = new ArrayList<>();
        for (Long partyId : partyIds) {
{'fraction_non_alphanumeric': 0.10863425458946943, 'fraction_numerical': 0.002521686503933831, 'mean_word_length': 4.174843423799582, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896848', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2657, 'n_words': 609}