///// <summary> ///// Copia un archivo de una localización a otroa ///// </summary> ///// <param name="uuidNodeToCopy"></param> ///// <param name="DestinationNodePath"></param> ///// <returns>En DestinationNodePath se devuelve la ruta final del archivo</returns> //public string CopyFile(string uuidNodeToCopy, ref string DestinationNodePath) //{ // if (string.IsNullOrEmpty(uuidNodeToCopy) || string.IsNullOrEmpty(DestinationNodePath)) // return null; // string documentId = null; // RepositoryWebService.Store cwsStore = new RepositoryWebService.Store(); // cwsStore.address = Constants.SPACES_STORE; // try // { // //Obtenemos la ruta donde se copiara el documento, o la creamos si no existe // FolderNode nod = new FolderNode(); // string destNodeId = nod.CreatePathRecursive(DestinationNodePath); // this.Name = GetNodeById(uuidNodeToCopy).Name; // UpdateResult[] rsrDest = CreateNode(destNodeId, null, Constants.TYPE_CONTENT); // ResultSetRow rsrOrigin = FindNodeById(uuidNodeToCopy); // RepositoryWebService.Reference refOrigin = GetReferenceFromResultSetRow(rsrOrigin); // RepositoryWebService.Predicate sourcePredicate = new RepositoryWebService.Predicate( // new Alfresco.RepositoryWebService.Reference[] { refOrigin }, cwsStore, null); // //reference for the target space // RepositoryWebService.ParentReference targetSpace = new RepositoryWebService.ParentReference(); // targetSpace.store = spacesStore; // targetSpace.path = DestinationNodePath; // targetSpace.associationType = Constants.ASSOC_CONTAINS; // targetSpace.childName = Name; // //copy content // CMLCopy copy = new CMLCopy(); // copy.where = sourcePredicate; // copy.to = targetSpace; // CML cmlCopy = new CML(); // cmlCopy.copy = new CMLCopy[] { copy }; // //perform a CML update to move the node // UpdateResult[] updateResult = WebServiceFactory.getRepositoryService().update(cmlCopy); // DestinationNodePath = ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(updateResult[0].destination.path)); // documentId = updateResult[0].destination.uuid; // } // catch (SoapException ex) // { // if (ex.Detail.InnerText.Contains("DuplicateChildNodeNameException")) // { // var node = new NodeBase(); // var nodePath = String.Format("{0}/{1}", DestinationNodePath, this.Name); // var id = node.GetIdByPath(nodePath); // throw new DuplicateDocumentException(id, nodePath); // } // else // throw ex; // } // catch (Exception ex) // { // throw ex; // } // return documentId; //} //public string CopyFile(string uuidNodeToCopy, ref string DestinationNodePath) //{ // if (string.IsNullOrEmpty(uuidNodeToCopy) || string.IsNullOrEmpty(DestinationNodePath)) // return null; // string documentId = null; // try // { // this.Name = GetNodeById(uuidNodeToCopy).Name; // //Obtenemos la ruta donde se copiara el documento, o la creamos si no existe // FolderNode nod = new FolderNode(); // string destNodeId = nod.CreatePathRecursive(DestinationNodePath); // UpdateResult[] updateNode = CreateNode(destNodeId, null, Constants.TYPE_CONTENT); // //reference for the target space // RepositoryWebService.ParentReference targetSpace = new RepositoryWebService.ParentReference(); // targetSpace.store = spacesStore; // targetSpace.path = updateNode[0].destination.path; // targetSpace.associationType = Constants.ASSOC_CONTAINS; // targetSpace.childName = Name; // RepositoryWebService.Predicate Source = new RepositoryWebService.Predicate( // new Alfresco.RepositoryWebService.Reference[] { GetReferenceFromResultSetRow(FindNodeById(uuidNodeToCopy)) }, spacesStore, null); // //copy content // CMLCopy copy = new CMLCopy(); // copy.where = Source; // copy.to = targetSpace; // CML cmlCopy = new CML(); // cmlCopy.copy = new CMLCopy[] { copy }; // //perform a CML update to move the node // RepositoryWebService.UpdateResult[] updateResult = WebServiceFactory.getRepositoryService().update(cmlCopy); // DestinationNodePath = ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(updateResult[0].destination.path)); // documentId = updateResult[0].destination.uuid; // } // catch (SoapException ex) // { // if (ex.Detail.InnerText.Contains("DuplicateChildNodeNameException")) // { // var node = new NodeBase(); // var nodePath = String.Format("{0}/{1}", DestinationNodePath, this.Name); // var id = node.GetIdByPath(nodePath); // throw new DuplicateDocumentException(id, nodePath); // } // else // throw ex; // } // catch (Exception ex) // { // throw ex; // } // return documentId; //} public string CopyFile(string uuidNodeToCopy, ref string DestinationNodePath) { if (string.IsNullOrEmpty(uuidNodeToCopy) || string.IsNullOrEmpty(DestinationNodePath)) { return(null); } string documentId = null; try { this.Name = GetNodeById(uuidNodeToCopy).Name; //Obtenemos la ruta donde se copiara el documento, o la creamos si no existe FolderNode nod = new FolderNode(); string destNodeId = nod.CreatePathRecursive(DestinationNodePath); RepositoryWebService.Predicate Source = new RepositoryWebService.Predicate( new Alfresco.RepositoryWebService.Reference[] { GetReferenceFromResultSetRow(FindNodeById(uuidNodeToCopy)) }, spacesStore, null); //copy content CMLCopy copy = new CMLCopy(); copy.where = Source; copy.to = createParentReference(destNodeId, Constants.ASSOC_CONTAINS, Name); CML cmlCopy = new CML(); cmlCopy.copy = new CMLCopy[] { copy }; //perform a CML update to move the node RepositoryWebService.UpdateResult[] updateResult = WebServiceFactory.getRepositoryService().update(cmlCopy); DestinationNodePath = ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(updateResult[0].destination.path)); documentId = updateResult[0].destination.uuid; } catch (SoapException ex) { if (ex.Detail.InnerText.Contains("DuplicateChildNodeNameException")) { var node = new NodeBase(); var nodePath = String.Format("{0}/{1}", DestinationNodePath, this.Name); var id = node.GetIdByPath(nodePath); throw new DuplicateDocumentException(id, nodePath); } else { throw ex; } } catch (Exception ex) { throw ex; } return(documentId); }
public void CanCopyNodes() { AuthenticationUtils.startSession("admin", "admin"); Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore"); String name = "AWS Book - Content Copied " + DateTime.Now.Ticks; String spaceNameForMove = "AWS Book - Copy Space Sample " + DateTime.Now.Ticks; String description = "This is a content created with a sample of the book"; //custom value object CreateSampleVO createSampleVo = Builder.BuildCreateSampleVO(name, name, description); CreateSampleVO createFolderSampleVo = Builder.BuildCreateSampleVO(spaceNameForMove, spaceNameForMove, description); try { //parent for the new node ParentReference parentForNode = new ParentReference( spacesStore, null, "/app:company_home", Constants.ASSOC_CONTAINS, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name ); //parent for the new space ParentReference parentForSpace = new ParentReference( spacesStore, null, "/app:company_home", Constants.ASSOC_CONTAINS, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + spaceNameForMove ); //build properties NamedValue[] properties = Builder.BuildCustomProperties(createSampleVo); NamedValue[] propertiesForSpace = Builder.BuildCustomPropertiesForSpace(createFolderSampleVo); //create a node CMLCreate create = new CMLCreate(); create.id = "1"; create.parent = parentForNode; create.type = Constants.TYPE_CONTENT; create.property = properties; //create a space CMLCreate createSpace = new CMLCreate(); createSpace.id = "2"; createSpace.parent = parentForSpace; createSpace.type = Constants.TYPE_FOLDER; createSpace.property = propertiesForSpace; //build the CML object CML cmlAdd = new CML(); cmlAdd.create = new CMLCreate[] { create, createSpace }; //perform a CML update to create nodes UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cmlAdd); String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Content_x0020_Copied_x0020_"; Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath)); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Copy_x0020_Space_x0020_Sample_x0020_"; Assert.IsTrue(result[1].destination.path.StartsWith(expectedPath)); //create a predicate with the first CMLCreate result Reference referenceForNode = result[0].destination; Predicate sourcePredicate = new Predicate(new Reference[] { referenceForNode }, spacesStore, null); //create a reference from the second CMLCreate performed for space Reference referenceForTargetSpace = result[1].destination; //reference for the target space ParentReference targetSpace = new ParentReference(); targetSpace.store = spacesStore; targetSpace.path = referenceForTargetSpace.path; targetSpace.associationType = Constants.ASSOC_CONTAINS; targetSpace.childName = name; //copy content CMLCopy copy = new CMLCopy(); copy.where = sourcePredicate; copy.to = targetSpace; CML cmlCopy = new CML(); cmlCopy.copy = new CMLCopy[] { copy }; //perform a CML update to move the node WebServiceFactory.getRepositoryService().update(cmlCopy); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Content_x0020_Copied_x0020_"; Assert.IsTrue(referenceForNode.path.StartsWith(expectedPath)); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Copy_x0020_Space_x0020_Sample_x0020_"; Assert.IsTrue(targetSpace.path.StartsWith(expectedPath)); } finally { AuthenticationUtils.endSession(); } }