Java Code Examples for org.alfresco.model.ContentModel.ASSOC_CONTAINS

The following are Jave code examples for showing how to use ASSOC_CONTAINS of the org.alfresco.model.ContentModel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: FileImporterImpl.java   View Source Code Vote up 6 votes
/**
 * Get the type of child association that should be created.
 * 
 * @param parentNodeRef the parent
 * @return Returns the appropriate child association type qualified name for the type of the
 *      parent.  Null will be returned if it can't be determined.
 */
private QName getAssocTypeQName(NodeRef parentNodeRef)
{
    // check the parent node's type to determine which association to use
    QName parentNodeTypeQName = nodeService.getType(parentNodeRef);
    QName assocTypeQName = null;
    if (dictionaryService.isSubClass(parentNodeTypeQName, ContentModel.TYPE_CONTAINER))
    {
        // it may be a root node or something similar
        assocTypeQName = ContentModel.ASSOC_CHILDREN;
    }
    else if (dictionaryService.isSubClass(parentNodeTypeQName, ContentModel.TYPE_FOLDER))
    {
        // more like a directory
        assocTypeQName = ContentModel.ASSOC_CONTAINS;
    }
    return assocTypeQName;
}
 
Example 2
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View Source Code Vote up 6 votes
/**
 * 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 3
Project: alfresco-repository   File: RenditionNodeManager.java   View Source Code Vote up 5 votes
/**
 * This method moves the old rendition to the required location giving it the correct parent-assoc type and
 * the specified association name.
 * 
 * @param renditionName the name to put on the newly created association.
 * @return the ChildAssociationRef of the moved nodeRef.
 */
private ChildAssociationRef moveOldRendition(QName renditionName)
{
    NodeRef parent = location.getParentRef();
    QName assocName = getAssociationName(parent.equals(sourceNode), renditionName);
    QName assocType = sourceNode.equals(parent) ? RenditionModel.ASSOC_RENDITION : ContentModel.ASSOC_CONTAINS;
    ChildAssociationRef result = nodeService.moveNode(existingLinkedRendition, parent, assocType, assocName);
    
    if (logger.isDebugEnabled())
    {
        logger.debug("The old rendition was moved to " + result);
    }
    return result;
}
 
Example 4
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View Source Code Vote up 5 votes
/**
 * @return
 */
private TransferManifestNormalNode createContentNode(/*String transferId*/) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);
    byte[] dummyContent = "This is some dummy content.".getBytes("UTF-8");

    node.setType(ContentModel.TYPE_CONTENT);
    
    /**
     * Get guest home
     */
    NodeRef parentFolder = guestHome;

    String nodeName = uuid + ".testnode" + getNameSuffix();

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(nodeService.getPath(parentFolder));
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    ContentData contentData = new ContentData("/" + uuid, "text/plain", dummyContent.length, "UTF-8");
    props.put(ContentModel.PROP_CONTENT, contentData);
    node.setProperties(props);

    return node;
}
 
Example 5
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View Source Code Vote up 5 votes
private TransferManifestNormalNode createFolderNode(String folderName) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);

    node.setType(ContentModel.TYPE_FOLDER);
    
    NodeRef parentFolder = repositoryHelper.getGuestHome();

    String nodeName = folderName == null ? uuid + ".folder" + getNameSuffix() : folderName;

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(nodeService.getPath(parentFolder));
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    node.setProperties(props);

    return node;
}
 
Example 6
Project: alfresco-repository   File: DbOrIndexSwitchingQueryLanguageTest.java   View Source Code Vote up 5 votes
private ChildAssociationRef childAssoc(String id)
{
    return new ChildAssociationRef(
        ContentModel.ASSOC_CONTAINS,
        new NodeRef("test://store/parentRef"),
        ContentModel.TYPE_CONTENT,
        new NodeRef("test://store/" + id)
    );
}
 
Example 7
Project: alfresco-file-transfer-receiver   File: FileTransferReceiverTest.java   View Source Code Vote up 5 votes
/**
 * @return TransferManifestNormalNode
 */
private TransferManifestNormalNode createContentNode(NodeRef parentFolder, String nodeName) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);
    byte[] dummyContent = "This is some dummy content.".getBytes("UTF-8");

    node.setType(ContentModel.TYPE_CONTENT);
    node.setAncestorType(ContentModel.TYPE_CONTENT);

    /**
     * Get guest home
     */

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(null);
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    ContentData contentData = new ContentData("/" + uuid, "text/plain", dummyContent.length, "UTF-8");
    props.put(ContentModel.PROP_CONTENT, contentData);
    node.setProperties(props);

    return node;
}
 
