Search in sources :

Example 1 with UserDataSetMetadata

use of org.talend.dataprep.dataset.service.UserDataSetMetadata 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 2 with UserDataSetMetadata

use of org.talend.dataprep.dataset.service.UserDataSetMetadata 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)

Example 3 with UserDataSetMetadata

use of org.talend.dataprep.dataset.service.UserDataSetMetadata in project data-prep by Talend.

the class SortAndOrderHelperTest method createUserDatasetMetadata.

private DataSetMetadata createUserDatasetMetadata(String id, String name, String author, long creationDate, long lastModificationDate, RowMetadata rowMetadata, String appVersion, String ownerName, String ownerLastName) {
    UserDataSetMetadata metadata = new UserDataSetMetadata();
    metadata.setId(id);
    metadata.setName(name);
    metadata.setAuthor(author);
    metadata.setCreationDate(creationDate);
    metadata.setLastModificationDate(lastModificationDate);
    metadata.setRowMetadata(rowMetadata);
    metadata.setAppVersion(appVersion);
    metadata.setOwner(new Owner(id, ownerName, ownerLastName));
    return metadata;
}
Also used : UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) Owner(org.talend.dataprep.api.share.Owner)

Aggregations

Owner (org.talend.dataprep.api.share.Owner)3 UserDataSetMetadata (org.talend.dataprep.dataset.service.UserDataSetMetadata)3 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 UserData (org.talend.dataprep.api.user.UserData)1 TDPException (org.talend.dataprep.exception.TDPException)1 Security (org.talend.dataprep.security.Security)1 UserDataRepository (org.talend.dataprep.user.store.UserDataRepository)1