use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class FileSystemFolderRepository method moveFolderEntry.
@Override
public void moveFolderEntry(FolderEntry folderEntry, String fromId, String toId) {
Path destinationPath = pathsConverter.toPath(fromId(toId));
if (Files.notExists(destinationPath)) {
throw new IllegalArgumentException("destinationPath doesn't exists");
}
Path originFilePath = Paths.get(pathsConverter.toPath(fromId(fromId)).toString(), buildFileName(folderEntry));
if (Files.notExists(originFilePath)) {
throw new IllegalArgumentException("entry doesn't exists");
}
Path destinationFile = Paths.get(destinationPath.toString(), buildFileName(folderEntry));
try {
Files.move(originFilePath, destinationFile);
} catch (IOException e) {
throw new TDPException(DataSetErrorCodes.UNABLE_TO_MOVE_FOLDER_ENTRY, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class FileSystemFolderRepository method addFolder.
@Override
public Folder addFolder(String parentId, String givenPath) {
// parent path must be set and exists
FolderPath parentFolderPath = fromId(parentId);
List<String> pathToAppend = Arrays.stream(givenPath.split(PATH_SEPARATOR.toString())).filter(StringUtils::isNotBlank).collect(Collectors.toList());
if (parentFolderPath == null || !exists(parentId)) {
throw new TDPException(UNABLE_TO_ADD_FOLDER, build().put("path", givenPath));
}
FolderPath folderPathToCreate = new FolderPath(parentFolderPath, pathToAppend.toArray(new String[pathToAppend.size()]));
try {
Path pathToCreate = pathsConverter.toPath(folderPathToCreate);
Files.createDirectories(pathToCreate);
return toFolder(pathToCreate, security.getUserId());
} catch (IOException e) {
throw new TDPException(UNABLE_TO_ADD_FOLDER, e, build().put("path", givenPath));
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class FileSystemFolderRepository method clear.
@Override
public void clear() {
try {
FileUtils.deleteDirectory(pathsConverter.getRootFolder().toFile());
init();
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class FileSystemUtils method toFolderEntry.
/**
* Tries to read a file for a dataprep {@link FolderEntry}.
*
* @param pathFile the location of the file
* @return the folder entry or throws an exception if it cannot be read
*/
static FolderEntry toFolderEntry(Path pathFile) {
FolderEntry folderEntry;
try (InputStream inputStream = Files.newInputStream(pathFile)) {
Properties properties = new Properties();
properties.load(inputStream);
folderEntry = new FolderEntry();
folderEntry.setFolderId(properties.getProperty(FOLDER_ID));
folderEntry.setContentType(FolderContentType.fromName(properties.getProperty(CONTENT_TYPE)));
folderEntry.setContentId(properties.getProperty(CONTENT_ID));
} catch (IOException e) {
throw new TDPException(UNABLE_TO_READ_FOLDER_ENTRY, e, build().put("path", pathFile));
}
return folderEntry;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class CSVFormatUtils method compileParameterProperties.
/**
* Retrieve properties associated with a dataset content and put them in a
* map with their corresponding key.
*
* @param separator the specified separator
* @param updatedParameters the updated header
*/
Map<String, String> compileParameterProperties(Separator separator, Map<String, String> updatedParameters) {
List<String> header = separator.getHeaders().stream().map(p -> p.getKey()).collect(Collectors.toList());
// header
String jsonHeader;
try {
jsonHeader = mapper.writeValueAsString(header);
} catch (Exception e) {
throw new TDPException(UNABLE_TO_SERIALIZE_TO_JSON, e);
}
updatedParameters.put(HEADER_COLUMNS_PARAMETER, jsonHeader);
// separator
updatedParameters.put(SEPARATOR_PARAMETER, String.valueOf(separator.getSeparator()));
// if no parameter set set take the default one
updatedParameters.putIfAbsent(TEXT_ENCLOSURE_CHAR, defaultTextEnclosure);
updatedParameters.putIfAbsent(ESCAPE_CHAR, defaultEscapeChar);
return updatedParameters;
}
Aggregations