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

The following examples show how to use org.alfresco.model.ContentModel#ASSOC_CONTAINS . 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: FileImporterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: SortCMISTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addSortableNull(NodeRef folder00NodeRef,
        NodeRef rootNodeRef, NodeRef baseFolderNodeRef, Object baseFolderQName, Object folder00QName,
        Date date1, String id, int offset) throws IOException
{
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Test null");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Test null"));
    content00Properties.put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1)));

    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Test null");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
                content00QName, content00NodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 200 + offset, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE,
                ContentModel.ASPECT_TITLED }, content00Properties, null, "andy",
                new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef,
                            folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/"
                            + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
}
 
Example 3
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 4
Source File: LoadCMISData.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param folder00NodeRef
 * @param rootNodeRef
 * @param baseFolderNodeRef
 * @param baseFolderQName
 * @param folder00QName
 * @param date1
 * @param id
 * @param offset
 * @throws IOException
 */
private void addSortableNull(NodeRef folder00NodeRef,
        NodeRef rootNodeRef, NodeRef baseFolderNodeRef, Object baseFolderQName, Object folder00QName,
        Date date1, String id, int offset) throws IOException
{
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Test null");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Test null"));
    content00Properties.put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1)));

    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Test null");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
                content00QName, content00NodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 200 + offset, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE,
                ContentModel.ASPECT_TITLED }, content00Properties, null, "andy",
                new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef,
                            folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/"
                            + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
}
 
Example 5
Source File: CustomContentModelIT.java    From alfresco-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new node, such as a file or a folder, with passed in type and properties
 *
 * @param name the name of the file or folder
 * @param type the content model type
 * @param properties the properties from the content model
 * @return the Node Reference for the newly created node
 */
private NodeRef createNode(String name, QName type, Map<QName, Serializable> properties) {
    NodeRef parentFolderNodeRef = getCompanyHomeNodeRef();
    QName associationType = ContentModel.ASSOC_CONTAINS;
    QName associationQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
            QName.createValidLocalName(name));
    properties.put(ContentModel.PROP_NAME, name);
    ChildAssociationRef parentChildAssocRef = getServiceRegistry().getNodeService().createNode(
            parentFolderNodeRef, associationType, associationQName, type, properties);

    return parentChildAssocRef.getChildRef();
}
 
Example 6
Source File: CustomContentModelIT.java    From alfresco-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new node, such as a file or a folder, with passed in type and properties
 *
 * @param name the name of the file or folder
 * @param type the content model type
 * @param properties the properties from the content model
 * @return the Node Reference for the newly created node
 */
private NodeRef createNode(String name, QName type, Map<QName, Serializable> properties) {
    NodeRef parentFolderNodeRef = getCompanyHomeNodeRef();
    QName associationType = ContentModel.ASSOC_CONTAINS;
    QName associationQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
            QName.createValidLocalName(name));
    properties.put(ContentModel.PROP_NAME, name);
    ChildAssociationRef parentChildAssocRef = getServiceRegistry().getNodeService().createNode(
            parentFolderNodeRef, associationType, associationQName, type, properties);

    return parentChildAssocRef.getChildRef();
}
 
Example 7
Source File: NodeLocatorWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 8
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @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 9
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 10
Source File: DbOrIndexSwitchingQueryLanguageTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source File: RenditionNodeManager.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 12
Source File: RenditionNodeManagerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 13
Source File: TrieFieldsCMISTest.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void addTrieTypeTestData(NodeRef folder00NodeRef, NodeRef rootNodeRef, NodeRef baseFolderNodeRef,
        QName baseFolderQName, QName folder00QName, Date date00) throws IOException
{
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Trie test1");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Trie test1"));
    content00Properties.put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00)));

    StringPropertyValue firstIntValue = new StringPropertyValue("98198");
    content00Properties.put(SINGLE_INTEGER,firstIntValue);
    
    StringPropertyValue firstLongValue = new StringPropertyValue("3956650");
    content00Properties.put(SINGLE_LONG,firstLongValue);
    
    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Trie test1");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
                content00QName, content00NodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 300, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE,
                ContentModel.ASPECT_TITLED }, content00Properties, null, "andy",
                new ChildAssociationRef[] { content00CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef,
                            folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/"
                            + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
    
    HashMap<QName, PropertyValue> content01Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc01 = new MLTextPropertyValue();
    desc01.addValue(Locale.ENGLISH, "Trie test2");
    content01Properties.put(ContentModel.PROP_DESCRIPTION, desc01);
    content01Properties.put(ContentModel.PROP_TITLE, desc01);
    content01Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Trie test2"));
    content01Properties.put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date00)));

    StringPropertyValue secondIntValue = new StringPropertyValue("98200");
    content01Properties.put(SINGLE_INTEGER,secondIntValue);
    
    StringPropertyValue secondLongValue = new StringPropertyValue("3956651");
    content01Properties.put(SINGLE_LONG,secondLongValue);
    
    NodeRef content01NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content01QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Trie test1");
    ChildAssociationRef content01CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
                content01QName, content01NodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 301, 1, extendedContent, new QName[] { ContentModel.ASPECT_OWNABLE,
                ContentModel.ASPECT_TITLED }, content01Properties, null, "andy",
                new ChildAssociationRef[] { content01CAR }, new NodeRef[] { baseFolderNodeRef, rootNodeRef,
                            folder00NodeRef }, new String[] { "/" + baseFolderQName.toString() + "/"
                            + folder00QName.toString() + "/" + content01QName.toString() }, content01NodeRef, true);
    
}
 
