public static NamedValue createNamedValue(String name, String value) { NamedValue namedValue = new NamedValue(); namedValue.name = name; namedValue.value = value; return namedValue; }
public static NamedValue[] BuildCustomPropertiesForSpace(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 string GetPropertyValue(NamedValue[] namedValues, string propertyName) { string lResult = null; foreach (NamedValue nValue in namedValues) { if (nValue.name.Contains(propertyName)) { lResult = nValue.value; } } return lResult; }
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); } }
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; }
//********************************************************** // Function: ReleaseDoc() // Scope: internal // Overview: Document release point. Use the ReleaseData // object to release the current document's data // to the external data source. // Params: none // Returns: One of the following: KFX_REL_SUCCESS, // KFX_REL_ERROR, KFX_REL_DOCCLASSERROR, // KFX_REL_QUEUED // Called By: The Batch Release Manager. Called once for each // document to be released. //********************************************************** public AscentRelease.KfxReturnValue ReleaseDoc() { try { String name = ReleaseUtils.getLinkValue(this.releaseData.Values, ReleaseConstants.CONTENT_TYPE + Alfresco.Constants.PROP_NAME); if (name == null || name.Equals("")) { // node name is null or "" Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc - Content name is empty, check index fields in Release setup or the Content Type properties in Alfresco", ""); return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } String location = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION); // get properties and aspects list int i = 0; ArrayList aspectFields = new ArrayList(); ArrayList properties = new ArrayList(); NamedValue nameValue = new NamedValue(); // if its a content type field then create a NamedValue otherwise // store in the aspect array to be used later on foreach (AscentRelease.Value oValue in releaseData.Values) { String value = oValue.Value; String destination = oValue.Destination; if (destination.StartsWith(ReleaseConstants.CONTENT_TYPE)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = ReleaseConstants.CONTENT_TYPE.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = value; nameValue.isMultiValue = false; properties.Add(nameValue); } else { // aspect field aspectFields.Add(oValue); } } // create the CML bool isNew = true; String existingUuid = this.getNodeUuidFromLocation(this.locationUuid, name); CML cml; // flag to delete refnode if there is an error uploading the content bool deleteOnErrFlag = true; if (existingUuid.Equals("")) { // new content to upload cml = this.getCMLCreate((NamedValue[])properties.ToArray(typeof(NamedValue))); } else { // update, set deleteFlag to false for updating node Content deleteOnErrFlag = false; cml = this.getCMLUpdate(existingUuid, (NamedValue[])properties.ToArray(typeof(NamedValue))); isNew = false; } // create any aspects CMLAddAspect[] cmlAspects = null; String aspects = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_ASPECTS); AscentRelease.Value aspectValue; if (aspects != null) { // seperate the aspects string String[] aspectNames = ReleaseUtils.SplitByString(aspects, ReleaseConstants.SEPERATOR); String aspectName; cmlAspects = new CMLAddAspect[aspectNames.Length]; // for each aspect create a aspect CML for (i = 0; i < aspectNames.Length; i++) { aspectName = aspectNames[i]; // create the aspect CML CMLAddAspect addAspect = new CMLAddAspect(); addAspect.aspect = aspectName; if (isNew) { addAspect.where_id = "1"; } else { // use predicate Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = existingUuid; Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate(); pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; addAspect.where = pred; } ArrayList aspectProperties = new ArrayList(); // add the aspect fields for this aspect for (int j = 0; j < aspectFields.Count; j++) { // loop thru the aspects fields and add the relevent fields aspectValue = (AscentRelease.Value)aspectFields[j]; String destination = aspectValue.Destination; String prefix = ReleaseConstants.ASPECT + ReleaseConstants.SEPERATOR + aspectName; if (destination.StartsWith(prefix)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = prefix.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = aspectValue.Value; nameValue.isMultiValue = false; aspectProperties.Add(nameValue); } } addAspect.property = (NamedValue[])aspectProperties.ToArray(typeof(NamedValue)); cmlAspects[i] = addAspect; } } // add any aspects if (cmlAspects != null && cmlAspects.Length > 0) { cml.addAspect = cmlAspects; } UpdateResult[] updateResult = this.repoService.update(cml); if (!this.writeNewContent(updateResult[0].destination, deleteOnErrFlag)) { // failed to update content, deleted return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } return AscentRelease.KfxReturnValue.KFX_REL_SUCCESS; } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc " + e.Message, e.StackTrace); return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } }
internal void AddProperty(string propertyName, string propertyValue) { bool propertyExists = false; if (properties == null) { properties = new NamedValue[1]; properties[0] = Utils.createNamedValue(propertyName, propertyValue); } else { foreach (NamedValue nv in properties) { if (nv.name.Equals(propertyName)) { nv.value = propertyValue; propertyExists = true; break; } } if (!propertyExists) { var tmp = new NamedValue[properties.Length + 1]; properties.CopyTo(tmp, 0); properties = tmp; } } }