Search in sources :

Example 46 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class DefaultsTest method shouldReadJsonResponse_ioException.

@Test
public void shouldReadJsonResponse_ioException() throws Exception {
    // Given
    final ObjectMapper mapper = new ObjectMapper();
    final BasicHttpResponse httpResponse = buildResponse();
    httpResponse.setEntity(new StringEntity("") {

        @Override
        public InputStream getContent() throws IOException {
            throw new IOException();
        }
    });
    // When
    try {
        Defaults.convertResponse(mapper, Response.class).apply(buildRequest(), httpResponse);
    } catch (TDPException e) {
        // Then
        assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION, e.getCode());
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) TDPException(org.talend.dataprep.exception.TDPException) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 47 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class AbstractFolderTest method create_child_with_two_entries_then_remove_expect_exception.

/**
 * This test create one child under root assert size, child list then create three folder entries then delete
 * expect exception
 */
@Test
public void create_child_with_two_entries_then_remove_expect_exception() throws Exception {
    long sizeBefore = getFolderRepository().size();
    Folder foo = getFolderRepository().addFolder(homeFolderId, "foo");
    Folder foobeer = getFolderRepository().addFolder(foo.getId(), "/beer");
    long sizeAfter = getFolderRepository().size();
    assertThat(sizeAfter).isEqualTo(sizeBefore + 2);
    assertChildrenSize(homeFolderId, 1);
    FolderEntry beerEntry = new FolderEntry(DATASET, "littlecreatures");
    FolderEntry wineEntry = new FolderEntry(DATASET, "bordeaux");
    getFolderRepository().addFolderEntry(beerEntry, foo.getId());
    getFolderRepository().addFolderEntry(wineEntry, foo.getId());
    wineEntry = new FolderEntry(DATASET, "bordeaux");
    getFolderRepository().addFolderEntry(wineEntry, foobeer.getId());
    assertThatFolderContainsExpectedNumberOfDatasets(foo.getId(), 2);
    assertThatExpectedNumberOfNamedDatasetIsFound("bordeaux", 2);
    assertThatExpectedNumberOfNamedDatasetIsFound("littlecreatures", 1);
    assertThatFolderContainsExpectedNumberOfDatasets(foo.getId(), 2);
    try {
        getFolderRepository().removeFolder(foo.getId());
        fail("Should throw exception because folder is not empty.");
    } catch (TDPException e) {
        assertEquals(FolderErrorCodes.FOLDER_NOT_EMPTY, e.getCode());
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 48 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class PreparationService method copy.

/**
 * Copy the given preparation to the given name / folder ans returns the new if in the response.
 *
 * @param name the name of the copied preparation, if empty, the name is "orginal-preparation-name Copy"
 * @param destination the folder path where to copy the preparation, if empty, the copy is in the same folder.
 * @return The new preparation id.
 */
public String copy(String preparationId, String name, String destination) {
    LOGGER.debug("copy {} to folder {} with {} as new name");
    Preparation original = preparationRepository.get(preparationId, Preparation.class);
    // if no preparation, there's nothing to copy
    if (original == null) {
        throw new TDPException(PREPARATION_DOES_NOT_EXIST, build().put("id", preparationId));
    }
    // use a default name if empty (original name + " Copy" )
    final String newName;
    if (StringUtils.isBlank(name)) {
        newName = message("preparation.copy.newname", original.getName());
    } else {
        newName = name;
    }
    checkIfPreparationNameIsAvailable(destination, newName);
    // copy the Preparation : constructor set HeadId and
    Preparation copy = new Preparation(original);
    copy.setId(UUID.randomUUID().toString());
    copy.setName(newName);
    final long now = System.currentTimeMillis();
    copy.setCreationDate(now);
    copy.setLastModificationDate(now);
    copy.setAuthor(security.getUserId());
    cloneStepsListBetweenPreparations(original, copy);
    // Save preparation to repository
    preparationRepository.add(copy);
    String newId = copy.getId();
    // add the preparation into the folder
    FolderEntry folderEntry = new FolderEntry(PREPARATION, newId);
    folderRepository.addFolderEntry(folderEntry, destination);
    LOGGER.debug("copy {} to folder {} with {} as new name", preparationId, destination, name);
    return newId;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) FolderEntry(org.talend.dataprep.api.folder.FolderEntry)

Example 49 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class PreparationService method setPreparationHead.

public void setPreparationHead(final String preparationId, final String headId) {
    final Step head = getStep(headId);
    if (head == null) {
        throw new TDPException(PREPARATION_STEP_DOES_NOT_EXIST, build().put("id", preparationId).put(STEP_ID, headId));
    }
    final Preparation preparation = lockPreparation(preparationId);
    try {
        setPreparationHead(preparation, head);
    } finally {
        unlockPreparation(preparationId);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation)

Example 50 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class PreparationService method searchLocation.

/**
 * Return the folder that holds this preparation.
 *
 * @param id the wanted preparation id.
 * @return the folder that holds this preparation.
 */
public Folder searchLocation(String id) {
    LOGGER.debug("looking the folder for {}", id);
    final Folder folder = folderRepository.locateEntry(id, PREPARATION);
    if (folder == null) {
        throw new TDPException(PREPARATION_DOES_NOT_EXIST, build().put("id", id));
    }
    LOGGER.info("found where {} is stored : {}", id, folder);
    return folder;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Folder(org.talend.dataprep.api.folder.Folder)

Aggregations

TDPException (org.talend.dataprep.exception.TDPException)123 IOException (java.io.IOException)43 InputStream (java.io.InputStream)25 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)21 Test (org.junit.Test)17 ApiOperation (io.swagger.annotations.ApiOperation)16 Timed (org.talend.dataprep.metrics.Timed)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 DataSet (org.talend.dataprep.api.dataset.DataSet)13 ServiceBaseTest (org.talend.ServiceBaseTest)11 StringEntity (org.apache.http.entity.StringEntity)10 JsonParser (com.fasterxml.jackson.core.JsonParser)9 URISyntaxException (java.net.URISyntaxException)9 HttpPost (org.apache.http.client.methods.HttpPost)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)9 List (java.util.List)8 URIBuilder (org.apache.http.client.utils.URIBuilder)8 Marker (org.slf4j.Marker)8 ErrorCode (org.talend.daikon.exception.error.ErrorCode)8