<commit_before>package dk.bemyndigelsesregister.bemyndigelsesservice.web;

import com.trifork.dgws.annotations.Protected;
import dk.bemyndigelsesregister.bemyndigelsesservice.BemyndigelsesService;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Delegation;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Metadata;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Status;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.RequestContext;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.RequestType;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.dao.ServiceTypeMapper_20160101;
import dk.nsi.bemyndigelse._2016._01._01.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.soap.SoapHeader;

import javax.inject.Inject;
import java.util.*;

@Repository("bemyndigelsesService")
@Endpoint
public class BemyndigelsesServiceImpl_20160101 extends AbstractServiceImpl implements BemyndigelsesService {
    private static Logger logger = Logger.getLogger(BemyndigelsesServiceImpl_20160101.class);

    @Inject
    ServiceTypeMapper_20160101 typeMapper;

    public BemyndigelsesServiceImpl_20160101() {
        super(logger);
    }

    @Override
    @Protected(minAuthLevel = 4)
    @Transactional
    @ResponsePayload
    public CreateDelegationsResponse createDelegations(@RequestPayload CreateDelegationsRequest request, SoapHeader soapHeader) {
        RequestContext.get().setRequestType(RequestType.CREATE);

        // auditlog call - one for each delegatee
        Set<String> delegateeCprs = new HashSet<>();
        for (CreateDelegationsRequest.Create createDelegation : request.getCreate()) {
            delegateeCprs.add(createDelegation.getDelegateeCpr());
        }
        for (String delegateeCpr : delegateeCprs) {
            auditLogger.log("Opret bemyndigelser", delegateeCpr);
        }
        logCallOfOldService("O<NAME>");

        Collection<Delegation> delegations = new ArrayList<>();

        for (CreateDelegationsRequest.Create createDelegation : request.getCreate()) {
            if (createDelegation.getState().equals(State.ANMODET)) {
                authorizeOperationForCpr("createDelegation", "IDCard CPR was different from both DelegatorCpr and DelegateeCpr", createDelegation.getDelegatorCpr(), createDelegation.getDelegateeCpr());
            } else {
                authorizeOperationForCpr("createDelegation", "IDCard CPR was different from DelegatorCpr", createDelegation.getDelegatorCpr());
            }
            logger.debug("Creating Delegation: " + createDelegation.toString());
            final Delegation delegation = delegationManager.createDelegation(
                    createDelegation.getSystemId(),
                    createDelegation.getDelegatorCpr(),
                    createDelegation.getDelegateeCpr(),
                    createDelegation.getDelegateeCvr(),
                    createDelegation.getRoleId(),
                    Status.fromValue(createDelegation.getState().value()),
                    createDelegation.getListOfPermissionIds().getPermissionId(),
                    nullableDateTime(createDelegation.getEffectiveFrom()),
                    nullableDateTime(createDelegation.getEffectiveTo()));
            logger.debug("Got delegation with code = [" + delegation.getCode() + "]");

            delegations.add(delegation);
        }

        final CreateDelegationsResponse response = new CreateDelegationsResponse();
        for (Delegation delegation : delegations) {
            response.getDelegation().add(typeMapper.toDelegationType(delegation));
        }
        return response;
    }

