예제 #1
0
        private CML getCMLUpdate(String uuid, NamedValue[] properties)
        {
            // ************ test ***********8

            /*
             * for (int i = 0; i < properties.Length; i++)
             * {
             *
             *  NamedValue name = properties[i];
             *  if (name.name.Equals(Alfresco.Constants.PROP_DESCRIPTION))
             *  {
             *      MessageBox.Show("Gotcha");
             *      name.value = "UPDATE";
             *      properties[i] = name;
             *  }
             * }
             */

            Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference();
            reference.store = this.spacesStore;
            reference.uuid  = uuid;

            CMLUpdate cmlUpdate = new CMLUpdate();

            Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate();
            pred.Items         = new Alfresco.RepositoryWebService.Reference[] { reference };
            cmlUpdate.where    = pred;
            cmlUpdate.property = properties;

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

            cml.update = new CMLUpdate[] { cmlUpdate };

            return(cml);
        }
예제 #2
0
        public void CanVersionNodes()
        {
            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);

                //update node version 1.1
                CMLUpdate update11 = new CMLUpdate();
                createSampleVo.Name  = "1.1 " + name;
                createSampleVo.Title = "1.1" + name;
                update11.property    = Builder.BuildCustomProperties(createSampleVo);
                update11.where       = sourcePredicate;

                CML cmlUpdate11 = new CML();
                cmlUpdate11.update = new CMLUpdate[] { update11 };

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

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

                //node history: the 1.0 version
                Alfresco.AuthoringWebService.Reference      reference   = Alfresco.AuthoringWebService.Reference.From(firstItem);
                Alfresco.AuthoringWebService.VersionHistory nodeHistory = WebServiceFactory.getAuthoringService().getVersionHistory(reference);

                Assert.AreEqual(2, nodeHistory.versions.Length);

                Alfresco.AuthoringWebService.Version latestVersion = nodeHistory.versions[0];
                Assert.NotNull(latestVersion.id.uuid);
                Assert.AreEqual("1.1", latestVersion.label);
                Assert.AreEqual(DateTime.Now.Date, latestVersion.created.Date);
                Assert.AreEqual("admin", latestVersion.creator);

                Alfresco.AuthoringWebService.Version previousVersion = nodeHistory.versions[1];
                Assert.NotNull(previousVersion.id.uuid);
                Assert.AreEqual("1.0", previousVersion.label);
                Assert.AreEqual(DateTime.Now.Date, previousVersion.created.Date);
                Assert.AreEqual("admin", previousVersion.creator);
            } finally {
                AuthenticationUtils.endSession();
            }
        }
예제 #3
0
        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 expectedName = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedName));

                expectedName = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_Space_x0020_Sample_x0020_";
                Assert.IsTrue(result[1].destination.path.StartsWith(expectedName));

                //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;

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

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

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

                expectedName = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_";
                Reference firstItem = sourcePredicate.Items[0] as Reference;
                Assert.IsTrue(firstItem.path.StartsWith(expectedName));
            } finally {
                AuthenticationUtils.endSession();
            }
        }