class NamingClientResponseValidator {

    public String validateNameGenResponse(ResponseEntity<NameGenResponse> response) throws BadResponseException {
        if (response == null) {
            logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(),
                    NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN", ErrorCode.UnknownError.getValue(),
                    NO_RESPONSE_FROM_NAMING_SERVICE);
            throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE);
        }

        int responseCode = response.getStatusCodeValue();
        String generatedName = "";
        NameGenResponse responseBody = response.getBody();
        if (responseBody == null) {
            logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(),
                    NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN", ErrorCode.UnknownError.getValue(),
                    NULL_RESPONSE_FROM_NAMING_SERVICE);
            throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE);
        }

        if (isHttpCodeSuccess(responseCode)) {
            logger.info("Successful Response from Naming Service");
            List<Respelement> respList = responseBody.getElements();

            if (respList != null) {
                for (int i = 0; i < respList.size(); i++) {
                    Respelement respElement = respList.get(i);
                    if (respElement != null) {
                        String resourceName = respElement.getResourceName();
                        if (INSTANCE_GROUP_NAME.equals(resourceName)) {
                            generatedName = respElement.getResourceValue();
                            break;
                        } else if (SERVICE_INSTANCE_NAME.equals(resourceName)) {
                            generatedName = respElement.getResourceValue();
                            break;
                        }
                    }
                }
            }
            return generatedName;
        } else {
            NameGenResponseError error = responseBody.getError();
            String errorMessageString = NAMING_SERVICE_ERROR;
            if (error != null) {
                errorMessageString = error.getMessage();
            }
            String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
            logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(), errorMessage, "BPMN",
                    ErrorCode.DataError.getValue(), errorMessage);
            throw new BadResponseException(errorMessage);
        }
    }

}