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

The following are top voted examples for showing how to use org.alfresco.service.cmr.repository.ChildAssociationRef. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: BaseNodeServiceTest.java   View source code 6 votes vote down vote up
public void testDuplicateChildAssocCleanup() throws Exception
{
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph();
    NodeRef n1Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE,"root_p_n1")).getChildRef();
    ChildAssociationRef n1pn3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE,"n1_p_n3"));
    // Recreate the association from n1 to n3 i.e. duplicate it
    QName assocQName = QName.createQName(BaseNodeServiceTest.NAMESPACE, "dup");
    ChildAssociationRef dup1 = nodeService.addChild(
            n1pn3Ref.getParentRef(),
            n1pn3Ref.getChildRef(),
            n1pn3Ref.getTypeQName(),
            assocQName);
    ChildAssociationRef dup2 = nodeService.addChild(
            n1pn3Ref.getParentRef(),
            n1pn3Ref.getChildRef(),
            n1pn3Ref.getTypeQName(),
            assocQName);
    assertEquals("Duplicate not created", dup1, dup2);
    List<ChildAssociationRef> dupAssocs = nodeService.getChildAssocs(n1pn3Ref.getParentRef(), n1pn3Ref.getTypeQName(), assocQName);
    assertEquals("Expected duplicates", 2, dupAssocs.size());
    // Now delete the specific association
    nodeService.removeChildAssociation(dup1);
    
    setComplete();
    endTransaction();
}
 
Example 2
Project: alfresco-repository   File: AbstractNodeServiceImpl.java   View source code 6 votes vote down vote up
/**
 * @see NodeServicePolicies.OnCreateNodePolicy#onCreateNode(ChildAssociationRef)
 */
protected void invokeOnCreateNode(ChildAssociationRef childAssocRef)
{
    NodeRef childNodeRef = childAssocRef.getChildRef();
    
    if (ignorePolicy(childNodeRef))
    {
        return;
    }
    
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(childNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.OnCreateNodePolicy policy = onCreateNodeDelegate.get(childNodeRef, qnames);
    policy.onCreateNode(childAssocRef);
}
 
Example 3
Project: alfresco-data-model   File: Child.java   View source code 6 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument selectorArgument = args.get(ARG_SELECTOR);
    String selectorName = DefaultTypeConverter.INSTANCE.convert(String.class, selectorArgument.getValue(context));
    Argument parentArgument = args.get(ARG_PARENT);
    NodeRef parent = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, parentArgument.getValue(context));

    NodeRef child = context.getNodeRefs().get(selectorName);

    for (ChildAssociationRef car : context.getNodeService().getParentAssocs(child))
    {
        if (car.getParentRef().equals(parent))
        {
            return Boolean.TRUE;
        }
    }
    return Boolean.FALSE;
}
 
Example 4
Project: alfresco-repository   File: WorkflowPackageImpl.java   View source code 6 votes vote down vote up
/**
 * Finds the system folder in which all packages are stored. If this folder
 * has not been created yet then this method creates a new packages folder.
 * 
 * @return The system folder containing all workflow packages.
 */
private NodeRef findOrCreatePackagesFolder()
{
    // create simple folder in workflow system folder
    NodeRef system = getSystemWorkflowContainer();

    // TODO: Consider structuring this folder, if number of children becomes
    // an issue
    List<NodeRef> packageFolders = searchService.selectNodes(system, "./" + NamespaceService.CONTENT_MODEL_PREFIX
                + ":" + PACKAGE_FOLDER, null, namespaceService, false);
    if (packageFolders.size() > 0)
    {
        return packageFolders.get(0); // Return folder if exists.
    }
    else
    // Create new package folder
    {
        QName packageFolderName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, PACKAGE_FOLDER);
        ChildAssociationRef packageFolderAssoc = nodeService.createNode(system, ContentModel.ASSOC_CHILDREN,
                    packageFolderName, ContentModel.TYPE_SYSTEM_FOLDER);
        return packageFolderAssoc.getChildRef();
    }
}
 