Example 14
Source File: LoadCMISData.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void addSortableNode(NodeRef folder00NodeRef,
        NodeRef rootNodeRef, NodeRef baseFolderNodeRef, Object baseFolderQName, Object folder00QName,
        Date date1, int position) throws IOException
{
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Test " + position);
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Test " + position));
    content00Properties.put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1)));

    StringPropertyValue single = new StringPropertyValue(orderable[position]);
    content00Properties.put(SINGLE_TEXT_UNTOKENISED, single);
    content00Properties.put(SINGLE_TEXT_TOKENISED, single);
    content00Properties.put(SINGLE_TEXT_BOTH, single);
    MultiPropertyValue multi = new MultiPropertyValue();
    multi.addValue(single);
    multi.addValue(new StringPropertyValue(orderable[position + 1]));
    content00Properties.put(MULTIPLE_TEXT_UNTOKENISED, multi);
    content00Properties.put(MULTIPLE_TEXT_TOKENISED, multi);
    content00Properties.put(MULTIPLE_TEXT_BOTH, multi);
    content00Properties.put(SINGLE_ML_TEXT_UNTOKENISED, makeMLText(position));
    content00Properties.put(SINGLE_ML_TEXT_TOKENISED, makeMLText(position));
    content00Properties.put(SINGLE_ML_TEXT_BOTH, makeMLText(position));
    content00Properties.put(MULTIPLE_ML_TEXT_UNTOKENISED, makeMLTextMVP(position));
    content00Properties.put(MULTIPLE_ML_TEXT_TOKENISED, makeMLTextMVP(position));
    content00Properties.put(MULTIPLE_ML_TEXT_BOTH, makeMLTextMVP());
    StringPropertyValue one = new StringPropertyValue("" + (1.1 * position));
    StringPropertyValue two = new StringPropertyValue("" + (2.2 * position));
    MultiPropertyValue multiDec = new MultiPropertyValue();
    multiDec.addValue(one);
    multiDec.addValue(two);
    content00Properties.put(SINGLE_FLOAT, one);
    content00Properties.put(MULTIPLE_FLOAT, multiDec);
    content00Properties.put(SINGLE_DOUBLE, one);
    content00Properties.put(MULTIPLE_DOUBLE, multiDec);
    one = new StringPropertyValue("" + (1 * position));
    two = new StringPropertyValue("" + (2 * position));
    MultiPropertyValue multiInt = new MultiPropertyValue();
    multiInt.addValue(one);
    multiInt.addValue(two);
    content00Properties.put(SINGLE_INTEGER, one);
    content00Properties.put(MULTIPLE_INTEGER, multiInt);
    content00Properties.put(SINGLE_LONG, one);
    content00Properties.put(MULTIPLE_LONG, multiInt);

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DAY_OF_MONTH, position);

    Date newdate1 = cal.getTime();
    cal.add(Calendar.DAY_OF_MONTH, -1);
    cal.add(Calendar.DAY_OF_MONTH, 2);
    Date date2 = cal.getTime();
    StringPropertyValue d1 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, newdate1));
    StringPropertyValue d2 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date2));
    MultiPropertyValue multiDate = new MultiPropertyValue();
    multiDate.addValue(d1);
    multiDate.addValue(d2);
    content00Properties.put(SINGLE_DATE, d1);
    content00Properties.put(MULTIPLE_DATE, multiDate);
    content00Properties.put(SINGLE_DATETIME, d1);
    content00Properties.put(MULTIPLE_DATETIME, multiDate);

    StringPropertyValue b = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class,
                position % 2 == 0 ? true : false));
    StringPropertyValue bTrue = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, true));
    StringPropertyValue bFalse = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, false));
    MultiPropertyValue multiBool = new MultiPropertyValue();
    multiBool.addValue(bTrue);
    multiBool.addValue(bFalse);

    content00Properties.put(SINGLE_BOOLEAN, b);
    content00Properties.put(MULTIPLE_BOOLEAN, multiBool);

    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Test " + position);
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
            content00QName, content00NodeRef, true, 0);
    addNode(getCore(),
            dataModel, 1, 1000 + position, 1, extendedContent, new QName[]{ContentModel.ASPECT_OWNABLE,
                    ContentModel.ASPECT_TITLED}, content00Properties, null, "andy",
            new ChildAssociationRef[]{content00CAR}, new NodeRef[]{baseFolderNodeRef, rootNodeRef,
                    folder00NodeRef}, new String[]{"/" + baseFolderQName.toString() + "/"
                    + folder00QName.toString() + "/" + content00QName.toString() }, content00NodeRef, true);
}
 
