Java Code Examples for org.alfresco.service.cmr.repository.ChildAssociationRef

The following examples show how to use org.alfresco.service.cmr.repository.ChildAssociationRef. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
 */
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
    boolean result = false;
    
    if (this.nodeService.exists(actionedUponNodeRef) == true)
    {
        // Default match pattern is to match all.
        QNamePattern matchAll = RegexQNamePattern.MATCH_ALL;

        // Retrieve any specified parameter values.
        QName assocTypeParam = (QName)ruleCondition.getParameterValue(PARAM_ASSOC_TYPE);
        QName assocNameParam = (QName)ruleCondition.getParameterValue(PARAM_ASSOC_NAME);

        // Use the specified QNames if there are any, else default to match_all.
        QNamePattern assocType = assocTypeParam == null ? matchAll : assocTypeParam;
        QNamePattern assocName = assocNameParam == null ? matchAll : assocNameParam;

        // Are there any children which match these association name/type patterns?
        List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef, assocType, assocName);
        result = !children.isEmpty();
    }
    
    return result;
}
 
Example 2
public ResolvedParentChildPair resolveCorrespondingNode(NodeRef sourceNodeRef, ChildAssociationRef primaryAssoc,
        Path parentPath)
{
    
    ResolvedParentChildPair result = cache.get(sourceNodeRef);

    if (result != null)
    {
        if (log.isDebugEnabled()) 
        {
            log.debug("Found fully-resolved entry in cache for node " + sourceNodeRef);
        }
        return result;
    }

    result = delegateResolver.resolveCorrespondingNode(sourceNodeRef, primaryAssoc, parentPath);

    //If we have fully resolved the parent and child nodes then stick it in the cache...
    if (result.resolvedChild != null && result.resolvedParent != null)
    {
        cache.put(sourceNodeRef, result);
    }
    return result;
}
 
Example 3
/**
 * Creates a new version history node, applying the root version aspect is required
 *
 * @param nodeRef   the node ref
 * @return          the version history node reference
 */
private NodeRef createVersionHistory(NodeRef nodeRef)
{
    HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeRef.getId());
    props.put(PROP_QNAME_VERSIONED_NODE_ID, nodeRef.getId());

    // Create a new version history node
    ChildAssociationRef childAssocRef = this.dbNodeService.createNode(
            getRootNode(),
            CHILD_QNAME_VERSION_HISTORIES,
            QName.createQName(VersionModel.NAMESPACE_URI, nodeRef.getId()),
            TYPE_QNAME_VERSION_HISTORY,
            props);
    return childAssocRef.getChildRef();
}
 
Example 4
private void writeParentAssocs(List<ChildAssociationRef> refs) throws SAXException
{
    if (refs != null)
    {
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS,
                    EMPTY_ATTRIBUTES);

        for (ChildAssociationRef assoc : refs)
        {
            writeParentAssoc(assoc);
        }

        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS);
    }
}
 
Example 5
@Override
public List<ChildAssociationRef> getChildAssocs(Reference parentReference, Set<QName> childNodeTypeQNames)
{
    List<ChildAssociationRef> allAssociations = getChildAssocs(parentReference,
                                                               RegexQNamePattern.MATCH_ALL,
                                                               RegexQNamePattern.MATCH_ALL,
                                                               Integer.MAX_VALUE,
                                                               false);

    List<ChildAssociationRef> associations = new LinkedList<>();

    for (ChildAssociationRef childAssociationRef : allAssociations)
    {
        QName childType = environment.getType(childAssociationRef.getChildRef());
        if (childNodeTypeQNames.contains(childType))
        {
            associations.add(childAssociationRef);
        }
    }

    return associations;
}
 
Example 6
/**
 * move transfer node to new parent.
 * @param childNode
 * @param newParent
 */
