问题描述
我想根据页面中匹配的某些条件来控制目标的部署。如果条件失败,则不应进行推广。
我已经使用BaseActionFactory和BaseAction创建了一个发布配置类。如果条件失败,我们可以放弃针对特定目标的部署吗?
@Component(Metatype=false)
@Service
public class FilterRoleActionFactory extends BaseActionFactory<BaseAction>{
private static final Logger LOG = LoggerFactory.getLogger(FilterRoleActionFactory.class);
@Property(name="liveActionName",propertyPrivate=true)
private static final String[] LIVE_ACTION_NAME = {FilterRoleAction.class.getSimpleName(),"filterRoleAction"};
@Reference
private RolloutManager rolloutManager;
protected void bindRolloutManager(RolloutManager rolloutManager) {
this.rolloutManager = rolloutManager;
}
protected void unbindRolloutManager(RolloutManager rolloutManager) {
if(this.rolloutManager == rolloutManager) {
this.rolloutManager = null;
}
}
@Override
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
@Override
protected BaseAction newActionInstance(ValueMap config) throws Wcmexception {
return new FilterRoleAction(config,this);
}
private static final class FilterRoleAction extends BaseAction{
private static final Logger LOG = LoggerFactory.getLogger(FilterRoleAction.class);
private static Map<String,List<String>> roleMap = new HashMap<>();
static {
roleMap.put("master-ip",Arrays.asList("enterprise:role/investment-professional/non-us-investment-professional","enterprise:role/investment-professional/us-investment-professional"));
roleMap.put("master-insti",Arrays.asList("enterprise:role/institutional/non-us-institutional","enterprise:role/institutional/us-institutional"));
roleMap.put("master-inv",Arrays.asList("enterprise:role/public/public-non-us","enterprise:role/public/public-us"));
};
protected FilterRoleAction(ValueMap config,BaseActionFactory<? extends LiveAction> liveActionFactory) {
super(config,liveActionFactory);
}
@Override
protected boolean handles(Resource resource,Resource target,LiveRelationship relation,boolean resetRollout)
throws RepositoryException,Wcmexception {
return target != null && relation.getStatus().isPage();
}
@Override
protected void doExecute(Resource resource,Wcmexception {
ValueMap valueMap = resource.getValueMap();
Object tags = valueMap.get(MFSConstants.CQ_COLON_TAGS);
LOG.debug("Tags {} ",tags);
String targetPath = StringUtils.replaceFirst(target.getPath(),"/content/mfs-enterprise/mfscom/masters/","");
String targetRole = StringUtils.substringBefore(targetPath,"/");
boolean isRolloutAllowed = false;
if(tags != null) {
String[] tagArray = (String[])tags;
for(String tag : tagArray) {
List<String> roles = roleMap.get(targetRole);
if(roles.contains(tag)) {
isRolloutAllowed = true;
break;
}
}
}
if(!isRolloutAllowed) {
LOG.debug("Throwing an Exception,as Role is not allowed. Page Path: {} ",target.getPath());
throw new Wcmexception("Rollout is not allowed on this page: "+target.getPath()) ;
}
}
}
如果isRolloutAllowed为false,则我需要放弃该目标的推出,同时继续处理其他目标页面。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)