    @Override
    @Protected(minAuthLevel = 4)
    @Transactional
    @ResponsePayload
    public GetDelegationsResponse getDelegations(@RequestPayload GetDelegationsRequest request, SoapHeader soapHeader) {
        RequestContext.get().setRequestType(RequestType.GET_METADATA);

        logCallOfOldService("Hent bemyndigelser");

        Collection<Delegation> delegations = getDelegationsCommon(request.getDelegatorCpr(), request.getDelegateeCpr(), request.getDelegationId());
<commit_msg>FMK-6795 Fix to saveReplay try-catch (3)<commit_after>package dk.bemyndigelsesregister.bemyndigelsesservice.web;

import com.trifork.dgws.annotations.Protected;
import dk.bemyndigelsesregister.bemyndigelsesservice.BemyndigelsesService;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Delegation;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Metadata;
import dk.bemyndigelsesregister.bemyndigelsesservice.domain.Status;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.RequestContext;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.RequestType;
import dk.bemyndigelsesregister.bemyndigelsesservice.server.dao.ServiceTypeMapper_20160101;
import dk.nsi.bemyndigelse._2016._01._01.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.soap.SoapHeader;

import javax.inject.Inject;
import java.util.*;

@Repository("bemyndigelsesService")
@Endpoint
public class BemyndigelsesServiceImpl_20160101 extends AbstractServiceImpl implements BemyndigelsesService {
    private static Logger logger = Logger.getLogger(BemyndigelsesServiceImpl_20160101.class);

    @Inject
    ServiceTypeMapper_20160101 typeMapper;

    public BemyndigelsesServiceImpl_20160101() {
        super(logger);
    }

    @Override
    @Protected(minAuthLevel = 4)
    @Transactional
    @ResponsePayload
    public CreateDelegationsResponse createDelegations(@RequestPayload CreateDelegationsRequest request, SoapHeader soapHeader) {
        RequestContext.get().setRequestType(RequestType.CREATE);

        // auditlog call - one for each delegatee
        Set<String> delegateeCprs = new HashSet<>();
        for (CreateDelegationsRequest.Create createDelegation : request.getCreate()) {
            delegateeCprs.add(createDelegation.getDelegateeCpr());
        }
        for (String delegateeCpr : delegateeCprs) {
            auditLogger.log("Opret bemyndigelser", delegateeCpr);
        }
        logCallOfOldService("Opret bemyndigelser");

        Collection<Delegation> delegations = new ArrayList<>();

        for (CreateDelegationsRequest.Create createDelegation : request.getCreate()) {
            if (createDelegation.getState().equals(State.ANMODET)) {
                authorizeOperationForCpr("createDelegation", "IDCard CPR was different from both DelegatorCpr and DelegateeCpr", createDelegation.getDelegatorCpr(), createDelegation.getDelegateeCpr());
            } else {
                authorizeOperationForCpr("createDelegation", "IDCard CPR was different from DelegatorCpr", createDelegation.getDelegatorCpr());
            }
            logger.debug("Creating Delegation: " + createDelegation.toString());
            final Delegation delegation = delegationManager.createDelegation(
                    createDelegation.getSystemId(),
                    createDelegation.getDelegatorCpr(),
                    createDelegation.getDelegateeCpr(),
                    createDelegation.getDelegateeCvr(),
                    createDelegation.getRoleId(),
                    Status.fromValue(createDelegation.getState().value()),
                    createDelegation.getListOfPermissionIds().getPermissionId(),
                    nullableDateTime(createDelegation.getEffectiveFrom()),
                    nullableDateTime(createDelegation.getEffectiveTo()));
            logger.debug("Got delegation with code = [" + delegation.getCode() + "]");

            delegations.add(delegation);
        }

        final CreateDelegationsResponse response = new CreateDelegationsResponse();
        for (Delegation delegation : delegations) {
            response.getDelegation().add(typeMapper.toDelegationType(delegation));
        }
        return response;
    }

    @Override
    @Protected(minAuthLevel = 4)
    @Transactional
    @ResponsePayload
    public GetDelegationsResponse getDelegations(@RequestPayload GetDelegationsRequest request, SoapHeader soapHeader) {
        RequestContext.get().setRequestType(RequestType.GET);

        logCallOfOldService("<NAME>");

        Collection<Delegation> delegations = getDelegationsCommon(request.getDelegatorCpr(), request.getDelegateeCpr(), request.getDelegationId());

{'fraction_non_alphanumeric': 0.0881567230632235, 'fraction_numerical': 0.011910062333036509, 'mean_word_length': 3.942244224422442, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569404', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2498, 'n_words': 363}