cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS-JavaScript trouble

raptus
Champ in-the-making
Champ in-the-making
Hello folks,

How can I implement (with cmis and javascript) a dynamic folder creation while uploading a document?

For example:  my java-rest-atom code with Abdera atom feeds put a document on "company home" folder… I wish to move or (better) create a folder named "today date" and put the document inside this new folder without other operations (like rules).

Is it possible with web scripts?

I have seen this script listed in the default alfresco cmis scripts repository, called when I use a rest-java code (children.post.atom.js) but I cannot understand how does it work..
…….
if (objectId == null)
    {
        // create node
        node = createNode(model.parent, entry, slug, versioningState);
        if (node == null)
        {
            break script;
        }
        node.save();
    }
else if (sourceFolderId == null || sourceFolderId.length == 0)
    {
       // Add node
       var object = getObjectFromObjectId(objectId);
       if (object.node == null)
       {
           break script;
       }
       node = object.node;
      
      //code to add?
     
     
       cmis.addObjectToFolder(node, model.parent);
    }
    //———————————-
    // success
    model.node = node;
    // TODO: set Content-Location
    status.code = 201;
    status.location = url.server + url.serviceContext + "/cmis/s/" + node.nodeRef.storeRef.protocol + ":" + node.nodeRef.storeRef.identifier + "/i/" + node.nodeRef.id;
    status.redirect = true;

Can I mod this file?
Thanks in advance for any help,

Raptus
6 REPLIES 6

unknown-user
Champ on-the-rise
Champ on-the-rise
Have you thought of putting an action on a folder.
Eg : your file is uploaded to company_home/uploads/

Upon the file hitting the folder the javascript is run.
This will then create the appropriate structure.

NB: javascript is fine but Java is faster, have a look at :
NodeServicePolicies.OnCreateNodePolicy

Hope it helps

raptus
Champ in-the-making
Champ in-the-making
Thankyou for reply,

Yes I thought that's a rapid solution but I'm sorry I must use java-atom-rest api's to add objects into the repository.
So I already use Java.
This is my Java code:
……………..Create Folder…
Abdera abdera = new Abdera();
        Entry entry = abdera.newEntry();
        entry.setTitle(newFoldersName);
        entry.setSummary(newFoldersDescription);

        ExtensibleElement objElement = (ExtensibleElement) entry.addExtension(NS_CMIS_RESTATOM, "object", CMISRA);
        ExtensibleElement propsElement = objElement.addExtension(NS_CMIS_CORE, "properties", CMIS);
        ExtensibleElement stringElement = propsElement.addExtension(NS_CMIS_CORE, "propertyId", CMIS);
…………..
String uri = server + "/alfresco/s/test/cmis/p/" + parentPath + "/test";
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("POST " + uri);
        }

        ClientResponse clientResponse = client.post(uri, entry, options);
        AlfrescoResponse alfResponse = parseResponseWithDocument(clientResponse);
        clientResponse.release();
        return alfResponse;
…………..

Then I post an atom url to javascript (children.post.atom.js) and this script execute all.
So I use both Java & JavaScript….

I have understood how to create folders in JS ( nodeParent = companyhome.childByNamePath("/TEST" ); nodeParent.createFolder("TESTFOLDER1"); ….)
this is simple, but when I want to "read" a custom model or a property I get problems.

1) How can I add a custom model to a folder and add a custom property inside? Eg.:   folder = TEST; Content= cm:customContent; Properties= cm:note, note=XXX

2) How can I do this for a document too?

Thankyou again,
Raptus

unknown-user
Champ on-the-rise
Champ on-the-rise
Hi,

I am guessing you want to do this is javascript right ?

Here is the api page : http://wiki.alfresco.com/wiki/3.3_JavaScript_API#Modifying_and_Creating_API

1) How can I add a custom model to a folder and add a custom property inside? Eg.: folder = TEST; Content= cm:customContent; Properties= cm:note, note=XXX

Normally you would be doing upon creation.
eg :  companyhome.createNode(TEST, cm:customContent, null , "cm:contains");

Changing type after creation is called specialization.
document.specializeType(cm:customContent) ;
document.save();

2) How can I do this for a document too?
Of course, same way, define type in model.

3) Reading the properties :
var prop = document.properties["cm:note"];

3) Adding the properties :
document.properties["cm:note"] = newProp;
document.save();

Hope is helps.

raptus
Champ in-the-making
Champ in-the-making
Yes it helps me a lot!
I don't understand 2 things:
1) "document.specializeType(cm:customContent) ;"  –> "document" is a special term or a variable? So, "document" is also referred to a folder and a "document"?  It says me "Reference error: document is not defined.

2) I have this object CMIS:
object=<cmisraSmiley Surprisedbject xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/"><cmisSmiley Tongueroperties> propertyDefinitionId="cmisSmiley SurprisedbjectTypeId"><cmis:value>F:cm:customFolder</cmis:value></cmisSmiley TongueropertyId><cmisSmiley TongueropertyString localNamespace="{http://www.e-projectsrl.it/model/content/1.1}" propertyDefinitionId="cm:Note"><cmis:value>00000</cmis:value></cmisSmiley TongueropertyString></cmisSmiley Tongueroperties></cmisraSmiley Surprisedbject>

This is the "rest" java object call.

How can I bring the value "00000" from cm:Note???  I can see the "objectTypeId, objectId etc.." (var object = entry.getExtension(atom.names.cmisra_object); var objID = object.objectId….) but I still can't see my own properties (and the values)… Why don't object.Note??? Still shows me that is "undefined"….

thankyou for reply and sorry for my dummy questions..

Raptus

unknown-user
Champ on-the-rise
Champ on-the-rise
Hi,

1) "document.specializeType(cm:customContent) ;" –> "document" is a special term or a variable? So, "document" is also referred to a folder and a "document"? It says me "Reference error: document is not defined.

document is your nodeRef object.
eg: var document = search.findNode("workspace://SpacesStore/1a2b9d2a-6e91-4b29-8b50-be5fbc22adbe")

2) i dont know 🙂
Have not had the time to work with cmis yet.


Good Luck

raptus
Champ in-the-making
Champ in-the-making
Thankyou again!

I have bypassed the problem using an external xml tag "cm:Note" outside the cmis "object" tags.
I set this value in this way in my script:  var note = entry.getSimpleExtension("{my model}","Note","cm");
It works!!!

Hope this would be helpful for you too.

Regards,

Raptus