Example 5
Project: alfresco-repository   File: RenditionServiceImpl.java   View source code 6 votes vote down vote up
public ChildAssociationRef getSourceNode(NodeRef renditionNode)
{
    // In normal circumstances only a node which is itself a rendition can have
    // a source node - as linked by the rn:rendition association.
    //
    // However there are some circumstances where a node which is not
    // technically a rendition can still have a source. One such example is the case
    // of thumbnail nodes created in a pre-3.3 Alfresco which have not been patched
    // to have the correct rendition aspect applied.
    // This will also occur *during* execution of the webscript patch and so the
    // decision was made not to throw an exception or log a warning if such a
    // situation is encountered.
    
    // A rendition node should have 1 and only 1 source node.
    List<ChildAssociationRef> parents = nodeService.getParentAssocs(renditionNode,
            RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
    if (parents.size() > 1)
    {
        StringBuilder msg = new StringBuilder();
        msg.append("NodeRef ")
                .append(renditionNode)
                .append(" unexpectedly has ")
                .append(parents.size())
                .append(" rendition parents.");
        if (log.isWarnEnabled())
        {
            log.warn(msg.toString());
        }
        throw new RenditionServiceException(msg.toString());
    }
    else
    {
        return parents.isEmpty() ? null : parents.get(0);
    }
}
 
Example 6
Project: alfresco-repository   File: AbstractNodeServiceImpl.java   View source code 6 votes vote down vote up
/**
 * @see NodeServicePolicies.BeforeMoveNodePolicy#beforeMoveNode(ChildAssociationRef, NodeRef)
 */
protected void invokeBeforeMoveNode(ChildAssociationRef oldChildAssocRef, NodeRef newParentRef)
{
    NodeRef childNodeRef = oldChildAssocRef.getChildRef();
    
    if (ignorePolicy(childNodeRef))
    {
        return;
    }
    
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(childNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.BeforeMoveNodePolicy policy = beforeMoveNodeDelegate.get(childNodeRef, qnames);
    policy.beforeMoveNode(oldChildAssocRef, newParentRef);
}
 
Example 7
Project: alfresco-remote-api   File: CommentsLibJs.java   View source code 6 votes vote down vote up
/**
 * Returns all comment nodes for a given node.
 * @return an array of comments.
 */
public static List<ChildAssociationRef> getComments(NodeRef node, ServiceRegistry services)
{
    List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
    
    NodeRef commentsFolder = getCommentsFolder(node, services);
    if (commentsFolder != null)
    {
        List<ChildAssociationRef> children = services.getNodeService().getChildAssocs(commentsFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
        if (!children.isEmpty())
        {
            result = children;
        }
    }
    
    return result;
}
 
Example 8
Project: alfresco-repository   File: DbNodeServiceImpl.java   View source code 6 votes vote down vote up
/**
 * Performs additional tasks associated with setting a property.
 * 
 * @return      Returns <tt>true</tt> if any work was done by this method
 */
private boolean setPropertiesCommonWork(Pair<Long, NodeRef> nodePair, Map<QName, Serializable> properties)
{
    Long nodeId = nodePair.getFirst();

    boolean changed = false;
    // cm:name special handling
    if (properties.containsKey(ContentModel.PROP_NAME))
    {
        String name = extractNameProperty(properties);
        Pair<Long, ChildAssociationRef> primaryParentAssocPair = nodeDAO.getPrimaryParentAssoc(nodeId);
        if (primaryParentAssocPair != null)
        {
            String oldName = extractNameProperty(nodeDAO.getNodeProperties(nodeId));
            String newName = DefaultTypeConverter.INSTANCE.convert(String.class, name);
            changed = setChildNameUnique(nodePair, newName, oldName);
        }
    }
    // Done
    return changed;
}
 
Example 9
Project: alfresco-repository   File: VersionServiceImplTest.java   View source code 6 votes vote down vote up
/**
 * Check that the version type property is actually set when creating a new version.
 * 
 * @see https://issues.alfresco.com/jira/browse/MNT-14681
 */
public void testVersionTypeIsSet()
{
    ChildAssociationRef childAssociation = nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
            QName.createQName("http://www.alfresco.org/test/versiontypeissettest/1.0", "versionTypeIsSetTest"), TEST_TYPE_QNAME);

    NodeRef newNode = childAssociation.getChildRef();
    assertNull(nodeService.getProperty(newNode, ContentModel.PROP_VERSION_TYPE));

    Map<String, Serializable> versionProps = new HashMap<String, Serializable>(1);
    versionProps.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);

    versionService.createVersion(newNode, versionProps);

    Serializable versionTypeProperty = nodeService.getProperty(newNode, ContentModel.PROP_VERSION_TYPE);
    assertNotNull(versionTypeProperty);
    assertTrue(versionTypeProperty.toString().equals(VersionType.MINOR.toString()));
}
 
Example 10
Project: alfresco-repository   File: ADMAccessControlListDAO.java   View source code 6 votes vote down vote up
public Long getInheritedAcl(NodeRef nodeRef)
{
    Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(nodeRef);
    if (nodePair == null)
    {
        return null;
    }
    Pair<Long, ChildAssociationRef> parentAssocRefPair = nodeDAO.getPrimaryParentAssoc(nodePair.getFirst());
    if (parentAssocRefPair == null || parentAssocRefPair.getSecond().getParentRef() == null)
    {
        return null;
    }
    Acl acl = getAccessControlList(parentAssocRefPair.getSecond().getParentRef());
    if (acl != null)
    {
        return acl.getId();
    }
    else
    {
        return null;
    }
}
 
Example 11
Project: alfresco-remote-api   File: CommentsLibJs.java   View source code 6 votes vote down vote up
/**
 * Returns the folder that contains all the comments.
 * 
 * We currently use the fm:discussable aspect where we
 * add a "Comments" topic to it.
 */
public static NodeRef getCommentsFolder(NodeRef node, ServiceRegistry services)
{
    //FIXME These methods are from the original JavaScript. Should use the (soon to arrive) CommentService.
    NodeRef result = null;
    if (services.getNodeService().hasAspect(node, ForumModel.ASPECT_DISCUSSABLE))
    {
        List<ChildAssociationRef> forumFolders = services.getNodeService().getChildAssocs(node, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
        // The JavaScript was retrieving the first child under this child-assoc so we'll do the same.
        NodeRef forumFolder = forumFolders.get(0).getChildRef();
        
        List<ChildAssociationRef> topicFolder = services.getNodeService().getChildAssocs(forumFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME));
        result = topicFolder.isEmpty() ? null : topicFolder.get(0).getChildRef();
    }
    return result;
}
 
Example 12
Project: alfresco-repository   File: VirtualStoreImpl.java   View source code 6 votes vote down vote up
@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(Reference parentReference, QName propertyQName,
            Serializable value)
{
    List<ChildAssociationRef> allAssociations = getChildAssocs(parentReference,
                                                               RegexQNamePattern.MATCH_ALL,
                                                               RegexQNamePattern.MATCH_ALL,
                                                               Integer.MAX_VALUE,
                                                               false);

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

    for (ChildAssociationRef childAssociationRef : allAssociations)
    {
        Serializable propertyValue = environment.getProperty(childAssociationRef.getChildRef(),
                                                             propertyQName);

        if ((value == null && propertyValue == null) || (value != null && value.equals(propertyValue)))
        {
            associations.add(childAssociationRef);
        }
    }

    return associations;
}
 
Example 13
Project: alfresco-repository   File: VirtualNodeServiceExtension.java   View source code 6 votes vote down vote up
@Override
public boolean removeChildAssociation(ChildAssociationRef childAssocRef)
{
    NodeServiceTrait theTrait = getTrait();

    NodeRef childRef = childAssocRef.getChildRef();
    if (Reference.fromNodeRef(childRef) != null)
    {
        List<ChildAssociationRef> assocsToRemove = revertVirtualAssociation(childAssocRef,
                                                                            theTrait,
                                                                            childRef);
        boolean removed = false;
        if (!assocsToRemove.isEmpty())
        {
            for (ChildAssociationRef assoc : assocsToRemove)
            {
                removed = removed || theTrait.removeChildAssociation(assoc);
            }
        }
        return removed;
    }
    else
    {
        return theTrait.removeChildAssociation(childAssocRef);
    }
}
 
Example 14
Project: alfresco-repository   File: BaseNodeServiceTest.java   View source code 6 votes vote down vote up
public void testCreateWithTooLongPathLocalname() throws Exception
{
    try
    {
        ChildAssociationRef assocRef = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN,
                QName.createQName("Recognize that VSEPR theory states that nonbonded electrons (lone "
                        + "pairs) exert strong electrostatic repulsive forces against the bonded pairs "
                        + "of electrons and, as a result, the electron pairs arrange themselves as far "
                        + "apart as possible in order to minimize the repulsive forces"),
                ContentModel.TYPE_CONTAINER);
        fail("Expected too-long QName localname to have been kicked out as illegal argument.");
    }
    catch (IllegalArgumentException e)
    {
        // Expected
    }
}
 
