<commit_before>// CedarRequestHandler.cc

// This file is part of the OPeNDAP Cedar data handler, providing data
// access views for CedarWEB data

// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
// Author: <NAME> <<EMAIL>> and <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact University Corporation for Atmospheric Research at
// 3080 Center Green Drive, Boulder, CO 80301
 
// (c) COPYRIGHT University Corporation for Atmostpheric Research 2004-2005
// Please read the full copyright statement in the file COPYRIGHT_UCAR.
//
// Authors:
//      pwest       <NAME> <<EMAIL>>
//      jgarcia     <NAME> <<EMAIL>>

#include "CedarRequestHandler.h"
#include "BESResponseHandler.h"
#include "BESInternalError.h"
#include "BESInternalFatalError.h"
#include "BESDapError.h"
#include "BESResponseNames.h"
#include "CedarResponseNames.h"
#include "BESDataNames.h"
#include "cedar_read_attributes.h"
#include "BESDASResponse.h"
#include "cedar_read_descriptors.h"
#include "BESDDSResponse.h"
#include "BESDataDDSResponse.h"
#include "cedar_read_tab.h"
#include "CedarTab.h"
#include "cedar_read_flat.h"
#include "CedarFlat.h"
#include "cedar_read_stream.h"
#include "BESVersionInfo.h"
#include "cedar_read_info.h"
#include "CedarVersion.h"
#include "TheBESKeys.h"
#include "BESDebug.h"
#include "config_cedar.h"

CedarRequestHandler::CedarRequestHandler( string name )
    : BESRequestHandler( name )
{
    add_handler( DAS_RESPONSE, CedarRequestHandler::cedar_build_das ) ;
    add_handler( DDS_RESPONSE, CedarRequestHandler::cedar_build_dds ) ;
    add_handler( DATA_RESPONSE, CedarRequestHandler::cedar_build_data ) ;
    add_handler( FLAT_RESPONSE, CedarRequestHandler::cedar_build_flat ) ;
    add_handler( STREAM_RESPONSE, CedarRequestHandler::cedar_build_stream ) ;
    add_handler( TAB_RESPONSE, CedarRequestHandler::cedar_build_tab ) ;
    add_handler( INFO_RESPONSE, CedarRequestHandler::cedar_build_info ) ;
    add_handler( VERS_RESPONSE, CedarRequestHandler::cedar_build_vers ) ;
    add_handler( HELP_RESPONSE, CedarRequestHandler::cedar_build_help ) ;
}

CedarRequestHandler::~CedarRequestHandler()
{
}

/** @brief dumps information about this object
 *
 * Displays the pointer value of this instance and calls the parent dump
 * method
 *
 * @param strm C++ i/o stream to dump the information to
 */
void
CedarRequestHandler::dump( ostream &strm ) const
{
    strm << BESIndent::LMarg << "CedarRequestHandler::dump - ("
			     << (void *)this << ")" << endl ;
    BESIndent::Indent() ;
    BESRequestHandler::dump( strm ) ;
    BESIndent::UnIndent() ;
}

