Search in sources :

Example 6 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class FormRestApiJsonPost_Test method testRemoveChildAssociationsFromNode.

/**
 * This test method attempts to remove an existing child association between two
 * existing nodes.
 */
public void testRemoveChildAssociationsFromNode() throws Exception {
    List<NodeRef> associatedNodes;
    checkOriginalChildAssocsBeforeChanges();
    // Remove an association
    JSONObject jsonPostData = new JSONObject();
    String assocsToRemove = childDoc_B.toString();
    jsonPostData.put(ASSOC_SYS_CHILDREN_REMOVED, assocsToRemove);
    String jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(containingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
    // Check the now updated child associations via the node service
    List<ChildAssociationRef> modifiedAssocs = nodeService.getChildAssocs(containerNodeRef);
    assertEquals(1, modifiedAssocs.size());
    // Extract the target nodeRefs to make them easier to examine
    associatedNodes = new ArrayList<NodeRef>(5);
    for (ChildAssociationRef assocRef : modifiedAssocs) {
        associatedNodes.add(assocRef.getChildRef());
    }
    assertTrue(associatedNodes.contains(childDoc_A));
// The Rest API should also give us the modified assocs.
/*Response response = sendRequest(new GetRequest(containingNodeUpdateUrl), 200);
        String jsonRspString = response.getContentAsString();
        JSONObject jsonGetResponse = new JSONObject(jsonRspString);
        JSONObject jsonData = (JSONObject)jsonGetResponse.get("data");
        assertNotNull(jsonData);

        JSONObject jsonFormData = (JSONObject)jsonData.get("formData");
        assertNotNull(jsonFormData);
        
        String jsonAssocs = (String)jsonFormData.get(ASSOC_SYS_CHILDREN);
        
        // We expect exactly 1 assoc on the test node
        assertEquals(1, jsonAssocs.split(",").length);
        for (ChildAssociationRef assocRef : modifiedAssocs)
        {
            assertTrue(jsonAssocs.contains(assocRef.getChildRef().toString()));
        }*/
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 7 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class InvitationWebScriptTest method makeAvatar.

public static String makeAvatar(final NodeService nodeService, final NodeRef person) {
    nodeService.addAspect(person, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(person, ContentModel.ASSOC_PREFERENCE_IMAGE, avatarQName, ContentModel.TYPE_CONTENT);
    NodeRef avatar = assoc.getChildRef();
    nodeService.createAssociation(person, avatar, ContentModel.ASSOC_AVATAR);
    return "api/node/" + avatar + "/content/thumbnails/avatar";
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 8 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class NodeWebScripTest method createNode.

private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName) {
    QName childName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, nodeCmName);
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeCmName);
    ChildAssociationRef childAssoc = nodeService.createNode(parentNode, ContentModel.ASSOC_CONTAINS, childName, nodeType, props);
    return childAssoc.getChildRef();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 9 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class NodeLocatorWebScriptTest method makeChildNode.

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();
}
Also used : QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 10 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class PersonServiceTest method addTextContent.

private NodeRef addTextContent(NodeRef folderRef, String name, String textData) {
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
    contentProps.put(ContentModel.PROP_NAME, name);
    ChildAssociationRef association = nodeService.createNode(folderRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), ContentModel.TYPE_CONTENT, contentProps);
    NodeRef content = association.getChildRef();
    ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(textData);
    return content;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)258 NodeRef (org.alfresco.service.cmr.repository.NodeRef)202 QName (org.alfresco.service.namespace.QName)109 Test (org.junit.Test)56 HashMap (java.util.HashMap)54 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)53 ArrayList (java.util.ArrayList)52 Serializable (java.io.Serializable)42 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)25 FacesContext (javax.faces.context.FacesContext)22 Map (java.util.Map)19 UserTransaction (javax.transaction.UserTransaction)18 Node (org.alfresco.web.bean.repository.Node)17 Date (java.util.Date)15 StoreRef (org.alfresco.service.cmr.repository.StoreRef)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 List (java.util.List)11 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)11 IOException (java.io.IOException)10