Example 15
Project: alfresco-repository   File: SystemNodeUtils.java   View source code 6 votes vote down vote up
/**
 * Returns the System Container for the current tenant
 */
public static NodeRef getSystemContainer(final NodeService nodeService, final Repository repositoryHelper)
{
    // Grab the root of the repository, for the current tennant
    final NodeRef root = repositoryHelper.getRootHome();

    // Locate the system folder, in the root 
    List<ChildAssociationRef> sysRefs = nodeService.getChildAssocs(
            root, ContentModel.ASSOC_CHILDREN, SYSTEM_FOLDER_QNAME);
    if (sysRefs.size() != 1)
    {
        throw new IllegalStateException("System folder missing / duplicated! Found " + sysRefs);
    }
    final NodeRef system = sysRefs.get(0).getChildRef();
    
    return system;
}
 
Example 16
Project: alfresco-repository   File: CheckOutCheckInServiceImplTest.java   View source code 6 votes vote down vote up
/**
 * Test when the aspect is not set when check-in is performed
 */
public void testVersionAspectNotSetOnCheckIn()
{
    // Create a bag of props
    Map<QName, Serializable> bagOfProps = createTypePropertyBag();
    bagOfProps.put(ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "UTF-8"));

    // Create a new node 
    ChildAssociationRef childAssocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("test"),
            ContentModel.TYPE_CONTENT,
            bagOfProps);
    NodeRef noVersionNodeRef = childAssocRef.getChildRef();
    
    // Check out and check in
    NodeRef workingCopy = cociService.checkout(noVersionNodeRef);
    cociService.checkin(workingCopy, new HashMap<String, Serializable>());
    
    // Check that the origional node has no version history dispite sending verion props
    assertNull(this.versionService.getVersionHistory(noVersionNodeRef));        
}
 
