Search in sources :

Example 1 with UserDataRepository

use of org.talend.dataprep.user.store.UserDataRepository 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)

Aggregations

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