<commit_before>package gov.nih.nci.integration.caaers.invoker;

import gov.nih.nci.cabig.caaers.integration.schema.adverseevent.CreateAdverseEventResponse;
import gov.nih.nci.cabig.caaers.integration.schema.adverseevent.DeleteAdverseEventResponse;
import gov.nih.nci.cabig.caaers.integration.schema.common.ServiceResponse;
import gov.nih.nci.cabig.caaers.integration.schema.common.WsError;
import gov.nih.nci.integration.caaers.CaAERSAdverseEventServiceWSClient;
import gov.nih.nci.integration.domain.ServiceInvocationMessage;
import gov.nih.nci.integration.domain.StrategyIdentifier;
import gov.nih.nci.integration.exception.IntegrationError;
import gov.nih.nci.integration.exception.IntegrationException;
import gov.nih.nci.integration.invoker.ServiceInvocationResult;
import gov.nih.nci.integration.invoker.ServiceInvocationStrategy;
import gov.nih.nci.integration.transformer.XSLTTransformer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.bind.JAXBException;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.SOAPFaultException;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This is Strategy class for Create Adverse Event for caAERS
 * 
 * @author <NAME>
 * 
 */
public class CaAERSAdverseEventServiceInvocationStrategy implements ServiceInvocationStrategy {

    private static final Logger LOG = LoggerFactory.getLogger(CaAERSAdverseEventServiceInvocationStrategy.class);

    private final CaAERSAdverseEventServiceWSClient client;

    private final int retryCount;

    private final XSLTTransformer xsltTransformer;

    private final Map<String, IntegrationError> msgToErrMap;

    /**
     * Constructor
     * 
     * @param xsltTransformer - XSLTTransformer
     * @param client - CaAERSAdverseEventServiceWSClient
     * @param retryCount - retryCount
     */
    public CaAERSAdverseEventServiceInvocationStrategy(XSLTTransformer xsltTransformer,
            CaAERSAdverseEventServiceWSClient client, int retryCount) {
        super();
        this.xsltTransformer = xsltTransformer;
        this.client = client;
        this.retryCount = retryCount;

        final HashMap<String, IntegrationError> msgToErrMapBase = new LinkedHashMap<String, IntegrationError>();
        msgToErrMapBase.put("Invalid Username/Password", IntegrationError._1011);
        msgToErrMapBase.put("could not be created in caAERS", IntegrationError._1014);
        msgToErrMapBase.put("Could not send Message", IntegrationError._1020);

        msgToErrMap = Collections.synchronizedMap(msgToErrMapBase);
    }

    @Override
    public int getRetryCount() {
        return retryCount;
    }

    @Override
    public StrategyIdentifier getStrategyIdentifier() {
        return StrategyIdentifier.CAEERS_CREATE_AE;
    }

