org.alfresco.service.cmr.repository.AssociationRef Java Examples

The following examples show how to use org.alfresco.service.cmr.repository.AssociationRef. 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
Source File: XMLTransferManifestWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void writeSourceAssocs(List<AssociationRef> refs) throws SAXException
{
    if (refs != null)
    {
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS,
                    EMPTY_ATTRIBUTES);

        for (AssociationRef assoc : refs)
        {
            writeAssoc(assoc);
        }
        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS);
    }
}
 
Example #2
Source File: CheckOutCheckInServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
public NodeRef getCheckedOut(NodeRef nodeRef)
{
    NodeRef original = null;
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
    {
        List<AssociationRef> assocs = nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
        // It is a 1:1 relationship
        if (assocs.size() == 0)
        {
            logger.warn("Found node with cm:workingcopy aspect but no association.  Current node state: " + nodeService.getNodeStatus(nodeRef));
        }
        else if (assocs.size() > 1)
        {
            logger.warn("Found multiple " + ContentModel.ASSOC_WORKING_COPY_LINK + " association to node: " + nodeRef);
        }
        else
        {
            original = assocs.get(0).getSourceRef();
        }
    }
    
    return original;
}
 
Example #3
Source File: CheckOutCheckInServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
public NodeRef getWorkingCopy(NodeRef nodeRef)
{
    NodeRef workingCopy = null;
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT))
    {
        List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
        // It is a 1:1 relationship
        if (assocs.size() == 0)
        {
            logger.warn("Found node with cm:checkedOut aspect but no association.  Current node state: " + nodeService.getNodeStatus(nodeRef));
        }
        else if (assocs.size() > 1)
        {
            logger.warn("Found multiple " + ContentModel.ASSOC_WORKING_COPY_LINK + " association from node: " + nodeRef);
        }
        else
        {
            workingCopy = assocs.get(0).getTargetRef();
        }
    }
    
    return workingCopy;
}
 
Example #4
Source File: Version2ServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Freeze associations
 *
 * @param versionNodeRef   the version node reference
 * @param associations     the list of associations
 * 
 * @since 3.3 (Ent)
 */
private void freezeAssociations(NodeRef versionNodeRef, List<AssociationRef> associations)
{
    for (AssociationRef targetAssocRef : associations)
    {
        HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
        
        QName sourceTypeRef = nodeService.getType(targetAssocRef.getSourceRef());
        
        NodeRef targetRef = targetAssocRef.getTargetRef();
        
        // Set the reference property to point to the target node
        properties.put(ContentModel.PROP_REFERENCE, targetRef);
        properties.put(Version2Model.PROP_QNAME_ASSOC_DBID, targetAssocRef.getId());
        
        // Create peer version reference
        dbNodeService.createNode(
                versionNodeRef,
                Version2Model.CHILD_QNAME_VERSIONED_ASSOCS,
                targetAssocRef.getTypeQName(),
                sourceTypeRef,
                properties);
    }
}
 
Example #5
Source File: WorkingCopyAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * onDeleteAssociation policy behaviour If the node has the aspect ASPECT_CMIS_CREATED_CHECKEDOUT and ASSOC_WORKING_COPY_LINK association is deleted, delete the node. Fix for MNT-14850.
 * 
 * @param nodeAssocRef ASSOC_WORKING_COPY_LINK association where the source is the checkedOut node and the target is the workingCopy
 */
public void onDeleteCmisCreatedCheckoutWorkingCopyAssociation(AssociationRef nodeAssocRef)
{
    NodeRef checkedOutNodeRef = nodeAssocRef.getSourceRef();
    policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
    try
    {

        nodeService.deleteNode(checkedOutNodeRef);
    }
    finally
    {
        policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
    }

}
 
