Alfresco. Duplicate Child Node Name Exception y Versionado (checkin/checkout)

Septiembre 26, 2008

Al mover o crear un nodo, nos podemos encontrar con un error de que ya existe un nodo con este nombre. Para resolver esta excepción tenemos varias opciones:

  • No hacer nada
  • No moverlo
  • Borrar el destino y luego moverlo
  • Moverlo con otro nombre
  • O, la opción más elegante, incrementar la versión del documento haciendo checkin, checkout

Basándome en este post lo probé y llegué a este código, que ya pongo en la respuesta, y que cuento a continuación:

El principio es este:

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.

Y esta es la solución en código:
(Está en inglés)

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


// 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

Entry Filed under: alfresco. Etiquetas: .

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


 

Septiembre 2008
L M X J V S D
« Jul   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

Posts Más Vistos