Ejemplo n.º 1
0
        //[DebuggerStepThrough()]
        public static Content GetContentByPath(string documentPath)
        {
            Content lResult = null;

            try
            {
                var spacesStore = new ContentWebService.Store();
                spacesStore.scheme  = ContentWebService.StoreEnum.workspace;
                spacesStore.address = Constants.SPACES_STORE;

                var reference = new ContentWebService.Reference();
                reference.store = spacesStore;
                reference.path  = PathUtils.ConvertToRepositoryPath(documentPath);

                var predicate = new ContentWebService.Predicate();
                predicate.Items = new Object[] { reference };
                Content[] contents = WebServiceFactory.getContentService().read(predicate, "{http://www.alfresco.org/model/content/1.0}content");

                if (contents.Length != 0)
                {
                    lResult = contents[0];
                }
            }
            catch (SoapException ex)
            {
                if (ex.Detail.InnerText.Contains("Node does not exist"))
                {
                    throw new NotFoundDocumentException(ErrorMessages.NoData, documentPath, ErrorMessages.DocumentNotFound);
                }
                //else
                //    throw ex;
            }

            return(lResult);
        }
Ejemplo n.º 2
0
        private void writeContentType(String filePath, Alfresco.RepositoryWebService.Reference rwsRef,
                                      String property, String mimetype)
        {
            Alfresco.ContentWebService.Reference newContentNode = new Alfresco.ContentWebService.Reference();
            newContentNode.path = rwsRef.path;
            newContentNode.uuid = rwsRef.uuid;

            Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store();
            cwsStore.address     = "SpacesStore";
            spacesStore.scheme   = Alfresco.RepositoryWebService.StoreEnum.workspace;
            newContentNode.store = cwsStore;

            // Open the file and convert to byte array
            FileStream inputStream = new FileStream(filePath, FileMode.Open);

            int bufferSize = (int)inputStream.Length;

            byte[] bytes = new byte[bufferSize];
            inputStream.Read(bytes, 0, bufferSize);
            inputStream.Close();

            ContentFormat contentFormat = new ContentFormat();

            contentFormat.mimetype = mimetype;
            WebServiceFactory.getContentService().write(newContentNode, property, bytes, contentFormat);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The form load event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Browse_Load(object sender, EventArgs e)
        {
            // Ensure the user has been authenticated
            if (AuthenticationUtils.IsSessionValid == false)
            {
                AuthenticationUtils.startSession("admin", "sametsis");
            }

            // Get a repository and content service from the web service factory
            this.repoService      = WebServiceFactory.getRepositoryService();
            this.contentService   = WebServiceFactory.getContentService();
            this.authoringService = WebServiceFactory.getAuthoringService();

            // Populate the list box
            populateListBox();
        }
Ejemplo n.º 5
0
        private Content UpdateDocument(Alfresco.RepositoryWebService.Reference reference, byte[] document)
        {
            MimetypeMap mimeType = new MimetypeMap();

            var newContentNode = new Alfresco.ContentWebService.Reference();

            newContentNode.path = reference.path;
            newContentNode.uuid = reference.uuid;
            Alfresco.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);

            return(WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, document, contentFormat));
        }
Ejemplo n.º 6
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                String file = this.textBox1.Text;

                if (file.Equals(""))
                {
                    MessageBox.Show("Please select a file");
                    this.btnSelect.Focus();
                    return;
                }

                if (this.tbLocation.Text.Equals(""))
                {
                    MessageBox.Show("Please select the location");
                    this.btnLocation.Focus();
                    return;
                }

                int start  = file.LastIndexOf("\\") + 1;
                int length = file.Length - start;
                // get the filename only
                String fileName = file.Substring(start, length);

                if (file == null || file.Equals(""))
                {
                    MessageBox.Show("please select a file");
                    return;
                }
                // Display a wait cursor while the file is uploaded
                Cursor.Current = Cursors.WaitCursor;

                // Initialise the reference to the spaces store
                Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store();
                spacesStore.scheme  = Alfresco.RepositoryWebService.StoreEnum.workspace;
                spacesStore.address = "SpacesStore";

                // Create the parent reference, the company home folder
                Alfresco.RepositoryWebService.ParentReference parentReference = new Alfresco.RepositoryWebService.ParentReference();
                parentReference.store = spacesStore;
                //                parentReference.path = "/app:company_home";
                parentReference.uuid = this.locationUuid;


                parentReference.associationType = Constants.ASSOC_CONTAINS;
                parentReference.childName       = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, fileName);

                // Create the properties list
                NamedValue nameProperty = new NamedValue();
                nameProperty.name         = Constants.PROP_NAME;
                nameProperty.value        = fileName;
                nameProperty.isMultiValue = false;

                NamedValue[] properties = new NamedValue[2];
                properties[0]             = nameProperty;
                nameProperty              = new NamedValue();
                nameProperty.name         = Constants.PROP_TITLE;
                nameProperty.value        = fileName;
                nameProperty.isMultiValue = false;
                properties[1]             = nameProperty;

                // Create the CML create object
                CMLCreate create = new CMLCreate();
                create.parent   = parentReference;
                create.id       = "1";
                create.type     = Constants.TYPE_CONTENT;
                create.property = properties;

                // Create and execute the cml statement
                CML cml = new CML();
                cml.create = new CMLCreate[] { create };
                UpdateResult[] updateResult = repoService.update(cml);

                // work around to cast Alfresco.RepositoryWebService.Reference to
                // Alfresco.ContentWebService.Reference
                Alfresco.RepositoryWebService.Reference rwsRef         = updateResult[0].destination;
                Alfresco.ContentWebService.Reference    newContentNode = new Alfresco.ContentWebService.Reference();
                newContentNode.path = rwsRef.path;
                newContentNode.uuid = rwsRef.uuid;
                Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store();
                cwsStore.address     = "SpacesStore";
                spacesStore.scheme   = Alfresco.RepositoryWebService.StoreEnum.workspace;
                newContentNode.store = cwsStore;

                // Open the file and convert to byte array
                FileStream inputStream = new FileStream(file, FileMode.Open);

                int    bufferSize = (int)inputStream.Length;
                byte[] bytes      = new byte[bufferSize];
                inputStream.Read(bytes, 0, bufferSize);

                inputStream.Close();

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

                WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);

                // Reset the cursor to the default for all controls.
                Cursor.Current = Cursors.Default;

                MessageBox.Show(file + " uploaded");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Ejemplo n.º 7
