<commit_before>package org.talend.dataprep.api.service;

import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.validation.Valid;

import org.apache.commons.io.IOUtils;
import org.apache.http.client.HttpClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.talend.daikon.exception.ExceptionContext;
import org.talend.dataprep.api.service.api.DynamicParamsInput;
import org.talend.dataprep.api.service.command.dataset.DataSetGet;
import org.talend.dataprep.api.service.command.preparation.PreparationGetContent;
import org.talend.dataprep.api.service.command.transformation.*;
import org.talend.dataprep.exception.TDPException;
import org.talend.dataprep.exception.error.APIErrorCodes;
import org.talend.dataprep.exception.error.CommonErrorCodes;
import org.talend.dataprep.http.HttpResponseContext;
import org.talend.dataprep.metrics.Timed;

import com.netflix.hystrix.HystrixCommand;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
public class TransformAPI extends APIService {

    @RequestMapping(value = "/api/transform/{id}", method = RequestMethod.POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "Transforms a data set given data set id. This operation retrieves data set content and pass it to the transformation service.", notes = "Returns the data set modified with the provided actions in request body.")
    public void transform(@PathVariable(value = "id") @ApiParam(value = "Data set id.") String dataSetId,
            @ApiParam(value = "Actions to perform on data set (as JSON format).") InputStream body, final OutputStream output) {
        if (dataSetId == null) {
            throw new IllegalArgumentException("Data set id cannot be null.");
        }
        LOG.debug("Transforming dataset id #{} (pool: {})...", dataSetId, getConnectionStats());
        try {
            // Configure transformation flow
            HttpResponseContext.header( "Content-Type", APPLICATION_JSON_VALUE); //$NON-NLS-1$
            HttpClient client = getClient();

            InputStream contentRetrieval = getCommand(DataSetGet.class, client, dataSetId, true, null).execute();
            HystrixCommand<InputStream> transformation = getCommand(Transform.class, client, contentRetrieval,
                    IOUtils.toString(body));

            // Perform transformation
            InputStream input = transformation.execute();

            IOUtils.copyLarge(input, output);
            output.flush();
        } catch (IOException e) {
            LOG.error("error while applying transform " + e.getMessage(), e);
            throw new TDPException(APIErrorCodes.UNABLE_TO_TRANSFORM_DATASET, e, ExceptionContext.build().put("dataSetId",
                    dataSetId));
        }

        LOG.debug("Transformation of dataset id #{} done.", dataSetId);
    }

    /**
     * Get all the possible actions for a given column.
     *
     * Although not rest compliant, this is done via a post in order to pass all the column metadata in the request body
     * without risking breaking the url size limit if GET would be used.
     *
     * @param body the column description (json encoded) in the request body.
     */
    @RequestMapping(value = "/api/transform/actions/column", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "Get all actions for a data set column.", notes = "Returns all actions for the given column.")
    @Timed
    public void columnActions(@ApiParam(value = "Optional column Metadata content as JSON") InputStream body,
                                     final OutputStream output) {

        HttpClient client = getClient();

        // Asks transformation service for all actions for column type and domain
        HystrixCommand<InputStream> getSuggestedActions = getCommand(ColumnActions.class, client, body);
        // Returns actions
        try {
            // olamy: this is weird to have to configure that manually whereas there is an annotation for the method!!
            HttpResponseContext.header("Content-Type", APPLICATION_JSON_VALUE); //$NON-NLS-1$
            IOUtils.copyLarge(getSuggestedActions.execute(), output);
            output.flush();<commit_msg>TDP-993: remove unused method "transform"<commit_after>package org.talend.dataprep.api.service;

import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.validation.Valid;

import org.apache.commons.io.IOUtils;
import org.apache.http.client.HttpClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.talend.dataprep.api.service.api.DynamicParamsInput;
import org.talend.dataprep.api.service.command.dataset.DataSetGet;
import org.talend.dataprep.api.service.command.preparation.PreparationGetContent;
import org.talend.dataprep.api.service.command.transformation.ColumnActions;
import org.talend.dataprep.api.service.command.transformation.LineActions;
import org.talend.dataprep.api.service.command.transformation.SuggestActionParams;
import org.talend.dataprep.api.service.command.transformation.SuggestColumnActions;
import org.talend.dataprep.exception.TDPException;
import org.talend.dataprep.exception.error.APIErrorCodes;
import org.talend.dataprep.exception.error.CommonErrorCodes;
import org.talend.dataprep.http.HttpResponseContext;
import org.talend.dataprep.metrics.Timed;

import com.netflix.hystrix.HystrixCommand;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
public class TransformAPI extends APIService {


    /**
     * Get all the possible actions for a given column.
     *
     * Although not rest compliant, this is done via a post in order to pass all the column metadata in the request body
     * without risking breaking the url size limit if GET would be used.
     *
     * @param body the column description (json encoded) in the request body.
     */
    @RequestMapping(value = "/api/transform/actions/column", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "Get all actions for a data set column.", notes = "Returns all actions for the given column.")
    @Timed
    public void columnActions(@ApiParam(value = "Optional column Metadata content as JSON") InputStream body,
                                     final OutputStream output) {

        HttpClient client = getClient();

        // Asks transformation service for all actions for column type and domain
        HystrixCommand<InputStream> getSuggestedActions = getCommand(ColumnActions.class, client, body);
        // Returns actions
        try {
            // olamy: this is weird to have to configure that manually whereas there is an annotation for the method!!
            HttpResponseContext.header("Content-Type", APPLICATION_JSON_VALUE); //$NON-NLS-1$
            IOUtils.copyLarge(getSuggestedActions.execute(), output);
            output.flush();
{'fraction_non_alphanumeric': 0.09279796048438496, 'fraction_numerical': 0.0007648183556405354, 'mean_word_length': 3.84320987654321, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '378347', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2079, 'n_words': 548}