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