use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class NoOpLockedResourceRepositoryTest method tryLock.
@Test
public void tryLock() {
// given
String preparationId = "preparation id";
PersistentPreparation preparationMock = mock(PersistentPreparation.class);
when(preparationRepository.get(preparationId, PersistentPreparation.class)).thenReturn(preparationMock);
// when
PersistentPreparation preparation = noOpLockedResourceRepository.tryLock(preparationId, "Toto", "toto de Charleville-Mézières");
// then
assertEquals(preparationMock, preparation);
verify(preparationRepository).get(preparationId, PersistentPreparation.class);
}
use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class PreparationAPITest method testOnTheFlyPreparationMigrationDatasetName_TDP_6195.
@Test
public void testOnTheFlyPreparationMigrationDatasetName_TDP_6195() throws IOException {
String datasetName = "my dataset - " + UUID.randomUUID().toString();
String datasetId = testClient.createDataset("/org/talend/dataprep/api/service/preparations/5L4Ccity_TDP-3858.csv", datasetName);
String preparationId = testClient.createPreparationFromDataset(datasetId, "5L4C city Preparation", home.getId());
PersistentPreparation persistentPreparation = preparationRepository.get(preparationId, PersistentPreparation.class);
persistentPreparation.setDataSetName(null);
preparationRepository.add(persistentPreparation);
// Our preparation do not have a dataset name
PreparationDTO preparationDetails = testClient.getPreparationSummary(preparationId);
assertNull(preparationDetails.getDataSetName());
// listing should trigger migration
testClient.listPreparations();
// then we have the dataset name set in the preparation
PreparationDTO preparationDetailsAfterList = testClient.getPreparationSummary(preparationId);
assertEquals(datasetName, preparationDetailsAfterList.getDataSetName());
}
use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class PreparationService method setPreparationHead.
public void setPreparationHead(final String preparationId, final String headId) {
final PersistentStep head = getStep(headId);
if (head == null) {
throw new TDPException(PREPARATION_STEP_DOES_NOT_EXIST, build().put(ID, preparationId).put(STEP_ID, headId));
}
final PersistentPreparation preparation = lockPreparation(preparationId);
try {
setPreparationHead(preparation, head);
} finally {
unlockPreparation(preparationId);
}
}
use of org.talend.dataprep.preparation.store.PersistentPreparation 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) {
LOGGER.debug("Moving {} preparation from '{}' folder to '{}' folder with the new name '{}' requested", preparationId, folder, destination, newName);
// get and lock the preparation to move
final PersistentPreparation 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);
}
original.setFolderId(destination);
preparationRepository.add(original);
// move the preparation
FolderEntry folderEntry = new FolderEntry(PREPARATION, preparationId);
folderRepository.moveFolderEntry(folderEntry, folder, destination);
LOGGER.info("Preparation {} moved from '{}' folder to '{}' folder with the new name '{}'", preparationId, folder, destination, targetName);
auditService.auditPreparationMove(preparationId, folder, destination, targetName);
} finally {
unlockPreparation(preparationId);
}
}
use of org.talend.dataprep.preparation.store.PersistentPreparation 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 PersistentPreparation preparationToDelete = lockPreparation(preparationId);
try {
preparationRepository.remove(preparationToDelete);
// 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);
auditService.auditPreparationDeletion(preparationId);
}
} finally {
// Just in case remove failed
unlockPreparation(preparationId);
}
}
Aggregations