Search in sources :

Example 11 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class APIPreparationConversions method toEnrichedPreparation.

private EnrichedPreparation toEnrichedPreparation(PreparationMessage preparationMessage, EnrichedPreparation enrichedPreparation, ApplicationContext applicationContext) {
    final SecurityProxy securityProxy = applicationContext.getBean(SecurityProxy.class);
    // Add related dataset information
    if (preparationMessage.getDataSetId() == null) {
        return enrichedPreparation;
    } else {
        // get the dataset metadata
        try {
            // because dataset are not shared
            securityProxy.asTechnicalUser();
            final DataSetGetMetadata bean = applicationContext.getBean(DataSetGetMetadata.class, preparationMessage.getDataSetId());
            final DataSetMetadata dataSetMetadata = bean.execute();
            enrichedPreparation.setSummary(new EnrichedPreparation.DataSetMetadataSummary(dataSetMetadata));
        } catch (Exception e) {
            LOGGER.debug("error reading dataset metadata {} : {}", enrichedPreparation.getId(), e);
            return enrichedPreparation;
        } finally {
            securityProxy.releaseIdentity();
        }
    }
    // Add step ids
    LinkedList<String> collected = new LinkedList<>();
    preparationMessage.getSteps().stream().map(Step::getId).forEach(s -> {
        if (s != null && (collected.isEmpty() || !collected.getLast().equals(s))) {
            collected.add(s);
        }
    });
    enrichedPreparation.setSteps(collected);
    // Add folder information
    final LocatePreparation command = applicationContext.getBean(LocatePreparation.class, enrichedPreparation.getId());
    final Folder folder = command.execute();
    enrichedPreparation.setFolder(folder);
    return enrichedPreparation;
}
Also used : LocatePreparation(org.talend.dataprep.api.service.command.preparation.LocatePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) SecurityProxy(org.talend.dataprep.security.SecurityProxy) Folder(org.talend.dataprep.api.folder.Folder) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) LinkedList(java.util.LinkedList)

Example 12 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class APIPreparationConversionsTest method shouldNotEnrichPreparationWithDataset.

@Test
public void shouldNotEnrichPreparationWithDataset() {
    // given
    final PreparationMessage preparation = getPreparationMessage(null);
    // when
    final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
    // then
    assertNotNull(actual);
    assertNull(actual.getSummary());
    assertNull(actual.getFolder());
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) Test(org.junit.Test)

Example 13 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class APIPreparationConversionsTest method shouldDealWithRepeatedStepIds.

@Test
public void shouldDealWithRepeatedStepIds() {
    // given
    DataSetMetadata metadata = getDataSetMetadata("super dataset", 1001L);
    setupHystrixCommand(DataSetGetMetadata.class, metadata);
    final PreparationMessage preparation = getPreparationMessage(metadata.getId());
    preparation.setSteps(asList(Step.ROOT_STEP, Step.ROOT_STEP));
    Folder folder = getFolder("F-753854");
    setupHystrixCommand(LocatePreparation.class, folder);
    // when
    final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
    // then
    assertEquals(1, actual.getSteps().size());
    assertEquals(Step.ROOT_STEP.id(), actual.getSteps().get(0));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) Folder(org.talend.dataprep.api.folder.Folder) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Aggregations

EnrichedPreparation (org.talend.dataprep.api.service.api.EnrichedPreparation)13 Test (org.junit.Test)12 PreparationMessage (org.talend.dataprep.api.preparation.PreparationMessage)4 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 Folder (org.talend.dataprep.api.folder.Folder)3 Response (com.jayway.restassured.response.Response)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 AppendStep (org.talend.dataprep.api.preparation.AppendStep)1 LocatePreparation (org.talend.dataprep.api.service.command.preparation.LocatePreparation)1 DataSetGet (org.talend.dataprep.command.dataset.DataSetGet)1 DataSetGetMetadata (org.talend.dataprep.command.dataset.DataSetGetMetadata)1 TDPException (org.talend.dataprep.exception.TDPException)1 SecurityProxy (org.talend.dataprep.security.SecurityProxy)1