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