2

I want to control rollout on a target on the basis of some condition matched in a page. If condition fails, the rollout should not happen.

I have create a rollout config class using BaseActionFactory and BaseAction. Can we abandon rollout on specific target if the condition fails.

@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()) ;
            }
        }
    }

if isRolloutAllowed is false then i need to abandon the rollout for the target while it should continue processing for other target pages.

Deo Priya
  • 51
  • 1
  • 5

0 Answers0