<commit_before>/**
 * @file reSysDataObjOpr.c
 *
 */

/*** Copyright (c), The Regents of the University of California            ***
 *** For more information please refer to files in the COPYRIGHT directory ***/

/* reSysDataObjOpr.c */

#include "reSysDataObjOpr.hpp"
#include "genQuery.hpp"
#include "getRescQuota.hpp"
#include "reServerLib.hpp"
#include "dataObjOpr.hpp"
#include "resource.hpp"
#include "physPath.hpp"

// =-=-=-=-=-=-=-
//
#include "irods_resource_backport.hpp"
#include "irods_server_api_table.hpp"

/**
 * \fn msiSetDefaultResc (msParam_t *xdefaultRescList, msParam_t *xoptionStr, ruleExecInfo_t *rei)
 *
 * \brief  This microservice sets the default resource and query resource metadata for
 *    the subsequent use based on an input array and condition given
 *    in the dataObject Input Structure.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  <NAME>
 * \date    2006-11
 *
 * \note This function is mandatory even no defaultResc is specified (null) and should be executed right after the screening function msiSetNoDirectRescInp.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xdefaultRescList - Required - a msParam of type STR_MS_T which is a list
 *    of %-delimited resourceNames. It is a resource to use if no resource is input.
 *    A "null" means there is no defaultResc.
 * \param[in] xoptionStr - a msParam of type STR_MS_T which is an option (preferred, forced, random)
 *    with random as default. A "forced" input means the defaultResc will be used regardless
 *    of the user input. The forced action only apply to to users with normal privilege.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence rei->doinp->condInput,
 *                    rei->rsComm->proxyUser.authInfo.authFlag
 * \DolVarModified rei->rgi gets set to a group (possibly singleton) list of resources in the preferred order.
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
 **/
int
msiSetDefaultResc( msParam_t *xdefaultRescList, msParam_t *xoptionStr, ruleExecInfo_t *rei ) {
    char *defaultRescList;
    char *optionStr;
    std::string default_resc;

    defaultRescList = ( char * ) xdefaultRescList->inOutStruct;

    optionStr = ( char * ) xoptionStr->inOutStruct;

    RE_TEST_MACRO( "    Calling msiSetDefaultResc" )

    // JMC - legacy resource - rei->status = setDefaultResc (rei->rsComm, defaultRescList, optionStr, &rei->doinp->condInput, &myRescGrpInfo );

    irods::error err = irods::set_default_resource( rei->rsComm, defaultRescList, optionStr, &rei->doinp->condInput, default_resc );
    rei->status = err.code();

    if ( rei->status >= 0 ) {
    	strncpy(rei->rescName, default_resc.c_str(), NAME_LEN);
    }
    else {
        irods::log( PASS( err ) );
        memset(&rei->rescName, 0, NAME_LEN);
    }
    return rei->status;
}

/**
 * \fn msiSetRescSortScheme (msParam_t *xsortScheme, ruleExecInfo_t *rei)
 *
 * \brief  This microservice sets the scheme for selecting the best resource to use when creating a data object.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author <NAME>
 * \date 2007
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xsortScheme - The sorting scheme. Valid schemes are "default", "random" and
 *    "byRescType". The "byRescType" scheme will put the cache class of resource on the top<commit_msg>[#2212] CID84916:<commit_after>/**
 * @file reSysDataObjOpr.c
 *
 */

/*** Copyright (c), The Regents of the University of California            ***
 *** For more information please refer to files in the COPYRIGHT directory ***/

/* reSysDataObjOpr.c */

#include "reSysDataObjOpr.hpp"
#include "genQuery.hpp"
#include "getRescQuota.hpp"
#include "reServerLib.hpp"
#include "dataObjOpr.hpp"
#include "resource.hpp"
#include "physPath.hpp"

// =-=-=-=-=-=-=-
//
#include "irods_resource_backport.hpp"
#include "irods_server_api_table.hpp"

/**
 * \fn msiSetDefaultResc (msParam_t *xdefaultRescList, msParam_t *xoptionStr, ruleExecInfo_t *rei)
 *
 * \brief  This microservice sets the default resource and query resource metadata for
 *    the subsequent use based on an input array and condition given
 *    in the dataObject Input Structure.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  <NAME>
 * \date    2006-11
 *
 * \note This function is mandatory even no defaultResc is specified (null) and should be executed right after the screening function msiSetNoDirectRescInp.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xdefaultRescList - Required - a msParam of type STR_MS_T which is a list
 *    of %-delimited resourceNames. It is a resource to use if no resource is input.
 *    A "null" means there is no defaultResc.
 * \param[in] xoptionStr - a msParam of type STR_MS_T which is an option (preferred, forced, random)
 *    with random as default. A "forced" input means the defaultResc will be used regardless
 *    of the user input. The forced action only apply to to users with normal privilege.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence rei->doinp->condInput,
 *                    rei->rsComm->proxyUser.authInfo.authFlag
 * \DolVarModified rei->rgi gets set to a group (possibly singleton) list of resources in the preferred order.
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
 **/
int
msiSetDefaultResc( msParam_t *xdefaultRescList, msParam_t *xoptionStr, ruleExecInfo_t *rei ) {
    char *defaultRescList;
    char *optionStr;
    std::string default_resc;

    defaultRescList = ( char * ) xdefaultRescList->inOutStruct;

    optionStr = ( char * ) xoptionStr->inOutStruct;

    RE_TEST_MACRO( "    Calling msiSetDefaultResc" )

    // JMC - legacy resource - rei->status = setDefaultResc (rei->rsComm, defaultRescList, optionStr, &rei->doinp->condInput, &myRescGrpInfo );

    irods::error err = irods::set_default_resource( rei->rsComm, defaultRescList, optionStr, &rei->doinp->condInput, default_resc );
    rei->status = err.code();

    if ( rei->status >= 0 ) {
    	snprintf(rei->rescName, NAME_LEN, "%s", default_resc.c_str());
    }
    else {
        irods::log( PASS( err ) );
        memset(&rei->rescName, 0, NAME_LEN);
    }
    return rei->status;
}

/**
 * \fn msiSetRescSortScheme (msParam_t *xsortScheme, ruleExecInfo_t *rei)
 *
 * \brief  This microservice sets the scheme for selecting the best resource to use when creating a data object.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author <NAME>
 * \date 2007
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xsortScheme - The sorting scheme. Valid schemes are "default", "random" and
 *    "byRescType". The "byRescType" scheme will put the cache class of resource on the top
{'fraction_non_alphanumeric': 0.11115754283326369, 'fraction_numerical': 0.0071040534893439195, 'mean_word_length': 3.4458204334365323, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, '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': '2258204', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2329, 'n_words': 735}