private void moveNode(TransferManifestNormalNode childNode, TransferManifestNormalNode newParent)
{
    List<ChildAssociationRef> currentParents = childNode.getParentAssocs();
    List<ChildAssociationRef> newParents = new ArrayList<ChildAssociationRef>();

    for (ChildAssociationRef parent : currentParents)
    {
        if (!parent.isPrimary())
        {
            newParents.add(parent);
        }
        else
        {
            ChildAssociationRef newPrimaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, newParent
                    .getNodeRef(), parent.getQName(), parent.getChildRef(), true, -1);
            newParents.add(newPrimaryAssoc);
            childNode.setPrimaryParentAssoc(newPrimaryAssoc);
            Path newParentPath = new Path();
            newParentPath.append(newParent.getParentPath());
            newParentPath.append(new Path.ChildAssocElement(newParent.getPrimaryParentAssoc()));
            childNode.setParentPath(newParentPath);
        }
    }
    childNode.setParentAssocs(newParents);
}
 
Example 7
/**
 * @return The display name for the node
 */
public String getName()
{
    if (this.name == null)
    {
        // try and get the name from the properties first
        this.name = (String)getProperties().get("cm:name");
        
        // if we didn't find it as a property get the name from the association name
        if (this.name == null)
        {
            ChildAssociationRef parentRef = this.services.getNodeService().getPrimaryParent(this.nodeRef);
            if (parentRef != null && parentRef.getQName() != null)
            {
                this.name = parentRef.getQName().getLocalName();
            }
            else
            {
                this.name = "";
            }
        }
    }
    
    return this.name;
}
 
Example 8
/**
 * Return the system container for the specified assoc name.
 * The containers are cached in a thread safe Tenant aware cache.
 *
 * @return System container, <b>which must exist</b>
 */
private NodeRef getSystemContainer(QName assocQName)
{
    final String cacheKey = KEY_SYSTEMCONTAINER_NODEREF + "." + assocQName.toString();
    NodeRef systemContainerRef = (NodeRef)singletonCache.get(cacheKey);
    if (systemContainerRef == null)
    {
        NodeRef rootNodeRef = nodeService.getRootNode(this.storeRef);
        List<ChildAssociationRef> results = nodeService.getChildAssocs(rootNodeRef, RegexQNamePattern.MATCH_ALL, qnameAssocSystem, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Required system path not found: " + qnameAssocSystem);
        }
        NodeRef sysNodeRef = results.get(0).getChildRef();
        results = nodeService.getChildAssocs(sysNodeRef, RegexQNamePattern.MATCH_ALL, assocQName, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Required path not found: " + assocQName);
        }
        systemContainerRef = results.get(0).getChildRef();
        singletonCache.put(cacheKey, systemContainerRef);
    }
    return systemContainerRef;
}
 
Example 9
/**
 * Force copy recursion after copying a rules folder
 * 
 * @return          Returns {@link ChildAssocRecurseAction#FORCE_RECURSE}
 *                  for {@link RuleModel#ASSOC_RULE_FOLDER}
 */
@Override
public ChildAssocRecurseAction getChildAssociationRecurseAction(
        QName classQName,
        CopyDetails copyDetails,
        CopyChildAssociationDetails childAssocCopyDetails)
{
    ChildAssociationRef childAssocRef = childAssocCopyDetails.getChildAssocRef();
    if (childAssocRef.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER))
    {
        return ChildAssocRecurseAction.FORCE_RECURSE;
    }
    else
    {
        super.throwExceptionForUnexpectedBehaviour(copyDetails, childAssocCopyDetails.toString());
        return null;            // Never reached
    }
}
 
Example 10
public void onCreateNode(ChildAssociationRef childAssocRef)
{
    // Restrict creation of group name that contain invalid characters.
    NodeRef authorityRef = childAssocRef.getChildRef();

    String authorityName = (String) this.nodeService.getProperty(authorityRef, ContentModel.PROP_AUTHORITY_NAME);

    if (authorityName != null)
    {
        for (char illegalCharacter : ILLEGAL_CHARACTERS)
        {
            if (authorityName.indexOf(illegalCharacter) != -1)
            {
                throw new IllegalArgumentException("Group name contains characters that are not permitted: "+authorityName.charAt(authorityName.indexOf(illegalCharacter)));
            }
        }
    }
}
 
