From a5272be193a01550ddaf5dc2526fe6ab03a80cb5 Mon Sep 17 00:00:00 2001 From: Silvia Tzeneva <3305245+stzva@users.noreply.github.com> Date: Wed, 16 Sep 2020 17:25:21 +0300 Subject: [PATCH 1/4] Add an example of a query using joins --- .../NoarkWsClientSample.csproj | 2 +- .../NoarkWsClientSample/Program.cs | 1 + .../NoarkWsClientSample/QuerySample.cs | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj index e1e9944..169406b 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj @@ -13,7 +13,7 @@ all - + all diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs index c3d1fab..cf75042 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs @@ -34,6 +34,7 @@ public static void Main(string[] args) finalizationSample.FinalizeObjectsInArchive("42", "43", "44", "45"); QuerySample querySample = new QuerySample(documasterClients); + querySample.GetCaseFileByTwoSecondaryClassesUsingJoins("45-67771344-7", "457-66-22-1"); querySample.GetCodeLists(); querySample.GetCaseFilesByExternalId("14", "2344-11", "External system"); querySample.GetCaseFileBySecondaryClass("14", "45503", "John Doe"); diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/QuerySample.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/QuerySample.cs index 3aca59b..35c3578 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/QuerySample.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/QuerySample.cs @@ -146,5 +146,28 @@ public void GetRegistryEntriesCreatedInDateRange(string seriesId, DateTime fromD Console.WriteLine($"Registry entry: Id: {registryEntry.Id}. Title: {registryEntry.Tittel}"); } } + + public void GetCaseFileByTwoSecondaryClassesUsingJoins(string secondaryClassIdent1, string secondaryClassIdent2) + { + NoarkClient client = this.documasterClients.GetNoarkClient(); + + int pageSize = 1; + + QueryResponse queryResponse = + client.Query("#klasse1.klasseIdent=@klasseIdent1 && #klasse2.klasseIdent=@klasseIdent2", + pageSize) + .AddJoin("#klasse1", "refSekundaerKlasse") + .AddJoin("#klasse2", "refSekundaerKlasse") + .AddQueryParam("@klasseIdent1", secondaryClassIdent1) + .AddQueryParam("@klasseIdent2", secondaryClassIdent2) + .Execute(); + + if (queryResponse.Results.Any()) + { + Saksmappe saksmappe = queryResponse.Results.First(); + Console.WriteLine($"Found a case file with title '{saksmappe.Tittel}' linked to two secondary classes with klasseIdent '{secondaryClassIdent1}' and klasseIdent '{secondaryClassIdent2}'"); + } + + } } } From 98d576435a88cb35d90411e9fe47135bff9defc9 Mon Sep 17 00:00:00 2001 From: Silvia Tzeneva <3305245+stzva@users.noreply.github.com> Date: Wed, 16 Sep 2020 17:26:18 +0300 Subject: [PATCH 2/4] Add an example of using Azure grant types parameters for authentication --- .../NoarkWsClientSample/DocumasterClients.cs | 14 ++++++++++++-- .../NoarkWsClientSample/Options.cs | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs index f7f92ef..3135fa6 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs @@ -53,8 +53,7 @@ private void RefreshAccessToken() if (this.refreshToken == null) { - PasswordGrantTypeParams passwordGrantTypeParams = new PasswordGrantTypeParams(this.opts.ClientId, - this.opts.ClientSecret, this.opts.Username, this.opts.Password, OpenIDConnectScope.OPENID); + PasswordGrantTypeParams passwordGrantTypeParams = GetDocumasterIdpGrantTypeParams(); AccessTokenResponse accessTokenResponse = this.idpClient.GetTokenWithPasswordGrantType(passwordGrantTypeParams); this.accessTokenExpirationTime = DateTime.Now.AddSeconds(accessTokenResponse.ExpiresInMs); @@ -73,6 +72,17 @@ private void RefreshAccessToken() } } + private PasswordGrantTypeParams GetDocumasterIdpGrantTypeParams() + { + return new PasswordGrantTypeParams(this.opts.ClientId, + this.opts.ClientSecret, this.opts.Username, this.opts.Password, OpenIDConnectScope.OPENID); + } + + private PasswordGrantTypeParams GetAzureGrantTypeParams() + { + return new AzureGrantTypeParams(this.opts.ClientId, this.opts.ClientSecret, this.opts.Username, this.opts.Password, OpenIDConnectScope.OPENID, this.opts.Resource); + } + private void InitIdpClient(Options options) { //IdpServerAddress is in the format https://clientname.dev.documaster.tech/idp/oauth2 diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Options.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Options.cs index dba9e52..c99c98a 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Options.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Options.cs @@ -24,6 +24,9 @@ public class Options [Option("password", Required = true, HelpText = "Password")] public string Password { get; set; } + [Option("resource", Required = false, HelpText = "Resource")] + public string Resource { get; set; } + [Option("addr", Required = true, HelpText = "Server address, such as https://clientname.dev.documaster.tech:8083")] public string ServerAddress { get; set; } From 60011415ed901f735a6a4d8c14caa03a0ee13a7e Mon Sep 17 00:00:00 2001 From: Silvia Tzeneva <3305245+stzva@users.noreply.github.com> Date: Wed, 16 Sep 2020 17:27:06 +0300 Subject: [PATCH 3/4] Add sample code for managing business specific metadata --- .../BusinessSpecificMetadataSample.cs | 160 ++++++++++++++++++ .../NoarkWsClientSample.csproj | 2 +- .../NoarkWsClientSample/Program.cs | 6 + 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs new file mode 100644 index 0000000..5322755 --- /dev/null +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Documaster.WebApi.Client.Noark5.Client; +using Documaster.WebApi.Client.Noark5.NoarkEntities; + +namespace NoarkWsClientSample +{ + public class BusinessSpecificMetadataSample + { + private readonly DocumasterClients documasterClients; + + public BusinessSpecificMetadataSample(DocumasterClients documasterClients) + { + this.documasterClients = documasterClients; + } + + public void GetBusinessSpecificMetadataRegistry() + { + Console.WriteLine($"Get business-specific metadata registry"); + + NoarkClient client = this.documasterClients.GetNoarkClient(); + + BusinessSpecificMetadataInfo info = client.BsmRegistry(); + + foreach (MetadataGroupInfo metadataGroupInfo in info.Groups) + { + Console.WriteLine($"Group: {metadataGroupInfo.GroupName}"); + foreach (MetadataFieldInfo metadataFieldInfo in metadataGroupInfo.Fields) + { + Console.WriteLine($"Field: Name={metadataFieldInfo.FieldName}, Type={metadataFieldInfo.FieldType}"); + if(metadataFieldInfo.FieldValues != null) + { + //the field has predefined values + Console.WriteLine($"Field values: [{String.Join(",", metadataFieldInfo.FieldValues.ToArray())}]"); + } + } + } + } + + public void CrudOperationsWithBusinessSpecificMetadata() + { + Console.WriteLine($"Create, update and delete business-specific metadata groups and fields"); + + NoarkClient client = this.documasterClients.GetNoarkClient(); + + //Create group + MetadataGroupInfo group = new MetadataGroupInfo("group-applications", "Applications", "Business-specific metadata for applications"); + MetadataGroupInfo savedGroup = client.PutBsmGroup(group); + Console.WriteLine($"Created group with group identifier {savedGroup.GroupId}"); + + //Create fields: + MetadataFieldInfo fieldAppliactionName = new MetadataFieldInfo("app-name", "Application name", "Application name", FieldType.String); + MetadataFieldInfo fieldAppliactionParticipants = new MetadataFieldInfo("app-participants", "Application participants", "Application participants", FieldType.String); + MetadataFieldInfo fieldAppliactionType = new MetadataFieldInfo("app-type", "Application type", "Application type", FieldType.Double, new List { 1, 2, 3 }); + MetadataFieldInfo fieldAppliactionSalary = new MetadataFieldInfo("app-salary", "Application salary", "Application salary", FieldType.Long); + MetadataFieldInfo fieldAppliactionDate = new MetadataFieldInfo("app-date", "Application date", "Application date", FieldType.Timestamp); + MetadataFieldInfo fieldAppliactionSecret = new MetadataFieldInfo("app-secret", "Application secret", "Application secret", FieldType.Encrypted); + + MetadataFieldInfo savedFieldAppliactionName = client.PutBsmField(savedGroup.GroupId, fieldAppliactionName); + MetadataFieldInfo savedFieldAppliactionParticipants = client.PutBsmField(savedGroup.GroupId, fieldAppliactionParticipants); + MetadataFieldInfo savedFieldAppliactionType = client.PutBsmField(savedGroup.GroupId, fieldAppliactionType); + MetadataFieldInfo savedFieldAppliactionSalary = client.PutBsmField(savedGroup.GroupId, fieldAppliactionSalary); + MetadataFieldInfo savedFieldAppliactionDate = client.PutBsmField(savedGroup.GroupId, fieldAppliactionDate); + MetadataFieldInfo savedFieldAppliactionSecret = client.PutBsmField(savedGroup.GroupId, fieldAppliactionSecret); + + Console.WriteLine($"Created fields with filed identifiers {savedFieldAppliactionName.FieldId}, " + + $"{savedFieldAppliactionType.FieldId}, {savedFieldAppliactionDate.FieldId}, {savedFieldAppliactionSalary.FieldId} and {savedFieldAppliactionSecret.FieldId}"); + + //Fetch and update group + BusinessSpecificMetadataInfo info = client.BsmRegistry(savedGroup.GroupId); + MetadataGroupInfo foundGroup = info.Groups.First(); + //Remove one of the fields from the group + foundGroup.Fields.RemoveAt(3); + client.PutBsmGroup(foundGroup); + + //Update a field with predefined values - add one more value + savedFieldAppliactionType.FieldValues.Add(4); + client.PutBsmField(savedGroup.GroupId, savedFieldAppliactionType); + + + //Delete a field + client.DeleteBsmField(savedGroup.GroupId, savedFieldAppliactionSalary.FieldId); + + //Delete a group + client.DeleteBsmGroup(savedGroup.GroupId); + } + + public void AddAndUpdateBusinessSpecificMetadataToCaseFile(string caseFileTitle) + { + //This example assumes the existence of a bsm group with identifier "group-applications" + //and of several bsm fields. + + Console.WriteLine("Add and update business-specific metadata to case file"); + NoarkClient client = this.documasterClients.GetNoarkClient(); + + //Find the file + Saksmappe saksmappe = + client.Query("tittel=@title", 1) + .AddQueryParam("@title", caseFileTitle) + .Execute() + .Results + .First(); + + //Set application name, date, type and secret as business-specific metadata to a case file + saksmappe.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("group-applications", "app-name", "Application for kindergarten place"); + saksmappe.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("group-applications", "app-participants", "Alice Smith", "John Doe"); + saksmappe.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("group-applications", "app-date", DateTime.Now); + saksmappe.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("group-applications", "app-type", 1); + saksmappe.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("group-applications", "app-secret", "some encrypted content here"); + + TransactionResponse transactionResponse = client.Transaction() + .Save(saksmappe) + .Commit(); + + Saksmappe savedCaseFile = transactionResponse.Saved[saksmappe.Id] as Saksmappe; + + Console.WriteLine("Added business-specific metadata fields to case file"); + foreach(string groupId in savedCaseFile.VirksomhetsspesifikkeMetadata.Keys) + { + Console.WriteLine($"Group with group identifier {groupId}"); + foreach(string fieldId in savedCaseFile.VirksomhetsspesifikkeMetadata[groupId].Keys) + { + BsmFieldValues fieldValues = savedCaseFile.VirksomhetsspesifikkeMetadata[groupId][fieldId]; + Console.WriteLine($@"Field with field identifier {fieldId}, type {fieldValues.Type} + and values [{String.Join(", ", fieldValues.Values)}]"); + } + } + + //Delete a field + savedCaseFile.VirksomhetsspesifikkeMetadata.DeleteBsmField("group-applications", "app-secret"); + + //Delete a field value only + savedCaseFile.VirksomhetsspesifikkeMetadata.DeleteBsmFieldValue("group-applications", "app-participants", "Alice Smith"); + + //Add a new value + savedCaseFile.VirksomhetsspesifikkeMetadata.UpdateBsmFieldValues("group-applications", "app-type", 2); + + transactionResponse = client.Transaction() + .Save(savedCaseFile) + .Commit(); + + savedCaseFile = transactionResponse.Saved[saksmappe.Id] as Saksmappe; + + Console.WriteLine("Update business-specific metadata fields of case file"); + foreach (string groupId in savedCaseFile.VirksomhetsspesifikkeMetadata.Keys) + { + Console.WriteLine($"Group with group identifier {groupId}"); + foreach (string fieldId in savedCaseFile.VirksomhetsspesifikkeMetadata[groupId].Keys) + { + BsmFieldValues fieldValues = savedCaseFile.VirksomhetsspesifikkeMetadata[groupId][fieldId]; + Console.WriteLine($@"Field with field identifier {fieldId}, type {fieldValues.Type} + and values [{String.Join(", ", fieldValues.Values)}]"); + } + } + } + } +} diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj index 169406b..0859ecc 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj @@ -13,7 +13,7 @@ all - + all diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs index cf75042..d02fcf4 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/Program.cs @@ -42,6 +42,12 @@ public static void Main(string[] args) FullTextSearchSample fullTextSearchSample = new FullTextSearchSample(documasterClients); fullTextSearchSample.Search(); + + BusinessSpecificMetadataSample businessSpecificMetadataSample = + new BusinessSpecificMetadataSample(documasterClients); + businessSpecificMetadataSample.GetBusinessSpecificMetadataRegistry(); + businessSpecificMetadataSample.CrudOperationsWithBusinessSpecificMetadata(); + businessSpecificMetadataSample.AddAndUpdateBusinessSpecificMetadataToCaseFile("case file title"); } private static Options ParserCommandLineArguments(string[] args) From a59fb5b2c02a68b7792d924348ef6517ffabd6ac Mon Sep 17 00:00:00 2001 From: stzva <3305245+stzva@users.noreply.github.com> Date: Thu, 24 Sep 2020 16:31:57 +0300 Subject: [PATCH 4/4] Fix typo Co-authored-by: Dimitar Kumanov --- .../NoarkWsClientSample/BusinessSpecificMetadataSample.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs index 5322755..0027de9 100644 --- a/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs +++ b/C#/v1/NoarkWsClientSample/NoarkWsClientSample/BusinessSpecificMetadataSample.cs @@ -129,7 +129,7 @@ public void AddAndUpdateBusinessSpecificMetadataToCaseFile(string caseFileTitle) } } - //Delete a field + //Delete all field values from the case file savedCaseFile.VirksomhetsspesifikkeMetadata.DeleteBsmField("group-applications", "app-secret"); //Delete a field value only