Search in sources :

Example 1 with Owner

use of org.talend.dataprep.api.share.Owner 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 Owner

use of org.talend.dataprep.api.share.Owner in project data-prep by Talend.

the class SortAndOrderHelperTest method createPreparation.

private Preparation createPreparation(String name, String author, long creation, long modification, long size, String dsId) {
    Preparation firstPrep = new Preparation();
    firstPrep.setDataSetId(dsId);
    firstPrep.setName(name);
    firstPrep.setAuthor(new Owner("1234", author, "").getDisplayName());
    firstPrep.setCreationDate(creation);
    firstPrep.setLastModificationDate(modification);
    List<Step> steps = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        steps.add(null);
    }
    firstPrep.setSteps(steps);
    return firstPrep;
}
Also used : Owner(org.talend.dataprep.api.share.Owner) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) ArrayList(java.util.ArrayList) Step(org.talend.dataprep.api.preparation.Step)

Example 3 with Owner

use of org.talend.dataprep.api.share.Owner in project data-prep by Talend.

the class SortAndOrderHelper method getPreparationComparator.

public static Comparator<Preparation> getPreparationComparator(Sort sortKey, Order orderKey, Function<? super Preparation, ? extends DataSetMetadata> dataSetFinder) {
    Comparator<Comparable> comparisonOrder = getOrderComparator(orderKey);
    // Select comparator for sort (either by name or date)
    Function<Preparation, Comparable> keyExtractor;
    if (sortKey == null) {
        // default to NAME sort
        keyExtractor = preparation -> preparation.getName().toUpperCase();
    } else {
        switch(sortKey) {
            // In case of API call error, default to NAME sort
            case NB_RECORDS:
            case NAME:
                keyExtractor = preparation -> Optional.ofNullable(preparation).map(p -> p.getName().toUpperCase()).orElse(StringUtils.EMPTY);
                break;
            case AUTHOR:
                keyExtractor = preparation -> {
                    // in order to just call a method to retrieve the author name
                    if (preparation instanceof UserPreparation) {
                        Owner owner = ((UserPreparation) preparation).getOwner();
                        return (owner != null) ? StringUtils.upperCase(owner.getDisplayName()) : StringUtils.EMPTY;
                    }
                    return preparation.getAuthor();
                };
                break;
            case CREATION_DATE:
            case DATE:
                keyExtractor = Preparation::getCreationDate;
                break;
            case LAST_MODIFICATION_DATE:
                keyExtractor = Preparation::getLastModificationDate;
                break;
            case NB_STEPS:
                keyExtractor = preparation -> preparation.getSteps().size();
                break;
            case DATASET_NAME:
                if (dataSetFinder != null) {
                    keyExtractor = p -> getUpperCaseNameFromNullable(dataSetFinder.apply(p));
                } else {
                    LOGGER.debug("There is no dataset finding function to sort preparations on dataset name. Default to natural name order.");
                    // default to sort on name
                    keyExtractor = preparation -> preparation.getName().toUpperCase();
                }
                break;
            default:
                // this should not be possible
                throw new TDPException(ILLEGAL_SORT_FOR_LIST, build().put("sort", sortKey));
        }
    }
    return Comparator.comparing(keyExtractor, comparisonOrder);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Owner(org.talend.dataprep.api.share.Owner) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation)

Example 4 with Owner

use of org.talend.dataprep.api.share.Owner 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 5 with Owner

use of org.talend.dataprep.api.share.Owner in project data-prep by Talend.

the class SortAndOrderHelper method getDataSetMetadataComparator.

/**
 * Return a dataset metadata comparator from the given parameters.
 *
 * @param sortKey the sort key. If null, default to {@link Sort#NAME}.
 * @param orderKey the order key to use. If null, default to {@link Order#ASC}.
 * @return a dataset metadata comparator from the given parameters.
 */
public static Comparator<DataSetMetadata> getDataSetMetadataComparator(Sort sortKey, Order orderKey) {
    Comparator<Comparable> comparisonOrder = getOrderComparator(orderKey);
    // Select comparator for sort (either by name or date)
    Function<DataSetMetadata, Comparable> keyExtractor;
    if (sortKey == null) {
        // default to NAME sort
        keyExtractor = dataSetMetadata -> dataSetMetadata.getName().toUpperCase();
    } else {
        switch(sortKey) {
            // In case of API call error, default to NAME sort
            case DATASET_NAME:
            case NB_STEPS:
            case NAME:
                keyExtractor = dataSetMetadata -> dataSetMetadata.getName().toUpperCase();
                break;
            case AUTHOR:
                keyExtractor = dataSetMetadata -> {
                    // in order to just call a method to retrieve the author name
                    if (dataSetMetadata instanceof UserDataSetMetadata) {
                        Owner owner = ((UserDataSetMetadata) dataSetMetadata).getOwner();
                        return (owner != null) ? StringUtils.upperCase(owner.getDisplayName()) : StringUtils.EMPTY;
                    }
                    return dataSetMetadata.getAuthor();
                };
                break;
            case CREATION_DATE:
            case DATE:
                keyExtractor = DataSetMetadata::getCreationDate;
                break;
            case LAST_MODIFICATION_DATE:
                keyExtractor = DataSetMetadata::getLastModificationDate;
                break;
            case NB_RECORDS:
                keyExtractor = metadata -> metadata.getContent().getNbRecords();
                break;
            default:
                // this should not be possible
                throw new TDPException(ILLEGAL_SORT_FOR_LIST, build().put("sort", sortKey));
        }
    }
    return Comparator.comparing(keyExtractor, comparisonOrder);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) Owner(org.talend.dataprep.api.share.Owner) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata)

Aggregations

Owner (org.talend.dataprep.api.share.Owner)9 UserDataSetMetadata (org.talend.dataprep.dataset.service.UserDataSetMetadata)4 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)3 Security (org.talend.dataprep.security.Security)3 ArrayList (java.util.ArrayList)2 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)2 Preparation (org.talend.dataprep.api.preparation.Preparation)2 Step (org.talend.dataprep.api.preparation.Step)2 TDPException (org.talend.dataprep.exception.TDPException)2 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 UserData (org.talend.dataprep.api.user.UserData)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