Search in sources :

Example 1 with FeedServiceLevelAgreement

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;
}
Also used : Collections2(com.google.common.collect.Collections2) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Model(com.thinkbiganalytics.feedmgr.rest.Model) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) ObligationGroupBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetricAssessment(com.thinkbiganalytics.metadata.sla.api.MetricAssessment) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) Nonnull(javax.annotation.Nonnull) Function(com.google.common.base.Function) Collection(java.util.Collection) Set(java.util.Set) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) ServiceLevelAgreementCheck(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck) Collectors(java.util.stream.Collectors) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed) ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) List(java.util.List) ServiceLevelAssessment(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment) ObligationBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) Feed(com.thinkbiganalytics.metadata.rest.model.feed.Feed)

Aggregations

Function (com.google.common.base.Function)1 Collections2 (com.google.common.collect.Collections2)1 Lists (com.google.common.collect.Lists)1 Model (com.thinkbiganalytics.feedmgr.rest.Model)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)1 Feed (com.thinkbiganalytics.metadata.rest.model.feed.Feed)1 FeedServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement)1 ServiceLevelAgreementCheck (com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreementCheck)1 MetricAssessment (com.thinkbiganalytics.metadata.sla.api.MetricAssessment)1 Obligation (com.thinkbiganalytics.metadata.sla.api.Obligation)1 ObligationAssessment (com.thinkbiganalytics.metadata.sla.api.ObligationAssessment)1 ObligationGroup (com.thinkbiganalytics.metadata.sla.api.ObligationGroup)1 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)1 ServiceLevelAssessment (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessment)1 ObligationBuilder (com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder)1 ObligationGroupBuilder (com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder)1 ServiceLevelAgreementBuilder (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder)1 ServiceLevelAgreementProvider (com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider)1 AccessController (com.thinkbiganalytics.security.AccessController)1