如何在AEM 6.4中的MSM中的特定目标页面上使用“发布配置操作类”放弃发布

时间:2020-09-17 10:57:05

标签: aem rollout

我想根据页面中匹配的某些条件来控制目标的部署。如果条件失败,则不应进行推广。

我已经使用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为false,则我需要放弃该目标的推出,同时继续处理其他目标页面。

0 个答案:

没有答案