<commit_before>/*  ============================================================================

  Copyright (C) 2006-2016 Talend Inc. - www.talend.com

  This source code is available under agreement available at
  https://github.com/Talend/data-prep/blob/master/LICENSE

  You should have received a copy of the agreement
  along with this program; if not, write to Talend SA
  9 rue Pages 92150 Suresnes, France

  ============================================================================*/

/**
 * @ngdoc service
 * @name data-prep.services.preparation.service:PreparationRestService
 * @description Preparation service. This service provides the entry point to preparation REST api. It holds the loaded preparation.<br/>
 * <b style="color: red;">WARNING : do NOT use this service directly.
 * {@link data-prep.services.preparation.service:PreparationService PreparationService} must be the only entry point for preparations</b>
 */
export default function PreparationRestService($http, RestURLs) {
    'ngInject';

    return {
        // lifecycle
        create,
        copy,
        move,
        update,
        delete: deletePreparation,

        // step
        appendStep,
        updateStep,
        removeStep,
        setHead,
        copySteps,

        // getter : list, content, details
        getContent,
        getDetails,

        // preview
        getPreviewDiff,
        getPreviewUpdate,
        getPreviewAdd,
    };

    //---------------------------------------------------------------------------------
    // ----------------------------------------GETTERS----------------------------------
    //---------------------------------------------------------------------------------
    /**
     * @ngdoc method
     * @name getContent
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id to load
     * @param {string} stepId The step id to load
     * @description Get preparation records at the specific step
     * @returns {promise} The GET promise
     */
    function getContent(preparationId, stepId) {
        const url = `${RestURLs.preparationUrl}/${preparationId}/content?version=${stepId}`;
        return $http.get(url).then((res) => res.data);
    }

    /**
     * @ngdoc method
     * @name getDetails
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id to load
     * @description Get current preparation details
     * @returns {promise} The GET promise
     */
    function getDetails(preparationId) {
        return $http.get(`${RestURLs.preparationUrl}/${preparationId}/details`).then((response) => response.data);
    }

    //---------------------------------------------------------------------------------
    // ---------------------------------------LIFECYCLE---------------------------------
    //---------------------------------------------------------------------------------
    /**
     * @ngdoc method
     * @name create
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} datasetId The dataset id
     * @param {string} name The preparation name
     * @param {string} folderId The destination folder id
     * @description Create a new preparation
     * @returns {promise} The POST promise
     */
    function create(datasetId, name, folderId = '') {
        const request = {
            method: 'POST',
            url: `${RestURLs.preparationUrl}?folder=${folderId}`,
            data: {
                name,
                dataSetId: datasetId,
            },
        };

        return $http(request);
    }

    /**
     * @ngdoc method
     * @name copy
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id
     * @param {string} folderId The destination folder id
     * @param {string} name The preparation name
     * @description Copy the preparation
     * @returns {promise} The POST promise
     */<commit_msg>TDP-2330: fix bug - can not create preparation<commit_after>/*  ============================================================================

  Copyright (C) 2006-2016 Talend Inc. - www.talend.com

  This source code is available under agreement available at
  https://github.com/Talend/data-prep/blob/master/LICENSE

  You should have received a copy of the agreement
  along with this program; if not, write to Talend SA
  9 rue Pages 92150 Suresnes, France

  ============================================================================*/

/**
 * @ngdoc service
 * @name data-prep.services.preparation.service:PreparationRestService
 * @description Preparation service. This service provides the entry point to preparation REST api. It holds the loaded preparation.<br/>
 * <b style="color: red;">WARNING : do NOT use this service directly.
 * {@link data-prep.services.preparation.service:PreparationService PreparationService} must be the only entry point for preparations</b>
 */
export default function PreparationRestService($http, RestURLs) {
    'ngInject';

    return {
        // lifecycle
        create,
        copy,
        move,
        update,
        delete: deletePreparation,

        // step
        appendStep,
        updateStep,
        removeStep,
        setHead,
        copySteps,

        // getter : list, content, details
        getContent,
        getDetails,

        // preview
        getPreviewDiff,
        getPreviewUpdate,
        getPreviewAdd,
    };

    //---------------------------------------------------------------------------------
    // ----------------------------------------GETTERS----------------------------------
    //---------------------------------------------------------------------------------
    /**
     * @ngdoc method
     * @name getContent
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id to load
     * @param {string} stepId The step id to load
     * @description Get preparation records at the specific step
     * @returns {promise} The GET promise
     */
    function getContent(preparationId, stepId) {
        const url = `${RestURLs.preparationUrl}/${preparationId}/content?version=${stepId}`;
        return $http.get(url).then((res) => res.data);
    }

    /**
     * @ngdoc method
     * @name getDetails
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id to load
     * @description Get current preparation details
     * @returns {promise} The GET promise
     */
    function getDetails(preparationId) {
        return $http.get(`${RestURLs.preparationUrl}/${preparationId}/details`).then((response) => response.data);
    }

    //---------------------------------------------------------------------------------
    // ---------------------------------------LIFECYCLE---------------------------------
    //---------------------------------------------------------------------------------
    /**
     * @ngdoc method
     * @name create
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} datasetId The dataset id
     * @param {string} name The preparation name
     * @param {string} folderId The destination folder id
     * @description Create a new preparation
     * @returns {promise} The POST promise
     */
    function create(datasetId, name, folderId = '') {
        const request = {
            method: 'POST',
            url: `${RestURLs.preparationUrl}?folder=${folderId}`,
            data: {
                name,
                dataSetId: datasetId,
            },
        };

        return $http(request).then((resp) => resp.data);
    }

    /**
     * @ngdoc method
     * @name copy
     * @methodOf data-prep.services.preparation.service:PreparationRestService
     * @param {string} preparationId The preparation id
     * @param {string} folderId The destination folder id
     * @param {string} name The preparation name
     * @description Copy the preparation
     * @returns {promise} The POST promise
     */
{'fraction_non_alphanumeric': 0.23688355749424453, 'fraction_numerical': 0.00387737792317945, 'mean_word_length': 1.801765105227427, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2500058', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1911, 'n_words': 555}