Example 17
Project: alfresco-repository   File: VirtualNodeServiceExtension.java   View source code 6 votes vote down vote up
@Override
public ChildAssociationRef moveNode(NodeRef nodeToMoveRef, NodeRef newParentRef, QName assocTypeQName,
            QName assocQName)
{
    if ((Reference.fromNodeRef(nodeToMoveRef) != null)|| (Reference.fromNodeRef(newParentRef) != null))
    {
        throw new UnsupportedOperationException("Unsuported operation for virtual source or destination");
    }
    else
    {
        return getTrait().moveNode(nodeToMoveRef,
                                   newParentRef,
                                   assocTypeQName,
                                   assocQName);
    }
}
 
Example 18
Project: alfresco-repository   File: VirtualizationIntegrationTest.java   View source code 6 votes vote down vote up
protected ChildAssociationRef createContent(NodeRef parent, final String name, String contentString,
            String mimeType, String encoding)
{
    ChildAssociationRef nodeAssoc = createTypedNode(parent,
                                                    name,
                                                    ContentModel.TYPE_CONTENT);
    NodeRef child = nodeAssoc.getChildRef();
    ContentWriter writer = contentService.getWriter(child,
                                                    ContentModel.PROP_CONTENT,
                                                    true);

    writer.setMimetype(mimeType);
    writer.setEncoding(encoding);
    writer.putContent(contentString);
    return nodeAssoc;
}
 
Example 19
Project: alfresco-repository   File: QuickShareServiceImpl.java   View source code 6 votes vote down vote up
@Override
public void onRestoreNode(ChildAssociationRef childAssocRef)
{
    final NodeRef childNodeRef = childAssocRef.getChildRef();
    AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
    {
        public Void doWork() throws Exception
        {
            if (nodeService.hasAspect(childNodeRef, QuickShareModel.ASPECT_QSHARE))
            {
                // Disable audit to preserve modifier and modified date
                behaviourFilter.disableBehaviour(childNodeRef, ContentModel.ASPECT_AUDITABLE);
                try
                {
                    nodeService.removeAspect(childNodeRef, QuickShareModel.ASPECT_QSHARE);
                }
                finally
                {
                    behaviourFilter.enableBehaviour(childNodeRef, ContentModel.ASPECT_AUDITABLE);
                }
            }
            return null;
        }
    });
}
 
Example 20
Project: alfresco-repository   File: NodeHierarchyWalker.java   View source code 6 votes vote down vote up
private VisitedNode(
        Long id,
        NodeRef nodeRef,
        QName type,
        Long aclId,
        Pair<Long, ChildAssociationRef> primaryParentAssocPair)
{
    this.id = id;
    this.nodeRef = nodeRef;
    this.nodeType = type;
    this.aclId = aclId;
    this.primaryParentAssocPair = primaryParentAssocPair;
    this.secondaryParentAssocs = new ArrayList<Pair<Long,ChildAssociationRef>>(17);
    this.secondaryChildAssocs = new ArrayList<Pair<Long,ChildAssociationRef>>(17);
    this.targetAssocs = new ArrayList<Pair<Long,AssociationRef>>();
    this.sourceAssocs = new ArrayList<Pair<Long,AssociationRef>>();
}
 