Example #6
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
        throws InvalidNodeRefException
{
    // The node(s) involved may not be pending deletion
    checkPendingDelete(sourceRef);
    checkPendingDelete(targetRef);
    
    Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef);
    Long sourceNodeId = sourceNodePair.getFirst();
    Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef);
    Long targetNodeId = targetNodePair.getFirst();

    AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
    // Invoke policy behaviours
    invokeBeforeDeleteAssociation(assocRef);

    // delete it
    int assocsDeleted = nodeDAO.removeNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName);
    
    if (assocsDeleted > 0)
    {
        // Invoke policy behaviours
        invokeOnDeleteAssociation(assocRef);
    }
}
 
Example #7
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
{
	Reference targetReference = Reference.fromNodeRef(targetRef);
    if (targetReference != null
                && getTrait().getType(materializeIfPossible(sourceRef)).equals(DownloadModel.TYPE_DOWNLOAD))
    {
        // NOTE : this is enables downloads of virtual structures
        createDownloadAssociation(sourceRef,
                                  targetRef);

        AssociationRef assocRef = new AssociationRef(sourceRef,
                                                     assocTypeQName,
                                                     targetRef);
        return assocRef;
    }
    else
    {
        return getTrait().createAssociation(materializeIfPossible(sourceRef),
                                            materializeIfPossible(targetRef),
                                            assocTypeQName);
    }
}
 
Example #8
Source File: ContentModelFormProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void updateAssociations(NodeService nodeService)
{
    List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
    for (AssociationRef assoc : existingAssocs)
    {
        if (assoc.getTargetRef().equals(targetNodeRef))
        {
            if (logger.isWarnEnabled())
            {
                logger.warn("Attempt to add existing association prevented. " + assoc);
            }
            return;
        }
    }
    nodeService.createAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
 
Example #9
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testGetSourceAssocs() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    NodeRef targetRef = assocRef.getTargetRef();
    QName qname = assocRef.getTypeQName();
    // get the source assocs
    List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(targetRef, qname);
    assertEquals("Incorrect number of source assocs", 1, sourceAssocs.size());
    assertTrue("Source not found", sourceAssocs.contains(assocRef));
    
    // Check that IDs are present
    for (AssociationRef sourceAssoc : sourceAssocs)
    {
        assertNotNull("Association does not have ID", sourceAssoc.getId());
    }
}
 
Example #10
Source File: AbstractNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see NodeServicePolicies.OnDeleteAssociationPolicy#onDeleteAssociation(AssociationRef)
 */
