Search in sources :

Example 16 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class GenerateSequence method getParameters.

@Override
public List<Parameter> getParameters(Locale locale) {
    final List<Parameter> parameters = super.getParameters(locale);
    parameters.add(ActionsUtils.getColumnCreationParameter(locale, true));
    Parameter startParameter = parameter(locale).setName(START_VALUE).setType(INTEGER).setDefaultValue("1").build(this);
    parameters.add(startParameter);
    Parameter stepParameter = parameter(locale).setName(STEP_VALUE).setType(INTEGER).setDefaultValue("1").build(this);
    parameters.add(stepParameter);
    return parameters;
}
Also used : Parameter(org.talend.dataprep.parameters.Parameter)

Example 17 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class TestI18nKeysForActionsTest method allActionShouldHaveTranslations.

@Test
public void allActionShouldHaveTranslations() {
    for (ActionDefinition actionMetadata : allActions) {
        final String name = actionMetadata.getName();
        assertNotNull(name);
        assertNotEquals("", name);
        actionMetadata.getLabel(Locale.US);
        actionMetadata.getDescription(Locale.US);
        String toString = actionMetadata.getName() + "," + actionMetadata.getCategory(Locale.US) + "," + actionMetadata.getLabel(Locale.US) + "," + actionMetadata.getDescription(Locale.US);
        LOGGER.info(toString);
        for (Parameter param : actionMetadata.getParameters(Locale.US)) {
            assertParameter(param);
        }
    }
}
Also used : Parameter(org.talend.dataprep.parameters.Parameter) SelectParameter(org.talend.dataprep.parameters.SelectParameter) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Test(org.junit.Test) TransformationBaseTest(org.talend.dataprep.transformation.TransformationBaseTest)

Example 18 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class TestI18nKeysForActionsTest method assertItem.

private void assertItem(Item value) {
    LOGGER.trace("    - " + value);
    List<Parameter> parameters = value.getParameters();
    if (parameters != null) {
        for (Parameter inlineParam : parameters) {
            String name = inlineParam.getName();
            String label = inlineParam.getLabel();
            String desc = inlineParam.getDescription();
            LOGGER.trace("      - " + name + " | " + label + " | " + desc);
        }
    }
}
Also used : Parameter(org.talend.dataprep.parameters.Parameter) SelectParameter(org.talend.dataprep.parameters.SelectParameter)

Example 19 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class ExportAPITest method get_all_export_types.

@Test
public void get_all_export_types() throws Exception {
    // given
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // when
    String actualJsonString = RestAssured.when().get("/api/export/formats").asString();
    List<ExportFormatMessage> exportFormatMessageList = mapper.readValue(actualJsonString, new TypeReference<List<ExportFormatMessage>>() {
    });
    ExportFormatMessage exportFormatMessageCSV = exportFormatMessageList.get(0);
    ExportFormatMessage exportFormatMessageXLSX = exportFormatMessageList.get(1);
    // then
    assertEquals("text/csv", exportFormatMessageCSV.getMimeType());
    assertEquals("CSV", exportFormatMessageCSV.getId());
    assertEquals("Local CSV file", exportFormatMessageCSV.getName());
    assertEquals(true, exportFormatMessageCSV.isNeedParameters());
    assertEquals(false, exportFormatMessageCSV.isDefaultExport());
    assertEquals(true, exportFormatMessageCSV.isEnabled());
    assertEquals(true, exportFormatMessageCSV.isSupportSampling());
    assertEquals("", exportFormatMessageCSV.getDisableReason());
    assertEquals("Export to CSV", exportFormatMessageCSV.getTitle());
    List<Parameter> parametersCSV = exportFormatMessageCSV.getParameters();
    assertNotNull(parametersCSV);
    assertEquals(6, parametersCSV.size());
    // Andthen
    assertEquals("application/vnd.ms-excel", exportFormatMessageXLSX.getMimeType());
    assertEquals("XLSX", exportFormatMessageXLSX.getId());
    assertEquals("Local XLSX file", exportFormatMessageXLSX.getName());
    assertEquals(true, exportFormatMessageXLSX.isNeedParameters());
    assertEquals(true, exportFormatMessageXLSX.isDefaultExport());
    assertEquals(true, exportFormatMessageXLSX.isEnabled());
    assertEquals(true, exportFormatMessageXLSX.isSupportSampling());
    assertEquals("", exportFormatMessageXLSX.getDisableReason());
    assertEquals("Export to XLSX", exportFormatMessageXLSX.getTitle());
    List<Parameter> parametersXLS = exportFormatMessageXLSX.getParameters();
    assertNotNull(parametersXLS);
    assertEquals(1, parametersXLS.size());
}
Also used : ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) Parameter(org.talend.dataprep.parameters.Parameter) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 20 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class ActionsStaticProfiler method profile.

