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()));
}
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);
}
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;
}
Aggregations