public void FinalizeObjectsInArchive(string seriesId,
                                             string folderId,
                                             string basicRecordId,
                                             string documentDescriptionId
                                             )
        {
            NoarkClient client = this.documasterClients.GetNoarkClient();

            // Note that currently finalizing objects will not finalize child objects!
            // We first finalize the objects in the bottom of the hierarchy, and then finalize parent objects up to Series.

            // Finalize series by setting changing the series status to Closed Period (P).
            Arkivdel series = GetNoarkEntityById <Arkivdel>(seriesId);

            series.Arkivdelstatus = Arkivdelstatus.AVSLUTTET_PERIODE;

            // Finalize folder by setting the finalized date field.
            Mappe folder = GetNoarkEntityById <Mappe>(folderId);

            folder.AvsluttetDato = DateTime.Now;

            // Finalize basic record by setting the finalized date field.
            Basisregistrering basicRecord = GetNoarkEntityById <Basisregistrering>(basicRecordId);

            basicRecord.AvsluttetDato = DateTime.Now;

            // Finalize document description by changing the document status to Finalized (F).
            Dokument documentDescription = GetNoarkEntityById <Dokument>(documentDescriptionId);

            documentDescription.Dokumentstatus = Dokumentstatus.DOKUMENTET_ER_FERDIGSTILT;

            client.Transaction()
            .Save(documentDescription)
            .Save(basicRecord)
            .Save(folder)
            .Save(series)
            .Commit();
        }
Exemple #2
0
        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 <Mappe>("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}");
        }