public ActionsProfile profile(final List<ColumnMetadata> columns, final List<RunnableAction> actions) {
    final Map<Action, ActionDefinition> metadataByAction = getActionMetadataByAction(actions);
    // Compile actions
    final Set<String> originalColumns = columns.stream().map(ColumnMetadata::getId).collect(toSet());
    final Set<String> valueModifiedColumns = new HashSet<>();
    final Set<String> metadataModifiedColumns = new HashSet<>();
    int createColumnActions = 0;
    // Analyze what columns to look at during analysis
    for (Map.Entry<Action, ActionDefinition> entry : metadataByAction.entrySet()) {
        final ActionDefinition actionMetadata = entry.getValue();
        final Action action = entry.getKey();
        Set<ActionDefinition.Behavior> behavior = actionMetadata.getBehavior();
        boolean createColumn = false;
        for (ActionDefinition.Behavior currentBehavior : behavior) {
            switch(currentBehavior) {
                case VALUES_ALL:
                    // All values are going to be changed, and all original columns are going to be modified.
                    valueModifiedColumns.addAll(originalColumns);
                    break;
                case METADATA_CHANGE_TYPE:
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    metadataModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    break;
                case VALUES_COLUMN:
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    break;
                case VALUES_MULTIPLE_COLUMNS:
                    // Add the action's source column
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    // ... then add all column parameter (COLUMN_ID is string, not column)
                    final List<Parameter> parameters = actionMetadata.getParameters(Locale.US);
                    valueModifiedColumns.addAll(// 
                    parameters.stream().filter(// 
                    parameter -> ParameterType.valueOf(parameter.getType().toUpperCase()) == ParameterType.COLUMN).map(// 
                    parameter -> action.getParameters().get(parameter.getName())).collect(Collectors.toList()));
                    break;
                case METADATA_COPY_COLUMNS:
                case METADATA_CREATE_COLUMNS:
                    createColumn = true;
                    break;
                case METADATA_DELETE_COLUMNS:
                case METADATA_CHANGE_NAME:
                    // Do nothing: no need to re-analyze where only name was changed.
                    break;
                default:
                    break;
            }
        }
        if (createColumn || isCreateColumnParameterOn(action)) {
            createColumnActions++;
        }
    }
    // when values are modified, we need to do a full analysis (schema + invalid + stats)
    boolean needFullAnalysis = !valueModifiedColumns.isEmpty() || createColumnActions > 0;
    // when only metadata is modified, we need to re-evaluate the invalids entries
    boolean needOnlyInvalidAnalysis = !needFullAnalysis && !metadataModifiedColumns.isEmpty();
    // only the columns with modified values or new columns need the schema + stats analysis
    SerializablePredicate<ColumnMetadata> filterForFullAnalysis = new FilterForFullAnalysis(originalColumns, valueModifiedColumns);
    // only the columns with metadata change or value changes need to re-evaluate invalids
    Predicate<ColumnMetadata> filterForInvalidAnalysis = new FilterForInvalidAnalysis(filterForFullAnalysis, metadataModifiedColumns);
    return new ActionsProfile(needFullAnalysis, needOnlyInvalidAnalysis, filterForFullAnalysis, filterForInvalidAnalysis, filterForInvalidAnalysis, metadataByAction);
}
Also used : ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) java.util(java.util) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) Parameter(org.talend.dataprep.parameters.Parameter) Predicate(java.util.function.Predicate) ParameterType(org.talend.dataprep.parameters.ParameterType) Collectors(java.util.stream.Collectors) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) COLUMN_ID(org.talend.dataprep.transformation.actions.common.ImplicitParameters.COLUMN_ID) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Action(org.talend.dataprep.api.preparation.Action) Collectors.toSet(java.util.stream.Collectors.toSet) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) Action(org.talend.dataprep.api.preparation.Action) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Parameter(org.talend.dataprep.parameters.Parameter)

Aggregations

Parameter (org.talend.dataprep.parameters.Parameter)25 Test (org.junit.Test)10 SelectParameter (org.talend.dataprep.parameters.SelectParameter)7 SelectParameter.selectParameter (org.talend.dataprep.parameters.SelectParameter.selectParameter)7 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)5 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)2 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)2 ExportFormatMessage (org.talend.dataprep.format.export.ExportFormatMessage)2 SelectParameterBuilder (org.talend.dataprep.parameters.SelectParameter.SelectParameterBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StringWriter (java.io.StringWriter)1 java.util (java.util)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 Action (org.talend.dataprep.api.preparation.Action)1 ParameterType (org.talend.dataprep.parameters.ParameterType)1