<commit_before>'use strict';

const utils = require('../utils.js');
const services = require('../services.js');
const dataConnect = services.dataConnect;
const metadataConnect = services.metadataConnect;
const async = require('async');

/**
 * PUT Object in the requested bucket. Steps include:
 * validating metadata for authorization, bucket and object existence etc.
 * store object data in datastore upon successful authorization
 * store object location returned by datastore and object's (custom) headers in metadata
 * return the result in final callback
 *
 * @param  {string}   accessKey - user access key
 * @param  {datastore}   datastore - data storage endpoint
 * @param  {metastore}   metastore - metadata storage endpoint
 * @param  {request}   request   - request object given by router, includes normalized headers
 * @param  {Function} callback  - final callback to call with the result
 */
let objectPut = function (accessKey, datastore, metastore, request, callback) {
    let bucketname = utils.getResourceNames(request).bucket;
    let objectKey = utils.getResourceNames(request).object;
    let contentMD5 = request.calculatedMD5;
    let metaHeaders = utils.getMetaHeaders(request.lowerCaseHeaders);
    let objectUID = utils.getResourceUID(request.namespace, bucketname + objectKey);
    let bucketUID = utils.getResourceUID(request.namespace, bucketname);
    let metadataValParams = {accessKey: accessKey, bucketUID: bucketUID, objectKey: objectKey, metastore: metastore};
    let dataStoreParams = {contentMD5: contentMD5, headers: request.lowerCaseHeaders, value: request.post, objectUID: objectUID};
    let metadataStoreParams = {objectKey: objectKey, accessKey: accessKey, objectUID: objectUID, metaHeaders: metaHeaders, headers: request.lowerCaseHeaders, contentMD5: contentMD5};

    async.waterfall([
            function (next) {
                services.metadataValidateAuthorization(metadataValParams, next);
            },
            function (bucket, objectMetadata, next) {
                services.dataStore(bucket, objectMetadata, datastore, dataStoreParams, next);
            },
            function (bucket, objectMetadata, newLocation, next) {
                services.metadataStoreObject(bucket, objectMetadata, newLocation, metastore, metadataStoreParams, next);
            }
    ], function (err, result) {
        return callback(err, result);
    });

};


module.exports = objectPut;<commit_msg>CLEANUP: Refactor objectPut.js per style guide<commit_after>import utils from '../utils.js';
import services from '../services.js';
import async from 'async';

/**
 * PUT Object in the requested bucket. Steps include:
 * validating metadata for authorization, bucket and object existence etc.
 * store object data in datastore upon successful authorization
 * store object location returned by datastore and
 *object's (custom) headers in metadata
 * return the result in final callback
 *
 * @param  {string}   accessKey - user access key
 * @param  {datastore}   datastore - data storage endpoint
 * @param  {metastore}   metastore - metadata storage endpoint
 * @param  {request}   request   - request object given by router,
 * includes normalized headers
 * @param  {Function} callback  - final callback to call with the result
 * @return {Function} calls callback from router
 * with err and result as arguments
 */
export default
function objectPut(accessKey, datastore, metastore, request, callback) {
    const bucketname = utils.getResourceNames(request).bucket;
    const objectKey = utils.getResourceNames(request).object;
    const contentMD5 = request.calculatedMD5;
    const metaHeaders = utils.getMetaHeaders(request.lowerCaseHeaders);
    const objectUID =
    utils.getResourceUID(request.namespace, bucketname + objectKey);
    const bucketUID = utils.getResourceUID(request.namespace, bucketname);
    const metadataValParams = {
        accessKey: accessKey,
        bucketUID: bucketUID,
        objectKey: objectKey,
        metastore: metastore
    };
    const dataStoreParams = {
        contentMD5: contentMD5,
        headers: request.lowerCaseHeaders,
        value: request.post,
        objectUID: objectUID
    };
    const metadataStoreParams = {
        objectKey: objectKey,
        accessKey: accessKey,
        objectUID: objectUID,
        metaHeaders: metaHeaders,
        headers: request.lowerCaseHeaders,
        contentMD5: contentMD5};

    async.waterfall([
        function waterfall1(next) {
            services.metadataValidateAuthorization(metadataValParams, next);
        },
        function waterfall2(bucket, objectMetadata, next) {
            services.dataStore(bucket, objectMetadata,
            datastore, dataStoreParams, next);
        },
        function waterfall3(bucket, objectMetadata, newLocation, next) {
            services.metadataStoreObject(bucket, objectMetadata,
            newLocation, metastore, metadataStoreParams, next);
        }
    ], function watefallFinal(err, result) {
        return callback(err, result);
    });
}
{'fraction_non_alphanumeric': 0.08743818001978239, 'fraction_numerical': 0.002967359050445104, 'mean_word_length': 3.604735883424408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4512649', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1288, 'n_words': 399}