    @Override
    public ServiceInvocationResult invoke(ServiceInvocationMessage msg) {
        final ServiceInvocationResult result = new ServiceInvocationResult();
        IntegrationException ie = null;
        try {
            final String adverseEventXMLStr = transformToAdverseEventXML(msg.getMessage().getRequest());

            final CreateAdverseEventResponse caaersresponse = client.createAdverseEvent(adverseEventXMLStr);
            final ServiceResponse response = caaersresponse.getCaaersServiceResponse().getServiceResponse();
            if ("0".equals(response.getResponsecode())) {
                result.setResult(response.getResponsecode() + " : " + response.getMessage());
                result.setDataChanged(true);
            } else {
                handleErrorResponse(response, result);
            }
        } catch (SOAPFaultException e) {
            LOG.error("SOAPFaultException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (JAXBException e) {
            LOG.error("JAXBException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (WebServiceException e) {
            LOG.error("WebServiceException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (IntegrationException e) {
            LOG.error("IntegrationException while calling createAdverseEvent.", e);<commit_msg>changes as per the updated response type<commit_after>package gov.nih.nci.integration.caaers.invoker;

import gov.nih.nci.cabig.caaers.integration.schema.adverseevent.CreateOrUpdateAdverseEventResponse;
import gov.nih.nci.cabig.caaers.integration.schema.adverseevent.DeleteAdverseEventResponse;
import gov.nih.nci.cabig.caaers.integration.schema.common.ServiceResponse;
import gov.nih.nci.cabig.caaers.integration.schema.common.WsError;
import gov.nih.nci.integration.caaers.CaAERSAdverseEventServiceWSClient;
import gov.nih.nci.integration.domain.ServiceInvocationMessage;
import gov.nih.nci.integration.domain.StrategyIdentifier;
import gov.nih.nci.integration.exception.IntegrationError;
import gov.nih.nci.integration.exception.IntegrationException;
import gov.nih.nci.integration.invoker.ServiceInvocationResult;
import gov.nih.nci.integration.invoker.ServiceInvocationStrategy;
import gov.nih.nci.integration.transformer.XSLTTransformer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.bind.JAXBException;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.SOAPFaultException;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This is Strategy class for Create Adverse Event for caAERS
 * 
 * @author <NAME>
 * 
 */
public class CaAERSAdverseEventServiceInvocationStrategy implements ServiceInvocationStrategy {

    private static final Logger LOG = LoggerFactory.getLogger(CaAERSAdverseEventServiceInvocationStrategy.class);

    private final CaAERSAdverseEventServiceWSClient client;

    private final int retryCount;

    private final XSLTTransformer xsltTransformer;

    private final Map<String, IntegrationError> msgToErrMap;

    /**
     * Constructor
     * 
     * @param xsltTransformer - XSLTTransformer
     * @param client - CaAERSAdverseEventServiceWSClient
     * @param retryCount - retryCount
     */
    public CaAERSAdverseEventServiceInvocationStrategy(XSLTTransformer xsltTransformer,
            CaAERSAdverseEventServiceWSClient client, int retryCount) {
        super();
        this.xsltTransformer = xsltTransformer;
        this.client = client;
        this.retryCount = retryCount;

        final HashMap<String, IntegrationError> msgToErrMapBase = new LinkedHashMap<String, IntegrationError>();
        msgToErrMapBase.put("Invalid Username/Password", IntegrationError._1011);
        msgToErrMapBase.put("could not be created in caAERS", IntegrationError._1014);
        msgToErrMapBase.put("Could not send Message", IntegrationError._1020);

        msgToErrMap = Collections.synchronizedMap(msgToErrMapBase);
    }

    @Override
    public int getRetryCount() {
        return retryCount;
    }

    @Override
    public StrategyIdentifier getStrategyIdentifier() {
        return StrategyIdentifier.CAEERS_CREATE_AE;
    }

    @Override
    public ServiceInvocationResult invoke(ServiceInvocationMessage msg) {
        final ServiceInvocationResult result = new ServiceInvocationResult();
        IntegrationException ie = null;
        try {
            final String adverseEventXMLStr = transformToAdverseEventXML(msg.getMessage().getRequest());

            final CreateOrUpdateAdverseEventResponse caaersresponse = client.createAdverseEvent(adverseEventXMLStr);
            final ServiceResponse response = caaersresponse.getCaaersServiceResponse().getServiceResponse();
            if ("0".equals(response.getResponsecode())) {
                result.setResult(response.getResponsecode() + " : " + response.getMessage());
                result.setDataChanged(true);
            } else {
                handleErrorResponse(response, result);
            }
        } catch (SOAPFaultException e) {
            LOG.error("SOAPFaultException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (JAXBException e) {
            LOG.error("JAXBException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (WebServiceException e) {
            LOG.error("WebServiceException while calling createAdverseEvent.", e);
            ie = new IntegrationException(IntegrationError._1053, e, e.getMessage());
        } catch (IntegrationException e) {
            LOG.error("IntegrationException while calling createAdverseEvent.", e);
{'fraction_non_alphanumeric': 0.08763492572405686, 'fraction_numerical': 0.005771080474511061, 'mean_word_length': 3.985615343633458, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4830120', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2592, 'n_words': 483}