Example 11
private void writePrimaryParent(ChildAssociationRef parentAssoc, Path parentPath) throws SAXException
{   
    writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PARENT, PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PARENT,  EMPTY_ATTRIBUTES);

    writeParentAssoc(parentAssoc);
    
    writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PATH, PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PATH,  EMPTY_ATTRIBUTES);
    if(parentPath != null)
    {  
        String path = parentPath.toString();
        writer.characters(path.toCharArray(), 0, path.length()); 
    }
    writer.endElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PATH, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_PRIMARY_PATH); 

    writer.endElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_PRIMARY_PARENT, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_PRIMARY_PARENT); 
}
 
Example 12
public NodeRef importNode(ImportNode node)
{                
    // replace existing node, if node to import has a UUID and an existing node of the same
    // uuid already exists
    String uuid = node.getUUID();
    if (uuid != null && uuid.length() > 0)
    {
        NodeRef existingNodeRef = new NodeRef(rootRef.getStoreRef(), uuid);
        if (nodeService.exists(existingNodeRef))
        {
            // remove primary parent link forcing deletion
            ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(existingNodeRef);
            nodeService.removeChild(childAssocRef.getParentRef(), childAssocRef.getChildRef());
            
            // update the parent context of the node being imported to the parent of the node just deleted
            node.getParentContext().setParentRef(childAssocRef.getParentRef());
            node.getParentContext().setAssocType(childAssocRef.getTypeQName());
        }
    }

    // import as if a new node
    return createNewStrategy.importNode(node);
}
 
Example 13
/**
 * Deny renames.
 */
public void onMoveNode(ChildAssociationRef oldChildAssocRef,
      ChildAssociationRef newChildAssocRef) 
{
   NodeRef oldParent = oldChildAssocRef.getParentRef();
   NodeRef newParent = newChildAssocRef.getParentRef();
   
   // Deny renames
   if (oldParent.equals(newParent))
   {
       QName type = nodeService.getType((oldChildAssocRef.getChildRef()));
       if (dictionaryService.isSubClass(type, SiteModel.TYPE_SITE))
       {
           throw new SiteServiceException("Sites can not be renamed.");
       }
       else
       {
           throw new SiteServiceException("Site containers can not be renamed.");
       }
   }
}
 
Example 14
/**
 * This method gets the <code>st:site</code> NodeRef for the Share Site which contains the given NodeRef.
 * If the given NodeRef is not contained within a Share Site, then <code>null</code> is returned.
 * 
 * @param nodeRef   the node whose containing site is to be found.
 * @return NodeRef  site node reference or null if node is not in a site
 */
private NodeRef getSiteNodeRef(NodeRef nodeRef)
{
    NodeRef siteNodeRef = null;        
    QName nodeRefType = directNodeService.getType(nodeRef);
    if (dictionaryService.isSubClass(nodeRefType, TYPE_SITE) == true)
    {
        siteNodeRef = nodeRef;
    }
    else
    {
        ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
        if (primaryParent != null && primaryParent.getParentRef() != null)
        {
            siteNodeRef = getSiteNodeRef(primaryParent.getParentRef());
        }
    }        
    return siteNodeRef;
}
 
Example 15
@Before
   public void before() throws Exception
   {
	// Get the required services
	this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
	this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
	this.serviceRegistry = (ServiceRegistry)this.applicationContext.getBean("ServiceRegistry");
	
	AuthenticationComponent authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
	authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
	
	// Create the store and get the root node reference
	this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
	NodeRef rootNodeRef = this.nodeService.getRootNode(storeRef);
	
	// Create folder node
	Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
	props.put(ContentModel.PROP_NAME, "TestFolder");
	ChildAssociationRef childAssocRef = this.nodeService.createNode(
			rootNodeRef,
			ContentModel.ASSOC_CHILDREN,
			QName.createQName("{test}TestFolder"),
			ContentModel.TYPE_FOLDER,
			props);
	this.folderNodeRef = childAssocRef.getChildRef();
}
 
