Search in sources :

Example 1 with UserData

use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.

the class DataSetAPITest method should_list_filtered_datasets_properly.

@Test
public void should_list_filtered_datasets_properly() throws Exception {
    // create data sets
    final String dataSetId1 = testClient.createDataset("dataset/dataset.csv", "dataset1");
    final String dataSetId2 = testClient.createDataset("dataset/dataset.csv", "dataset2");
    final String dataSetId3 = testClient.createDataset("dataset/dataset.csv", "dataset3");
    testClient.createDataset("dataset/dataset.csv", "dataset4");
    // Make dataset1 more recent
    final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
    dataSetMetadata1.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
    dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
    dataSetMetadataRepository.save(dataSetMetadata1);
    final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
    dataSetMetadataRepository.save(dataSetMetadata2);
    final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
    dataSetMetadata3.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
    dataSetMetadataRepository.save(dataSetMetadata3);
    // add favorite
    UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
    HashSet<String> favorites = new HashSet<>();
    favorites.add(dataSetMetadata1.getId());
    favorites.add(dataSetMetadata2.getId());
    userData.setFavoritesDatasets(favorites);
    userDataRepository.save(userData);
    // @formatter:off
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "dataset").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset1")).body("name", hasSize(1));
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "2").when().get("/api/datasets").then().statusCode(200).body("name", hasSize(0));
    // only names
    given().queryParam("name", "ATASET2").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset2")).body("name", hasSize(1));
    // only favorites
    given().queryParam("favorite", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2")).body("name", hasSize(2));
    // only certified
    given().queryParam("certified", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3")).body("name", hasSize(2));
    // only recent
    given().queryParam("limit", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset2", "dataset3", "dataset4")).body("name", hasSize(3));
    // all
    when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4")).body("name", hasSize(4));
// @formatter:on
}
Also used : UserData(org.talend.dataprep.api.user.UserData) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with UserData

use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.

the class DataSetServiceTest method testGetFavoritesDatasetList.

@Test
public void testGetFavoritesDatasetList() {
    when().get("/datasets/favorites").then().statusCode(OK.value()).body(equalTo("[]"));
    String dsId1 = UUID.randomUUID().toString();
    String dsId2 = UUID.randomUUID().toString();
    UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
    HashSet<String> favorites = new HashSet<>();
    favorites.add(dsId1);
    favorites.add(dsId2);
    userData.setFavoritesDatasets(favorites);
    userDataRepository.save(userData);
    List<String> favoritesResp = from(when().get("/datasets/favorites").asString()).get();
    assertEquals(2, favoritesResp.size());
    assertThat(favoritesResp, hasItems(dsId1, dsId2));
}
Also used : UserData(org.talend.dataprep.api.user.UserData) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) HashSet(java.util.HashSet) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 3 with UserData

use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.

the class DataSetServiceTest method should_list_filtered_datasets_properly.

@Test
public void should_list_filtered_datasets_properly() throws Exception {
    // create data sets
    final String dataSetId1 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada3.csv"), "dataset1");
    final String dataSetId2 = createCSVDataSet(this.getClass().getResourceAsStream("../avengers.csv"), "dataset2");
    final String dataSetId3 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada.csv"), "dataset3");
    createCSVDataSet(this.getClass().getResourceAsStream("../tagada2.csv"), "dataset4");
    // Make dataset1 more recent
    final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
    dataSetMetadata1.getGovernance().setCertificationStep(Certification.CERTIFIED);
    dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
    dataSetMetadataRepository.save(dataSetMetadata1);
    final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
    dataSetMetadataRepository.save(dataSetMetadata2);
    final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
    dataSetMetadata3.getGovernance().setCertificationStep(Certification.CERTIFIED);
    dataSetMetadataRepository.save(dataSetMetadata3);
    UserData userData = new UserData();
    userData.setUserId(security.getUserId());
    userData.addFavoriteDataset(dataSetMetadata1.getId());
    userData.addFavoriteDataset(dataSetMetadata2.getId());
    userDataRepository.save(userData);
    // @formatter:off
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").when().get("/datasets").then().statusCode(200).body("name", hasItem("dataset1")).body("name", hasSize(1));
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "2").when().get("/datasets").then().statusCode(200).body("name", hasSize(0));
    // only names
    given().queryParam("name", "ATAset2").when().get("/datasets").then().statusCode(200).body("name", hasItem("dataset2")).body("name", hasSize(1));
    // only favorites
    given().queryParam("favorite", "true").when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2")).body("name", hasSize(2));
    // only certified
    given().queryParam("certified", "true").when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3")).body("name", hasSize(2));
    // only recent
    given().queryParam("limit", "true").queryParam("sort", LAST_MODIFICATION_DATE.camelName()).when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3", "dataset4")).body("name", hasSize(3));
    // all
    when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4")).body("name", hasSize(4));
// @formatter:on
}
Also used : UserData(org.talend.dataprep.api.user.UserData) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 4 with UserData

use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.

the class FileSystemUserDataRepositoryTest method getRandomUserData.

@Override
protected UserData getRandomUserData() {
    UserData userData = new UserData();
    userData.setUserId(UUID.randomUUID().toString());
    userData.setAppVersion("12.3");
    return userData;
}
Also used : UserData(org.talend.dataprep.api.user.UserData)

Example 5 with UserData

use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.

the class FileSystemUserDataRepositoryTest method shouldIgnoreHiddenFiles.

@Test
public void shouldIgnoreHiddenFiles() throws Exception {
    // given
    repository.clear();
    // when
    File hidden = new File("target/test/store/userdata/.hidden_file");
    FileOutputStream fos = new FileOutputStream(hidden);
    fos.write("hello".getBytes());
    // then
    final UserData userData = repository.get(".hidden");
    hidden.delete();
    assertNull(userData);
}
Also used : UserData(org.talend.dataprep.api.user.UserData) FileOutputStream(java.io.FileOutputStream) File(java.io.File) AbstractUserDataRepositoryTest(org.talend.dataprep.user.store.AbstractUserDataRepositoryTest) Test(org.junit.Test)

Aggregations

UserData (org.talend.dataprep.api.user.UserData)12 Test (org.junit.Test)7 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)7 HashSet (java.util.HashSet)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)5 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Timed (org.talend.dataprep.metrics.Timed)3 CSVFormatFamily (org.talend.dataprep.schema.csv.CSVFormatFamily)3 InputStream (java.io.InputStream)2 UserDataSetMetadata (org.talend.dataprep.dataset.service.UserDataSetMetadata)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Owner (org.talend.dataprep.api.share.Owner)1 DataSetMetadataBuilder (org.talend.dataprep.dataset.DataSetMetadataBuilder)1 TDPException (org.talend.dataprep.exception.TDPException)1