Example 15
Source File: LoadCMISData.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static void addTypeTestData(NodeRef folder00NodeRef,
        NodeRef rootNodeRef,
        NodeRef baseFolderNodeRef,
        Object baseFolderQName,
        Object folder00QName,
        Date date1)throws IOException
{
    HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
    MLTextPropertyValue desc00 = new MLTextPropertyValue();
    desc00.addValue(Locale.ENGLISH, "Test One");
    desc00.addValue(Locale.US, "Test 1");
    content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
    content00Properties.put(ContentModel.PROP_TITLE, desc00);
    content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Test One"));
    content00Properties.put(ContentModel.PROP_CREATED,
    new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1)));
    
    StringPropertyValue single = new StringPropertyValue("Un tokenised");
    content00Properties.put(SINGLE_TEXT_UNTOKENISED, single);
    content00Properties.put(SINGLE_TEXT_TOKENISED, single);
    content00Properties.put(SINGLE_TEXT_BOTH, single);
    MultiPropertyValue multi = new MultiPropertyValue();
    multi.addValue(single);
    multi.addValue(new StringPropertyValue("two parts"));
    content00Properties.put(MULTIPLE_TEXT_UNTOKENISED, multi);
    content00Properties.put(MULTIPLE_TEXT_TOKENISED, multi);
    content00Properties.put(MULTIPLE_TEXT_BOTH, multi);
    content00Properties.put(SINGLE_ML_TEXT_UNTOKENISED, makeMLText());
    content00Properties.put(SINGLE_ML_TEXT_TOKENISED, makeMLText());
    content00Properties.put(SINGLE_ML_TEXT_BOTH, makeMLText());
    content00Properties.put(MULTIPLE_ML_TEXT_UNTOKENISED, makeMLTextMVP());
    content00Properties.put(MULTIPLE_ML_TEXT_TOKENISED, makeMLTextMVP());
    content00Properties.put(MULTIPLE_ML_TEXT_BOTH, makeMLTextMVP());
    StringPropertyValue one = new StringPropertyValue("1");
    StringPropertyValue two = new StringPropertyValue("2");
    MultiPropertyValue multiDec = new MultiPropertyValue();
    multiDec.addValue(one);
    multiDec.addValue(new StringPropertyValue("1.1"));
    content00Properties.put(SINGLE_FLOAT, one);
    content00Properties.put(MULTIPLE_FLOAT, multiDec);
    content00Properties.put(SINGLE_DOUBLE, one);
    content00Properties.put(MULTIPLE_DOUBLE, multiDec);
    MultiPropertyValue multiInt = new MultiPropertyValue();
    multiInt.addValue(one);
    multiInt.addValue(two);
    content00Properties.put(SINGLE_INTEGER, one);
    content00Properties.put(MULTIPLE_INTEGER, multiInt);
    content00Properties.put(SINGLE_LONG, one);
    content00Properties.put(MULTIPLE_LONG, multiInt);
    
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DAY_OF_MONTH, -1);
    cal.add(Calendar.DAY_OF_MONTH, 2);
    Date date2 = cal.getTime();
    StringPropertyValue d1 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date1));
    StringPropertyValue d2 = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, date2));
    MultiPropertyValue multiDate = new MultiPropertyValue();
    multiDate.addValue(d1);
    multiDate.addValue(d2);
    content00Properties.put(SINGLE_DATE, d1);
    content00Properties.put(MULTIPLE_DATE, multiDate);
    content00Properties.put(SINGLE_DATETIME, d1);
    content00Properties.put(MULTIPLE_DATETIME, multiDate);
    
    StringPropertyValue bTrue = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, true));
    StringPropertyValue bFalse = new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, false));
    MultiPropertyValue multiBool = new MultiPropertyValue();
    multiBool.addValue(bTrue);
    multiBool.addValue(bFalse);
    
    content00Properties.put(SINGLE_BOOLEAN, bTrue);
    content00Properties.put(MULTIPLE_BOOLEAN, multiBool);
    
    NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Test One");
    ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, folder00NodeRef,
    content00QName, content00NodeRef, true, 0);
    addNode(getCore(),
    dataModel,
    1,
    100,
    1,
    extendedContent,
    new QName[] { ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED },
    content00Properties,
    null,
    "andy",
    new ChildAssociationRef[] { content00CAR },
    new NodeRef[] { baseFolderNodeRef, rootNodeRef, folder00NodeRef },
    new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() + "/" + content00QName.toString() },
    content00NodeRef,
    true);
}
 
