cancel
Showing results for 
Search instead for 
Did you mean: 

Change made through a webscript not reflected on ShareUI

annakan
Champ in-the-making
Champ in-the-making
Hello all,

I am trying to make changes to nodes through a webscript not although all API call are ok (not raising any error), NOTHING is translated in the shareUI.

The exact same thing happens when I run code into the debugger evaluate console
Taking a leaf from http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook#Creating_different_child_node_types.2C_includi...
% var props = new Array();
% props["cm:name"] = "node name4.txt";
% destNode.nodeRef
workspace://SpacesStore/2ce29180-ea37-4511-a754-fd3a6f6f5fab
% destNode.name
AutreAutreDossier
% var node5 = destNode.createNode(null, "cm:content", props, "cm:contains");
for(i in destNode.children) {logger.log(i +":"+destNode.children[i].name)}
The console output this
1:599_2.jpg
2:Bidon Folder
3:47dae0d4-1b44-4208-bbe9-e9965b4f9a77
4:node name4.txt

but going into the folder shows nothing, the node name4.txt is not there.
The "Bidon folder" was created like this :
% destNode.createFolder("Bidon Folder")
Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable]
and then doing
% destNode.name
AutreAutreDossier
% destNode.createFolder("Bidon Folder")
Wrapped org.alfresco.service.cmr.model.FileExistsException: Existing file or folder Bidon Folder already exists
shows the folder exists.
but it does not shows up in the UI as a child of destNode ????
and in the  the node explorer examining the nodeDest folder shows that it has NONE of the children I just added, in fact looking for node5.nodeRef shows it as non existent, but trying to do
% var node5 = destNode.createNode(null, "cm:content", props, "cm:contains");
Wrapped org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: node name4.txt

The debugger seems to operate in another transaction ? how can I merge the changes then ?

The root of the problem, why did I try this :

I tried this because I try to do this in my code to no avail :
if (String(curParent.qnamePath)===String(sourceFolder.qnamePath))
                        {
                           logger.log("Complexe MATCH : " + curParent.qnamePath );
                           //fileNode.parents[i]=sourceFolder // Too obvious DOES NOT WORK
                           logger.log("creating association to:" + destNode.qnamePath);
                           destNode.createAssociation(fileNode,"cm:contains");
                           logger.log("removing association toward:" + sourceFolder.qnamePath);
                           fileNode.removeAssociation(sourceFolder,"cm:contains");
                           //fileNode.save(); //Does not change a thing
                           break;
                        }
                     };

the code
logger.log("*********** parents AFTER ****************** ");
                     for(i=0;i < fileNode.parents.length; i+=1){
                        curParent=fileNode.parents[i];
                        logger.log("curParent"+curParent);
                        logger.log("Parent["+i+"]:"+curParent.qnamePath+"**"+curParent.id);
                        };    
                     logger.log("*********** assoc contains AFTER ****************** ");
                     for(i=0;i < fileNode.parentAssocs["cm:contains"][0].length; i+=1){
                        curParent=fileNode.parentAssocs["cm:contains"][0][i];
                        logger.log("curParent"+curParent);
                        logger.log("Parent["+i+"]:"+curParent.qnamePath+"**"+curParent.id);
                        };    
Shows that NONE of the parents properties where updated/changed ??????

But the repository IS modified, I can see that because  the next time I run that code on the same "fileNode", Alfresco throw an exception for the duplicate items, but NOTHING happens in the UI, nowhere in my sight.



It is highly probable that I miss something obvious or misunderstand the "containment semantic" but right now I am at a loss.