protected void invokeOnDeleteAssociation(AssociationRef nodeAssocRef)
{
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    
    if (ignorePolicy(sourceNodeRef))
    {
        return;
    }
    
    QName assocTypeQName = nodeAssocRef.getTypeQName();
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(sourceNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.OnDeleteAssociationPolicy policy = onDeleteAssociationDelegate.get(sourceNodeRef, qnames, assocTypeQName);
    policy.onDeleteAssociation(nodeAssocRef);
}
 
Example #11
Source File: NodeBrowserPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the current source associations
 * 
 * @return associations
 */
public List<PeerAssociation> getSourceAssocs(NodeRef nodeRef)
{
    List<AssociationRef> refs = null;
    try
    {
        refs = getNodeService().getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
    }
    catch (UnsupportedOperationException err)
    {
       // some stores do not support associations
       // but we doesn't want NPE in code below
       refs = new ArrayList<AssociationRef>(); 
    }
    List<PeerAssociation> assocs = new ArrayList<PeerAssociation>(refs.size());
    for (AssociationRef ref : refs)
    {
        assocs.add(new PeerAssociation(ref.getTypeQName(), ref.getSourceRef(), ref.getTargetRef()));
    }
    return assocs;
}
 
Example #12
Source File: AbstractNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see NodeServicePolicies.BeforeDeleteAssociationPolicy#beforeDeleteAssociation(AssociationRef)
 */
protected void invokeBeforeDeleteAssociation(AssociationRef nodeAssocRef)
{
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    
    if (ignorePolicy(sourceNodeRef))
    {
        return;
    }
    
    QName assocTypeQName = nodeAssocRef.getTypeQName();
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(sourceNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.BeforeDeleteAssociationPolicy policy = beforeDeleteAssociationDelegate.get(sourceNodeRef, qnames, assocTypeQName);
    policy.beforeDeleteAssociation(nodeAssocRef);
}
 
Example #13
Source File: NodeServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Tests get target associations by property value.</p>
 * See <b>MNT-14504</b> for more details.
 */
@Test
public void testGetTargetAssocsByPropertyValue()
{
    // Create a new versionable node
    NodeRef versionableNode = createNewVersionableNode();

    QName propertyQName = PROP_1;
    Serializable propertyValue = VALUE_1;
    // Store the current details of the target associations
    List<AssociationRef> origAssocs = this.dbNodeService.getTargetAssocsByPropertyValue(versionableNode, RegexQNamePattern.MATCH_ALL,
            propertyQName, propertyValue);

    // Create a new version
    Version version = createVersion(versionableNode, this.versionProperties);

    List<AssociationRef> assocs = this.versionStoreNodeService.getTargetAssocsByPropertyValue(version.getFrozenStateNodeRef(),
            RegexQNamePattern.MATCH_ALL, propertyQName, propertyValue);
    assertNotNull(assocs);
    assertEquals(origAssocs.size(), assocs.size());
}
 
Example #14
Source File: PolicyScope.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get associations
 * 
 * @param classRef QName
 */
public List<AssociationRef> getAssociations(QName classRef) 
{
	List<AssociationRef> result = null;
	if (classRef.equals(this.classRef) == true)
	{
		result = getAssociations();
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails != null)
		{
			result = aspectDetails.getAssociations();
		}
	}
	
	return result;
}
 
Example #15
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testGetNull()
{
    assertNull(tenantService.getName((NodeRef)null));
    assertNull(tenantService.getName((String)null));
    assertNull(tenantService.getName((StoreRef) null));
    assertNull(tenantService.getName("", (StoreRef) null));
    assertNull(tenantService.getName((ChildAssociationRef) null));
    assertNull(tenantService.getName((AssociationRef) null));
    assertNull(tenantService.getName((NodeRef)null,(NodeRef)null));
    assertNull(tenantService.getBaseName((StoreRef) null));
    assertNull(tenantService.getBaseName((AssociationRef) null));
    assertNull(tenantService.getBaseName((ChildAssociationRef) null, false));
    assertNull(tenantService.getBaseName((String)null, false));
    tenantService.checkDomain((String)null);
}
 
Example #16
Source File: PolicyScope.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Add an association
 * 
 * @param classRef QName
 * @param nodeAssocRef AssociationRef
 */
public void addAssociation(QName classRef, AssociationRef nodeAssocRef)
{
	if (classRef.equals(this.classRef) == true)
	{
		addAssociation(nodeAssocRef);
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails == null)
		{
			// Add the aspect
			aspectDetails = addAspect(classRef);
		}
		aspectDetails.addAssociation(nodeAssocRef);
	}
}
 
Example #17
Source File: NodeServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test getAssociationTargets
 */
@Test
public void testGetAssociationTargets()
{
    // Create a new versionable node
    NodeRef versionableNode = createNewVersionableNode();
    
    // Store the current details of the target associations
    List<AssociationRef> origAssocs = this.dbNodeService.getTargetAssocs(
            versionableNode,
            RegexQNamePattern.MATCH_ALL);
    
    // Create a new version
    Version version = createVersion(versionableNode, this.versionProperties);
    
    List<AssociationRef> assocs = this.versionStoreNodeService.getTargetAssocs(
            version.getFrozenStateNodeRef(), 
            RegexQNamePattern.MATCH_ALL);
    assertNotNull(assocs);
    assertEquals(origAssocs.size(), assocs.size());
}
 