Example 16
@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(NodeRef nodeRef, QName propertyQName,
            Serializable value)
{
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize)
    {
        Reference reference = smartStore.virtualize(nodeRef);
        List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocsByPropertyValue(reference,
                                                                                                   propertyQName,
                                                                                                   value);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference))
        {
            NodeRef materialReference = smartStore.materialize(reference);
            List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocsByPropertyValue(materialReference,
                                                                                                  propertyQName,
                                                                                                  value);
            associations.addAll(actualAssociations);
        }

        return associations;
    }
    else
    {
        return theTrait.getChildAssocsByPropertyValue(nodeRef,
                                                      propertyQName,
                                                      value);
    }
}
 
Example 17
private void verifyChildAssocExistence(ChildAssociationRef childAssocRef, boolean exists)
{
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(
            childAssocRef.getParentRef(),
            childAssocRef.getTypeQName(),
            childAssocRef.getQName());
    if (exists)
    {
        assertEquals("Expected exactly one match for child association: " + childAssocRef, 1, childAssocs.size());
    }
    else
    {
        assertEquals("Expected zero matches for child association: " + childAssocRef, 0, childAssocs.size());
    }
}
 
Example 18
@Test
@SuppressWarnings("deprecation")
public void test22Version1HomeFolderProvider() throws Exception
{
    // Should just log a message to say it can't do anything
    final String name = "v1Provider";
    HomeFolderProvider v1Provider = new HomeFolderProvider()
    {
        @Override
        public void onCreateNode(ChildAssociationRef childAssocRef)
        {
        }

        @Override
        public String getName()
        {
            return name;
        }
    };
    homeFolderManager.addProvider(v1Provider);

    createUser("a/b/c", "fred");
    
    homeFolderProviderSynchronizer.setOverrideHomeFolderProviderName(name);
    moveUserHomeFolders();

    assertHomeFolderLocation("fred", "a/b/c/fred");
}
 
Example 19
private NodeRef addContent(NodeRef spaceRef, String name, InputStream is, String mimeType)
{
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
    contentProps.put(ContentModel.PROP_NAME, name);
    
    ChildAssociationRef association = nodeService.createNode(spaceRef,
            ContentModel.ASSOC_CONTAINS, 
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), 
            ContentModel.TYPE_CONTENT,
            contentProps);
    
    NodeRef content = association.getChildRef();
    
    // add titled aspect (for Web Client display)
    Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
    titledProps.put(ContentModel.PROP_TITLE, name);
    titledProps.put(ContentModel.PROP_DESCRIPTION, name);
    this.nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
    
    ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
    
    writer.setMimetype(mimeType);
    writer.setEncoding("UTF-8");
    
    writer.putContent(is);
    
    return content;
}
 
Example 20
public void testDenyParentAssocNode() throws Exception
{
    runAs("andy");

    permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.READ),
            "andy", AccessStatus.ALLOWED));

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class[] { ChildAssociationRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));

    proxyFactory.setTargetSource(new SingletonTargetSource(o));

    Object proxy = proxyFactory.getProxy();

    try
    {
        method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
        assertNotNull(null);
    }
    catch (InvocationTargetException e)
    {

    }
}
 
Example 21
/**
 * @return The list of children of this Node that match a specific object type.
 */
public List<TemplateNode> getChildAssocsByType(String type)
{
    Set<QName> types = new HashSet<QName>(1, 1.0f);
    types.add(createQName(type));
    List<ChildAssociationRef> refs = this.services.getNodeService().getChildAssocs(this.nodeRef, types);
    List<TemplateNode> nodes = new ArrayList<TemplateNode>(refs.size());
    for (ChildAssociationRef ref : refs)
    {
        String qname = ref.getTypeQName().toString();
        nodes.add( new TemplateNode(ref.getChildRef(), this.services, this.imageResolver) );
    }
    return nodes;
}
 