Changing parents from java DOES work, and is reflected in the shareUI… (but I can't do what I am doing in JAVA for complex reasons tied to the current state of share (for the whole story see http://forums.alfresco.com/en/viewtopic.php?f=11&t=37710http://forums.alfresco.com/en/viewtopic.php?f=47&t=38098, and my goal is http://forums.alfresco.com/en/viewtopic.php?f=48&t=38233, but none of this matter for the problem at hand)

I am a few hours before declaring our proof of concept with alfresco a failure, so any help would be greatly appreciated Smiley Happy

thanks a lot for your time.


What am I missing ?
3 REPLIES 3

annakan
Champ in-the-making
Champ in-the-making
First things I was missing :

change in the debugger do not reflect in the repository, probably different transaction or thread+transactions

Second thing I was missing :

TargetFolder.addNode(actionedUponNodeRef)

SourceFolder.removeNode(actionedUponNodeRef)

no need to fidle with the relationships.

I really need to wrap my head better around the alfresco content model beyond the "everything is a node" simple thing.
The java and javascript API differs a bit too, in java you do nodeService.addChild(ParentNode, actionedUponNodeRef, AssocType, AssocQname), I suppose javascript does not support directly adding "typed" containment relationships.

Everything works but I still have a bug when I added a node to a folder, added it multiple parents, and then suppress the node, the folder it was added first seems to Keep a hidden reference to it that prevent adding it again. (many retries then ibatis sql error
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
— The error occurred in alfresco/ibatis/#resource.dialect#/node-insert-SqlMap.xml.
— The error occurred while applying a parameter map.
— Check the alfresco.node.insert_ChildAssoc-InlineParameterMap.
— Check the statement (update failed).
— Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '4958-33-2164579964-c4_small.jpg' for key 'parent_node_id'
        at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
        at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
        at org.springframework.orm.ibatis.SqlMapClientTemplate$8.doInSqlMapClient(SqlMapClientTemplate.java:366)
        at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
        … 129 more
I don't know if it is an alfresco bug for being "on the fringe" with multiple parents, or something I induce by mis-using the API.

Neither do I know if I should do some clean-up in the onBeforeDelete behavior ?

mrogers
Star Contributor
Star Contributor
Glad you got beyond last night's problems. Smiley Happy

You are posting long posts containing many different issues which makes it difficult to respond.
Perhaps you could start by saying what are you trying to do?   Rather than jumping to implementation.

annakan
Champ in-the-making
Champ in-the-making
Thanks for your reply.

Though everything is explained inline with references to my previous posts explaining both the problem and the context, I did not want to reproduce them and clutter even more the post or cross post.

Basically my post boils down to this :

First part is about the debugger obviously not allowing to experiment with the API because wathever call or change I make in it does not reflect on the repository I can browse through the web. Probably a transaction or session thing.
Could this be confirmed as a fact ?

The second part is about the fact that this experience lead me to doubt about what I was experiencing while trying to build my webscript based action.
I was trying to add and remove parents from a node to no avail, and my experiences in the debugger were, to say the least inconclusive too,  leading me to think that the API might be "faulty" in the way I used it.
Later on I discovered there was a higher level API to add and remove parents with TargetFolder.addNode(actionedUponNodeRef) & SourceFolder.removeNode(actionedUponNodeRef)
that wraps the nodeService.addChild(ParentNode, actionedUponNodeRef, AssocType, AssocQname) with a "contains" kind of relationship.
It still does not explain why I could not do it "directly" through the nodeRef.parents property but I suspect the javascript wrapping does so many magic behind the scene that sometimes it get itself lost. At the very least the semantic is unclear, at least to me.

My last problem was when deleting a node some leftover datas were preventing me to add the same document again, I add to implement the beforeDelete behavior with the "NotificationFrequency.FIRST_EVENT" policy to be able to remove the non primary parents from the node before deletion.

Why all this : because I want to properly support multiple parents for nodes, so that a document can really appears in multiple folders at once. I must say I constantly discovers new creative ways the "primary parent = container" is entrenched into the shareUI (for instance the "path webscript" that is used when constructing the crumb on a document detail page …. ), it is like the concept of "context" (where I came from as a user, where I am sited on as a document) is for now absent from share. Most assumption seems to be that the document is "self describing" in full, and that is not right neither in practice nor in the underlying model (where multiple parents ARE supported for the best).

I hope it answered your questions, I already have more to ask…
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.