Example 16
Source File: AuthDataLoad.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws Exception
{
    //Start test haness
    initAlfrescoCore("schema.xml");
    // Root

    NodeRef rootNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    addStoreRoot(getCore(), dataModel, rootNodeRef, 1, 1, 1, 1);
    //        rsp.add("StoreRootNode", 1);

    // Base

    HashMap<QName, PropertyValue> baseFolderProperties = new HashMap<QName, PropertyValue>();
    baseFolderProperties.put(ContentModel.PROP_NAME, new StringPropertyValue("Base Folder"));
    NodeRef baseFolderNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName baseFolderQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "baseFolder");
    ChildAssociationRef n01CAR = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef,
                baseFolderQName, baseFolderNodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 2, 1, ContentModel.TYPE_FOLDER, null, baseFolderProperties, null, "andy",
                new ChildAssociationRef[] { n01CAR }, new NodeRef[] { rootNodeRef }, new String[] { "/"
                            + baseFolderQName.toString() }, baseFolderNodeRef, true);

    // Folders

    HashMap<QName, PropertyValue> folder00Properties = new HashMap<QName, PropertyValue>();
    folder00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Folder 0"));
    NodeRef folder00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    QName folder00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Folder 0");
    ChildAssociationRef folder00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
                baseFolderNodeRef, folder00QName, folder00NodeRef, true, 0);
    addNode(getCore(), dataModel, 1, 3, 1, ContentModel.TYPE_FOLDER, null, folder00Properties, null, "andy",
                new ChildAssociationRef[] { folder00CAR },
                new NodeRef[] { baseFolderNodeRef, rootNodeRef },
                new String[] { "/" + baseFolderQName.toString() + "/" + folder00QName.toString() },
                folder00NodeRef, true);

    for (long i = 0; i < count; i++)
    {
        addAcl(getCore(), dataModel, 10 + (int) i, 10 + (int) i, (int) (i % maxReader), (int) maxReader);

        HashMap<QName, PropertyValue> content00Properties = new HashMap<QName, PropertyValue>();
        MLTextPropertyValue desc00 = new MLTextPropertyValue();
        desc00.addValue(Locale.ENGLISH, "Doc " + i);
        desc00.addValue(Locale.US, "Doc " + i);
        content00Properties.put(ContentModel.PROP_DESCRIPTION, desc00);
        content00Properties.put(ContentModel.PROP_TITLE, desc00);
        content00Properties.put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.UK, 0l, "UTF-8",
                    "text/plain", null));
        content00Properties.put(ContentModel.PROP_NAME, new StringPropertyValue("Doc " + i));
        content00Properties.put(ContentModel.PROP_CREATOR, new StringPropertyValue("Test"));
        content00Properties.put(ContentModel.PROP_MODIFIER, new StringPropertyValue("Test"));
        content00Properties.put(ContentModel.PROP_VERSION_LABEL, new StringPropertyValue("1.0"));
        content00Properties.put(ContentModel.PROP_OWNER, new StringPropertyValue("Test"));
        Date date00 = new Date();
        content00Properties.put(ContentModel.PROP_CREATED, new StringPropertyValue(
                    DefaultTypeConverter.INSTANCE.convert(String.class, date00)));
        content00Properties.put(ContentModel.PROP_MODIFIED, new StringPropertyValue(
                    DefaultTypeConverter.INSTANCE.convert(String.class, date00)));
        HashMap<QName, String> content00Content = new HashMap<QName, String>();
        content00Content.put(ContentModel.PROP_CONTENT, "Test doc number " + i);
        NodeRef content00NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
        QName content00QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Doc-" + i);
        ChildAssociationRef content00CAR = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
                    folder00NodeRef, content00QName, content00NodeRef, true, 0);
        addNode(getCore(), dataModel, 1, 10 + (int) i, 10 + (int) i, ContentModel.TYPE_CONTENT, new QName[] {
                    ContentModel.ASPECT_OWNABLE, ContentModel.ASPECT_TITLED }, content00Properties,
                    content00Content, "andy", new ChildAssociationRef[] { content00CAR }, new NodeRef[] {
                                baseFolderNodeRef, rootNodeRef, folder00NodeRef }, new String[] { "/"
                                + baseFolderQName.toString() + "/" + folder00QName.toString() + "/"
                                + content00QName.toString() }, content00NodeRef, false);
    }
    getCore().getUpdateHandler().commit(new CommitUpdateCommand(req(), false));

}
 
Example 17
Source File: ThumbnailServiceImplParameterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 18
Source File: GetChildAssocsMethod.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 19
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 20
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
    }
}