Example 22
@Override
public void onCreateNode(ChildAssociationRef childAssocRef)
{
    NodeRef nodeRef = childAssocRef.getChildRef();
    Map<QName, Serializable> fromProperties = Collections.<QName, Serializable>emptyMap();
    Map<QName, Serializable> toProperties = nodeInfoFactory.getProperties(nodeRef);
    this.fromProperties = null; // Sometimes onCreateNode policy is out of order (e.g. create a person)
    setFromProperties(fromProperties);
    setToProperties(toProperties);

    appendSubAction(new NodeChange(nodeInfoFactory, namespaceService, nodeRef).
            setAction(CREATE_NODE).
            setFromProperties(fromProperties).
            setToProperties(toProperties));
}
 
Example 23
/**
 * The node will appear to be attached to the root of the version store
 *
 * @see NodeService#getParentAssocs(NodeRef, QNamePattern, QNamePattern)
 */
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern)
{
    List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
    if (qnamePattern.isMatch(rootAssocName) == true)
    {
        result.add(new ChildAssociationRef(
                ContentModel.ASSOC_CHILDREN,
                dbNodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID)),
                rootAssocName,
                nodeRef));
    }
    return result;
}
 
Example 24
protected ChildAssociationRef createContent(NodeRef parent, final String name, InputStream stream, String mimeType,
            String encoding)
{
    return createContent(parent,
                         name,
                         stream,
                         mimeType,
                         encoding,
                         ContentModel.TYPE_CONTENT);
}
 
Example 25
@Override
protected void executeImpl(final Action containingAction, final NodeRef actionedUponNodeRef)
{
    final RenditionDefinition renditionDefinition = getRenditionDefinition(containingAction);
    if (log.isDebugEnabled())
    {
        StringBuilder msg = new StringBuilder();
        msg.append("Rendering node ").append(actionedUponNodeRef).append(" with rendition definition ").append(
                    renditionDefinition.getRenditionName());
        msg.append("\n").append("  parameters:").append("\n");
        if (renditionDefinition.getParameterValues().isEmpty() == false)
        {
        	for (String paramKey : renditionDefinition.getParameterValues().keySet())
        	{
        		msg.append("    ").append(paramKey).append("=").append(renditionDefinition.getParameterValue(paramKey)).append("\n");
        	}
        }
        else
        {
        	msg.append("    [None]");
        }
        log.debug(msg.toString());
    }

    ChildAssociationRef result = executeRendition(actionedUponNodeRef, renditionDefinition);
    containingAction.setParameterValue(PARAM_RESULT, result);
}
 
Example 26
@Test
public void testCreatesFoldersForTemplatedLocation() throws Exception
{
    QName fooName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFooFolder");
    QName barName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testBarFolder");
    String fooPath = "/testFooFolder";
    String barPath = fooPath + "/testBarFolder";

    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(companyHome, ContentModel.ASSOC_CONTAINS,
                fooName);
    assertTrue("Folder " + fooPath + " should not exist!", childAssocs.isEmpty());

    QName renditionKind = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
    NodeRef sourceFolder = makeNode(companyHome, ContentModel.TYPE_FOLDER);
    NodeRef sourceNode = makeNode(sourceFolder, ContentModel.TYPE_CONTENT);
    NodeRef tempRenditionNode = makeNode(companyHome, ContentModel.TYPE_CONTENT);

    RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionKind,
                "nicks_test_engine");

    String pathTemplate = barPath + "${cwd}nick.xml";
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, pathTemplate);
    
    RenditionLocation location = 
        locationResolver.getRenditionLocation(sourceNode,renditionDef, tempRenditionNode);

    NodeRef fooNode = checkFolder(fooName, companyHome, "Foo");
    NodeRef barNode = checkFolder(barName, fooNode, "Bar");
    NodeRef finalFolderNode = checkFolder(nodeService.getPrimaryParent(sourceFolder).getQName(), barNode, "Final Folder");

    assertEquals("Final folder is not the rendition parent!", finalFolderNode, location.getParentRef());
    assertEquals("nick.xml", location.getChildName());
}
 
