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); }
public string CreateFonds() { Console.WriteLine($"Create Fonds"); NoarkClient client = this.documasterClients.GetNoarkClient(); //When new objects are initialized, a temporary Id is assigned to them. Arkivskaper fondsCreator = new Arkivskaper("B7-23-W5", "John Smith"); Arkiv fonds = new Arkiv("Arkiv"); // Execute transaction TransactionResponse transactionResponse = client.Transaction() .Save(fonds) .Save(fondsCreator) .Link(fonds.LinkArkivskaper(fondsCreator)) .Commit(); //transactionResponse.Saved contains a mapping between the temporary id's and the saved objects with their permanent id's Arkiv savedFonds = transactionResponse.Saved[fonds.Id] as Arkiv; Arkivskaper savedFondsCreator = transactionResponse.Saved[fondsCreator.Id] as Arkivskaper; Console.WriteLine( $"Fonds creator '{savedFondsCreator.ArkivskaperNavn}' created. Temporary Id: {fondsCreator.Id}. Permanent Id: {savedFondsCreator.Id}."); Console.WriteLine( $"Fonds '{savedFonds.Tittel}' created. Temporary Id: {fonds.Id}. Permanent Id: {savedFonds.Id}."); // Return the id of the new fonds return(savedFonds.Id); }
private Klasse CreateClass(string classificationSystemId, string classId, string title) { NoarkClient client = this.documasterClients.GetNoarkClient(); //When new objects are initialized, a temporary Id is assigned to them. Klasse klass = new Klasse(classId, title); TransactionResponse transactionResponse = client.Transaction() .Save(klass) .Link(klass.LinkKlassifikasjonssystem(classificationSystemId)) .Commit(); //transactionResponse.Saved contains a mapping between the temporary id's and the saved objects with their permament id's Klasse savedClass = transactionResponse.Saved[klass.Id] as Klasse; Console.WriteLine($"Created a new class '{savedClass.Tittel}'. Permanent Id: {savedClass.Id}."); return(savedClass); }
public void SignOffRegistryEntry(string registryEntryId, List <string> associatedRegistryEntryIds = null) { NoarkClient client = this.documasterClients.GetNoarkClient(); Avskrivning signOff = new Avskrivning(Avskrivningsmaate.TATT_TIL_ETTERRETNING); Transaction transaction = client.Transaction() .Save(signOff) .Link(signOff.LinkJournalpost(registryEntryId)); if (associatedRegistryEntryIds != null) { foreach (string associatedRegistryEntryId in associatedRegistryEntryIds) { transaction.Link(signOff.LinkTilknyttetJournalpost(associatedRegistryEntryId)); } } transaction.Commit(); }
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(); }
public void FinalizeObjectsInJournal(string seriesId, string caseFileId, string registryEntryId, 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 case file by changing the case file status to Finalized (A). Saksmappe caseFile = GetNoarkEntityById <Saksmappe>(caseFileId); caseFile.Saksstatus = Saksstatus.AVSLUTTET; // Finalized registry entry by changing the record status to Archived (A). Journalpost registryEntry = GetNoarkEntityById <Journalpost>(registryEntryId); registryEntry.Journalstatus = Journalstatus.ARKIVERT; // 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(registryEntry) .Save(caseFile) .Save(series) .Commit(); }
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(); }
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)); }