Example #18
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testDuplicateAssociationDetection() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    NodeRef targetRef = assocRef.getTargetRef();
    QName qname = assocRef.getTypeQName();
    try
    {
        // attempt repeat
        nodeService.createAssociation(sourceRef, targetRef, qname);
        fail("Duplicate assocation not detected");
    }
    catch (AssociationExistsException e)
    {
        // expected
    }
}
 
Example #19
Source File: CopyServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Callback behaviour for the 'original' assoc ('copiedfrom' aspect).
 */
public void beforeDeleteOriginalAssociation(AssociationRef nodeAssocRef)
{
    // Remove the cm:copiedfrom aspect
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    // We are about to modify a copied node.  For this specific action, we do not
    // want to leave any trace of the action as it's a task invisible to the end-user.
    try
    {
        behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_LOCKABLE);
        behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
        internalNodeService.removeAspect(sourceNodeRef, ContentModel.ASPECT_COPIEDFROM);
    }
    finally
    {
        behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_LOCKABLE);
        behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
    }
}
 
Example #20
Source File: XMLTransferManifestWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void writeTargetAssocs(List<AssociationRef> refs) throws SAXException
{
    if (refs != null)
    {
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS,
                    EMPTY_ATTRIBUTES);

        for (AssociationRef assoc : refs)
        {
            writeAssoc(assoc);
        }
        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                    ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS, PREFIX + ":"
                                + ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS);
    }
}
 
Example #21
Source File: TemplateAssociation.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Construct
 * 
 * @param services
 * @param assocRef
 */
public TemplateAssociation(AssociationRef assocRef, ServiceRegistry services, TemplateImageResolver resolver)
{
    this.assocRef = assocRef;
    this.services = services;
    this.resolver = resolver;
}
 
Example #22
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<AssociationRef> getDownloadTargetAssocs(NodeRef sourceNodeRef)
{
    try
    {
        List<AssociationRef> result = new ArrayList<AssociationRef>();

        NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve();
        if (tempFolderNodeRef == null)
        {
            return result;
        }

        String tempFileName = sourceNodeRef.getId();

        NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef,
                                                             ContentModel.ASSOC_CONTAINS,
                                                             tempFileName);
        if (tempFileNodeRef == null)
        {
            return result;
        }
        List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef),
                                                   StandardCharsets.UTF_8);
        for (String line : readLines)
        {
            NodeRef targetRef = new NodeRef(line);
            AssociationRef assocRef = new AssociationRef(sourceNodeRef,
                                                         DownloadModel.ASSOC_REQUESTED_NODES,
                                                         targetRef);
            result.add(assocRef);
        }

        return result;
    }
    catch (IOException e)
    {
        throw new VirtualizationException(e);
    }
}
 
Example #23
Source File: PeerAssociationRepoEventIT.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAddAndRemovePeerAssociationSameTransaction()
{
    final NodeRef content1NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef content2NodeRef = createNode(ContentModel.TYPE_CONTENT);

    checkNumOfEvents(2);

    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(),
            resultRepoEvent.getType());

    resultRepoEvent = getRepoEventWithoutWait(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(),
            resultRepoEvent.getType());

    // Create peer association
    retryingTransactionHelper.doInTransaction(() ->
            
            {
                nodeService.createAssociation(
                        content1NodeRef,
                        content2NodeRef,
                        ContentModel.ASSOC_ORIGINAL);

                nodeService.removeAssociation(
                        content1NodeRef,
                        content2NodeRef,
                        ContentModel.ASSOC_ORIGINAL);
                return null;
            });
    
    List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(
            () ->
                    nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(0, peerAssociationRefs.size());

    checkNumOfEvents(2);
}
 
Example #24
Source File: PeerAssociationEventConsolidator.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Add peer association created event on create of a peer association.
 *
 * @param associationRef AssociationRef
 */
@Override
public void onCreateAssociation(AssociationRef associationRef)
{
    eventTypes.add(EventType.PEER_ASSOC_CREATED);
    resource = buildPeerAssociationResource(associationRef);
}
 