Example 8
Project: alfresco-file-transfer-receiver   File: FileTransferReceiverTest.java   View Source Code Vote up 5 votes
/**
 * @return TransferManifestNormalNode
 */
private TransferManifestNormalNode createFolderNode(NodeRef parentFolder, String nodeName) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);
    node.setType(ContentModel.TYPE_FOLDER);
    node.setAncestorType(ContentModel.TYPE_FOLDER);

    /**
     * Get guest home
     */

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(null);
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    node.setProperties(props);

    return node;
}
 
Example 9
Project: alfresco-file-transfer-receiver   File: FileTransferReceiverTest.java   View Source Code Vote up 5 votes
private void modifyParentNode(NodeRef parentFolder, TransferManifestNormalNode nodeToMove ) throws Exception
{

    String nodeName = (String)nodeToMove.getProperties().get(ContentModel.PROP_NAME);


    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), nodeToMove.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    nodeToMove.setParentAssocs(parents);
    nodeToMove.setParentPath(null);
    nodeToMove.setPrimaryParentAssoc(primaryAssoc);

}
 
Example 10
Project: alfresco-remote-api   File: NodeLocatorWebScriptTest.java   View Source Code Vote up 5 votes
private NodeRef makeChildNode(NodeRef parent, QName type)
{
    QName qName = QName.createQName("", GUID.generate());
    QName contains = ContentModel.ASSOC_CONTAINS;
    ChildAssociationRef result = nodeService.createNode(parent, contains, qName, type);
    return result.getChildRef();
}
 
Example 11
Project: alfresco-test-assertions   File: NodeAssertTest.java   View Source Code Vote up 5 votes
@Test
public void a_non_exisiting_target_for_an_association_can_be_asserted() {
    final NodeRef nonExistingTarget = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "1");
    final QName assoc = ContentModel.ASSOC_CONTAINS;
    nodeService.createAssociation(nodeRef, nodeRef, assoc);
    assertThat(nodeRef).doesNotHaveTargetAssociationTo(assoc, nonExistingTarget);
}
 
Example 12
Project: alfresco-repository   File: VirtualNodeServiceExtension.java   View Source Code Vote up 4 votes
@Override
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern,
            QNamePattern qnamePattern)
{
    NodeServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null)
    {
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null)
        {
            return theTrait.getParentAssocs(reference.execute(new GetActualNodeRefMethod(environment)),
                                            typeQNamePattern,
                                            qnamePattern);
        }
        else
        {
            if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS))
            {
                Reference parentsParent = parent.execute(new GetParentReferenceMethod());

                NodeRef parentNodeRef = parent.toNodeRef();
                if (parentsParent == null)
                {
                    parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));

                }

                NodeRef referenceNodeRef = reference.toNodeRef();
                Map<QName, Serializable> properties = smartStore.getProperties(reference);
                Serializable name = properties.get(ContentModel.PROP_NAME);
                QName assocChildName = QName
                            .createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI,
                                                           name.toString());
                if (qnamePattern.isMatch(assocChildName))
                {
                    ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
                                                                        parentNodeRef,
                                                                        assocChildName,
                                                                        referenceNodeRef);
                    return Arrays.asList(assoc);
                }
                else
                {
                    return Collections.emptyList();
                }
            }
            else
            {
                return Collections.emptyList();
            }
        }
    }
    else
    {
        return theTrait.getParentAssocs(nodeRef,
                                        typeQNamePattern,
                                        qnamePattern);
    }
}
 
Example 13
Project: alfresco-repository   File: VirtualNodeServiceExtension.java   View Source Code Vote up 4 votes
@Override
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef)
{
	Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null)
    {  
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null)
        {
            return getTrait().getPrimaryParent(reference.execute(new GetActualNodeRefMethod(environment)));
        }
        else
        {
            Reference parentsParent = parent.execute(new GetParentReferenceMethod());

            NodeRef parentNodeRef = parent.toNodeRef();
            if (parentsParent == null)
            {
                parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));

            }

            NodeRef referenceNodeRef = reference.toNodeRef();
            Map<QName, Serializable> refProperties = smartStore.getProperties(reference);
            Serializable childName = refProperties.get(ContentModel.PROP_NAME);
            QName childAssocQName = QName
                        .createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI,
                                                       childName.toString());
            ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
                                                                parentNodeRef,
                                                                childAssocQName,
                                                                referenceNodeRef,
                                                                true,
                                                                -1);
            return assoc;
        }
    }
    else
    {
        return getTrait().getPrimaryParent(nodeRef);
    }
}
 
