我想根据页面中匹配的某些条件来控制目标的推出。如果条件失败,则不应发生推出。
我已经使用 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, Resource target, LiveRelationship relation, boolean resetRollout)
throws RepositoryException, 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 为假,那么我需要放弃目标的推出,而它应该继续处理其他目标页面。