Search in sources :

Example 1 with SecurityProxy

use of org.talend.dataprep.security.SecurityProxy in project data-prep by Talend.

the class APIPreparationConversions method toEnrichedPreparation.

private EnrichedPreparation toEnrichedPreparation(PreparationMessage preparationMessage, EnrichedPreparation enrichedPreparation, ApplicationContext applicationContext) {
    final SecurityProxy securityProxy = applicationContext.getBean(SecurityProxy.class);
    // Add related dataset information
    if (preparationMessage.getDataSetId() == null) {
        return enrichedPreparation;
    } else {
        // get the dataset metadata
        try {
            // because dataset are not shared
            securityProxy.asTechnicalUser();
            final DataSetGetMetadata bean = applicationContext.getBean(DataSetGetMetadata.class, preparationMessage.getDataSetId());
            final DataSetMetadata dataSetMetadata = bean.execute();
            enrichedPreparation.setSummary(new EnrichedPreparation.DataSetMetadataSummary(dataSetMetadata));
        } catch (Exception e) {
            LOGGER.debug("error reading dataset metadata {} : {}", enrichedPreparation.getId(), e);
            return enrichedPreparation;
        } finally {
            securityProxy.releaseIdentity();
        }
    }
    // Add step ids
    LinkedList<String> collected = new LinkedList<>();
    preparationMessage.getSteps().stream().map(Step::getId).forEach(s -> {
        if (s != null && (collected.isEmpty() || !collected.getLast().equals(s))) {
            collected.add(s);
        }
    });
    enrichedPreparation.setSteps(collected);
    // Add folder information
    final LocatePreparation command = applicationContext.getBean(LocatePreparation.class, enrichedPreparation.getId());
    final Folder folder = command.execute();
    enrichedPreparation.setFolder(folder);
    return enrichedPreparation;
}
Also used : LocatePreparation(org.talend.dataprep.api.service.command.preparation.LocatePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) SecurityProxy(org.talend.dataprep.security.SecurityProxy) Folder(org.talend.dataprep.api.folder.Folder) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 Folder (org.talend.dataprep.api.folder.Folder)1 EnrichedPreparation (org.talend.dataprep.api.service.api.EnrichedPreparation)1 LocatePreparation (org.talend.dataprep.api.service.command.preparation.LocatePreparation)1 DataSetGetMetadata (org.talend.dataprep.command.dataset.DataSetGetMetadata)1 SecurityProxy (org.talend.dataprep.security.SecurityProxy)1