示例#1
0
        /// <summary>
        /// Guarda un fichero en el nodo especificado
        /// </summary>
        /// <param name="parentId">uuid del nodo donde queremos guardar el documento</param>
        /// <param name="documentPath">Ruta local de la que se debe sacar el fichero, aquí se devuelve la ruta del repositorio donde se ha guardado el  documento</param>
        /// <param name="document">raw document, si este valor es null se intentará leer el documento del documentPath</param>
        /// <returns>uuid del documento que se ha salvado</returns>
        public string CreateFileByParentId(string parentId, ref string documentName, byte[] document)
        {
            if (document == null) return null;

            string documentId = null;
            var mimeType = new MimetypeMap();

            try
            {
                UpdateResult[] updateResult = CreateNode(parentId, null, Constants.TYPE_CONTENT);

                // work around to cast Alfresco.RepositoryWebService.Reference to Alfresco.ContentWebService.Reference
                RepositoryWebService.Reference rwsRef = updateResult[0].destination;
                ContentWebService.Reference newContentNode = new Alfresco.ContentWebService.Reference();
                newContentNode.path = rwsRef.path;
                newContentNode.uuid = rwsRef.uuid;
                ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store();
                cwsStore.address = Constants.SPACES_STORE;
                newContentNode.store = cwsStore;

                var contentFormat = new Alfresco.ContentWebService.ContentFormat();
                contentFormat.mimetype = mimeType.GuessMimetype(Name);

                Content lContent = WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, document, contentFormat);
                documentName = ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(lContent.node.path));
                documentId = lContent.node.uuid;
            }
            catch (SoapException ex)
            {
                if (ex.Detail.InnerText.Contains("DuplicateChildNodeNameException"))
                {
                    var node = new NodeBase();
                    var nodePath = String.Format("{0}/{1}", node.GetPathById(parentId), System.IO.Path.GetFileName(documentName));
                    var id = node.GetIdByPath(nodePath);

                    throw new DuplicateDocumentException(id, nodePath);
                }
                else
                    throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return documentId;
        }
示例#2
0
        public static NodeBase GetNodeById(string documentId)
        {
            NodeBase lNode = null;

            Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store();
            spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace;
            spacesStore.address = Constants.SPACES_STORE;

            // Create a query object
            Alfresco.RepositoryWebService.Query query = new Alfresco.RepositoryWebService.Query();
            query.language = Constants.QUERY_LANG_LUCENE;
            query.statement = string.Format("@sys\\:node-uuid:\"{0}\"", documentId);
            QueryResult result = WebServiceFactory.getRepositoryService().query(spacesStore, query, true);

            if (result.resultSet.rows != null)
            {
                ResultSetRow row = result.resultSet.rows[0];
                lNode = new NodeBase();
                lNode.properties = new NamedValue[row.columns.Length];
                row.columns.CopyTo(lNode.properties, 0);
                lNode.id = documentId;
            }

            return lNode;
        }
示例#3
0
        ///// <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;
        }