Example 21
Project: alfresco-repository   File: VirtualNodeServiceExtensionTest.java   View source code 6 votes vote down vote up
protected void assertAssocNames(List<ChildAssociationRef> assocs, QName... expectedNames)
{
    List<QName> actualNames = new LinkedList<>();
    for (ChildAssociationRef childAssociationRef : assocs)
    {
        actualNames.add(childAssociationRef.getQName());
    }

    assertEquals(expectedNames.length,
                 actualNames.size());
    for (int i = 0; i < expectedNames.length; i++)
    {
        assertTrue(expectedNames[i] + " assoc name was expected  within " + actualNames,
                   actualNames.contains(expectedNames[i]));
        actualNames.remove(expectedNames[i]);
    }
}
 
Example 22
Project: alfresco-remote-api   File: TestCMIS.java   View source code 6 votes vote down vote up
private NodeRef makeRenditionNode(NodeRef parent, String title, String name, String mimetype)
  {
      Map<QName, Serializable> props = new HashMap<QName, Serializable>();
      props.put(ContentModel.PROP_NAME, name);
      props.put(ContentModel.PROP_TITLE, title);
      QName assocQName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, name);
      ChildAssociationRef assoc = nodeService.createNode(parent, RenditionModel.ASSOC_RENDITION,
          assocQName, ContentModel.TYPE_THUMBNAIL, props);
      NodeRef childRef = assoc.getChildRef();

      if (!nodeService.hasAspect(parent, RenditionModel.ASPECT_RENDITIONED))
      {
          nodeService.addAspect(parent, RenditionModel.ASPECT_RENDITIONED, null);
      }

      ContentWriter writer = contentService.getWriter(childRef, ContentModel.PROP_CONTENT, true);
      writer.setMimetype(mimetype);
      writer.setEncoding("UTF-8");
writer.putContent("Dummy "+name+" content");

      return childRef;
  }
 
Example 23
Project: alfresco-repository   File: BaseNodeServiceTest.java   View source code 6 votes vote down vote up
/**
 * Tests node creation with a pre-determined {@link ContentModel#PROP_NODE_UUID uuid}.
 */
public void testCreateNodeWithId() throws Exception
{
    String uuid = GUID.generate();
    // create a node with an explicit UUID
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>(5);
    properties.put(ContentModel.PROP_NODE_UUID, uuid);
    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName("pathA"),
            ContentModel.TYPE_CONTAINER,
            properties);
    // check it
    NodeRef expectedNodeRef = new NodeRef(rootNodeRef.getStoreRef(), uuid);
    NodeRef checkNodeRef = assocRef.getChildRef();
    assertEquals("Failed to create node with a chosen ID", expectedNodeRef, checkNodeRef);
}
 
Example 24
Project: alfresco-repository   File: BufferedContentDiskDriver.java   View source code 5 votes vote down vote up
@Override
public void onDeleteNode(ChildAssociationRef oldChildAssocRef, boolean isArchived)
{
    if(fileInfoCache.contains(oldChildAssocRef.getChildRef()))
    {
        logger.debug("cached node deleted - clear the cache");
        fileInfoCache.clear();
    }
}
 
Example 25
Project: alfresco-repository   File: XSLTFunctions.java   View source code 5 votes vote down vote up
public Map<String, Document> parseXMLDocuments(final String typeName, NodeRef rootNode, String repoPath)
        throws IOException, SAXException
{
    final Map<String, Document> result = new TreeMap<String, Document>();

    String[] pathElements = breakDownPath(repoPath);

    try
    {
        FileInfo file = fileService.resolveNamePath(rootNode, Arrays.asList(pathElements));

        if (file.isFolder())
        {
            QName typeQName = QName.createQName(typeName, namespaceService);
            Set<QName> types = new HashSet<QName>(dictionaryService.getSubTypes(typeQName, true));
            types.add(typeQName);
            List<ChildAssociationRef> children = nodeService.getChildAssocs(file.getNodeRef(), types);
            for (ChildAssociationRef child : children)
            {
                String name = (String) nodeService.getProperty(child.getChildRef(), ContentModel.PROP_NAME);
                Document doc = XMLUtil.parse(child.getChildRef(), contentService);
                result.put(name, doc);
            }
        }
    }
    catch (Exception ex)
    {
        log.warn("Unexpected exception caught in call to parseXMLDocuments", ex);
    }
    return result;
}
 
