Search in sources :

Example 1 with PersistentPreparation

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

Example 2 with PersistentPreparation

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

Example 3 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 4 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 5 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)

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