public void CanDeleteNodes() { 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 cmlAdd = new CML(); cmlAdd.create = new CMLCreate[] { create }; //perform a CML update to create the node UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cmlAdd); String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_"; Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath)); //create a predicate Reference reference = result[0].destination; Predicate predicate = new Predicate(new Reference[] { reference }, spacesStore, null); //delete content CMLDelete delete = new CMLDelete(); delete.where = predicate; CML cmlRemove = new CML(); cmlRemove.delete = new CMLDelete[] { delete }; //perform a CML update to remove the node WebServiceFactory.getRepositoryService().update(cmlRemove); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_"; Assert.IsTrue(reference.path.StartsWith(expectedPath)); } finally { AuthenticationUtils.endSession(); } }
public static NamedValue[] BuildCustomProperties(CreateSampleVO createSampleVo) { NamedValue[] properties = new NamedValue[3]; properties[0] = Utils.createNamedValue(Constants.PROP_NAME, createSampleVo.Name); properties[1] = Utils.createNamedValue(Constants.PROP_TITLE, createSampleVo.Title); properties[2] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, createSampleVo.Description); return(properties); }
public static CreateSampleVO BuildCreateSampleVO(String name, String title, String description) { CreateSampleVO createSample = new CreateSampleVO(); createSample.Name = name; createSample.Title = title; createSample.Description = description; return(createSample); }
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(); } }
public void CanRemoveChildNodes() { 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; //add child CMLAddChild addChild = new CMLAddChild(); addChild.where = sourcePredicate; addChild.to = targetSpace; CML cmlAddChild = new CML(); cmlAddChild.addChild = new CMLAddChild[] { addChild }; //perform a CML update to add a child node UpdateResult[] resultAddChild = WebServiceFactory.getRepositoryService().update(cmlAddChild); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_"; Assert.IsTrue(referenceForNode.path.StartsWith(expectedPath)); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_Space_x0020_Sample_x0020_"; Assert.IsTrue(targetSpace.path.StartsWith(expectedPath)); Reference refUpdate = resultAddChild[0].destination; Predicate nodeToRemove = new Predicate(new Reference[] { refUpdate }, spacesStore, null); //remove child CMLRemoveChild removeChild = new CMLRemoveChild(); removeChild.Item = targetSpace; removeChild.where = nodeToRemove; CML cmlRemoveChild = new CML(); cmlRemoveChild.removeChild = new CMLRemoveChild[] { removeChild }; //perform a CML update to remove the node WebServiceFactory.getRepositoryService().update(cmlRemoveChild); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_"; Reference firtsItem = nodeToRemove.Items[0] as Reference; Assert.IsTrue(firtsItem.path.StartsWith(expectedPath)); expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_Space_x0020_Sample_x0020_"; Assert.IsTrue(referenceForTargetSpace.path.StartsWith(expectedPath)); } finally { AuthenticationUtils.endSession(); } }
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(); } }