Example 14
Project: alfresco-repository   File: GetChildAssocsMethod.java   View Source Code Vote up 4 votes
@Override
public List<ChildAssociationRef> execute(VirtualProtocol virtualProtocol, Reference reference)
            throws ProtocolMethodException
{
    if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS))
    {
        List<ChildAssociationRef> childAssocs = new LinkedList<>();
        List<Reference> children = smartStore.list(reference);
        NodeRef nodeRefReference = reference.toNodeRef();
        int count = 0;
        for (Reference child : children)
        {
            if (count >= maxResults)
            {
                break;
            }

            NodeRef childNodeRef = child.toNodeRef();
            Serializable childName = environment.getProperty(childNodeRef,
                                                             ContentModel.PROP_NAME);
            QName childAssocQName = QName
                        .createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI,
                                                       childName.toString());
            if (qnamePattern.isMatch(childAssocQName))
            {

                ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
                                                                         nodeRefReference,
                                                                         childAssocQName,
                                                                         childNodeRef,
                                                                         true,
                                                                         -1);
                childAssocs.add(childAssoc);
                count++;
            }
        }

        return childAssocs;
    }
    else
    {
        return Collections.emptyList();
    }
}
 
Example 15
Project: alfresco-repository   File: ThumbnailServiceImplParameterTest.java   View Source Code Vote up 4 votes
/**
 * This test method ensures that the parameters on thumbnail-create are
 * passed through the RenditionService to the ActionService
 */
@Test
public void createThumbnailPassesParametersToActionService()
{
    // As most of the services are mocked out, the actual values used here
    // don't matter.
    final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
    parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
    parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
    parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE, new Integer(2));
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE, new Integer(2));
    parametersUnderTest.put(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET, "00:00:00.5");
    

    ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
    imageTransOpts.setTargetNodeRef(dummyNodeRef2);
    
    imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
    imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));

    ImageResizeOptions resizeOptions = new ImageResizeOptions();
    resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
    resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
    resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
    resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
    resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
    imageTransOpts.setResizeOptions(resizeOptions);
    
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE));
    pagedSourceOptions.setEndPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE));
    imageTransOpts.addSourceOptions(pagedSourceOptions);
    
    TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
    temporalSourceOptions.setOffset((String) parametersUnderTest.get(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET));
    imageTransOpts.addSourceOptions(temporalSourceOptions);
    
    ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3,
                ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
                            "homerSimpson"));
    
    // Now request the creation of the the thumbnail.
    thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
                imageTransOpts, "bartSimpson", assocDetails);

    
    ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
    verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
    final Action action = argument.getValue();
    final RenditionDefinition renditionDefn = (RenditionDefinition)action;
    Map<String, Serializable> parameters = renditionDefn.getParameterValues();
    
    for (String s : parametersUnderTest.keySet())
    {
        if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0)
        {
            fail("Missing parameter " + s);
        }
        assertEquals("Parameter " + s + " had wrong value.",
                parametersUnderTest.get(s), parameters.get(s));
    }
}
 
Example 16
Project: alfresco-repository   File: RenditionNodeManagerTest.java   View Source Code Vote up 4 votes
private ChildAssociationRef makeAssoc(NodeRef parent, NodeRef child, QName assocName, boolean isRenditionAssoc)
{
    QName assocType = isRenditionAssoc ? RenditionModel.ASSOC_RENDITION : ContentModel.ASSOC_CONTAINS;
    return new ChildAssociationRef(assocType, parent, assocName, child);
}
 
Example 17
Project: alfresco-test-assertions   File: NodeAssertTest.java   View Source Code Vote up 4 votes
@Test(expected = AssertionError.class)
public void an_association_present_when_testing_for_non_exisiting_association_is_an_assertion_error() {
    final QName assoc = ContentModel.ASSOC_CONTAINS;
    nodeService.createAssociation(nodeRef, nodeRef, assoc);
    assertThat(nodeRef).doesNotHaveTargetAssociation(assoc);
}
 
Example 18
Project: alfresco-test-assertions   File: NodeAssertTest.java   View Source Code Vote up 4 votes
@Test(expected = AssertionError.class)
public void an_association_taget_present_when_testing_for_non_exisiting_association_target_is_an_assertion_error() {
    final QName assoc = ContentModel.ASSOC_CONTAINS;
    nodeService.createAssociation(nodeRef, nodeRef, assoc);
    assertThat(nodeRef).doesNotHaveTargetAssociationTo(assoc, nodeRef);
}