Search in sources :

Example 1 with Security

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

the class PreparationConversions method toStudioPreparation.

private PreparationSummary toStudioPreparation(Preparation source, PreparationSummary target, ApplicationContext applicationContext) {
    if (target.getOwner() == null) {
        final Security security = applicationContext.getBean(Security.class);
        Owner owner = new Owner(security.getUserId(), security.getUserDisplayName(), StringUtils.EMPTY);
        target.setOwner(owner);
    }
    final PreparationRepository preparationRepository = applicationContext.getBean(PreparationRepository.class);
    final ActionRegistry actionRegistry = applicationContext.getBean(ActionRegistry.class);
    // Get preparation actions
    PreparationActions prepActions = preparationRepository.get(source.getHeadId(), PreparationActions.class);
    if (prepActions != null) {
        List<Action> actions = prepActions.getActions();
        boolean allowDistributedRun = true;
        for (Action action : actions) {
            final ActionDefinition actionDefinition = actionRegistry.get(action.getName());
            if (actionDefinition.getBehavior().contains(ActionDefinition.Behavior.FORBID_DISTRIBUTED)) {
                // Disallow distributed run
                allowDistributedRun = false;
                break;
            }
        }
        target.setAllowDistributedRun(allowDistributedRun);
    }
    return target;
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) Owner(org.talend.dataprep.api.share.Owner) Security(org.talend.dataprep.security.Security) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition)

Example 2 with Security

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

the class DataSetConversions method doWith.

@Override
public BeanConversionService doWith(BeanConversionService conversionService, String beanName, ApplicationContext applicationContext) {
    conversionService.register(// 
    fromBean(DataSetMetadata.class).toBeans(// 
    UserDataSetMetadata.class).using(UserDataSetMetadata.class, (dataSetMetadata, userDataSetMetadata) -> {
        final Security security = applicationContext.getBean(Security.class);
        final UserDataRepository userDataRepository = applicationContext.getBean(UserDataRepository.class);
        String userId = security.getUserId();
        // update the dataset favorites
        final UserData userData = userDataRepository.get(userId);
        if (userData != null) {
            userDataSetMetadata.setFavorite(userData.getFavoritesDatasets().contains(dataSetMetadata.getId()));
        }
        // and the owner (if not already present).
        if (userDataSetMetadata.getOwner() == null) {
            userDataSetMetadata.setOwner(new Owner(userId, security.getUserDisplayName(), StringUtils.EMPTY));
        }
        return userDataSetMetadata;
    }).build());
    return conversionService;
}
Also used : UserDataRepository(org.talend.dataprep.user.store.UserDataRepository) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) Owner(org.talend.dataprep.api.share.Owner) UserData(org.talend.dataprep.api.user.UserData) Security(org.talend.dataprep.security.Security)

Example 3 with Security

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

the class PreparationConversions method toUserPreparation.

private UserPreparation toUserPreparation(UserPreparation target, ApplicationContext applicationContext) {
    if (target.getOwner() == null) {
        final Security security = applicationContext.getBean(Security.class);
        Owner owner = new Owner(security.getUserId(), security.getUserDisplayName(), StringUtils.EMPTY);
        target.setOwner(owner);
    }
    return target;
}
Also used : Owner(org.talend.dataprep.api.share.Owner) Security(org.talend.dataprep.security.Security)

Aggregations

Owner (org.talend.dataprep.api.share.Owner)3 Security (org.talend.dataprep.security.Security)3 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 UserData (org.talend.dataprep.api.user.UserData)1 UserDataSetMetadata (org.talend.dataprep.dataset.service.UserDataSetMetadata)1 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)1 ActionRegistry (org.talend.dataprep.transformation.pipeline.ActionRegistry)1 UserDataRepository (org.talend.dataprep.user.store.UserDataRepository)1