From 875a85f7f80604bea7551f6fea54b9d870391c71 Mon Sep 17 00:00:00 2001
From: Silvia Tzeneva <3305245+stzva@users.noreply.github.com>
Date: Wed, 4 Sep 2019 16:10:51 +0300
Subject: [PATCH] Add a sample code for Documaster's integration to eByggesak.
---
.gitignore | 1 +
.../NoarkWsClientSample/DocumasterClients.cs | 92 +++
.../NoarkWsClientSample.csproj | 6 +-
.../NoarkWsClientSample/Options.cs | 39 +
.../NoarkWsClientSample/Program.cs | 740 +-----------------
.../NoarkWsClientSample/Samples.cs | 674 ++++++++++++++++
.../DocumasterToEByggesakSubmitter.cs | 128 +++
.../eByggesak/EByggesakIntegrationSample.cs | 31 +
.../EByggesakToDocumasterSubmitter.cs | 300 +++++++
.../NoarkWsClientSample/eByggesak/README.md | 48 ++
10 files changed, 1328 insertions(+), 731 deletions(-)
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/Options.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/Samples.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/eByggesak/DocumasterToEByggesakSubmitter.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/eByggesak/EByggesakIntegrationSample.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/eByggesak/EByggesakToDocumasterSubmitter.cs
create mode 100644 NoarkWsClientSample/NoarkWsClientSample/eByggesak/README.md
diff --git a/.gitignore b/.gitignore
index 77d3ac9..eb4d800 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ bld/
# Visual Studo cache/options directory
.vs/
*/.vs/
+**/Properties/*
# MSTest test Results
[Tt]est[Rr]esult*/
diff --git a/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs b/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs
new file mode 100644
index 0000000..7954c5b
--- /dev/null
+++ b/NoarkWsClientSample/NoarkWsClientSample/DocumasterClients.cs
@@ -0,0 +1,92 @@
+using CommandLine;
+using Documaster.WebApi.Client.IDP;
+using Documaster.WebApi.Client.IDP.Oauth2;
+using Documaster.WebApi.Client.Noark5.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NoarkWsClientSample
+{
+ public class DocumasterClients
+ {
+ protected NoarkClient noarkClient;
+ protected Oauth2HttpClient idpClient;
+
+ private string refreshToken;
+ private DateTime acccessTokenExpirationTime;
+ private Options opts;
+
+ public DocumasterClients(Options opts)
+ {
+ this.opts = opts;
+
+ /*
+ * Using the Noark 5 web services requires providing a valid access token.
+ * The way this token is obtained depends on the system implementing the services.
+ * This sample code obtains the token from the Documaster's identity provider service
+ * with the help of a designated Documaster IDP client.
+ * If the Noark client is used in the context of an application that has access to a web browser,
+ * we strongly recommend choosing the Oauth2 Authorization Code Grant Flow supported for obtaining
+ * access tokens.
+ */
+
+ //Initialize an IDP client and request an authorization token
+ InitIdpClient(opts);
+
+ //Initialize a Noark client
+ InitClientWithoutClientCertificate(opts);
+
+ //Notice that it is also possible to initialize а ssl-based Noark client by providing a client certificate:
+ //InitClient(opts);
+ }
+
+ public NoarkClient getNoarkClient()
+ {
+ RefreshAccessToken();
+ return noarkClient;
+ }
+
+ private void RefreshAccessToken()
+ {
+ //access token expires in 60 minutes
+
+ if (refreshToken == null)
+ {
+ PasswordGrantTypeParams passwordGrantTypeParams = new PasswordGrantTypeParams(opts.ClientId, opts.ClientSecret, opts.Username, opts.Password, OpenIDConnectScope.OPENID);
+ var accessTokenResponse = idpClient.GetTokenWithPasswordGrantType(passwordGrantTypeParams);
+ acccessTokenExpirationTime = DateTime.Now.AddSeconds(accessTokenResponse.ExpiresInMs);
+ refreshToken = accessTokenResponse.RefreshToken;
+
+ noarkClient.AuthToken = accessTokenResponse.AccessToken;
+
+ }
+ else if (DateTime.Now > acccessTokenExpirationTime)
+ {
+ RefreshTokenGrantTypeParams refreshTokenGrantTypeParams = new RefreshTokenGrantTypeParams(refreshToken, opts.ClientId, opts.ClientSecret, OpenIDConnectScope.OPENID);
+ var accessTokenResponse = idpClient.RefreshToken(refreshTokenGrantTypeParams);
+ acccessTokenExpirationTime = DateTime.Now.AddSeconds(accessTokenResponse.ExpiresInMs);
+ refreshToken = accessTokenResponse.RefreshToken;
+
+ noarkClient.AuthToken = accessTokenResponse.AccessToken;
+ }
+ }
+
+ private void InitIdpClient(Options options)
+ {
+ idpClient = new Oauth2HttpClient(options.IdpServerAddress, true);
+ }
+
+ private void InitClient(Options options)
+ {
+ noarkClient = new NoarkClient(options.ServerAddress, true, options.CertificatePath, options.CertificatePass);
+ }
+
+ private void InitClientWithoutClientCertificate(Options options)
+ {
+ noarkClient = new NoarkClient(options.ServerAddress, true);
+ }
+ }
+}
diff --git a/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj b/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj
index 4e44e96..e1e9944 100644
--- a/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj
+++ b/NoarkWsClientSample/NoarkWsClientSample/NoarkWsClientSample.csproj
@@ -9,14 +9,14 @@
all
-
+
all
-
+
all
-
+
all
diff --git a/NoarkWsClientSample/NoarkWsClientSample/Options.cs b/NoarkWsClientSample/NoarkWsClientSample/Options.cs
new file mode 100644
index 0000000..ba6a73d
--- /dev/null
+++ b/NoarkWsClientSample/NoarkWsClientSample/Options.cs
@@ -0,0 +1,39 @@
+using CommandLine;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NoarkWsClientSample
+{
+ public class Options
+ {
+ [Option("idpaddr", Required = true, HelpText = "Idp server address")]
+ public string IdpServerAddress { get; set; }
+
+ [Option("clientid", Required = true, HelpText = "Idp Client Id")]
+ public string ClientId { get; set; }
+
+ [Option("clientsecret", Required = true, HelpText = "Idp Client Secret")]
+ public string ClientSecret { get; set; }
+
+ [Option("username", Required = true, HelpText = "Username")]
+ public string Username { get; set; }
+
+ [Option("password", Required = true, HelpText = "Password")]
+ public string Password { get; set; }
+
+ [Option("addr", Required = true, HelpText = "Server address")]
+ public string ServerAddress { get; set; }
+
+ [Option("cert", HelpText = "Path to certificate file")]
+ public string CertificatePath { get; set; }
+
+ [Option("certpass", HelpText = "Certificate password")]
+ public string CertificatePass { get; set; }
+
+ [Option("testdoc", Required = true, HelpText = "Path to test file")]
+ public string TestDoc { get; set; }
+ }
+}
diff --git a/NoarkWsClientSample/NoarkWsClientSample/Program.cs b/NoarkWsClientSample/NoarkWsClientSample/Program.cs
index e5ff91d..25f6e86 100644
--- a/NoarkWsClientSample/NoarkWsClientSample/Program.cs
+++ b/NoarkWsClientSample/NoarkWsClientSample/Program.cs
@@ -8,25 +8,26 @@
using Documaster.WebApi.Client.Noark5.NoarkEntities;
using Documaster.WebApi.Client.IDP;
using Documaster.WebApi.Client.IDP.Oauth2;
+using NoarkWsClientSample.eByggesak;
namespace NoarkWsClientSample
{
- class Program
+ static class Program
{
- private static NoarkClient client;
- private static Oauth2HttpClient idpClient;
- static string testDoc;
-
public static void Main(string[] args)
{
var options = ParserCommandLineArguments(args);
- InitializeSample(options);
- JournalingSample();
- ArchiveSample();
- MeetingAndBoardHandlingDataSample();
- BusinessSpecificMetadataSample();
- CodeListsSample();
+ Samples samples = new Samples(options);
+
+ samples.JournalingSample();
+ samples.ArchiveSample();
+ samples.MeetingAndBoardHandlingDataSample();
+ samples.BusinessSpecificMetadataSample();
+ samples.CodeListsSample();
+
+ EByggesakIntegrationSample eByggesakIntegrationSample = new EByggesakIntegrationSample(options);
+ eByggesakIntegrationSample.ExecuteSample();
}
private static Options ParserCommandLineArguments(string[] args)
@@ -44,722 +45,5 @@ private static Options ParserCommandLineArguments(string[] args)
return opts;
}
-
- private static void InitializeSample(Options opts)
- {
- /*
- * Using the Noark 5 web services requires providing a valid access token.
- * The way this token is obtained depends on the system implementing the services.
- * This sample code obtains the token from the Documaster's identity provider service
- * with the help of a designated Documaster IDP client.
- * If the Noark client is used in the context of an application that has access to a web browser,
- * we strongly recommend choosing the Oauth2 Authorization Code Grant Flow supported for obtaining
- * access tokens.
- */
-
- //Initialize an IDP client and request an authorization token
- InitIdpClient(opts);
- PasswordGrantTypeParams passwordGrantTypeParams = new PasswordGrantTypeParams(
- opts.ClientId, opts.ClientSecret, opts.Username, opts.Password, OpenIDConnectScope.OPENID);
- var accessToken = idpClient.GetTokenWithPasswordGrantType(passwordGrantTypeParams).AccessToken;
-
- //Initialize a Noark client
- InitClient(opts);
- client.AuthToken = accessToken;
-
- //Notice that it is also possible to initialize а ssl-based Noark client without providing
- //client certificate:
- //InitClientWithoutClientCertificate(opts);
-
- testDoc = opts.TestDoc;
- }
-
- private static void InitIdpClient(Options options)
- {
- idpClient = new Oauth2HttpClient(options.IdpServerAddress, true);
- }
-
- private static void InitClient(Options options)
- {
- client = new NoarkClient(options.ServerAddress, options.CertificatePath, options.CertificatePass, true);
- }
-
- private static void InitClientWithoutClientCertificate(Options options)
- {
- client = new NoarkClient(options.ServerAddress, true);
- }
-
- private static void JournalingSample()
- {
- Console.WriteLine($"Journaling example {Environment.NewLine}");
-
- //Create a new Arkiv with an Arkivskaper
- //When new objects are initialized, a temporary Id is assigned to them.
- var newArkivskaper = new Arkivskaper("B7-23-W5", "John Smith");
- var newArkiv = new Arkiv("Arkiv");
-
- var transactionResponse = client.Transaction()
- .Save(newArkiv)
- .Save(newArkivskaper)
- .Link(newArkiv.LinkArkivskaper(newArkivskaper))
- .Commit();
-
- //When the transaction is committed, the transaction response contains a map with saved objects.
- //One can access the saved Arkiv by providing its temporary Id as a key to the map.
- //Notice that arkiv.Id is the permanent Id of the Arkiv.
- var arkiv = transactionResponse.Saved[newArkiv.Id] as Arkiv;
- Console.WriteLine(
- $"Created Arkiv: Id={arkiv.Id}, Tittel={arkiv.Tittel}, OpprettetDato={arkiv.OpprettetDato}");
-
- //Update the description of the Arkiv and create a new Arkivdel in it
- //Create a new Klassifikasjonssystem with one Klasse
- //Set the new Klassifikasjonssystem as the primary Klassifikasjonssystem for the Arkivdel
- arkiv.Beskrivelse = "Barnehage Arkiv";
- var newArkivdel = new Arkivdel("2007/8");
- var newKlassifikasjonssystem = new Klassifikasjonssystem("Barnehage");
- var newKlasse = new Klasse("01", "Tilbud");
-
- transactionResponse = client.Transaction()
- .Save(arkiv)
- .Save(newArkivdel)
- .Link(newArkivdel.LinkArkiv(arkiv))
- .Save(newKlassifikasjonssystem)
- .Link(newArkivdel.LinkPrimaerKlassifikasjonssystem(newKlassifikasjonssystem))
- .Save(newKlasse)
- .Link(newKlasse.LinkKlassifikasjonssystem(newKlassifikasjonssystem))
- .Commit();
-
- arkiv = transactionResponse.Saved[arkiv.Id] as Arkiv;
- Console.WriteLine($"Updated Arkiv: Id={arkiv.Id}, Beskrivelse={arkiv.Beskrivelse}");
-
- var arkivdel = transactionResponse.Saved[newArkivdel.Id] as Arkivdel;
- Console.WriteLine($"Created Arkivdel: Id={arkivdel.Id}, Tittel={arkivdel.Tittel}");
-
- var klassifikasjonssystemId = transactionResponse.Saved[newKlassifikasjonssystem.Id].Id;
- var klasseId = transactionResponse.Saved[newKlasse.Id].Id;
-
- //Create a screening code
- Skjerming newSkjerming = new Skjerming(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Description",
- "Authority");
- Skjerming skjerming = client.PutCodeListValue(newSkjerming);
-
- //Screen the Arkivdel
- arkivdel.Skjerming = skjerming;
- transactionResponse = client.Transaction()
- .Save(arkivdel)
- .Commit();
-
- //Find the Arkivdel by id
- //By default the service will return null values for all screened fields of screened objects
- //To see the values of screened fields call SetPublicUse(false)
- var queryResults = client.Query("id=@arkivdelId", 10)
- .AddQueryParam("@arkivdelId", arkivdel.Id)
- .Execute();
- Console.WriteLine($"Found {queryResults.Results.Count()} Arkivdel object(s) with Id {arkivdel.Id}");
-
- //Print a screened field:
- arkivdel = queryResults.Results.First();
- Console.WriteLine($"Tittel of Arkivdel is masked: {arkivdel.Tittel}");
-
- //For convenience, objects in query and transaction responses contain the id's of many-to-one reference fields
- Console.WriteLine($"Arkivdel.RefArkiv: {arkivdel.RefArkiv}");
- Console.WriteLine($"Arkivdel.RefPrimaerKlassifikasjonssystem: {arkivdel.RefPrimaerKlassifikasjonssystem}");
-
- //Create two other Klassifikasjonssystem objects and link them to the Arkivdel as secondary Klassifikasjonssystem
- var sekundaerKlassifikasjonssystemSkole = new Klassifikasjonssystem("Skole");
- var klasseInSekundaerKlassifikasjonssystemSkole = new Klasse("07", "Report");
- var sekundaerKlassifikasjonssystem2 = new Klassifikasjonssystem("EOP");
-
- transactionResponse = client.Transaction()
- .Save(sekundaerKlassifikasjonssystemSkole)
- .Save(klasseInSekundaerKlassifikasjonssystemSkole)
- .Link(sekundaerKlassifikasjonssystemSkole.LinkKlasse(klasseInSekundaerKlassifikasjonssystemSkole))
- .Save(sekundaerKlassifikasjonssystem2)
- .Link(arkivdel.LinkSekundaerKlassifikasjonssystem(sekundaerKlassifikasjonssystemSkole,
- sekundaerKlassifikasjonssystem2))
- .Commit();
-
- //We need the id of the saved Klasse for the next transactions
- var sekundaerKlasseId =
- transactionResponse.Saved[klasseInSekundaerKlassifikasjonssystemSkole.Id].Id;
-
- //Create a new administrativEnhet value
- AdministrativEnhet newAdministrativEnhet =
- new AdministrativEnhet(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
- AdministrativEnhet administrativEnhet = client.PutCodeListValue(newAdministrativEnhet);
-
- //Create a new Saksmappe in the Arkivdel
- //The new Saksmappe needs to have a Klasse in the primary Klassifikasjonssystem of the Arkivdel
- //Also link the Saksmappe to a secondary Klasse
- var newSaksmappe = new Saksmappe("Tilbud (Smith, John)", administrativEnhet);
- var newSakspart = new Sakspart("Alice", "internal");
-
- var savedObjects = client.Transaction()
- .Save(newSaksmappe)
- .Link(newSaksmappe.LinkArkivdel(arkivdel))
- .Link(newSaksmappe.LinkPrimaerKlasse(klasseId))
- .Link(newSaksmappe.LinkSekundaerKlasse(sekundaerKlasseId))
- .Save(newSakspart)
- .Link(newSaksmappe.LinkSakspart(newSakspart))
- .Commit()
- .Saved;
-
- var saksmappe = savedObjects[newSaksmappe.Id] as Saksmappe;
- Console.WriteLine($"Created Saksmappe: Id={saksmappe.Id}, Saksdato: {saksmappe.Saksdato}");
-
- //Create another Klasse
- //Unlink the Saksmappe from its Klasse and link it to the new Klasse
- var anotherKlasse = new Klasse("02", "Klage");
-
- client.Transaction()
- .Save(anotherKlasse)
- .Link(anotherKlasse.LinkKlassifikasjonssystem(klassifikasjonssystemId))
- .Unlink(saksmappe.UnlinkPrimaerKlasse(klasseId))
- .Link(saksmappe.LinkPrimaerKlasse(anotherKlasse))
- .Commit();
- Console.WriteLine(
- $"Unlinked Saksmappe wiht Id {saksmappe.Id} from Klasse '{newKlasse.Tittel}' and linked it to Klasse '{anotherKlasse.Tittel}'");
-
- //Find all available codes for journalstatus in Journalpost
- var journalstatusCodeList = client.CodeLists(type: "Journalpost", field: "journalstatus").First();
- Console.WriteLine($"CodeList list for {journalstatusCodeList.Type}.{journalstatusCodeList.Field}:");
- foreach (var code in journalstatusCodeList.Values)
- {
- Console.WriteLine($" Code={code.Code}, Name={code.Name}");
- }
-
- //Create a new Journalpost in the Saksmappe
- //Create an EksternId object and link it to the Journalpost
- //Create a new Korrespondansepart and link it to the Journalpost
- //Create a Noekkelord (keyword) object and link it to the Journalpost
- var newJournalpost = new Journalpost("Tilbud (Smith, John, Godkjent)", Journalposttype.UTGAAENDE_DOKUMENT)
- {
- Journalaar = 2007,
- Journalsekvensnummer = 46
- };
-
- var newEksternId = new EksternId("External System", Guid.NewGuid().ToString());
- var newKorrespondansepart = new Korrespondansepart(Korrespondanseparttype.INTERN_MOTTAKER, "John Smith");
- var newNoekkelord = new Noekkelord("keyword");
-
- savedObjects = client.Transaction()
- .Save(newJournalpost)
- .Link(newJournalpost.LinkMappe(saksmappe))
- .Save(newEksternId)
- .Link(newJournalpost.LinkEksternId(newEksternId))
- .Save(newKorrespondansepart)
- .Link(newJournalpost.LinkKorrespondansepart(newKorrespondansepart))
- .Save(newNoekkelord)
- .Link(newNoekkelord.LinkRegistrering(newJournalpost))
- .Commit()
- .Saved;
-
- var journalPost = savedObjects[newJournalpost.Id] as Journalpost;
- Console.WriteLine(
- $"Created Journalpost: Id={journalPost.Id}, Tittel={journalPost.Tittel}, Journalstatus={journalPost.Journalstatus.Code}");
-
- //Find the Journalpost by the eksternID value
- var journalpstQueryResults = client.Query("refEksternId.eksternID=@eksternId", 10)
- .AddQueryParam("@eksternId", newEksternId.EksternID)
- .Execute();
- Console.WriteLine(
- $"Found {journalpstQueryResults.Results.Count()} Journalpost objects with eksternID {newEksternId.EksternID}");
-
- //Upload a file
- Dokumentfil dokumentfil;
- using (var inputStream = File.OpenRead(testDoc))
- {
- dokumentfil = client.Upload(inputStream, "godkjenning.pdf");
- }
- Console.WriteLine($"Uploaded file {testDoc}");
-
- //Create a new value for Dokumenttype
- Dokumenttype newDokumenttype = new Dokumenttype(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
- Dokumenttype dokumenttype = client.PutCodeListValue(newDokumenttype);
-
- //Create a new Dokument and Dokumentversjon using the uploaded file
- var newDokument = new Dokument(dokumenttype, "Tilbud (Smith, John, Godkjent)",
- TilknyttetRegistreringSom.HOVEDDOKUMENT);
- var newDokumentversjon = new Dokumentversjon(Variantformat.PRODUKSJONSFORMAT, ".pdf", dokumentfil);
-
- savedObjects = client.Transaction()
- .Save(newDokument)
- .Link(newDokument.LinkRegistrering(journalPost))
- .Save(newDokumentversjon)
- .Link(newDokumentversjon.LinkDokument(newDokument))
- .Commit()
- .Saved;
-
- var dokumentversjon = savedObjects[newDokumentversjon.Id] as Dokumentversjon;
- Console.WriteLine(
- $"Created Dokumentversjon: Id={dokumentversjon.Id}, Versjonsnummer: {dokumentversjon.Versjonsnummer}, Filstoerrelse: {dokumentversjon.Filstoerrelse}");
-
- //Download the Dokumentversjon file
- var downloadPath = Path.GetTempFileName();
- using (var outputStream = File.Create(downloadPath))
- {
- client.Download(dokumentversjon.Dokumentfil, outputStream);
- }
- Console.WriteLine($"Downloaded file {downloadPath}");
-
- //Find all dokument objects in a Saksmappe called "Tilbud (Smith, John)"
- //Results should be ordered by creation date in descending order
- var queryResponse = client.Query("refRegistrering.refMappe.tittel=@saksmappeTittel", 50)
- .AddQueryParam("@saksmappeTittel", "Tilbud (Smith, John)")
- .AddSortOrder("opprettetDato", Order.Descending)
- .Execute();
- Console.WriteLine(
- $"Query returned {queryResponse.Results.Count()} Dokument objects in Saksmappe objects called 'Tilbud (Smith, John)'");
- Console.WriteLine($"More results available: {queryResponse.HasMore}");
-
- //Delete the DokumentVersjon by id
- client.Transaction().Delete(dokumentversjon.Id).Commit();
- Console.WriteLine($"Deleted Dokumentversjon with Id {dokumentversjon.Id}");
- Console.WriteLine();
- }
-
- private static void ArchiveSample()
- {
- Console.WriteLine($"Archive example {Environment.NewLine}");
-
- //Create a new Arkiv with an Arkivskaper
- //Create a new Arkivdel in the Arkiv
- var newArkivskaper = new Arkivskaper("B7-23-W5", "John Smith");
- var newArkiv = new Arkiv("Arkiv");
- var newArkivdel = new Arkivdel("2007/8");
-
- var transactionResponse = client.Transaction()
- .Save(newArkiv)
- .Save(newArkivskaper)
- .Save(newArkivdel)
- .Link(newArkiv.LinkArkivskaper(newArkivskaper))
- .Link(newArkivdel.LinkArkiv(newArkiv))
- .Commit();
-
- var arkiv = transactionResponse.Saved[newArkiv.Id] as Arkiv;
- Console.WriteLine(
- $"Created Arkiv: Id={arkiv.Id}, Arkivstatus={arkiv.Arkivstatus.Code}, OpprettetDato={arkiv.OpprettetDato}");
-
- var arkivdel = transactionResponse.Saved[newArkivdel.Id] as Arkivdel;
- Console.WriteLine($"Created Arkivdel: Id={arkivdel.Id}, Arkivdelstatus={arkivdel.Arkivdelstatus.Code}");
-
- //Get all available values for the Mappetype code list
- var mappetypeList = client.CodeLists("Mappe", "mappetype").First();
- if (mappetypeList.Values.Count == 0)
- {
- Console.WriteLine(
- "Can not create an instance of Mappe because there are not available values in the Mappetype code list!");
- return;
- }
- var mappetypeCode = mappetypeList.Values.First().Code;
-
- //Create a new Mappe
- var newMappe = new Mappe("Barnehage Tilbud")
- {
- Beskrivelse = "Mappe Beskrivelse",
- Mappetype = new Mappetype(mappetypeCode)
- };
-
- transactionResponse = client.Transaction()
- .Save(newMappe)
- .Link(newMappe.LinkArkivdel(arkivdel))
- .Commit();
-
- var mappe = transactionResponse.Saved[newMappe.Id] as Mappe;
- Console.WriteLine($"Created Mappe: Id={mappe.Id}, Tittel: {mappe.Tittel}");
-
- //Create a child Mappe in the Mappe
- var newBarnMappe = new Mappe("Tilbud (Smith, John)");
-
- var savedObjects = client.Transaction()
- .Save(newBarnMappe)
- .Link(newBarnMappe.LinkForelderMappe(mappe))
- .Commit()
- .Saved;
-
- var barnMappe = savedObjects[newBarnMappe.Id] as Mappe;
- Console.WriteLine(
- $"Created a new Mappe (Id={barnMappe.Id}, Tittel={barnMappe.Tittel}) in Mappe with Id {mappe.Id}");
-
- //Find all children of the Mappe
- var queryResults = client.Query("refForelderMappe.id=@forelderMappeId", 10)
- .AddQueryParam("@forelderMappeId", mappe.Id)
- .Execute();
- Console.WriteLine($"Found {queryResults.Results.Count()} Mappe objects in Mappe with Id {mappe.Id}");
-
- //Create a new Basisregistrering in the child Mappe
- //Link one Korrespondansepart to the Basisregistrering
- var newBasisregistrering = new Basisregistrering("Tilbud (Smith, John, Godkjent)");
- var newKorrespondansepart = new Korrespondansepart(Korrespondanseparttype.MOTTAKER, "John Smith");
-
- savedObjects = client.Transaction()
- .Save(newBasisregistrering)
- .Save(newKorrespondansepart)
- .Link(newBasisregistrering.LinkMappe(barnMappe))
- .Link(newBasisregistrering.LinkKorrespondansepart(newKorrespondansepart))
- .Commit()
- .Saved;
-
- var basisregistrering = savedObjects[newBasisregistrering.Id] as Basisregistrering;
- Console.WriteLine(
- $"Created Basisregistrering: Id={basisregistrering.Id}, Tittel={basisregistrering.Tittel}");
-
- //Upload a file
- Dokumentfil dokumentfil;
- using (var inputStream = File.OpenRead(testDoc))
- {
- dokumentfil = client.Upload(inputStream, "godkjenning.pdf");
- }
- Console.WriteLine($"Uploaded file {testDoc}");
-
- //Get available values for the Dokumenttype code list
- var dokumenttypeList = client.CodeLists("Dokument", "dokumenttype").First();
- if (dokumenttypeList.Values.Count == 0)
- {
- Console.WriteLine(
- "Can not create an instance of Dokument because there are not available values in the Dokumenttype code list!");
- return;
- }
- var dokumenttypeCode = dokumenttypeList.Values.First().Code;
-
- //Create a new Dokument and Dokumentversjon using the uploaded file
- //Link the Dokument to the Basisregistrering
- var newDokument = new Dokument(new Dokumenttype(dokumenttypeCode), "Tilbud (Smith, John, Godkjent)",
- TilknyttetRegistreringSom.HOVEDDOKUMENT);
- var newDokumentversjon = new Dokumentversjon(Variantformat.PRODUKSJONSFORMAT, ".pdf", dokumentfil);
-
- savedObjects = client.Transaction()
- .Save(newDokument)
- .Link(newDokument.LinkRegistrering(basisregistrering))
- .Save(newDokumentversjon)
- .Link(newDokumentversjon.LinkDokument(newDokument))
- .Commit()
- .Saved;
-
- var dokumentversjon = savedObjects[newDokumentversjon.Id] as Dokumentversjon;
- Console.WriteLine(
- $"Created Dokumentversjon: Id={dokumentversjon.Id}, Versjonsnummer: {dokumentversjon.Versjonsnummer}, Filstoerrelse: {dokumentversjon.Filstoerrelse}");
- }
-
- private static void MeetingAndBoardHandlingDataSample()
- {
- Console.WriteLine($"Meeting and board handling data example {Environment.NewLine}");
-
- //Create a new Arkiv with an Arkivskaper
- //Create a new Arkivdel in the Arkiv
- var newArkivskaper = new Arkivskaper("B7-23-W5", "John Smith");
- var newArkiv = new Arkiv("Arkiv");
- var newArkivdel = new Arkivdel("2007/8");
-
- var transactionResponse = client.Transaction()
- .Save(newArkiv)
- .Save(newArkivskaper)
- .Save(newArkivdel)
- .Link(newArkiv.LinkArkivskaper(newArkivskaper))
- .Link(newArkivdel.LinkArkiv(newArkiv))
- .Commit();
-
- var arkiv = transactionResponse.Saved[newArkiv.Id] as Arkiv;
- Console.WriteLine(
- $"Created Arkiv: Id={arkiv.Id}, Arkivstatus={arkiv.Arkivstatus.Code}, OpprettetDato={arkiv.OpprettetDato}");
-
- var arkivdel = transactionResponse.Saved[newArkivdel.Id] as Arkivdel;
- Console.WriteLine($"Created Arkivdel: Id={arkivdel.Id}, Arkivdelstatus={arkivdel.Arkivdelstatus.Code}");
-
- //Create a new Moetemappe and Moetedeltaker
- Moetemappe newMappe = new Moetemappe("Moetemappe Tittel", "Moetenummer", "Utvalg");
- Moetedeltaker moetedeltaker = new Moetedeltaker("Moetedeltaker Navn");
-
- transactionResponse = client.Transaction()
- .Save(newMappe)
- .Link(newMappe.LinkArkivdel(arkivdel))
- .Save(moetedeltaker)
- .Link(moetedeltaker.LinkMappe(newMappe))
- .Commit();
-
- var mappe = transactionResponse.Saved[newMappe.Id] as Moetemappe;
- Console.WriteLine($"Created Mappe: Id={mappe.Id}, Tittel={mappe.Tittel}");
- Console.WriteLine($"Created Moetedeltaker: Navn={moetedeltaker.Navn}");
-
- //Create a new AdministrativEnhett code list value
- AdministrativEnhet newAdministrativEnhet =
- new AdministrativEnhet(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
- AdministrativEnhet administrativEnhet = client.PutCodeListValue(newAdministrativEnhet);
-
- //Create a new Moeteregistrering
- Moeteregistrering newMoeteregistrering = new Moeteregistrering("Tittel", "Saksbehandler",
- administrativEnhet, Moeteregistreringstype.MOETEINNKALLING);
- transactionResponse = client.Transaction()
- .Save(newMoeteregistrering)
- .Link(newMoeteregistrering.LinkMappe(mappe))
- .Commit();
-
- var moeteregistrering = transactionResponse.Saved[newMoeteregistrering.Id] as Moeteregistrering;
- Console.WriteLine(
- $"Created Moeteregistrering: Id={moeteregistrering.Id}, Tittel={moeteregistrering.Tittel}");
- ;
-
- //Upload a file
- Dokumentfil dokumentfil;
- using (var inputStream = File.OpenRead(testDoc))
- {
- dokumentfil = client.Upload(inputStream, "godkjenning.pdf");
- }
- Console.WriteLine($"Uploaded file {testDoc}");
-
- //Create a new Dokumenttype code list value
- Dokumenttype newDokumenttype = new Dokumenttype(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
- Dokumenttype dokumenttype = client.PutCodeListValue(newDokumenttype);
-
- //Link the Dokument to the Moeteregistrering
- var newDokument = new Dokument(dokumenttype, "Tilbud (Smith, John, Godkjent)",
- TilknyttetRegistreringSom.HOVEDDOKUMENT);
- var newDokumentversjon = new Dokumentversjon(Variantformat.PRODUKSJONSFORMAT, ".pdf", dokumentfil);
-
- transactionResponse = client.Transaction()
- .Save(newDokument)
- .Link(newDokument.LinkRegistrering(moeteregistrering))
- .Save(newDokumentversjon)
- .Link(newDokumentversjon.LinkDokument(newDokument))
- .Commit();
-
- var dokumentversjon = transactionResponse.Saved[newDokumentversjon.Id] as Dokumentversjon;
- Console.WriteLine(
- $"Created Dokumentversjon: Id={dokumentversjon.Id}, Versjonsnummer: {dokumentversjon.Versjonsnummer}, Filstoerrelse: {dokumentversjon.Filstoerrelse}");
- Console.WriteLine();
- }
-
- private static void BusinessSpecificMetadataSample()
- {
- string GROUP_ID = $"gr-{Guid.NewGuid().ToString()}";
- string STRING_FIELD_ID = $"f-{Guid.NewGuid().ToString()}";
- string DOUBLE_FIELD_ID = $"f-{Guid.NewGuid().ToString()}";
- string LONG_FIELD_ID = $"f-{Guid.NewGuid().ToString()}";
-
- //Create a business-specific metadata group
- MetadataGroupInfo newGroup = new MetadataGroupInfo(GROUP_ID, "BSM Group Name", "BSM Group Description");
- MetadataGroupInfo savedGroup = client.PutBsmGroup(newGroup);
- Console.WriteLine(
- $"Created new group: GroupId={savedGroup.GroupId}, GroupDescription={savedGroup.GroupDescription}, GroupName={savedGroup.GroupName}");
- Console.WriteLine();
-
- //Create a new string field with predefined values "value 1", "value 2" and "value 3"
- MetadataFieldInfo newFieldStr = new MetadataFieldInfo(STRING_FIELD_ID, "BSM Field String",
- "BSM Field Description", FieldType.String, new List