Example 26
Project: alfresco-repository   File: DbNodeServiceImpl.java   View source code 5 votes vote down vote up
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public boolean removeChildAssociation(ChildAssociationRef childAssocRef)
{
    // The node(s) involved may not be pending deletion
    checkPendingDelete(childAssocRef.getParentRef());
    checkPendingDelete(childAssocRef.getChildRef());
    
    Long parentNodeId = getNodePairNotNull(childAssocRef.getParentRef()).getFirst();
    Long childNodeId = getNodePairNotNull(childAssocRef.getChildRef()).getFirst();
    QName assocTypeQName = childAssocRef.getTypeQName();
    QName assocQName = childAssocRef.getQName();
    Pair<Long, ChildAssociationRef> assocPair = nodeDAO.getChildAssoc(
            parentNodeId, childNodeId, assocTypeQName, assocQName);
    if (assocPair == null)
    {
        // No association exists
        return false;
    }
    Long assocId = assocPair.getFirst();
    ChildAssociationRef assocRef = assocPair.getSecond();
    if (assocRef.isPrimary())
    {
        NodeRef childNodeRef = assocRef.getChildRef();
        // Delete the child node
        this.deleteNode(childNodeRef);
        // Done
        return true;
    }
    else
    {
        // Delete the association
        invokeBeforeDeleteChildAssociation(childAssocRef);
        nodeDAO.deleteChildAssoc(assocId);
        invokeOnDeleteChildAssociation(childAssocRef);
        // Index
        nodeIndexer.indexDeleteChildAssociation(childAssocRef);
        // Done
        return true;
    }
}
 
Example 27
Project: alfresco-repository   File: CreateNodeRuleTrigger.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void onCreateNode(ChildAssociationRef childAssocRef)
{
    // Break out early if rules are not enabled
    if (!areRulesEnabled())
    {
        return;
    }
    NodeRef nodeRef = childAssocRef.getChildRef();
    
    // Keep track of new nodes to prevent firing of updates in the same transaction
    Set<NodeRef> newNodeRefSet = TransactionalResourceHelper.getSet(RULE_TRIGGER_NEW_NODES);
    newNodeRefSet.add(nodeRef);
    
    if (nodeRef != null && 
        nodeService.exists(nodeRef) == true &&
        nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT) == false)
    {
        NodeRef parentNodeRef = childAssocRef.getParentRef();
        
        if (logger.isDebugEnabled() == true)
        {
            logger.debug(
                    "Create node rule trigger fired for parent node " + 
                    this.nodeService.getType(parentNodeRef).toString() + " " + parentNodeRef + 
                    " and child node " +
                    this.nodeService.getType(nodeRef).toString() + " " + nodeRef);
        }
        
        triggerRules(parentNodeRef, nodeRef);
    }
}
 
Example 28
Project: alfresco-repository   File: WellKnownNodes.java   View source code 5 votes vote down vote up
/**
 * Returns the given System Container
 */
public NodeRef getSystemContainer(QName containerName)
{
    NodeRef system = getSystemRoot();
    List<ChildAssociationRef> containerRefs = nodeService.getChildAssocs(
            system, ContentModel.ASSOC_CHILDREN, containerName);
    if (containerRefs.size() != 1)
    {
        throw new IllegalStateException("System Container " + containerName + " missing / duplicated! Found " + containerRefs);
    }
    final NodeRef container = containerRefs.get(0).getChildRef();
    return container;
}
 
Example 29
Project: alfresco-repository   File: ACLEntryVoterTest.java   View source code 5 votes vote down vote up
public void testMultiChildAssocRefMethodsArg2() throws Exception
{
    runAs("andy");

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

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.2.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    method.invoke(proxy, new Object[] { null, null, null, null });

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

    }

    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ),
            "andy", AccessStatus.ALLOWED));
    method.invoke(proxy, new Object[] { null, null, nodeService.getPrimaryParent(rootNodeRef), null });
}
 
Example 30
Project: alfresco-repository   File: ApplyTemplateMethodTest.java   View source code 5 votes vote down vote up
@Test
public void testExecute_vanillaRepositoryJSON() throws Exception
{
    ChildAssociationRef templateAssoc = createContent(testRootFolder.getNodeRef(),
                                                      "template1.json",
                                                      ApplyTemplateMethodTest.class
                                                                  .getResourceAsStream(TEST_TEMPLATE_1_JSON_NAME),
                                                      MimetypeMap.MIMETYPE_JSON,
                                                      StandardCharsets.UTF_8.name());
    ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);

    NewVirtualReferenceMethod newVirtualReferenceMethod = new NewVirtualReferenceMethod(templateAssoc.getChildRef(),
                                                                                        "/",
                                                                                        virtualFolder1NodeRef,
                                                                                        VANILLA_PROCESSOR_JS_CLASSPATH);
    Reference ref = Protocols.VANILLA.protocol.dispatch(newVirtualReferenceMethod,
                                                        null);
    VirtualFolderDefinition structure = ref.execute(applyTemplateMethod);

    String templateName = structure.getName();
    assertEquals("Test",
                 templateName);

    List<VirtualFolderDefinition> children = structure.getChildren();
    assertEquals(2,
                 children.size());

    VirtualFolderDefinition child1 = structure.findChildByName("Node1");
    assertTrue(child1 != null);

    VirtualFolderDefinition child2 = structure.findChildByName("Node2");
    assertTrue(child2 != null);

}
 
