VersionCopyActionFactory.java 26.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.commons.jcr.JcrUtil
 *  com.day.cq.replication.ReplicationStatus
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.api.Revision
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.msm.api.LiveAction
 *  com.day.cq.wcm.msm.api.LiveRelationship
 *  com.day.cq.wcm.msm.api.LiveRelationshipManager
 *  com.day.cq.wcm.msm.api.LiveStatus
 *  com.day.cq.wcm.msm.api.RolloutManager
 *  com.day.cq.wcm.msm.commons.BaseActionFactory
 *  com.day.cq.wcm.msm.commons.FilteredAction
 *  com.day.cq.wcm.msm.commons.FilteredActionFactoryBase
 *  com.day.cq.wcm.msm.commons.ItemFilterImpl
 *  com.day.cq.wcm.msm.commons.ItemFilterUtil
 *  com.day.text.Text
 *  javax.jcr.Node
 *  javax.jcr.NodeIterator
 *  javax.jcr.Property
 *  javax.jcr.PropertyIterator
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.jcr.Value
 *  javax.jcr.nodetype.NodeType
 *  javax.jcr.nodetype.PropertyDefinition
 *  javax.jcr.version.Version
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyUnbounded
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.msm.impl.actions;

import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.replication.ReplicationStatus;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.Revision;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.commons.FilteredAction;
import com.day.cq.wcm.msm.commons.FilteredActionFactoryBase;
import com.day.cq.wcm.msm.commons.ItemFilterImpl;
import com.day.cq.wcm.msm.commons.ItemFilterUtil;
import com.day.cq.wcm.msm.impl.LiveRelationshipManagerImpl;
import com.day.cq.wcm.msm.impl.Utils;
import com.day.text.Text;
import java.util.Calendar;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.version.Version;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service
public class VersionCopyActionFactory
extends FilteredActionFactoryBase<FilteredAction> {
    @Reference
    private RolloutManager rolloutManager = null;
    @Reference
    private LiveRelationshipManager liveRelationshipManager = null;
    @org.apache.felix.scr.annotations.Property(name="liveActionName")
    private static final String[] LIVE_ACTION_NAME = new String[]{VersionCopyAction.class.getSimpleName()};
    @org.apache.felix.scr.annotations.Property(name="cq.wcm.msm.action.excludednodetypes")
    private static final String[] DEFAULT_FILTER_NODE_TYPES = ItemFilterUtil.EMPTY_PROPERTIES;
    @org.apache.felix.scr.annotations.Property(name="cq.wcm.msm.action.excludedparagraphitems")
    private static final String[] DEFAULT_EXCLUDED_PARAGRAPH_ITEMS = ItemFilterUtil.EMPTY_PROPERTIES;
    @org.apache.felix.scr.annotations.Property(name="cq.wcm.msm.action.excludedprops")
    private static final String[] DEFAULT_EXCLUDED_PROPERTIES = ItemFilterUtil.EMPTY_PROPERTIES;
    private static final String PARAMETER_RESERVED_ITEMS = "cq.wcm.msm.action.reservedItems";
    @org.apache.felix.scr.annotations.Property(unbounded=PropertyUnbounded.ARRAY, propertyPrivate=1, name="cq.wcm.msm.action.reservedItems")
    private static final String[] RESERVED_ITEMS_DEFAULT = new String[]{"jcr:frozen.*", "jcr:uuid", "cq:lastRolledOut.*", "sling:vanity.*"};
    private static final String PARAMETER_RESERVED_MIXINS = "cq.wcm.msm.action.exludedMixinTypes";
    @org.apache.felix.scr.annotations.Property(unbounded=PropertyUnbounded.ARRAY, propertyPrivate=1, name="cq.wcm.msm.action.exludedMixinTypes")
    private static final String[] RESERVED_MXINS_DEFAULT = new String[]{"sling:vanityPath", "cq:.*", "mix:versionable"};
    private ItemFilterImpl reservedFilter;

    public String createsAction() {
        return LIVE_ACTION_NAME[0];
    }

    protected VersionCopyAction newActionInstance(ValueMap config) {
        return new VersionCopyAction(config, this, this.reservedFilter, this.liveRelationshipManager);
    }

    @Activate
    @Modified
    protected void configure(ComponentContext context) {
        this.setupFilter(context, this.rolloutManager);
        Dictionary props = context.getProperties();
        String[] reservedMxinis = PropertiesUtil.toStringArray(props.get("cq.wcm.msm.action.exludedMixinTypes"), (String[])RESERVED_MXINS_DEFAULT);
        String[] reservedItems = PropertiesUtil.toStringArray(props.get("cq.wcm.msm.action.reservedItems"), (String[])RESERVED_ITEMS_DEFAULT);
        this.reservedFilter = ItemFilterUtil.createFilter((String[])reservedMxinis, (String[])reservedItems, (String[])reservedItems, (RolloutManager)this.rolloutManager);
    }

    protected RolloutManager getRolloutManager() {
        return this.rolloutManager;
    }

    protected void bindRolloutManager(RolloutManager rolloutManager) {
        this.rolloutManager = rolloutManager;
    }

    protected void unbindRolloutManager(RolloutManager rolloutManager) {
        if (this.rolloutManager == rolloutManager) {
            this.rolloutManager = null;
        }
    }

    protected void bindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
        this.liveRelationshipManager = liveRelationshipManager;
    }

    protected void unbindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
        if (this.liveRelationshipManager == liveRelationshipManager) {
            this.liveRelationshipManager = null;
        }
    }

    private static class VersionCopyAction
    extends FilteredAction {
        private static final Logger log = LoggerFactory.getLogger(VersionCopyAction.class);
        private static final String PROP_THRESHOLD = "threshold";
        private static final long DEFAULT_THRESHOLD = 72000;
        private final LiveRelationshipManager liveRelationshipManager;
        private final RolloutManager rolloutManager;
        private final ItemFilterImpl paragraphFilter;
        private final ItemFilterImpl reservedFilter;

        private VersionCopyAction(ValueMap config, VersionCopyActionFactory factory, ItemFilterImpl reservedFilter, LiveRelationshipManager relManager) {
            super(config, factory.getPagePropertyFilter(), factory.getComponentFilter(), (BaseActionFactory)factory);
            this.liveRelationshipManager = relManager;
            this.rolloutManager = factory.getRolloutManager();
            this.paragraphFilter = factory.getComponentFilter();
            this.reservedFilter = reservedFilter;
        }

        protected boolean doHandle(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws WCMException, RepositoryException {
            if (!relation.getStatus().isPage()) {
                log.debug("Skipped execution of {}: only act on Pages", (Object)this.getName());
                return false;
            }
            LiveStatus status = relation.getStatus();
            if (status.isCancelled()) {
                log.debug("Skipped execution of {}: Relation cancelled at {}", (Object)this.getName(), (Object)relation.getSourcePath());
                return false;
            }
            if (!status.isSourceExisting()) {
                log.debug("Skipped execution of {}: No source to copy at {}", (Object)this.getName(), (Object)relation.getSourcePath());
                return false;
            }
            Node masterNode = Utils.getWorkingNode((Node)source.adaptTo(Node.class));
            if (masterNode == null) {
                log.warn("Skipped execution of {}: No source to copy at {}, though status indicated it exists", (Object)this.getName(), (Object)relation.getSourcePath());
                return false;
            }
            try {
                return VersionCopyAction.findRevision(source, this.getConfig()) != null;
            }
            catch (WCMException e) {
                throw new RepositoryException((Throwable)e);
            }
        }

        public void doExecute(Resource source, Resource target, LiveRelationship relation, boolean reset) throws WCMException, RepositoryException {
            Node frozenNode;
            PageManager pmgr;
            Page targetPage;
            Revision revision = VersionCopyAction.findRevision(source, this.getConfig());
            if (revision != null && revision.getVersion().hasNode("jcr:frozenNode") && this.updateLevel(frozenNode = revision.getVersion().getNode("jcr:frozenNode"), target, source.getResourceResolver(), relation, reset) && (pmgr = (PageManager)source.getResourceResolver().adaptTo(PageManager.class)) != null && (targetPage = pmgr.getContainingPage(relation.getTargetPath())) != null) {
                pmgr.touch((Node)targetPage.adaptTo(Node.class), true, Calendar.getInstance(), false);
            }
        }

        protected RolloutManager getRolloutManager() {
            return this.rolloutManager;
        }

        private boolean updateLevel(Node frozenNode, Resource target, ResourceResolver resolver, LiveRelationship relation, boolean reset) throws RepositoryException, WCMException {
            boolean updated = false;
            log.debug("Found active relation for {} to {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
            if (!VersionCopyAction.isExcludedFrozenNode(frozenNode, this.paragraphFilter)) {
                if (VersionCopyAction.needsCreation(target, relation)) {
                    log.debug("Included Source Node {} needs to create a target", (Object)frozenNode.getPath());
                    target = this.doCreate(frozenNode, relation, resolver, reset);
                    updated = true;
                    if (target == null) {
                        log.debug("Could not create Target at {}: excluded Node", (Object)relation.getTargetPath());
                        return false;
                    }
                } else {
                    log.debug("Included Source Node {} needs to update", (Object)frozenNode.getPath());
                    this.doUpdate(Utils.getWorkingNode(frozenNode), Utils.getWorkingNode((Node)target.adaptTo(Node.class)), relation, reset);
                    updated = true;
                }
            }
            HashSet<String> processed = new HashSet<String>();
            if (frozenNode != null) {
                NodeIterator itr = frozenNode.getNodes();
                while (itr.hasNext()) {
                    Node childSrc = itr.nextNode();
                    Resource childTarget = target.getChild(childSrc.getName());
                    if (childTarget == null) {
                        childTarget = resolver.resolve(Utils.appendPath(target.getPath(), childSrc.getName()));
                    }
                    if ((relation = this.liveRelationshipManager.getLiveRelationship(childTarget, true)) == null || relation.getStatus().isCancelled()) continue;
                    updated |= this.updateLevel(childSrc, childTarget, resolver, relation, reset);
                    processed.add(childSrc.getName());
                }
            }
            if (target != null) {
                Iterator children = target.listChildren();
                while (children.hasNext()) {
                    LiveRelationship childShip;
                    Node childNode;
                    Resource childTarget = (Resource)children.next();
                    if (processed.remove(childTarget.getName()) || (childNode = (Node)childTarget.adaptTo(Node.class)) == null || this.getFilter(childNode).excludes(childNode) || (childShip = this.liveRelationshipManager.getLiveRelationship(childTarget, true)).getStatus().isCancelled() || !reset && childShip.getStatus().getAdvancedStatus("msm:isTargetManuallyCreated").booleanValue()) continue;
                    this.doDelete(childTarget, childShip.getStatus(), reset);
                    updated = true;
                    log.debug("Included Target Node {} not in Source Version, try to delete", (Object)target.getPath());
                }
            }
            return updated;
        }

        private void doDelete(Resource toDelete, LiveStatus status, boolean reset) throws RepositoryException, WCMException {
            if (reset || !status.getAdvancedStatus("msm:isTargetManuallyCreated").booleanValue()) {
                this.liveRelationshipManager.endRelationship(toDelete, false);
                if (toDelete.adaptTo(Node.class) != null) {
                    ((Node)toDelete.adaptTo(Node.class)).remove();
                    log.debug("Deleted Node at Target {}", (Object)toDelete.getPath());
                }
            }
        }

        private Resource doCreate(Node frozen, LiveRelationship relation, ResourceResolver resourceResolver, boolean reset) throws WCMException, RepositoryException {
            String hierarchyNode = Utils.getPagePath(relation.getTargetPath());
            String parent = Text.getRelativeParent((String)hierarchyNode, (int)1);
            if (relation.getStatus().isPage()) {
                PageManager pmgr = (PageManager)resourceResolver.adaptTo(PageManager.class);
                if (pmgr != null && pmgr.getPage(parent) != null) {
                    if (relation.getStatus().isTargetExisting() && pmgr.getPage(hierarchyNode) != null) {
                        Page moved = pmgr.move(pmgr.getPage(hierarchyNode), hierarchyNode + "1", null, false, true, null);
                        log.debug("Moved manually created Node at {} to {}", (Object)hierarchyNode, (Object)moved.getName());
                    }
                    Page master = pmgr.getContainingPage(relation.getSourcePath());
                    Page newPage = pmgr.copy(master, Utils.getPagePath(relation.getTargetPath()), null, true, true, false);
                    Node content = (Node)newPage.getContentResource().adaptTo(Node.class);
                    String orgName = content.getName();
                    Session session = content.getSession();
                    session.move(content.getPath(), content.getParent().getPath() + "/bak");
                    Node newContent = content.getParent().addNode(orgName, content.getPrimaryNodeType().getName());
                    PropertyIterator itr = content.getProperties();
                    while (itr.hasNext()) {
                        Property prop = itr.nextProperty();
                        JcrUtil.copy((Property)prop, (Node)newContent, (String)prop.getName());
                    }
                    content.remove();
                    this.doUpdate(frozen, newContent, relation, true);
                    log.debug("Created new Page {}", (Object)newPage.getPath());
                    return newPage.getContentResource();
                }
            } else {
                Session session = (Session)resourceResolver.adaptTo(Session.class);
                if (session != null && session.nodeExists(parent)) {
                    Node parentNode = session.getNode(parent);
                    if (parentNode.hasNode(frozen.getName())) {
                        String newName = JcrUtil.createValidChildName((Node)parentNode, (String)(Text.getName((String)frozen.getName()) + "1"));
                        parentNode.getSession().move(parentNode.getPath() + "/" + frozen.getName(), parentNode.getPath() + "/" + newName);
                        log.debug("Moved manually created Node at {} to {}", (Object)(parentNode.getPath() + frozen.getName()), (Object)newName);
                    }
                    Node newNode = parentNode.addNode(frozen.getName(), frozen.getProperty("jcr:frozenPrimaryType").getString());
                    this.doUpdate(frozen, newNode, relation, reset);
                    log.debug("Created new Node {}", (Object)newNode.getPath());
                    if (newNode.isNodeType("nt:hierarchyNode") && frozen.hasNode("jcr:content")) {
                        Node content = newNode.addNode("jcr:content", frozen.getNode("jcr:content").getProperty("jcr:frozenPrimaryType").getString());
                        LiveRelationshipManagerImpl.markRelationship(content, true);
                        this.getRolloutManager().updateRolloutInfo(content, false, false);
                    }
                    return resourceResolver.getResource(newNode.getPath());
                }
            }
            return null;
        }

        private void doUpdate(Node frozen, Node node, LiveRelationship relation, boolean reset) throws RepositoryException {
            log.debug("Start update Target at {}", (Object)node.getPath());
            HashSet<String> requiredMixins = new HashSet<String>();
            if (frozen.hasProperty("jcr:frozenMixinTypes")) {
                for (Value val : frozen.getProperty("jcr:frozenMixinTypes").getValues()) {
                    String name = val.getString();
                    if (this.reservedFilter.excludesNodeType(name)) continue;
                    requiredMixins.add(name);
                }
            }
            if (node.hasProperty("jcr:mixinTypes")) {
                for (Value type : node.getMixinNodeTypes()) {
                    String mixinName = type.getName();
                    if (!reset || requiredMixins.remove(mixinName) || this.reservedFilter.excludesNodeType(mixinName)) continue;
                    node.removeMixin(mixinName);
                    log.debug("Removed mixin {} from {} from Version", (Object)mixinName, (Object)node.getPath());
                }
            }
            for (String mixinName : requiredMixins) {
                if (!node.canAddMixin(mixinName)) continue;
                node.addMixin(mixinName);
                log.debug("Added mixin {} to {} from Version", (Object)mixinName, (Object)node.getPath());
            }
            HashSet<String> processed = new HashSet<String>();
            PropertyIterator properties = frozen.getProperties();
            while (properties.hasNext()) {
                PropertyDefinition def;
                Property prop = properties.nextProperty();
                String propertyName = prop.getName();
                if (VersionCopyAction.filteredByName(propertyName, this.getFilter(node), this.reservedFilter) || relation.getStatus().getCanceledProperties().contains(propertyName) || !VersionCopyAction.canSet(node, propertyName, (def = prop.getDefinition()).isMultiple())) continue;
                if (def.isMultiple()) {
                    node.setProperty(propertyName, prop.getValues());
                } else {
                    node.setProperty(propertyName, prop.getValue());
                }
                processed.add(propertyName);
                log.debug("Set Property {} to {} from Version", (Object)propertyName, (Object)node.getPath());
            }
            Iterator props = this.getFilteredProperties(node);
            while (props.hasNext()) {
                Property prop = (Property)props.next();
                if (this.reservedFilter.excludes(prop) || relation.getStatus().getCanceledProperties().contains(prop.getName()) || processed.remove(prop.getName()) || !node.getSession().hasCapability("remove", (Object)prop, null)) continue;
                prop.remove();
            }
        }

        private static boolean isExcludedFrozenNode(Node srcNode, ItemFilterImpl filter) throws RepositoryException {
            Set nodeTypePattern = filter.getNodeTypePattern();
            boolean exclude = VersionCopyAction.matchOne(nodeTypePattern, srcNode.getProperty("jcr:frozenPrimaryType").getString());
            if (!exclude && srcNode.hasProperty("jcr:frozenMixinTypes")) {
                for (Value mixin : srcNode.getProperty("jcr:frozenMixinTypes").getValues()) {
                    if (!VersionCopyAction.matchOne(nodeTypePattern, mixin.getString())) continue;
                    return true;
                }
            }
            return exclude;
        }

        private static boolean filteredByName(String propertyName, ItemFilterImpl filter, ItemFilterImpl reservedFilter) {
            return VersionCopyAction.matchOne(reservedFilter.getPropertyNamePattern(), propertyName) || VersionCopyAction.matchOne(filter.getPropertyNamePattern(), propertyName);
        }

        private static boolean matchOne(Set<Pattern> patterns, String name) {
            for (Pattern pattern : patterns) {
                if (!pattern.matcher(name).matches()) continue;
                return true;
            }
            return false;
        }

        private static boolean canSet(Node node, String propName, boolean multiple) throws RepositoryException {
            PropertyDefinition residual = null;
            for (PropertyDefinition def : node.getPrimaryNodeType().getPropertyDefinitions()) {
                if (def.getName().equals(propName)) {
                    if (!def.isAutoCreated() && !def.isProtected()) {
                        return def.isMultiple() || !multiple;
                    }
                    log.debug("PropertyDefinition {} denies to set Property {}", (Object)def.getName(), (Object)propName);
                    return false;
                }
                if (!def.getName().equals("*") || !def.isMultiple() && multiple) continue;
                residual = def;
            }
            for (PropertyDefinition mixin : node.getMixinNodeTypes()) {
                for (PropertyDefinition def2 : mixin.getPropertyDefinitions()) {
                    if (def2.getName().equals(propName)) {
                        if (!def2.isAutoCreated() && !def2.isProtected()) {
                            return def2.isMultiple() || !multiple;
                        }
                        log.debug("PropertyDefinition {} denies to set Property {}", (Object)def2.getName(), (Object)propName);
                        return false;
                    }
                    if (!def2.getName().equals("*") || !def2.isMultiple() && multiple) continue;
                    residual = def2;
                }
            }
            if (residual == null) {
                log.debug("Denies to set Property {}: No PropertyDefinition could be found", (Object)propName);
                return false;
            }
            return residual.isMultiple() || !multiple;
        }

        private static boolean needsCreation(Resource target, LiveRelationship relation) {
            try {
                return target == null || target.adaptTo(Node.class) == null || Utils.isGhost((Node)target.adaptTo(Node.class)) || relation.getStatus().getAdvancedStatus("msm:isTargetManuallyCreated") != null && relation.getStatus().getAdvancedStatus("msm:isTargetManuallyCreated") != false;
            }
            catch (RepositoryException e) {
                log.debug("Failed to check status for target {}", (Object)target.getPath());
                return false;
            }
        }

        private static Revision findRevision(Resource source, ValueMap config) throws WCMException {
            PageManager pm = (PageManager)source.getResourceResolver().adaptTo(PageManager.class);
            if (pm != null) {
                ReplicationStatus status;
                Page containingPage = pm.getContainingPage(source);
                ReplicationStatus replicationStatus = status = containingPage == null ? null : (ReplicationStatus)containingPage.adaptTo(ReplicationStatus.class);
                if (status != null && status.isActivated()) {
                    log.debug("Page at {} is active, search for Version", (Object)containingPage.getPath());
                    Calendar lp = status.getLastPublished();
                    for (Revision revision : pm.getRevisions(containingPage.getPath(), null)) {
                        if (revision.getCreated().after(lp)) {
                            long timeDifference = revision.getCreated().getTimeInMillis() - lp.getTimeInMillis();
                            long threshold = 72000;
                            if (config != null && config.get((Object)"threshold") != null) {
                                threshold = (Long)config.get("threshold", Long.class);
                            }
                            if (timeDifference >= threshold) continue;
                            log.debug("Found published Version for {} at {} ", (Object)containingPage.getPath(), (Object)revision.getId());
                            return revision;
                        }
                        return revision;
                    }
                    log.debug("No published Version for {}", (Object)containingPage.getPath());
                } else {
                    log.warn("Resource at {}, is not Active, do not act", (Object)source.getPath());
                }
            } else {
                log.warn("Can not access PageManager from Resource {}, fail creation of LiveCopy Resource", (Object)source.getPath());
            }
            return null;
        }
    }

}