package org.sky.resource.rule.oss;

import org.sky.core.literule.annotation.LiteRuleComponent;
import org.sky.core.literule.core.RuleComponent;
import org.sky.core.oss.LocalFileTemplate;
import org.sky.core.oss.OssTemplate;
import org.sky.core.oss.props.OssProperties;
import org.sky.core.oss.rule.OssRule;
import org.sky.resource.pojo.entity.Oss;
import org.sky.resource.rule.constant.OssRuleConstant;
import org.sky.resource.rule.context.OssContext;

/**
 * 本地云存储构建类
 *
 */
@LiteRuleComponent(id = OssRuleConstant.LOCAL_FILE_RULE, name = "localFileOSS构建")
public class LocalFileRule extends RuleComponent {

	@Override
	public void process() {
		// 获取上下文
		OssContext contextBean = this.getContextBean(OssContext.class);
		Oss oss = contextBean.getOss();
		OssRule ossRule = contextBean.getOssRule();

		// 创建配置类
		OssProperties ossProperties = new OssProperties();
		ossProperties.setEndpoint(oss.getEndpoint());
		ossProperties.setTransformEndpoint(oss.getTransformEndpoint());
		ossProperties.setAccessKey(oss.getAccessKey());
		ossProperties.setBucketName(oss.getBucketName());

		OssTemplate ossTemplate = new LocalFileTemplate(ossRule, ossProperties);

		// 设置上下文
		contextBean.setOssTemplate(ossTemplate);

	}
}