Example 31
Project: alfresco-remote-api   File: NodeBrowserPost.java   View source code 5 votes vote down vote up
public Node(NodeRef nodeRef)
{
    this.nodeRef = nodeRef;
    Path path = getNodeService().getPath(nodeRef);
    this.qnamePath = path.toString();
    this.prefixedQNamePath = path.toPrefixString(getNamespaceService());
    this.parentNodeRef = getPrimaryParent(nodeRef);
    ChildAssociationRef ref = getNodeService().getPrimaryParent(nodeRef);
    this.childAssoc = ref.getQName() != null ? new QNameBean(ref.getQName()) : null;
    this.type = new QNameBean(getNodeService().getType(nodeRef));
}
 
Example 32
Project: alfresco-repository   File: VirtualNodeServiceExtension.java   View source code 5 votes vote down vote up
@Override
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef)
{
    if (Reference.fromNodeRef(nodeRef)!= null)
    {
        return getParentAssocs(nodeRef,
                               RegexQNamePattern.MATCH_ALL,
                               RegexQNamePattern.MATCH_ALL);
    }
    else
    {
        return getTrait().getParentAssocs(nodeRef);
    }
}
 
Example 33
Project: alfresco-repository   File: MultilingualContentServiceImpl.java   View source code 5 votes vote down vote up
/**
 * Does the work of making the translation a simple node again.  No parent-child relationships
 * are modified and the pivot-container logic is not done here.
 * 
 * @param translationNodeRef                a translation
 */
