use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class ToPEPersistentIdentifiable method run.
@Override
public void run() {
LOGGER.debug("starting upgrade from {} to {}.", Step.class, PersistentStep.class);
final AtomicLong counter = new AtomicLong(0L);
fileSystemPreparationRepository.list(Step.class).forEach(s -> {
fileSystemPreparationRepository.remove(s);
PersistentStep persistentStep = turnToPersistentStep(s);
preparationRepository.add(persistentStep);
LOGGER.debug("step {} updated to {}", s, persistentStep);
counter.incrementAndGet();
});
LOGGER.info("Upgrade from {} to {} done, {} steps processed.", Step.class, PersistentStep.class, counter.get());
LOGGER.debug("starting upgrade from {} to {}.", Preparation.class, PersistentPreparation.class);
final Stream<Preparation> preparations = fileSystemPreparationRepository.list(Preparation.class);
preparations.forEach(p -> {
fileSystemPreparationRepository.remove(p);
PersistentPreparation persistentPreparation = turnToPersistentPreparation(p);
preparationRepository.add(persistentPreparation);
});
LOGGER.info("Upgrade from {} to {} done.", Preparation.class, PersistentPreparation.class);
LOGGER.info("Migration of step ids in preparation...");
final Stream<PersistentPreparation> persistentPreparations = preparationRepository.list(PersistentPreparation.class);
persistentPreparations.forEach(p -> {
LOGGER.info("Migration of preparation #{}", p.getId());
final List<String> stepsIds = preparationUtils.listStepsIds(p.getHeadId(), preparationRepository);
p.setSteps(stepsIds);
final DataSetMetadata metadata = dataSetMetadataRepository.get(p.getDataSetId());
if (metadata != null) {
LOGGER.info("Set metadata {} in preparation {}.", p.getDataSetId(), p.getId());
p.setRowMetadata(metadata.getRowMetadata());
} else {
LOGGER.info("Metadata {} not found for preparation {}.", p.getDataSetId(), p.getId());
p.setRowMetadata(new RowMetadata());
}
preparationRepository.add(p);
LOGGER.info("Migration of preparation #{} done ({} steps)", p.getId(), stepsIds.size());
});
LOGGER.info("Migration of step ids in preparation done.");
}
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);
}
}
use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class PreparationService method moveStep.
/**
* Moves the step with specified <i>stepId</i> just after the step with <i>parentStepId</i> as identifier within the
* specified
* preparation.
*
* @param preparationId the id of the preparation containing the step to move
* @param stepId the id of the step to move
* @param parentStepId the id of the step which wanted as the parent of the step to move
*/
public void moveStep(final String preparationId, String stepId, String parentStepId) {
LOGGER.debug("Moving step {} after step {}, within preparation {}", stepId, parentStepId, preparationId);
final PersistentPreparation preparation = lockPreparation(preparationId);
try {
reorderSteps(preparation, stepId, parentStepId);
auditService.auditPreparationMoveStep(preparationId, preparation.getName(), stepId, parentStepId);
} finally {
unlockPreparation(preparationId);
}
}
Aggregations