package com.thinkbiganalytics.metadata.upgrade.v084;

import com.thinkbiganalytics.KyloVersion;
import com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl;
import com.thinkbiganalytics.metadata.api.MetadataAccess;
import com.thinkbiganalytics.security.action.AllowedActions;
import com.thinkbiganalytics.security.action.config.ActionsModuleBuilder;
import com.thinkbiganalytics.server.upgrade.KyloUpgrader;
import com.thinkbiganalytics.server.upgrade.UpgradeState;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.inject.Inject;

@Component("slaEmailTemplateUpgradeAction084")
@Order(Ordered.LOWEST_PRECEDENCE)
@Profile(KyloUpgrader.KYLO_UPGRADE)
public class ServiceLevelAgreementEmailTemplateUpgradeAction implements UpgradeState {

    @Inject
    private MetadataAccess metadata;

    @Inject
    private ActionsModuleBuilder builder;

    private static final Logger log = LoggerFactory.getLogger(ServiceLevelAgreementEmailTemplateUpgradeAction.class);

    @Override
    public boolean isTargetVersion(KyloVersion version) {
        return version.matches("0.8", "4", "");
    }

    @Override
    public boolean isTargetFreshInstall() {
        return true;
    }


    public void upgradeTo(final KyloVersion startingVersion) {
        metadata.commit(() -> builder
            .module(AllowedActions.SERVICES)
            .action(FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENT_EMAIL_TEMPLATE)
            .add()
            .build(), MetadataAccess.SERVICE);
    }

}

@@ -46,16 +46,669 @@
 e.v084;%0A
+/*-%0A * #%25L%0A * kylo-upgrade-service%0A * %25%25%0A * Copyright (C) 2017 ThinkBig Analytics%0A * %25%25%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A * #L%25%0A */
 %0Aimport 

add header to file