private void unmakeTranslationSimple(NodeRef translationNodeRef)
{      
    try
    {
        this.policyBehaviourFilter.disableBehaviour(ContentModel.TYPE_MULTILINGUAL_CONTAINER);
        if (nodeService.hasAspect(translationNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
        {
            nodeService.removeAspect(translationNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION);
            nodeService.addAspect(translationNodeRef, ContentModel.ASPECT_TEMPORARY, null);
        }
        else
        {
            if (nodeService.hasAspect(translationNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
            {
                nodeService.removeAspect(translationNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
            }
        }
        List<ChildAssociationRef> assocRefs = nodeService.getParentAssocs(
                translationNodeRef,
                ContentModel.ASSOC_MULTILINGUAL_CHILD, 
                RegexQNamePattern.MATCH_ALL);
        if (assocRefs.size() != 1)
        {
            throw new AlfrescoRuntimeException(
                    "Unable to remove ASSOC_MULTILINGUAL_CHILD on : " + translationNodeRef.toString());
        }
    }
    finally
    {
        this.policyBehaviourFilter.enableBehaviour(ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    }
}
 
Example 34
Project: alfresco-repository   File: AuthorityDAOImpl.java   View source code 5 votes vote down vote up
public Set<String> getAuthorityZones(String name)
{
    Set<String> zones = new TreeSet<String>();
    NodeRef childRef = getAuthorityOrNull(name);
    if (childRef == null)
    {
        return null;
    }
    List<ChildAssociationRef> results = nodeService.getParentAssocs(childRef, ContentModel.ASSOC_IN_ZONE, RegexQNamePattern.MATCH_ALL);
    if (results.isEmpty())
    {
        return zones;
    }

    for (ChildAssociationRef current : results)
    {
        NodeRef zoneRef = current.getParentRef();
        Serializable value = nodeService.getProperty(zoneRef, ContentModel.PROP_NAME);
        if (value == null)
        {
            continue;
        }
        else
        {
            String zone = DefaultTypeConverter.INSTANCE.convert(String.class, value);
            zones.add(zone);
        }
    }
    return zones;
}
 
Example 35
Project: alfresco-repository   File: MultilingualContentServiceImpl.java   View source code 5 votes vote down vote up
/** {@inheritDoc} */
public Map<Locale, NodeRef> getTranslations(NodeRef translationOfNodeRef)
{
    NodeRef mlContainerNodeRef = null;
    // Were we given the translation or the container
    QName typeQName = nodeService.getType(translationOfNodeRef);
    if (typeQName.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
    {
        // We have the container
        mlContainerNodeRef = translationOfNodeRef;
    }
    else
    {
        // Get the container
        mlContainerNodeRef = getOrCreateMLContainer(translationOfNodeRef, false);
    }
    // Get all the children
    List<ChildAssociationRef> assocRefs = nodeService.getChildAssocs(
            mlContainerNodeRef,
            ContentModel.ASSOC_MULTILINGUAL_CHILD,
            RegexQNamePattern.MATCH_ALL);
    // Iterate over them and build the map
    Map<Locale, NodeRef> nodeRefsByLocale = new HashMap<Locale, NodeRef>(13);
    for (ChildAssociationRef assocRef : assocRefs)
    {
        NodeRef nodeRef = assocRef.getChildRef();
        // Get the locale
        Locale locale = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
        // Map it
        nodeRefsByLocale.put(locale, nodeRef);
    }
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug("Found all translations: \n" +
                "   Node: " + translationOfNodeRef + " (type " + typeQName + ")\n" +
                "   Map: " + nodeRefsByLocale);
    }
    return nodeRefsByLocale;
}
 
Example 36
Project: alfresco-repository   File: AbstractRenderingEngine.java   View source code 5 votes vote down vote up
/**
 * Lazily instantiation of the ChildAssociationRef
 * @return ChildAssociationRef
 */
public synchronized ChildAssociationRef getChildAssociationRef()
{
    if (this.caNodeRef == null)
    {
        this.caNodeRef = createRenditionNodeAssoc(sourceNode, definition);
    }
    return this.caNodeRef;
}
 
Example 37
Project: alfresco-repository   File: TaggingServiceImpl.java   View source code 5 votes vote down vote up
/**
 * Called after a copy / delete / move, to trigger a 
 *  tag scope update of all the tags on the node.
 * Will update all parent tag scopes for the node, by either 
 *  adding or removing all tags from the node (based on the 
 *  isAdd parameter).
 */
private void updateAllScopeTags(NodeRef nodeRef, Boolean isAdd)
{
   ChildAssociationRef assocRef = this.nodeService.getPrimaryParent(nodeRef);
   if (assocRef != null)
   {
      updateAllScopeTags(nodeRef, assocRef.getParentRef(), isAdd);
   }
}
 
Example 38
Project: alfresco-repository   File: SolrJSONResultSet.java   View source code 5 votes vote down vote up
@Override
public List<ChildAssociationRef> getChildAssocRefs()
{
    ArrayList<ChildAssociationRef> refs = new ArrayList<ChildAssociationRef>(page.size());
    for(int i = 0; i < page.size(); i++ )
    {
        refs.add( getChildAssocRef(i));
    }
    return refs;
}
 
Example 39
Project: alfresco-repository   File: NodeIndexer.java   View source code 5 votes vote down vote up
public void indexCreateChildAssociation(ChildAssociationRef childAssocRef)
{
    if (enabled && started)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("indexCreateChildAssociation: " + childAssocRef, new Exception("Stack Trace"));
        }
        indexer.createChildRelationship(childAssocRef);
    }
}
 
Example 40
Project: alfresco-repository   File: RulesAspect.java   View source code 5 votes vote down vote up
/**
 * The rule folder & below will be deleted automatically in the normal way, so we don't need to worry about them.
 * But we need additional handling for any other folders which have rules linked to this folder's rules. See
 * ALF-11923, ALF-15262.
 * 
 * @see org.alfresco.repo.node.NodeServicePolicies.BeforeRemoveAspectPolicy#beforeRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
 */
@Override
public void beforeRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
{
    if (!aspectTypeQName.equals(RuleModel.ASPECT_RULES))
    {
        return;
    }

    this.ruleService.disableRules(nodeRef);
    try
    {
        for (ChildAssociationRef childAssocRef : nodeService.getChildAssocs(nodeRef, RuleModel.ASSOC_RULE_FOLDER,
                RuleModel.ASSOC_RULE_FOLDER, false))
        {
            // We are only interested in the deletion of primary associations to a rule folder, which usually
            // happens when all rules in a folder are deleted and the ASPECT_RULES aspect is removed
            if (!childAssocRef.isPrimary())
            {
                continue;
            }
            NodeRef savedRuleFolderRef = childAssocRef.getChildRef();
            // Cascade the removal to all secondary (linked) parents
            List<ChildAssociationRef> linkedAssocs = nodeService.getParentAssocs(savedRuleFolderRef);
            for (ChildAssociationRef linkAssoc : linkedAssocs)
            {
                if (!linkAssoc.isPrimary())
                {
                    // Remove the aspect from linked parents; this will also delete the linking secondary
                    // association
                    nodeService.removeAspect(linkAssoc.getParentRef(), RuleModel.ASPECT_RULES);
                }
            }
        }
    }
    finally
    {
        this.ruleService.enableRules(nodeRef);
    }
}