bool
CedarRequestHandler::cedar_build_das( BESDataHandlerInterface &dhi )
{
    BESDEBUG( "cedar", "building cedar das response:" << endl )

    bool ret = true ;
    BESDASResponse *bdas =
	dynamic_cast<BESDASResponse *>(dhi.response_handler->get_response_object());
    DAS *das = bdas->get_das() ;

    try
    {
	string cedar_error ;
	string container = dhi.container->access() ;
	if( !cedar_read_attributes( *das, container, cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DAS";
        BESInternalFatalError ex(s, __FILE__, __LINE__);
        throw ex;
    }

    BESDEBUG( "cedar", "returning from building cedar das response:" << endl << *das << endl )

    return ret ;
}

bool
CedarRequestHandler::cedar_build_dds( BESDataHandlerInterface &dhi )
{
    bool ret = true ;
    BESDDSResponse *bdds =
	dynamic_cast<BESDDSResponse *>(dhi.response_handler->get_response_object());
    DDS *dds = bdds->get_dds() ;

    try
    {
	string cedar_error ;
	string container = dhi.container->access() ;
	if( !cedar_read_descriptors( *dds, container,
				     dhi.container->get_symbolic_name(),
				     dhi.container->get_constraint(),
				     cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	dhi.data[POST_CONSTRAINT] = "" ;
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DDS";
        BESInternalFatalError ex(s, __FILE__, __LINE__);
        throw ex;
    }
    return ret ;
}

bool
CedarRequestHandler::cedar_build_data( BESDataHandlerInterface &dhi )
{
    BESDataDDSResponse *bdds = 
	dynamic_cast<BESDataDDSResponse *>(dhi.response_handler->get_response_object());
    DataDDS *dds = bdds->get_dds() ;

    try
    {
	string cedar_error ;
	if( !cedar_read_descriptors( *dds, dhi.container->access(),
				     dhi.container->get_symbolic_name(),
				     dhi.container->get_constraint(),
				     cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	dhi.data[POST_CONSTRAINT] = "" ;
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DataDDS";<commit_msg>Adding ancillary das and dds information. M    CedarRequestHandler.cc<commit_after>// CedarRequestHandler.cc

// This file is part of the OPeNDAP Cedar data handler, providing data
// access views for CedarWEB data

// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
// Author: <NAME> <<EMAIL>> and <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact University Corporation for Atmospheric Research at
// 3080 Center Green Drive, Boulder, CO 80301
 
// (c) COPYRIGHT University Corporation for Atmostpheric Research 2004-2005
// Please read the full copyright statement in the file COPYRIGHT_UCAR.
//
// Authors:
//      pwest       <NAME> <<EMAIL>>
//      jgarcia     <NAME> <<EMAIL>>

#include "CedarRequestHandler.h"
#include "BESResponseHandler.h"
#include "BESInternalError.h"
#include "BESInternalFatalError.h"
#include "BESDapError.h"
#include "BESResponseNames.h"
#include "CedarResponseNames.h"
#include "BESDataNames.h"
#include "cedar_read_attributes.h"
#include "BESDASResponse.h"
#include "cedar_read_descriptors.h"
#include "BESDDSResponse.h"
#include "BESDataDDSResponse.h"
#include "Ancillary.h"
#include "cedar_read_tab.h"
#include "CedarTab.h"
#include "cedar_read_flat.h"
#include "CedarFlat.h"
#include "cedar_read_stream.h"
#include "BESVersionInfo.h"
#include "cedar_read_info.h"
#include "CedarVersion.h"
#include "TheBESKeys.h"
#include "BESDebug.h"
#include "config_cedar.h"

CedarRequestHandler::CedarRequestHandler( string name )
    : BESRequestHandler( name )
{
    add_handler( DAS_RESPONSE, CedarRequestHandler::cedar_build_das ) ;
    add_handler( DDS_RESPONSE, CedarRequestHandler::cedar_build_dds ) ;
    add_handler( DATA_RESPONSE, CedarRequestHandler::cedar_build_data ) ;
    add_handler( FLAT_RESPONSE, CedarRequestHandler::cedar_build_flat ) ;
    add_handler( STREAM_RESPONSE, CedarRequestHandler::cedar_build_stream ) ;
    add_handler( TAB_RESPONSE, CedarRequestHandler::cedar_build_tab ) ;
    add_handler( INFO_RESPONSE, CedarRequestHandler::cedar_build_info ) ;
    add_handler( VERS_RESPONSE, CedarRequestHandler::cedar_build_vers ) ;
    add_handler( HELP_RESPONSE, CedarRequestHandler::cedar_build_help ) ;
}

CedarRequestHandler::~CedarRequestHandler()
{
}

/** @brief dumps information about this object
 *
 * Displays the pointer value of this instance and calls the parent dump
 * method
 *
 * @param strm C++ i/o stream to dump the information to
 */
void
CedarRequestHandler::dump( ostream &strm ) const
{
    strm << BESIndent::LMarg << "CedarRequestHandler::dump - ("
			     << (void *)this << ")" << endl ;
    BESIndent::Indent() ;
    BESRequestHandler::dump( strm ) ;
    BESIndent::UnIndent() ;
}

bool
CedarRequestHandler::cedar_build_das( BESDataHandlerInterface &dhi )
{
    BESDEBUG( "cedar", "building cedar das response:" << endl )

    bool ret = true ;
    BESDASResponse *bdas =
	dynamic_cast<BESDASResponse *>(dhi.response_handler->get_response_object());
    DAS *das = bdas->get_das() ;

    try
    {
	string cedar_error ;
	string container = dhi.container->access() ;
	if( !cedar_read_attributes( *das, container, cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	Ancillary::read_ancillary_das( *das, container ) ;
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DAS";
        BESInternalFatalError ex(s, __FILE__, __LINE__);
        throw ex;
    }

    BESDEBUG( "cedar", "returning from building cedar das response:" << endl << *das << endl )

    return ret ;
}

bool
CedarRequestHandler::cedar_build_dds( BESDataHandlerInterface &dhi )
{
    bool ret = true ;
    BESDDSResponse *bdds =
	dynamic_cast<BESDDSResponse *>(dhi.response_handler->get_response_object());
    DDS *dds = bdds->get_dds() ;

    try
    {
	string cedar_error ;
	string accessed = dhi.container->access() ;
	if( !cedar_read_descriptors( *dds, accessed,
				     dhi.container->get_symbolic_name(),
				     dhi.container->get_constraint(),
				     cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	Ancillary::read_ancillary_dds( *dds, accessed ) ;

	// The dds now includes attribute information. Read the attributes,
	// including any ancillary attributes
	DAS das ;
	if( !cedar_read_attributes( das, accessed, cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	Ancillary::read_ancillary_das( das, accessed ) ;

	// transfer the attributes to the dds.
	dds->transfer_attributes(&das);

	dhi.data[POST_CONSTRAINT] = "" ;
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DDS";
        BESInternalFatalError ex(s, __FILE__, __LINE__);
        throw ex;
    }
    return ret ;
}

bool
CedarRequestHandler::cedar_build_data( BESDataHandlerInterface &dhi )
{
    BESDataDDSResponse *bdds = 
	dynamic_cast<BESDataDDSResponse *>(dhi.response_handler->get_response_object());
    DataDDS *dds = bdds->get_dds() ;

    try
    {
	string cedar_error ;
	string accessed = dhi.container->access() ;
	if( !cedar_read_descriptors( *dds, accessed,
				     dhi.container->get_symbolic_name(),
				     dhi.container->get_constraint(),
				     cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	Ancillary::read_ancillary_dds( *dds, accessed ) ;

	// The dds now includes attribute information. Read the attributes,
	// including any ancillary attributes
	DAS das ;
	if( !cedar_read_attributes( das, accessed, cedar_error ) )
	{
	    throw BESInternalError( cedar_error, __FILE__, __LINE__ ) ;
	}
	Ancillary::read_ancillary_das( das, accessed ) ;

	// transfer the attributes to the dds.
	dds->transfer_attributes(&das);

	dhi.data[POST_CONSTRAINT] = "" ;
    }
    catch( BESError &e ) {
	throw e ;
    }
    catch(InternalErr & e) {
        BESDapError ex( e.get_error_message(), true, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(Error & e) {
        BESDapError ex( e.get_error_message(), false, e.get_error_code(),
	                __FILE__, __LINE__ ) ;
        throw ex;
    }
    catch(...) {
        string s = "unknown exception caught building DataDDS";
{'fraction_non_alphanumeric': 0.11101783840503672, 'fraction_numerical': 0.0057362714235746765, 'mean_word_length': 3.4647095565271706, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 61, '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': '7353328', 'n_tokens_mistral': 5028, 'n_tokens_neox': 4747, 'n_words': 1178}