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;
}
Aggregations