Search in sources :

Example 31 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PreparationConversions method toPreparationDetailsDTO.

private PreparationDetailsDTO toPreparationDetailsDTO(PreparationDTO source, PreparationDetailsDTO target, ApplicationContext applicationContext) {
    final PreparationRepository preparationRepository = applicationContext.getBean(PreparationRepository.class);
    List<String> idsStep = source.getSteps();
    final List<StepDiff> diffs = preparationRepository.list(PersistentStep.class, in("id", idsStep.toArray(new String[] {}))).filter(// 
    step -> !Step.ROOT_STEP.id().equals(step.getId())).sorted((step1, step2) -> {
        // we need to keep the order from the original list (source.getSteps())
        int idPosStep1 = idsStep.indexOf(step1.getId());
        int idPosStep2 = idsStep.indexOf(step2.getId());
        return idPosStep1 - idPosStep2;
    }).map(// 
    PersistentStep::getDiff).collect(toList());
    target.setDiff(diffs);
    // TDP-5888: It is important for Spark runs to have a row metadata to describe initial data schema.
    // and also to display column names in filter labels of steps
    final PersistentPreparation preparation = preparationRepository.get(source.getId(), PersistentPreparation.class);
    target.setRowMetadata(preparation.getRowMetadata());
    injectColumnNamesIntoActions(source.getHeadId(), target, applicationContext.getBean(PreparationService.class));
    return target;
}
Also used : ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) CREATE_NEW_COLUMN(org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN) BeanConversionService.fromBean(org.talend.dataprep.conversions.BeanConversionService.fromBean) LoggerFactory(org.slf4j.LoggerFactory) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PreparationSummary(org.talend.dataprep.api.preparation.PreparationSummary) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) StringUtils(org.apache.commons.lang3.StringUtils) StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) ArrayList(java.util.ArrayList) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) FilterTranslator(org.talend.dataprep.api.filter.FilterTranslator) Map(java.util.Map) TQLFilterService(org.talend.dataprep.api.filter.TQLFilterService) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) StepDiff(org.talend.dataprep.api.preparation.StepDiff) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) ActionForm(org.talend.dataprep.api.action.ActionForm) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) TqlBuilder.in(org.talend.tql.api.TqlBuilder.in) PreparationService(org.talend.dataprep.preparation.service.PreparationService) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) Collections(java.util.Collections) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) BeanConversionServiceWrapper(org.talend.dataprep.processor.BeanConversionServiceWrapper) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) StepDiff(org.talend.dataprep.api.preparation.StepDiff) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) PreparationService(org.talend.dataprep.preparation.service.PreparationService)

Example 32 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class SortAndOrderHelperTest method getPreparationComparison.

private // 
int getPreparationComparison(// 
String firstName, // 
String secondName, // 
String firstAuthor, // 
String secondAuthor, // 
long firstCreation, // 
long secondCreation, // 
long firstModification, // 
long secondModification, // 
long firstSize, // 
long secondSize, // 
String firstDsName, // 
String secondDsName, Sort sort, Order order) {
    PreparationDTO firstUserPrep = createUserPreparation(firstName, firstAuthor, firstCreation, firstModification, firstSize, firstDsName);
    PreparationDTO secondUserPrep = createUserPreparation(secondName, secondAuthor, secondCreation, secondModification, secondSize, secondDsName);
    PreparationDTO firstPrep = createUserPreparation(firstName, firstAuthor, firstCreation, firstModification, firstSize, firstDsName);
    PreparationDTO secondPrep = createUserPreparation(secondName, secondAuthor, secondCreation, secondModification, secondSize, secondDsName);
    // when
    Comparator<PreparationDTO> preparationComparator = SortAndOrderHelper.getPreparationComparator(sort, order);
    // then
    assertNotNull(preparationComparator);
    final int userPreparationOrder = preparationComparator.compare(firstUserPrep, secondUserPrep);
    final int preparationOrder = preparationComparator.compare(firstPrep, secondPrep);
    assertEquals(userPreparationOrder, preparationOrder);
    return userPreparationOrder;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO)

Example 33 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class SortAndOrderHelperTest method createUserPreparation.

private PreparationDTO createUserPreparation(String name, String author, long creation, long modification, long size, String dataSetName) {
    PreparationDTO firstPrep = new PreparationDTO();
    firstPrep.setDataSetName(dataSetName);
    firstPrep.setName(name);
    firstPrep.setAuthor("1234");
    firstPrep.setOwner(new Owner("1234", author, ""));
    firstPrep.setCreationDate(creation);
    firstPrep.setLastModificationDate(modification);
    List<String> steps = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        steps.add(null);
    }
    firstPrep.setSteps(steps);
    return firstPrep;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Owner(org.talend.dataprep.api.share.Owner) ArrayList(java.util.ArrayList)

Example 34 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PersistentPreparationTest method should_merge_from_source.

@Test
public void should_merge_from_source() {
    PreparationDTO theOtherOne = new PreparationDTO();
    theOtherOne.setId("#23874");
    PersistentPreparation source = new PersistentPreparation();
    source.setId("#158387");
    source.setAuthor("Bloc Party");
    source.setCreationDate(theOtherOne.getCreationDate() - 1000);
    source.setDataSetId("ds#65478");
    source.setDataSetName("My Dataset Name");
    source.setLastModificationDate(source.getCreationDate() + 2658483);
    source.setName("banquet");
    source.setHeadId(Step.ROOT_STEP.id());
    PersistentPreparation actual = source.merge(theOtherOne);
    assertEquals("#23874", actual.getId());
    assertEquals("Bloc Party", actual.getAuthor());
    assertEquals("ds#65478", actual.getDataSetId());
    assertEquals("My Dataset Name", actual.getDataSetName());
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Test(org.junit.Test)

Example 35 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PersistentPreparationTest method should_merge_from_other.

@Test
public void should_merge_from_other() {
    PersistentPreparation source = new PersistentPreparation();
    source.setId("#4837");
    PreparationDTO theOtherOne = new PreparationDTO();
    theOtherOne.setAuthor("Joss Stone");
    theOtherOne.setCreationDate(source.getCreationDate() - 1000);
    theOtherOne.setDataSetId("ds#123456");
    theOtherOne.setDataSetName("My Dataset Name");
    theOtherOne.setLastModificationDate(theOtherOne.getCreationDate() + 12345682);
    theOtherOne.setName("my preparation name");
    theOtherOne.setHeadId(Step.ROOT_STEP.id());
    PersistentPreparation actual = source.merge(theOtherOne);
    assertEquals("Joss Stone", actual.getAuthor());
    assertEquals(source.getCreationDate() - 1000, actual.getCreationDate());
    assertEquals("ds#123456", actual.getDataSetId());
    assertEquals("My Dataset Name", actual.getDataSetName());
    assertEquals(theOtherOne.getCreationDate() + 12345682, actual.getLastModificationDate());
    assertEquals("my preparation name", actual.getName());
    assertEquals(Step.ROOT_STEP.id(), actual.getHeadId());
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Test(org.junit.Test)

Aggregations

PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)45 Test (org.junit.Test)22 ExportParameters (org.talend.dataprep.api.export.ExportParameters)9 ApiOperation (io.swagger.annotations.ApiOperation)7 InputStream (java.io.InputStream)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArrayList (java.util.ArrayList)6 Action (org.talend.dataprep.api.preparation.Action)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)5 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDetailsDTO (org.talend.dataprep.api.preparation.PreparationDetailsDTO)5 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)5 TDPException (org.talend.dataprep.exception.TDPException)5 OutputStream (java.io.OutputStream)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4