Exemplo n.º 1
0
        public string CreateSeriesWithClassificationSystem(string fondsId)
        {
            Console.WriteLine($"Create a Series with a classification system and one class.");
            NoarkClient client = this.documasterClients.GetNoarkClient();

            //When new objects are initialized, a temporary Id is assigned to them.
            Klassifikasjonssystem classificationSystem = new Klassifikasjonssystem("Oppkvest");
            Klasse   klass  = new Klasse("01", "Tilbud");
            Arkivdel series = new Arkivdel("Barnehage");

            TransactionResponse transactionResponse = client.Transaction()
                                                      .Save(series)
                                                      .Link(series.LinkArkiv(fondsId))
                                                      .Save(classificationSystem)
                                                      .Link(series.LinkPrimaerKlassifikasjonssystem(classificationSystem))
                                                      .Save(klass)
                                                      .Link(klass.LinkKlassifikasjonssystem(classificationSystem))
                                                      .Commit();

            //transactionResponse.Saved contains a mapping between the temporary id's and the saved objects with their permanent id's
            Klassifikasjonssystem savedClassificationSystem =
                transactionResponse.Saved[classificationSystem.Id] as Klassifikasjonssystem;
            Klasse   savedClass  = transactionResponse.Saved[klass.Id] as Klasse;
            Arkivdel savedSeries = transactionResponse.Saved[series.Id] as Arkivdel;

            Console.WriteLine(
                $"New classification system '{savedClassificationSystem.Tittel}' created. Temporary Id: {classificationSystem.Id}. Permanent Id: {savedClassificationSystem.Id}.");
            Console.WriteLine(
                $"New class '{savedClass.Tittel}' created. Temporary Id: {klass.Id}. Permanent Id: {savedClass.Id}.");
            Console.WriteLine(
                $"New series '{savedSeries.Tittel}' created. Temporary Id: {series.Id}. Permanent Id: {savedSeries.Id}.");

            return(savedSeries.Id);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        public void Execute()
        {
            #region Set sample values

            string seriesTitle             = "Skole";
            string primaryClassTitle       = "Tilbud";
            string secondaryClassTitle     = "John Smith";
            string secondaryClassId        = "45-67771344-7";
            string administrativeUnit      = "Privat GSK";
            string screeningCode           = "UOFF";
            string documentType            = "Rapport";
            string caseFileTitle           = "John Smith - Test Skole";
            string caseFileExternalId      = "4551-54555";
            string caseResponsibleName     = "Maria Doe";
            string caseResponsibleId       = "3445555";
            string registryEntryTitle      = "Half-year report - 2019 - John Smith";
            string registryEntryExternalId = "45-67771344-7";

            #endregion

            // We assume that a series and a primary class already exist and we will just fetch them.
            // SystemInitializationSample.cs shows how to create these objects.
            Arkivdel series = GetSeriesByTitle(seriesTitle);

            if (series == null)
            {
                Console.WriteLine($"Did not find a series with title {seriesTitle}!");
                return;
            }

            Klasse primaryClass = GetClassByTitle(series.RefPrimaerKlassifikasjonssystem, primaryClassTitle);

            if (primaryClass == null)
            {
                Console.WriteLine($"Could not find a class with title {primaryClassTitle}!");
                return;
            }

            /* Now, we are going to fetch or create a secondary class.
             * A secondary class id and title might be a person's number and name, such as 12356 John Doe.
             * To fetch the secondary class we need to know in which secondary classification system the class resides.
             * A series can be linked to more than one secondary classification systems.
             * For simplicity, in this example we will randomly pick one of the series's secondary classification systems.
             */

            Klassifikasjonssystem secondaryClassificationSystem = GetSecondaryClassificationSystem(series.Id);

            if (secondaryClassificationSystem == null)
            {
                Console.WriteLine("Series does not have a secondary classification system!");
                return;
            }

            Klasse secondaryClass = GetClassByTitle(secondaryClassificationSystem.Id, secondaryClassTitle)
                                    ??
                                    CreateClass(secondaryClassificationSystem.Id, secondaryClassId,
                                                secondaryClassTitle);


            // We also need to find the code values used for the creation of an Archive structure.
            // SystemInitializationSample.cs shows how to create these code values.
            CodeValue administrativeUnitCodeValue = GetAdministrativeUnitByName(administrativeUnit);
            CodeValue screeningCodeValue          = GetScreeningCodeByName(screeningCode);
            CodeValue documentTypeCodeValue       = GetDocumentTypeByName(documentType);

            if (administrativeUnitCodeValue == null)
            {
                Console.WriteLine($"Could not find an administrative unit code value '{administrativeUnit}'!");
                return;
            }

            if (screeningCodeValue == null)
            {
                Console.WriteLine($"Could not find an screening code value '{seriesTitle}'!");
                return;
            }

            if (documentTypeCodeValue == null)
            {
                Console.WriteLine($"Could not find an document type code value '{documentType}'!");
                return;
            }

            SubmitData(series,
                       primaryClass,
                       secondaryClass,
                       new AdministrativEnhet(administrativeUnitCodeValue.Code),
                       new Skjerming(screeningCodeValue.Code),
                       new Dokumenttype(documentTypeCodeValue.Code),
                       caseFileTitle,
                       caseFileExternalId,
                       caseResponsibleName,
                       caseResponsibleId,
                       registryEntryTitle,
                       registryEntryExternalId);
        }