Search in sources :

Example 11 with FolderEntry

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());
}
Also used : Path(java.nio.file.Path) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) FolderContentType(org.talend.dataprep.api.folder.FolderContentType) Test(org.junit.Test)

Example 12 with FolderEntry

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;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) FolderEntry(org.talend.dataprep.api.folder.FolderEntry)

Example 13 with FolderEntry

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

Example 14 with FolderEntry

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

Example 15 with FolderEntry

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

Aggregations

FolderEntry (org.talend.dataprep.api.folder.FolderEntry)25 Folder (org.talend.dataprep.api.folder.Folder)14 Test (org.junit.Test)10 ServiceBaseTest (org.talend.ServiceBaseTest)6 Response (com.jayway.restassured.response.Response)5 PreparationSearchCriterion.filterPreparation (org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation)4 Properties (java.util.Properties)3 Preparation (org.talend.dataprep.api.preparation.Preparation)3 TDPException (org.talend.dataprep.exception.TDPException)3 StandalonePreparation (org.talend.dataprep.StandalonePreparation)2 EnrichedPreparation (org.talend.dataprep.api.service.api.EnrichedPreparation)2 BasePreparationTest (org.talend.dataprep.preparation.BasePreparationTest)2 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 FolderContentType (org.talend.dataprep.api.folder.FolderContentType)1