Search in sources :

Example 1 with UserPreparation

use of org.talend.dataprep.preparation.service.UserPreparation in project data-prep by Talend.

the class PreparationAPITest method testPreparationsList.

@Test
public void testPreparationsList() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
    // when : short format
    final JsonPath shortFormat = when().get("/api/preparations/?format=short").jsonPath();
    // then
    final List<String> values = shortFormat.getList("");
    assertThat(values.get(0), is(preparationId));
    // when : long format
    Response response1 = when().get("/api/preparations/?format=long");
    // then
    List<UserPreparation> preparations = mapper.readerFor(UserPreparation.class).<UserPreparation>readValues(response1.asInputStream()).readAll();
    assertEquals(1, preparations.size());
    UserPreparation userPreparation = preparations.iterator().next();
    assertThat(userPreparation.getDataSetId(), is(tagadaId));
    assertThat(userPreparation.getAuthor(), is(security.getUserId()));
    assertThat(userPreparation.getId(), is(preparationId));
    assertThat(userPreparation.getActions(), is(empty()));
    // when : summary format
    Response response = when().get("/api/preparations/?format=summary");
    // then
    List<PreparationSummary> preparationSummaries = mapper.readerFor(PreparationSummary.class).<PreparationSummary>readValues(response.asInputStream()).readAll();
    assertEquals(1, preparationSummaries.size());
    PreparationSummary preparationSummary = preparationSummaries.iterator().next();
    assertThat(preparationSummary.getId(), is(preparationId));
    assertThat(preparationSummary.getName(), is("testPreparation"));
    assertThat(preparationSummary.getLastModificationDate(), is(notNullValue()));
    assertThat(preparationSummary.isAllowDistributedRun(), is(notNullValue()));
}
Also used : Response(com.jayway.restassured.response.Response) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) PreparationSummary(org.talend.dataprep.api.preparation.PreparationSummary) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 2 with UserPreparation

use of org.talend.dataprep.preparation.service.UserPreparation in project data-prep by Talend.

the class SortAndOrderHelper method getPreparationComparator.

public static Comparator<Preparation> getPreparationComparator(Sort sortKey, Order orderKey, Function<? super Preparation, ? extends DataSetMetadata> dataSetFinder) {
    Comparator<Comparable> comparisonOrder = getOrderComparator(orderKey);
    // Select comparator for sort (either by name or date)
    Function<Preparation, Comparable> keyExtractor;
    if (sortKey == null) {
        // default to NAME sort
        keyExtractor = preparation -> preparation.getName().toUpperCase();
    } else {
        switch(sortKey) {
            // In case of API call error, default to NAME sort
            case NB_RECORDS:
            case NAME:
                keyExtractor = preparation -> Optional.ofNullable(preparation).map(p -> p.getName().toUpperCase()).orElse(StringUtils.EMPTY);
                break;
            case AUTHOR:
                keyExtractor = preparation -> {
                    // in order to just call a method to retrieve the author name
                    if (preparation instanceof UserPreparation) {
                        Owner owner = ((UserPreparation) preparation).getOwner();
                        return (owner != null) ? StringUtils.upperCase(owner.getDisplayName()) : StringUtils.EMPTY;
                    }
                    return preparation.getAuthor();
                };
                break;
            case CREATION_DATE:
            case DATE:
                keyExtractor = Preparation::getCreationDate;
                break;
            case LAST_MODIFICATION_DATE:
                keyExtractor = Preparation::getLastModificationDate;
                break;
            case NB_STEPS:
                keyExtractor = preparation -> preparation.getSteps().size();
                break;
            case DATASET_NAME:
                if (dataSetFinder != null) {
                    keyExtractor = p -> getUpperCaseNameFromNullable(dataSetFinder.apply(p));
                } else {
                    LOGGER.debug("There is no dataset finding function to sort preparations on dataset name. Default to natural name order.");
                    // default to sort on name
                    keyExtractor = preparation -> preparation.getName().toUpperCase();
                }
                break;
            default:
                // this should not be possible
                throw new TDPException(ILLEGAL_SORT_FOR_LIST, build().put("sort", sortKey));
        }
    }
    return Comparator.comparing(keyExtractor, comparisonOrder);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Owner(org.talend.dataprep.api.share.Owner) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation)

Example 3 with UserPreparation

use of org.talend.dataprep.preparation.service.UserPreparation in project data-prep by Talend.

the class SortAndOrderHelperTest method createUserPreparation.

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

Aggregations

UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)3 Owner (org.talend.dataprep.api.share.Owner)2 JsonPath (com.jayway.restassured.path.json.JsonPath)1 Response (com.jayway.restassured.response.Response)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Preparation (org.talend.dataprep.api.preparation.Preparation)1 PreparationSummary (org.talend.dataprep.api.preparation.PreparationSummary)1 Step (org.talend.dataprep.api.preparation.Step)1 TDPException (org.talend.dataprep.exception.TDPException)1