<commit_before>package gov.nih.nci.cabig.caaers.api.impl;

import gov.nih.nci.cabig.caaers.api.ProcessingOutcome;
import gov.nih.nci.cabig.caaers.integration.schema.common.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <NAME>
 */
public class Helper {
    
    public static CaaersServiceResponse createResponse(){
    	
    	EntityProcessingOutcomes entityProcessingOutcomes = new EntityProcessingOutcomes();
        ServiceResponse serviceResponse = new ServiceResponse();
        serviceResponse.setEntityProcessingOutcomes(entityProcessingOutcomes);
        serviceResponse.setStatus(Status.PROCESSED);
        serviceResponse.setResponsecode("0");
        serviceResponse.setWsError(new ArrayList<WsError>());
        CaaersServiceResponse caaersServiceResponse = new CaaersServiceResponse();
        caaersServiceResponse.setServiceResponse(serviceResponse);
        
        return caaersServiceResponse;
    }


    public static EntityProcessingOutcomeType createProcessingOutcomeType(boolean failed, String klass, String businessId, String caaersId, String correlationId, List<String> messages){
        EntityProcessingOutcomeType  outcomeType = new EntityProcessingOutcomeType();
        outcomeType.setBusinessIdentifier(businessId);
        outcomeType.setCorrelationId(correlationId);
        outcomeType.setDataBaseId(caaersId);
        outcomeType.setKlassName(klass);
        outcomeType.setFailed(failed);
        if(messages != null) {
            for(String m : messages) outcomeType.getMessage().add(m);
        }
        return outcomeType;
    }


    public static CaaersServiceResponse populateError(CaaersServiceResponse response, String errorCode, String description){
        ServiceResponse serviceResponse = response.getServiceResponse();
        serviceResponse.setStatus(Status.FAILED_TO_PROCESS);
        serviceResponse.setResponsecode("1");
        WsError error = new WsError();
        error.setErrorCode(errorCode);
        error.setErrorDesc(description);
        serviceResponse.getWsError().add(error);
        return response;
    }

    public static CaaersServiceResponse populateMessage(CaaersServiceResponse response, String message) {
        ServiceResponse serviceResponse = response.getServiceResponse();
        serviceResponse.setResponsecode("0");
        serviceResponse.setMessage(message);
        return response;
    }

    public static CaaersServiceResponse populateErrorOutcome(CaaersServiceResponse response, String businessId, String caaersId, String corelationId, List<String> messages){

        ServiceResponse serviceRespons = response.getServiceResponse();
        serviceRespons.setStatus(Status.FAILED_TO_PROCESS);
        serviceRespons.setResponsecode("1");

        EntityProcessingOutcomes entityProcessingOutcomes = serviceRespons.getEntityProcessingOutcomes();
        if(entityProcessingOutcomes == null){
            entityProcessingOutcomes = new EntityProcessingOutcomes();
            serviceRespons.setEntityProcessingOutcomes(entityProcessingOutcomes);
        }
        EntityProcessingOutcomeType entityProcessingOutcomeType = createProcessingOutcomeType(true, "NA",
                businessId, caaersId, corelationId, messages);
        entityProcessingOutcomes.getEntityProcessingOutcome().add(entityProcessingOutcomeType);<commit_msg>Fix for caaers response validation error. (Raised by Vinodh) CAAERS-5313<commit_after>package gov.nih.nci.cabig.caaers.api.impl;

import gov.nih.nci.cabig.caaers.api.ProcessingOutcome;
import gov.nih.nci.cabig.caaers.integration.schema.common.*;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <NAME>
 */
public class Helper {
    
    public static CaaersServiceResponse createResponse(){
    	
    	EntityProcessingOutcomes entityProcessingOutcomes = new EntityProcessingOutcomes();
        ServiceResponse serviceResponse = new ServiceResponse();
        serviceResponse.setEntityProcessingOutcomes(entityProcessingOutcomes);
        serviceResponse.setStatus(Status.PROCESSED);
        serviceResponse.setResponsecode("0");
        serviceResponse.setWsError(new ArrayList<WsError>());
        CaaersServiceResponse caaersServiceResponse = new CaaersServiceResponse();
        caaersServiceResponse.setServiceResponse(serviceResponse);
        
        return caaersServiceResponse;
    }


    public static EntityProcessingOutcomeType createProcessingOutcomeType(boolean failed, String klass, String businessId, String caaersId, String correlationId, List<String> messages){
        EntityProcessingOutcomeType  outcomeType = new EntityProcessingOutcomeType();
        outcomeType.setBusinessIdentifier(businessId);
        outcomeType.setCorrelationId(correlationId);
        outcomeType.setDataBaseId(caaersId);
        outcomeType.setKlassName(klass);
        outcomeType.setFailed(failed);
        if(messages != null) {
            for(String m : messages) outcomeType.getMessage().add(m);
        }
        return outcomeType;
    }


    public static CaaersServiceResponse populateError(CaaersServiceResponse response, String errorCode, String description){
        ServiceResponse serviceResponse = response.getServiceResponse();
        serviceResponse.setStatus(Status.FAILED_TO_PROCESS);
        serviceResponse.setResponsecode("1");
        WsError error = new WsError();
        error.setErrorCode(errorCode);
        error.setErrorDesc(description);
        serviceResponse.getWsError().add(error);
        return response;
    }

    public static CaaersServiceResponse populateMessage(CaaersServiceResponse response, String message) {
        ServiceResponse serviceResponse = response.getServiceResponse();
        serviceResponse.setResponsecode("0");
        serviceResponse.setMessage(message);
        return response;
    }

    public static CaaersServiceResponse populateErrorOutcome(CaaersServiceResponse response, String businessId, String caaersId, String corelationId, List<String> messages){

        ServiceResponse serviceRespons = response.getServiceResponse();
        serviceRespons.setStatus(Status.FAILED_TO_PROCESS);
        serviceRespons.setResponsecode("1");

        EntityProcessingOutcomes entityProcessingOutcomes = serviceRespons.getEntityProcessingOutcomes();
        if(entityProcessingOutcomes == null){
            entityProcessingOutcomes = new EntityProcessingOutcomes();
            serviceRespons.setEntityProcessingOutcomes(entityProcessingOutcomes);
        }
        EntityProcessingOutcomeType entityProcessingOutcomeType = createProcessingOutcomeType(true, "NA",
                StringUtils.isEmpty(businessId) ? "UNKNOWN" : businessId, caaersId, corelationId, messages);
        entityProcessingOutcomes.getEntityProcessingOutcome().add(entityProcessingOutcomeType);
{'fraction_non_alphanumeric': 0.0794972965073798, 'fraction_numerical': 0.0017536168347216134, 'mean_word_length': 4.173091458805745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3231669', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1731, 'n_words': 300}