Duplicate Child Node Name Exception

Support questions relating to the Alfresco JSF Web Client

Duplicate Child Node Name Exception

Postby patrik on 21 Sep 2007, 14:02

Hi! I'm having a problem when using simple workflow and transformation from doc to pdf. I trigger the workflow to copy an item to another space where a rule says that the item should be transformed to pdf and copied to a space. This works fine the first time. But the second time i get this error:

ERROR [ui.common.Utils] Failed to approve the document due to system error: Duplicate child name not allowed: {filename}
org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: {filename}

Can't alfresco replace this file and update it with a new version? It doesn't matter if i delete the previous doc-file that was created if i keep the pdf. As long as any of the two files are left nothing happens besides the duplicate error. It works well when i replace the recently created doc-file in webdav. Then the pdf gets updated.

I use alfresco 2.1 Enterprise version.

Help appreciated
patrik
Community Member
Community Member
 
Posts: 17
Joined: 13 Jul 2007, 14:13
Alfresco Version: 3.0

0 Points (What's this)

Postby kevinr on 25 Sep 2007, 12:41

The transform rule is pretty basic - you best bet is a JavaScript rule:
http://forums.alfresco.com/viewtopic.php?p=29257#29257
kevinr
Alfresco Engineer
Alfresco Engineer
 
Posts: 2539
Joined: 27 Jun 2005, 15:56
Location: London
Alfresco Version: 3.2

14 Points (What's this)

Postby patrik on 25 Sep 2007, 13:29

It seems to be the copy operation that doesn't support replacement (or update)

I've moved on to try to solve it with a javascript instead. The javascript first removes the file that is supposed to be replaced and then places the new transformed copy there instead. The problem that i have left is to set the version in accordance to the source object. I posted a thread on that here http://forums.alfresco.com/viewtopic.php?t=8806 .
patrik
Community Member
Community Member
 
Posts: 17
Joined: 13 Jul 2007, 14:13
Alfresco Version: 3.0

0 Points (What's this)

Postby SCHNEIKA on 01 Oct 2007, 16:57

Please can you post your complete javascript as an example here?
SCHNEIKA
Community Achiever
Community Achiever
 
Posts: 117
Joined: 25 Apr 2007, 09:41
Location: Germany

0 Points (What's this)

Postby patrik on 02 Oct 2007, 08:47

Here's the script. Now the version number is taken from the previous file. That means that i lose the version history. Is it possible to add a version to an existing node? E.g. by connecting the new file to the old one by workingCopyOwner and then check it in?
Code: Select all
var document = search.findNode(args["node"]);
var space = document.parent;
var parentFolderName = space.properties.name;
var releasable;
var fileName = document.properties.name;
var fileNameBase = fileName.substring(0,fileName.length-4);
var reply;
var version=document.properties.versionLabel;

//Test if the document is releasable
if(document.hasAspect("cm:releasable"))
{
   releasable=document.properties.releasable;
}
else
{
   releasable=false;
}

if(releasable)
{
   var parentFolderParent=space.parent.parent;
   var destFolder = parentFolderParent.childByNamePath("Released/"+parentFolderName);
   
   //Remove current document if it exists
   var destFile = destFolder.childByNamePath(fileNameBase + ".pdf")
   if (destFile!=null)
   {
      destFile.remove();
   }
   
   //Transform and move the document
   var trans = document.transformDocument("application/pdf");
   var copy = trans.copy(destFolder);
   
   //Set version according to source document
   copy.addAspect("cm:versionable");
   copy.properties.initialVersion=false;
   copy.properties.versionLabel=version;
   copy.save();
   trans.remove();
   //reply="The document has been successfully released. Push the back button to return to Alfresco.";
   var goBack = "<script>history.back();</script>";
   goBack;
}
else
{
   reply="The document is not releasable. Push the back button to return to Alfresco.";
}
patrik
Community Member
Community Member
 
Posts: 17
Joined: 13 Jul 2007, 14:13
Alfresco Version: 3.0

0 Points (What's this)

Postby bjorn_r on 03 Oct 2007, 16:21

Hi Patrik,

From 2.1 Enterprise and onwards there is a write method in the ScriptContent API, which is capable of copying binary content.

You should design your script to:
* Check out a working copy of your versioned node.
* Use the new write method to update the content of your working copy.
* Check in your working copy.

Cheers,
Björn
bjorn_r
Community Member
Community Member
 
Posts: 15
Joined: 03 Jan 2007, 23:21
Location: Gothenburg, Sweden

0 Points (What's this)

Postby SCHNEIKA on 04 Oct 2007, 20:28

Perhaps anybody can give an example how to use this new write method in the ScriptContent-API of V2.1.0E and V2.2.0CE? A little script-snippet?
SCHNEIKA
Community Achiever
Community Achiever
 
Posts: 117
Joined: 25 Apr 2007, 09:41
Location: Germany

0 Points (What's this)

Postby kevinr on 05 Oct 2007, 13:51

Code: Select all
// assume you have a document node called 'document' and that you have permissions to write to the current space

// first create a new node in the current space
var destNode = space.createFile("copy.txt");

// write the content from the current document into the destination
document.properties["cm:content"].write(destNode.properties["cm:content"]);
Alfresco Applications Team Leader
http://twitter.com/kevinroast - Find me on Twitter
http://www.alfresco.com/community/register - Alfresco Manuals
http://wiki.alfresco.com - Alfresco Wiki docs
http://wiki.alfresco.com/wiki/Developer_Guide - Alfresco Developer Guide
kevinr
Alfresco Engineer
Alfresco Engineer
 
Posts: 2539
Joined: 27 Jun 2005, 15:56
Location: London
Alfresco Version: 3.2

14 Points (What's this)

Re:

Postby sacco on 31 May 2008, 05:00

kevinr wrote:
Code: Select all
// write the content from the current document into the destination
document.properties["cm:content"].write(destNode.properties["cm:content"]);


Kevin, it looks as if you meant:
Code: Select all
// write the content from the current document into the destination
destNode.content.write(document.properties.content);


The .write() method copies from its argument to the current node.

But what is the point of this method? It create another file in the content
store on disk containing a copy of the content of the source, but with
Alfresco's 'write once' approach, there's surely no real point in storing
identical content in two different places ... is there?
sacco
Community Guru
Community Guru
 
Posts: 166
Joined: 18 Feb 2007, 18:28
Location: Italy

1 Point (What's this)

Re: Duplicate Child Node Name Exception

Postby kevinr on 02 Jun 2008, 13:22

The destination node may have different permissions i.e. may be accessable by different users. I'm sure you can think of other reasons why a copy of a content is useful :)

Cheers

Kevin
Alfresco Applications Team Leader
http://twitter.com/kevinroast - Find me on Twitter
http://www.alfresco.com/community/register - Alfresco Manuals
http://wiki.alfresco.com - Alfresco Wiki docs
http://wiki.alfresco.com/wiki/Developer_Guide - Alfresco Developer Guide
kevinr
Alfresco Engineer
Alfresco Engineer
 
Posts: 2539
Joined: 27 Jun 2005, 15:56
Location: London
Alfresco Version: 3.2

14 Points (What's this)

Re: Duplicate Child Node Name Exception

Postby sacco on 02 Jun 2008, 19:38

kevinr wrote:The destination node may have different permissions i.e. may be accessable by different users.


Yes, I can see that, but, if I've understood correctly, content data
(i.e. binary files stored in the Content Store) are effectively read-only
in Alfresco.

So if I were to replace:
Code: Select all
// write the content from the current document into the destination
destNode.content.write(document.properties.content);

with:
Code: Select all
// set the destination to refer to the content from the current document
destNode.properties["cm:content"] = document.properties.content;


then I would simply have an extra reference to the same stream of bits on the disk.
As this binary data is never modified, each user's access sees the same data in
both cases. I'm guessing that they could even see the same data with different
MIME types (set in the node's content metadata),
e.g. text/html and application/xhtml+xml

So I'm trying to understand why I would ever want to have two instances of the
exact same sequence of bits: where does the access control for download stream
come from, particularly in the case of multiple references to the same raw content?

I'm assuming that it can't depend directly upon the node from which it is accessed,
but all of my experiments so far suggest that access to the content stream through
different nodes is achieved through different URLs, and so different permissions
can be set for exactly the same bits for read-only access through different URLs.

Is there some loophole in this that I am missing?
sacco
Community Guru
Community Guru
 
Posts: 166
Joined: 18 Feb 2007, 18:28
Location: Italy

1 Point (What's this)

Re: Duplicate Child Node Name Exception

Postby adelatorre on 26 Sep 2008, 08:39

Hi!

I'll help with a code snippet this helpful reply

You should design your script to:
* Check out a working copy of your versioned node.
* Use the new write method to update the content of your working copy.
* Check in your working copy.


This is a move function, that detects if a node already exists
(Variables are in spanish)

Code: Select all
// Moves a node to a destination
function moveNode (nodo, destino) {
   // Search if exists
   var encontrado = destino.childByNamePath(nodo.name);
   
   if (encontrado != null) {
      if (! encontrado.hasAspect("cm:versionable")) {
         encontrado.addAspect("cm:versionable");
      }
      var wc = encontrado.checkout();
      wc.properties["cm:content"]=nodo.properties["cm:content"];
      wc.save();     
      wc.checkin("Update element: "+nodo.name);
      nodo.remove();
   }
   else
   {
      nodo.move(destino);
   }   
}


This only has a problem, increases two versions each time. I guess wc.save(), make his part in it, while we are updating that node.

I hope this helps
adelatorre
 
Posts: 4
Joined: 05 Mar 2008, 17:40

1 Point (What's this)


Return to Alfresco Explorer

Who is online

Users browsing this forum: freddy_r and 1 guest