Example 27
/**
 * Helper to convert a path into an indexed path which uniquely identifies a node
 * 
 * @param nodeRef NodeRef
 * @param path Path
 * @return Path
 */
private Path createIndexedPath(NodeRef nodeRef, Path path)
{
    // Add indexes for same name siblings
    // TODO: Look at more efficient approach
    for (int i = path.size() - 1; i >= 0; i--)
    {
        Path.Element pathElement = path.get(i);
        if (i > 0 && pathElement instanceof Path.ChildAssocElement)
        {
            int index = 1;  // for xpath index compatibility
            String searchPath = path.subPath(i).toPrefixString(namespaceService);
            List<NodeRef> siblings = searchService.selectNodes(nodeRef, searchPath, null, namespaceService, false);
            if (siblings.size() > 1)
            {
                ChildAssociationRef childAssoc = ((Path.ChildAssocElement)pathElement).getRef();
                NodeRef childRef = childAssoc.getChildRef();
                for (NodeRef sibling : siblings)
                {
                    if (sibling.equals(childRef))
                    {
                        childAssoc.setNthSibling(index);
                        break;
                    }
                    index++;
                }
            }
        }
    }
    
    return path;
}
 
Example 28
@Override
public ChildAssociationRef getChildAssocRef(int n)
{
    ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(getNodeRef(n));
    if(primaryParentAssoc != null)
    {
        return primaryParentAssoc;
    }
    else
    {
        return null;
    }
}
 
Example 29
/**
 * @throws UnsupportedOperationException always
 */
public ChildAssociationRef createNode(
        NodeRef parentRef,
        QName assocTypeQName,
        QName assocQName,
        QName nodeTypeQName) throws InvalidNodeRefException
{
    // This operation is not supported for a version store
    throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
 
Example 30
/**
 * {@inheritDoc}
 */
@Override
public void onMoveNode(final ChildAssociationRef oldChildAssocRef, final ChildAssociationRef newChildAssocRef)
{
    // only act on active nodes which can actually be in a site
    final NodeRef movedNode = oldChildAssocRef.getChildRef();
    final NodeRef oldParent = oldChildAssocRef.getParentRef();
    final NodeRef newParent = newChildAssocRef.getParentRef();
    if (StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.equals(movedNode.getStoreRef()) && !EqualsHelper.nullSafeEquals(oldParent, newParent))
    {
        LOGGER.debug("Processing onMoveNode for {} from {} to {}", movedNode, oldChildAssocRef, newChildAssocRef);

        // check for actual move-relevant site move
        final Boolean moveRelevant = AuthenticationUtil.runAsSystem(() -> {
            final NodeRef sourceSite = this.resolveSiteForNode(oldParent);
            final NodeRef targetSite = this.resolveSiteForNode(newParent);

            ContentStore sourceStore = this.resolveStoreForSite(sourceSite);
            sourceStore = sourceStore != null ? sourceStore : this.fallbackStore;
            ContentStore targetStore = this.resolveStoreForSite(targetSite);
            targetStore = targetStore != null ? targetStore : this.fallbackStore;

            final boolean differentStores = sourceStore != targetStore;
            return Boolean.valueOf(differentStores);
        });

        if (Boolean.TRUE.equals(moveRelevant))
        {
            LOGGER.debug("Node {} was moved to a location for which content should be stored in a different store", movedNode);
            this.checkAndProcessContentPropertiesMove(movedNode);
        }
        else
        {
            LOGGER.debug("Node {} was not moved into a location for which content should be stored in a different store", movedNode);
        }
    }
}