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); }
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); }
public static NodeBase GetNodeById(string documentId) { NodeBase lNode = null; Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store(); spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; spacesStore.address = Constants.SPACES_STORE; // Create a query object Alfresco.RepositoryWebService.Query query = new Alfresco.RepositoryWebService.Query(); query.language = Constants.QUERY_LANG_LUCENE; query.statement = string.Format("@sys\\:node-uuid:\"{0}\"", documentId); QueryResult result = WebServiceFactory.getRepositoryService().query(spacesStore, query, true); if (result.resultSet.rows != null) { ResultSetRow row = result.resultSet.rows[0]; lNode = new NodeBase(); lNode.properties = new NamedValue[row.columns.Length]; row.columns.CopyTo(lNode.properties, 0); lNode.id = documentId; } return(lNode); }
//********************************************************** // Function: OpenScript() // Scope: internal // Overview: Script initialization point. Perform any // necessary initialization such as logging // in to a remote data source, allocated any // necessary resources, etc. // Params: none // Returns: One of the following: // KFX_REL_SUCCESS, KFX_REL_ERROR // Called By: The Batch Release Manager. Called once // when the script object is loaded. //********************************************************** public AscentRelease.KfxReturnValue OpenScript() { // Start the Alfresco session try { string repository = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_REPOSITORY); WebServiceFactory.setEndpointAddress(repository); string userName = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_USERNAME); string password = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_PASSWORD); AuthenticationUtils.startSession(userName, password); this.repoService = WebServiceFactory.getRepositoryService(); // the uuid of the location to be saved this.locationUuid = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION_UUID); this.contentType = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_CONTENT_TYPE); this.imageContentProp = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_IMAGE); this.ocrContentProp = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_OCR); this.pdfContentProp = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_PDF); // Initialise the reference to the spaces store this.spacesStore = new Alfresco.RepositoryWebService.Store(); spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; spacesStore.address = "SpacesStore"; return(AscentRelease.KfxReturnValue.KFX_REL_SUCCESS); } catch (Exception) { return(AscentRelease.KfxReturnValue.KFX_REL_ERROR); } }
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(); } }
///// <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); }
public UploadExample() { InitializeComponent(); AuthenticationUtils.startSession("admin", "sametsis"); // Get the repository service this.repoService = WebServiceFactory.getRepositoryService(); }
public ImageUploadExample() { InitializeComponent(); AuthenticationUtils.startSession("admin", "sametsis"); // Create the repo service and set the authentication credentials this.repoService = WebServiceFactory.getRepositoryService(); }
public void CanPerformSearches() { AuthenticationUtils.startSession("admin", "admin"); try { RepositoryService repositoryService = WebServiceFactory.getRepositoryService(); Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore"); String luceneQuery = "PATH:\"/app:company_home\""; Query query = new Query(Constants.QUERY_LANG_LUCENE, luceneQuery); QueryResult queryResult = repositoryService.query(spacesStore, query, false); ResultSet resultSet = queryResult.resultSet; ResultSetRow[] results = resultSet.rows; //your custom list IList <CustomResultVO> customResultList = new List <CustomResultVO>(); //retrieve results from the resultSet foreach (ResultSetRow resultRow in results) { ResultSetRowNode nodeResult = resultRow.node; //create your custom value object CustomResultVO customResultVo = new CustomResultVO(); customResultVo.Id = nodeResult.id; customResultVo.Type = nodeResult.type; //retrieve properties from the current node foreach (NamedValue namedValue in resultRow.columns) { if (Constants.PROP_NAME.Equals(namedValue.name)) { customResultVo.Name = namedValue.value; } else if (Constants.PROP_DESCRIPTION.Equals(namedValue.name)) { customResultVo.Description = namedValue.value; } } //add the current result to your custom list customResultList.Add(customResultVo); } Assert.AreEqual(1, customResultList.Count); CustomResultVO firstResult = customResultList[0]; Assert.IsNotNull(firstResult.Id); Assert.AreEqual("{http://www.alfresco.org/model/content/1.0}folder", firstResult.Type); } finally { AuthenticationUtils.endSession(); } }
/// <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(); }
private void DeleteNodes(Alfresco.RepositoryWebService.Reference[] references) { var predicate = new RepositoryWebService.Predicate(references, 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); }
public ResultSetRow FindNodeById(string nodeId) { ResultSetRow lResult = null; Alfresco.RepositoryWebService.Query query = new Alfresco.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 = "@sys\\:node-uuid:\"" + nodeId + "\""; QueryResult result = WebServiceFactory.getRepositoryService().query(spacesStore, query, false); if (result.resultSet.rows != null) { lResult = result.resultSet.rows[0]; } return(lResult); }
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(); } }