Search in sources :

Example 6 with PersistentPreparation

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.");
}
Also used : PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) AtomicLong(java.util.concurrent.atomic.AtomicLong) Preparation(org.talend.dataprep.api.preparation.Preparation) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 7 with PersistentPreparation

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);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 8 with PersistentPreparation

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);
    }
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 9 with PersistentPreparation

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);
    }
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 10 with PersistentPreparation

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);
    }
}
Also used : PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Aggregations

PersistentPreparation (org.talend.dataprep.preparation.store.PersistentPreparation)25 Test (org.junit.Test)8 TDPException (org.talend.dataprep.exception.TDPException)7 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 FolderEntry (org.talend.dataprep.api.folder.FolderEntry)5 Action (org.talend.dataprep.api.preparation.Action)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)5 Step (org.talend.dataprep.api.preparation.Step)5 ArrayList (java.util.ArrayList)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)4 StepDiff (org.talend.dataprep.api.preparation.StepDiff)4 StepRowMetadata (org.talend.dataprep.api.preparation.StepRowMetadata)4 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 StringUtils (org.apache.commons.lang3.StringUtils)3