예제 #1
0
        public void CanStoreNodes()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore");

            String name = "AWS Book " + 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);

            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;

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

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

                String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));

            } finally {
                AuthenticationUtils.endSession();
            }
        }
        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);
            }
        }
        public void CanUpdateNodes()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name = "AWS Book - Remove Child " + DateTime.Now.Ticks;
            String spaceNameForMove = "AWS Book - Remove Child 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_Remove_x0020_Child_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));

                expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_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;

                name = "AWS Book - Changed by CMLUpdate " + DateTime.Now.Ticks;
                createSampleVo.Name = name;
                createSampleVo.Title = name;
                createSampleVo.Description = "Changed by CMLUpdate " + description;

                //add versionable aspect to the node
                CMLAddAspect aspect = new CMLAddAspect();
                aspect.aspect = Constants.ASPECT_VERSIONABLE;
                aspect.where = sourcePredicate;

                //update node
                CMLUpdate update = new CMLUpdate();
                update.property = Builder.BuildCustomProperties(createSampleVo);
                update.where = sourcePredicate;

                CML cmlUpdate = new CML();
                cmlUpdate.addAspect = new CMLAddAspect[] { aspect };
                cmlUpdate.update = new CMLUpdate[] { update };

                //perform a CML update
                WebServiceFactory.getRepositoryService().update(cmlUpdate);

                expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_";
                Reference firtItem = sourcePredicate.Items[0] as Reference;
                Assert.IsTrue(firtItem.path.StartsWith(expectedPath));

            }
            finally
            {
                AuthenticationUtils.endSession();
            }
        }
예제 #4
0
        private CML getCMLCreate(NamedValue[] properties)
        {
            string qName = "ASCENT_" + releaseData.UniqueDocumentID.ToString();

            // get the parent reference
            Alfresco.RepositoryWebService.ParentReference parentReference = new Alfresco.RepositoryWebService.ParentReference();
            parentReference.store = spacesStore;
            parentReference.uuid = this.locationUuid;

            parentReference.associationType = Constants.ASSOC_CONTAINS;
            // set node content type
            parentReference.childName = this.contentType;

            // Create the CML create object
            CMLCreate create = new CMLCreate();
            create.parent = parentReference;
            create.id = "1";

            // set the contenttype
            create.type = this.contentType;
            create.property = properties;

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

            return cml;
        }
        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();
            }
        }
예제 #6
0
        protected UpdateResult[] CreateNode(string parentId, string parentPath, string nodeType)
        {
            UpdateResult[] result = null;
            var parent = new RepositoryWebService.ParentReference(
                spacesStore,
                parentId,
                parentPath,
                Constants.ASSOC_CONTAINS,
                Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, name)
                );

            //build properties
            BuildCustomProperties();

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

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

            //perform a CML update to create the node
            result = WebServiceFactory.getRepositoryService().update(cml);

            return result;
        }