Example #25
Source File: HttpClientTransmitterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRef getFileTransferRootNodeRef(NodeRef transferNodeRef)
{
    //testing if transferring to file system
    if(!TransferModel.TYPE_FILE_TRANSFER_TARGET.equals(nodeService.getType(transferNodeRef)))
        return null;

    //get association
    List<AssociationRef> assocs = nodeService.getTargetAssocs(transferNodeRef, TransferModel.ASSOC_ROOT_FILE_TRANSFER);
    if(assocs.size() == 0 || assocs.size() > 1)
        return null;

    return assocs.get(0).getTargetRef();
}
 
Example #26
Source File: PeerAssociatedNodeFinder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Set<NodeRef> processIncludedSet(NodeRef startingNode)
{
    NodeService nodeService = serviceRegistry.getNodeService();
    Set<NodeRef> foundNodes = new HashSet<NodeRef>(89);
    for (QName assocType : peerAssociationTypes)
    {
        List<AssociationRef> targets = nodeService.getTargetAssocs(startingNode, assocType);
        for (AssociationRef target : targets)
        {
            foundNodes.add(target.getTargetRef());
        }
    }
    return foundNodes;
}
 
Example #27
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test attachment extraction with a TNEF message
 * @throws Exception
 */
public void testAttachmentExtraction() throws Exception
{
    AuthenticationUtil.setRunAsUserSystem();
    /**
     * Load a TNEF message
     */
    ClassPathResource fileResource = new ClassPathResource("imap/test-tnef-message.eml");
    assertNotNull("unable to find test resource test-tnef-message.eml", fileResource);
    InputStream is = new FileInputStream(fileResource.getFile());
    MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), is);

    NodeRef companyHomeNodeRef = findCompanyHomeNodeRef();

    FileInfo f1 = fileFolderService.create(companyHomeNodeRef, "ImapServiceImplTest", ContentModel.TYPE_FOLDER);
    FileInfo f2 = fileFolderService.create(f1.getNodeRef(), "test-tnef-message.eml", ContentModel.TYPE_CONTENT);
    
    ContentWriter writer = fileFolderService.getWriter(f2.getNodeRef());
    writer.putContent(new FileInputStream(fileResource.getFile()));
    
    imapService.extractAttachments(f2.getNodeRef(), message);

    List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(f2.getNodeRef(), ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
    assertTrue("attachment folder is found", targetAssocs.size() == 1);
    NodeRef attachmentFolderRef = targetAssocs.get(0).getTargetRef();
    
    assertNotNull(attachmentFolderRef);

    List<FileInfo> files = fileFolderService.listFiles(attachmentFolderRef);
    assertTrue("three files not found", files.size() == 3);

}
 
Example #28
Source File: MultiTServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public AssociationRef getName(AssociationRef assocRef)
{
    if (assocRef == null)
    {
        return null;
    }

    return new AssociationRef(assocRef.getId(),
            getName(assocRef.getSourceRef()),
            assocRef.getTypeQName(),
            getName(assocRef.getTargetRef()));
}
 
Example #29
Source File: NodeTargetsRelation.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * List targets
 *
 * @param sourceNodeId String id of source node
 */
@Override
@WebApiDescription(title = "Return a paged list of target nodes based on (peer) assocs")
public CollectionWithPagingInfo<Node> readAll(String sourceNodeId, Parameters parameters)
{
    NodeRef sourceNodeRef = nodes.validateOrLookupNode(sourceNodeId, null);

    QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);

    List<AssociationRef> assocRefs = nodeService.getTargetAssocs(sourceNodeRef, assocTypeQNameParam);

    return listNodePeerAssocs(assocRefs, parameters, true);
}
 
Example #30
Source File: AbstractNodeDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId)
{
    Pair<Long, AssociationRef> ret = getNodeAssocOrNull(assocId);
    if (ret == null)
    {
        throw new ConcurrencyFailureException("Assoc ID does not point to a valid association: " + assocId);
    }
    else
    {
        return ret;
    }
}