use of com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement in project kylo by Teradata.
the class ServiceLevelAgreementModelTransform method toModel.
/**
* Transforms the specified domain objects to REST objects.
*
* @param domain the SLA domain object
* @param feeds the feed domain objects
* @param deep {@code true} to include action configurations
* @return the SLA REST object
*/
public FeedServiceLevelAgreement toModel(ServiceLevelAgreement domain, Set<com.thinkbiganalytics.metadata.api.feed.Feed> feeds, boolean deep) {
com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement slaModel = toModel(domain, deep);
FeedServiceLevelAgreement feedServiceLevelAgreement = new FeedServiceLevelAgreement(slaModel);
boolean canEdit = false;
boolean canView = true;
if (feeds != null && !feeds.isEmpty()) {
final Set<Feed> feedModels = feeds.stream().filter(feed -> feed != null).map(model::domainToFeed).collect(Collectors.toSet());
feedServiceLevelAgreement.setFeeds(feedModels);
if (accessController.isEntityAccessControlled()) {
// set the flag on the sla edit to true only if the user has access to edit the feeds assigned to this sla
canEdit = feeds.stream().allMatch(feed -> feed.getAllowedActions().hasPermission(FeedAccessControl.EDIT_DETAILS));
// can view
canView = feeds.stream().allMatch(feed -> feed.getAllowedActions().hasPermission(FeedAccessControl.ACCESS_FEED));
} else {
canEdit = this.accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
}
} else {
canEdit = this.accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
}
slaModel.setCanEdit(canEdit);
if (feedServiceLevelAgreement.getFeeds() == null) {
feedServiceLevelAgreement.setFeeds(new HashSet<>());
}
feedServiceLevelAgreement.setCanEdit(canEdit);
return feedServiceLevelAgreement;
}
Aggregations