use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.
the class FileSystemUtilsTest method toFolderEntry.
@Test
public void toFolderEntry() throws Exception {
Path testEntry = testFolder.resolve("testEntry");
String contentId = "contentId";
String folderId = "folderId";
FolderContentType contentType = FolderContentType.PREPARATION;
createEntry(testEntry, contentId, folderId, contentType);
FolderEntry folderEntry = FileSystemUtils.toFolderEntry(testEntry);
assertNotNull(folderEntry);
assertEquals(contentId, folderEntry.getContentId());
assertEquals(folderId, folderEntry.getFolderId());
assertEquals(contentType, folderEntry.getContentType());
}
use of org.talend.dataprep.api.folder.FolderEntry 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.api.folder.FolderEntry in project data-prep by Talend.
the class PreparationService method delete.
/**
* Delete the preparation that match the given id.
*
* @param preparationId the preparation id to delete.
*/
public void delete(String preparationId) {
LOGGER.debug("Deletion of preparation #{} requested.", preparationId);
final Preparation preparationToDelete = lockPreparation(preparationId);
try {
preparationRepository.remove(preparationToDelete);
for (Step step : preparationToDelete.getSteps()) {
if (!Step.ROOT_STEP.id().equals(step.id())) {
// Remove step metadata
final StepRowMetadata rowMetadata = new StepRowMetadata();
rowMetadata.setId(step.getRowMetadata());
preparationRepository.remove(rowMetadata);
// Remove preparation action (if it's the only step using these actions)
final Stream<Step> steps = preparationRepository.list(Step.class, eq("contentId", step.getContent()));
if (steps.count() == 1) {
// Remove action
final PreparationActions preparationActions = new PreparationActions();
preparationActions.setId(step.getContent());
preparationRepository.remove(preparationActions);
}
// Remove step
preparationRepository.remove(step);
}
}
// delete the associated folder entries
try (final Stream<FolderEntry> entries = folderRepository.findFolderEntries(preparationId, PREPARATION)) {
entries.forEach(e -> folderRepository.removeFolderEntry(e.getFolderId(), preparationId, PREPARATION));
LOGGER.info("Deletion of preparation #{} done.", preparationId);
}
} finally {
// Just in case remove failed
unlockPreparation(preparationId);
}
}
use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.
the class PreparationService method move.
/**
* Move a preparation to an other folder.
*
* @param folder The original folder of the preparation.
* @param destination The new folder of the preparation.
* @param newName The new preparation name.
*/
public void move(String preparationId, String folder, String destination, String newName) {
// @formatter:on
LOGGER.debug("moving {} from {} to {} with the new name '{}'", preparationId, folder, destination, newName);
// get and lock the preparation to move
final Preparation original = lockPreparation(preparationId);
try {
// set the target name
final String targetName = StringUtils.isEmpty(newName) ? original.getName() : newName;
// first check if the name is already used in the target folder
checkIfPreparationNameIsAvailable(destination, targetName);
// rename the dataset only if we received a new name
if (!targetName.equals(original.getName())) {
original.setName(newName);
preparationRepository.add(original);
}
// move the preparation
FolderEntry folderEntry = new FolderEntry(PREPARATION, preparationId);
folderRepository.moveFolderEntry(folderEntry, folder, destination);
LOGGER.info("preparation {} moved from {} to {} with the new name {}", preparationId, folder, destination, targetName);
} finally {
unlockPreparation(preparationId);
}
}
use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.
the class AddAllPreparationsTaskToHome method run.
/**
* @see UpgradeTask#run()
*/
@Override
public void run() {
final Stream<Preparation> preparations = preparationRepository.list(Preparation.class);
final String homeId = folderRepository.getHome().getId();
preparations.forEach(p -> {
folderRepository.addFolderEntry(new FolderEntry(FolderContentType.PREPARATION, p.id()), homeId);
LOG.debug("preparation #{} added to home", p.getId());
});
LOG.debug("All preparations were added to the home folder.");
}
Aggregations