public UpdateResult[] update(CML statements) { object[] results = this.Invoke("update", new object[] { statements }); return((UpdateResult[])(results[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(); } }
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; }
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; }
private void deleteReference(Alfresco.RepositoryWebService.Reference reference) { Alfresco.RepositoryWebService.Predicate where = new Alfresco.RepositoryWebService.Predicate(); where.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; CMLDelete cmlDelete = new CMLDelete(); cmlDelete.where = where; CML cml = new CML(); cml.delete = new CMLDelete[] { cmlDelete }; this.repoService.update(cml); }
/// <remarks/> public System.IAsyncResult Beginupdate(CML statements, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("update", new object[] { statements }, callback, asyncState)); }
/// <remarks/> public System.IAsyncResult Beginupdate(CML statements, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("update", new object[] { statements}, callback, asyncState); }
public UpdateResult[] update(CML statements) { object[] results = this.Invoke("update", new object[] { statements}); return ((UpdateResult[])(results[0])); }
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(); } }
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); }
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; }
///// <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; }