Beispiel #1
0
        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 <Arkivdel>("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 <Journalpost>("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 <Dokument>("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>(dokumentversjon.Id).Commit();
            Console.WriteLine($"Deleted Dokumentversjon with Id {dokumentversjon.Id}");
            Console.WriteLine();
        }
Beispiel #2
0
        private void SubmitData(
            Arkivdel series,
            Klasse primaryClass,
            Klasse secondaryClass,
            AdministrativEnhet administrativeUnit,
            Skjerming screeningCode,
            Dokumenttype documentType,
            string caseFileTitle,
            string caseFileExternalId,
            string caseResponsibleName,
            string caseResponsibleId,
            string registryEntryTitle,
            string registryEntryExternalId)
        {
            #region Case file

            Saksmappe caseFile = new Saksmappe(caseFileTitle, administrativeUnit)
            {
                Saksansvarlig            = caseResponsibleName,
                SaksansvarligBrukerIdent = caseResponsibleId
            };

            EksternId caseFileExternalIdObj = new EksternId(EXTERNAL_SYSTEM, caseFileExternalId);

            #endregion Case file

            #region Registry entry

            Journalpost registryEntry = new Journalpost(registryEntryTitle, Journalposttype.UTGAAENDE_DOKUMENT)
            {
                Skjerming = screeningCode
            };

            registryEntry.VirksomhetsspesifikkeMetadata.AddBsmFieldValues("gr-1", "f-string", "value 1");

            EksternId registryEntryExternalIdObj = new EksternId(EXTERNAL_SYSTEM, registryEntryExternalId);

            Korrespondansepart correspondenceParty =
                new Korrespondansepart(Korrespondanseparttype.AVSENDER, "John Smith");

            #endregion Registry entry

            #region Documents

            //Upload two files

            Dokumentfil mainFile       = UploadDocument(this.testFile1);
            Dokumentfil attachmentFile = UploadDocument(this.testFile2);

            //Link the first document description to the registry entry as main document (HOVEDDOKUMENT).
            //Subsequent document descriptions will be linked as attachments (VEDLEGG).

            Dokument mainDocumentDescription =
                new Dokument("Main Document", TilknyttetRegistreringSom.HOVEDDOKUMENT)
            {
                Dokumenttype = documentType,
            };

            Dokumentversjon mainDocumentVersion =
                new Dokumentversjon(Variantformat.ARKIVFORMAT, ".pdf", mainFile);

            Dokument attachmentDocumentDescription =
                new Dokument("Attachment", TilknyttetRegistreringSom.VEDLEGG)
            {
                Dokumenttype = documentType     //here might as well be used another type
            };

            Dokumentversjon attachmentDocumentVersion =
                new Dokumentversjon(Variantformat.ARKIVFORMAT, ".pdf", attachmentFile);

            #endregion Documents

            NoarkClient client = this.documasterClients.GetNoarkClient();

            TransactionResponse transactionResponse = client.Transaction()
                                                      .Save(caseFile)
                                                      .Link(caseFile.LinkArkivdel(series))
                                                      .Link(caseFile.LinkPrimaerKlasse(primaryClass))
                                                      .Link(caseFile.LinkSekundaerKlasse(secondaryClass))
                                                      .Save(caseFileExternalIdObj)
                                                      .Link(caseFileExternalIdObj.LinkMappe(caseFile))
                                                      .Save(registryEntry)
                                                      .Link(registryEntry.LinkMappe(caseFile))
                                                      .Save(correspondenceParty)
                                                      .Link(correspondenceParty.LinkRegistrering(registryEntry))
                                                      .Save(registryEntryExternalIdObj)
                                                      .Link(registryEntryExternalIdObj.LinkRegistrering(registryEntry))
                                                      .Save(mainDocumentDescription)
                                                      .Link(mainDocumentDescription.LinkRegistrering(registryEntry))
                                                      .Save(mainDocumentVersion)
                                                      .Link(mainDocumentVersion.LinkDokument(mainDocumentDescription))
                                                      .Save(attachmentDocumentDescription)
                                                      .Link(attachmentDocumentDescription.LinkRegistrering(registryEntry))
                                                      .Save(attachmentDocumentVersion)
                                                      .Link(attachmentDocumentVersion.LinkDokument(attachmentDocumentDescription))
                                                      .Commit();

            // When new objects are initialized, a temporary Id is assigned to them.
            // transactionResponse.Saved contains a mapping between the temporary id's and the saved objects with their permanent id's
            Dictionary <string, INoarkEntity> savedObjects = transactionResponse.Saved;

            string template = "{0}: Temporary Id: {1} Permanent Id: {2}";

            Console.WriteLine(String.Format(template, "Case file", caseFile.Id, savedObjects[caseFile.Id].Id));
            Console.WriteLine(String.Format(template, "Registry entry", registryEntry.Id,
                                            savedObjects[registryEntry.Id].Id));
            Console.WriteLine(String.Format(template, "Main document description", mainDocumentDescription.Id,
                                            savedObjects[mainDocumentDescription.Id].Id));
            Console.WriteLine(String.Format(template, "Attachment document description",
                                            attachmentDocumentDescription.Id, savedObjects[attachmentDocumentDescription.Id].Id));
        }