Search in sources :

Example 1 with StepRowMetadata

use of org.talend.dataprep.api.preparation.StepRowMetadata in project data-prep by Talend.

the class StepRowMetadataMigration method run.

@Override
public void run() {
    // Allow non numeric value like NaN
    objectMapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
    LOGGER.info("Migration of step row metadata in preparations...");
    preparationRepository.list(PersistentStep.class).forEach(persistentStep -> {
        String id = persistentStep.getId();
        LOGGER.info("Migration of step #{}", id);
        String rowMetadata = persistentStep.getRowMetadata();
        try {
            // the rootstep has no metadata => avoid conversion
            if (rowMetadata != null) {
                // Dirty patch to convert all histogram (2.0) to new one (2.1)
                rowMetadata = rowMetadata.replace("_class", "type").replace("org.talend.dataprep.api.dataset.statistics.number.NumberHistogram", "number").replace("org.talend.dataprep.api.dataset.statistics.date.DateHistogram", "date");
                final DataSetMetadata dataSetMetadata = objectMapper.readerFor(DataSetMetadata.class).readValue(rowMetadata);
                final StepRowMetadata stepRowMetadata = new StepRowMetadata(dataSetMetadata.getRowMetadata());
                persistentStep.setRowMetadata(stepRowMetadata.getId());
                preparationRepository.add(persistentStep);
                preparationRepository.add(stepRowMetadata);
            }
        } catch (Exception e) {
            LOGGER.info("Ignore migration of step #{} (enable debug for full log).", id);
            LOGGER.debug("Unable to migrate step", e);
        }
    });
    LOGGER.info("Migration of step metadata in preparations done.");
}
Also used : StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 2 with StepRowMetadata

use of org.talend.dataprep.api.preparation.StepRowMetadata in project data-prep by Talend.

the class PreparationCleaner method removeCurrentOrphanSteps.

/**
 * Remove all orphan steps in preparation repository.
 */
public void removeCurrentOrphanSteps() {
    securityProxy.asTechnicalUser();
    try {
        getCurrentOrphanSteps().forEach(step -> {
            // Remove step
            final Step stepToRemove = new Step();
            stepToRemove.setId(step.getId());
            repository.remove(stepToRemove);
            // Remove actions linked to step
            // if this step re-use an existing actions we don't delete the actions
            boolean criterion = repository.exist(PersistentStep.class, eq("contentId", step.getContent()));
            if (criterion) {
                LOGGER.debug("Don't removing step content {} it still used by another step.", step.getContent());
            } else {
                LOGGER.debug("Removing step content {}.", step.getContent());
                final PreparationActions preparationActionsToRemove = new PreparationActions();
                preparationActionsToRemove.setId(step.getContent());
                repository.remove(preparationActionsToRemove);
            }
            // Remove metadata linked to step
            final StepRowMetadata stepRowMetadataToRemove = new StepRowMetadata();
            stepRowMetadataToRemove.setId(stepToRemove.getRowMetadata());
            repository.remove(stepRowMetadataToRemove);
        });
    } finally {
        securityProxy.releaseIdentity();
    }
}
Also used : StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step)

Aggregations

StepRowMetadata (org.talend.dataprep.api.preparation.StepRowMetadata)2 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)2 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)1 Step (org.talend.dataprep.api.preparation.Step)1