Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public string UpdateFileById(string id, byte[] document)
        {
            if (document == null)
            {
                return(string.Empty);
            }

            Id = id;
            RepositoryWebService.Reference reference;
            ResultSetRow row = FindNodeById(id);

            if (row == null)
            {
                throw new NotFoundDocumentException(id, ErrorMessages.DocumentNotFound);
            }

            reference = GetReferenceFromResultSetRow(row);
            Content lContent = UpdateDocument(reference, document);

            return(ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(lContent.node.path)));
        }
Exemplo n.º 4
0
        public string UpdateFileByPath(string path, byte[] document)
        {
            if (document == null)
            {
                return(string.Empty);
            }

            this.Path = path;
            ResultSetRow row = FindNodeByPath(ref path);

            if (row == null)
            {
                throw new NotFoundDocumentException(Id, path, ErrorMessages.DocumentNotFound);
            }

            var reference = GetReferenceFromResultSetRow(row);

            Id = reference.uuid;
            Content lContent = UpdateDocument(reference, document);

            return(ISO9075.Decode(PathUtils.ConvertFromRepositoryPath(lContent.node.path)));
        }
        public void CanCreateNodesWithContent()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store  spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name        = "AWSBook " + DateTime.Now.Ticks;
            String description = "This is a content created with a sample of the book";
            String mimeType    = "text/plain";
            String encoding    = "UTF-8";

            //custom value object
            CreateSampleVO createSampleVo = Builder.BuildCreateSampleVO(name, name, description);

            try {
                ParentReference parent = new ParentReference(
                    spacesStore,
                    null,
                    "/app:company_home",
                    Constants.ASSOC_CONTAINS,
                    "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name
                    );

                //build properties
                NamedValue[] properties = Builder.BuildCustomProperties(createSampleVo);

                //create operation
                CMLCreate create = new CMLCreate();
                create.id       = "1";
                create.parent   = parent;
                create.type     = Constants.TYPE_CONTENT;
                create.property = properties;

                //create the node reference
                Reference reference = new Reference();
                reference.store = spacesStore;
                reference.path  = "/app:company_home/cm:" + ISO9075.Encode(name);

                //create the predicate
                Predicate predicate = new Predicate();
                predicate.Items = new Reference[] { reference };

                //set mime type and encoding for indexing
                ContentFormat format = new ContentFormat(mimeType, encoding);

                //write operation
                CMLWriteContent writeContent = new CMLWriteContent();
                writeContent.format   = format;
                writeContent.where    = predicate;
                writeContent.property = Constants.PROP_CONTENT;
                writeContent.content  = new ASCIIEncoding().GetBytes("This is the content for the new node");

                //build the CML object
                CML cml = new CML();
                cml.create       = new CMLCreate[] { create };
                cml.writeContent = new CMLWriteContent[] { writeContent };

                //perform a complete CML update for the node and the related file
                UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);

                String expectedPath = "/app:company_home/cm:AWSBook_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));
            } finally {
                AuthenticationUtils.endSession();
            }
        }
Exemplo n.º 6
0
        public ResultSetRow FindNodeByPath(ref string nodePath)
        {
            ResultSetRow lResult = null;

            nodePath = PathUtils.NormalicePath(nodePath);

            string queryString = PathUtils.ConvertToRepositoryPath(System.IO.Path.GetDirectoryName(nodePath) + "/" + ISO9075.Encode(System.IO.Path.GetFileName(nodePath)));
            var    query       = new RepositoryWebService.Query();

            query.language = Constants.QUERY_LANG_LUCENE;
            //TODO: Consultas que sí funcionan:
            //query.statement = "PATH:\"//app:company_home//cm:Pruebas//cm:Test_Folder/*\"";
            //query.statement = "PATH:\"//cm:Pruebas//cm:Test_Folder/*\"";  Todos los archivos de un folder
            //query.statement = "PATH:\"//cm:Pruebas//cm:Test_Folder\"";   Devuelve un folder
            query.statement = "PATH:\"" + queryString + "\"";

            QueryResult result = WebServiceFactory.getRepositoryService().query(spacesStore, query, false);

            if (result.resultSet.rows != null)
            {
                lResult = result.resultSet.rows[0];
            }

            return(lResult);
        }