0
        private void UploadNow(string fileName, string file)
        {
            // Initialise the reference to the spaces store
            Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store();
            spacesStore.scheme  = Alfresco.RepositoryWebService.StoreEnum.workspace;
            spacesStore.address = "SpacesStore";

            // Create the parent reference, the company home folder
            Alfresco.RepositoryWebService.ParentReference parentReference = new Alfresco.RepositoryWebService.ParentReference();
            parentReference.store = spacesStore;
            //parentReference.path = "/app:company_home"
            parentReference.uuid            = LocationUuid;
            parentReference.associationType = Constants.ASSOC_CONTAINS;
            parentReference.childName       = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, fileName);

            // Create the properties list
            NamedValue nameProperty = new NamedValue();

            nameProperty.name         = Constants.PROP_NAME;
            nameProperty.value        = fileName;
            nameProperty.isMultiValue = false;

            NamedValue[] properties = new NamedValue[2];
            properties[0]             = nameProperty;
            nameProperty              = new NamedValue();
            nameProperty.name         = Constants.PROP_TITLE;
            nameProperty.value        = fileName;
            nameProperty.isMultiValue = false;
            properties[1]             = nameProperty;

            // Create the CML create object
            CMLCreate create = new CMLCreate();

            create.parent   = parentReference;
            create.id       = "1";
            create.type     = Constants.TYPE_CONTENT;
            create.property = properties;

            // Create and execute the cml statement
            CML cml = new CML();

            cml.create = new CMLCreate[] { create };
            UpdateResult[] updateResult = repoService.update(cml);

            // work around to cast Alfresco.RepositoryWebService.Reference to
            // Alfresco.ContentWebService.Reference
            Alfresco.RepositoryWebService.Reference rwsRef         = updateResult[0].destination;
            Alfresco.ContentWebService.Reference    newContentNode = new Alfresco.ContentWebService.Reference();
            newContentNode.path = rwsRef.path;
            newContentNode.uuid = rwsRef.uuid;
            Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store();
            cwsStore.address     = "SpacesStore";
            spacesStore.scheme   = Alfresco.RepositoryWebService.StoreEnum.workspace;
            newContentNode.store = cwsStore;

            // Open the file and convert to byte array
            FileStream inputStream = new FileStream(file, FileMode.Open);

            int bufferSize = (int)inputStream.Length;

            byte[] bytes = new byte[bufferSize];
            inputStream.Read(bytes, 0, bufferSize);

            inputStream.Close();

            ContentFormat contentFormat = new ContentFormat();

            if (rdjpeg.Checked == true)
            {
                contentFormat.mimetype = "image/jpeg";
            }
            else if (rdgif.Checked == true)
            {
                contentFormat.mimetype = "image/gif";
            }
            else if (rdtiff.Checked == true)
            {
                contentFormat.mimetype = "image/tiff";
            }

            WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);
        }
        public void CanCreateNodesWithContent()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store  spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name        = "AWS Book - Chapter 2 - " + 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 };

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

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

                //get the new node reference
                Alfresco.ContentWebService.Reference referenceForContent = Alfresco.ContentWebService.Reference.From(result[0].destination);

                //create content with ContentService
                Alfresco.ContentWebService.ContentFormat format  = new Alfresco.ContentWebService.ContentFormat(mimeType, encoding);
                Alfresco.ContentWebService.Content       content = WebServiceFactory.getContentService().write(
                    referenceForContent,
                    Constants.PROP_CONTENT,
                    new ASCIIEncoding().GetBytes("This is the content for the new node"),
                    format
                    );

                String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Chapter_x0020_2_x0020_-_x0020_";
                Assert.IsTrue(content.node.path.StartsWith(expectedPath));
            } finally {
                AuthenticationUtils.endSession();
            }
        }