public void GetRegistryEntriesCreatedInDateRange(string seriesId, DateTime fromDate, DateTime toDate) { NoarkClient client = this.documasterClients.GetNoarkClient(); List <Journalpost> registryEntries = new List <Journalpost>(); bool hasMoreResults = true; int pageSize = 30; int offset = 0; while (hasMoreResults) { QueryResponse <Journalpost> queryResponse = client.Query <Journalpost>("refMappe.refArkivdel.id=@seriesId && opprettetDato=[@from:@to]", pageSize) .AddQueryParam("@seriesId", seriesId) .AddQueryParam("@from", fromDate) .AddQueryParam("@to", toDate) .SetOffset(offset) .Execute(); offset += pageSize; hasMoreResults = queryResponse.HasMore; registryEntries.AddRange(queryResponse.Results); } foreach (Journalpost registryEntry in registryEntries) { Console.WriteLine($"Registry entry: Id: {registryEntry.Id}. Title: {registryEntry.Tittel}"); } }
public void GetCaseFileBySecondaryClass(string seriesId, string secondaryClassId, string secondaryClassTitle) { NoarkClient client = this.documasterClients.GetNoarkClient(); //Note that folders, basic records and registry entries might also be linked to a secondary class. List <Saksmappe> caseFiles = new List <Saksmappe>(); bool hasMoreResults = true; int pageSize = 30; int offset = 0; while (hasMoreResults) { QueryResponse <Saksmappe> queryResponse = client .Query <Saksmappe>( "refArkivdel.id=@seriesId && refSekundaerKlasse.klasseIdent=@classId && refSekundaerKlasse.tittel=@title", 1) .AddQueryParam("@seriesId", seriesId) .AddQueryParam("@classId", secondaryClassId) .AddQueryParam("@title", secondaryClassTitle) .SetOffset(0) .Execute(); hasMoreResults = queryResponse.HasMore; offset += pageSize; caseFiles.AddRange(queryResponse.Results); } foreach (Saksmappe caseFile in caseFiles) { Console.WriteLine($"Case file: Id: {caseFile.Id}. Title: {caseFile.Tittel}"); } }
public void Search() { /** * Search for a free text string in index documents with the specified doctype. * An index document is a set of fields and their corresponding values stored in a search index. * Each index document has a doctype which corresponds to a set of Noark 5 fields stored in the index document. * The supported doctypes are Tekst, Arkivdel, Mappe, Registrering and Korrespondansepart. * Search fields are specific to each object type (eg. tittel in Arkivdel, klasseIdent and tittel in Klass etc.) */ NoarkClient client = this.documasterClients.GetNoarkClient(); int offset = 0; bool hasMoreResults = true; int pageSize = 30; int resultsCount = 0; List <SearchResponse> searchResults = new List <SearchResponse>(); while (hasMoreResults) { //Search for the string "Test" SearchResponse searchResponse = client.Search(Doctype.Tekst, "Test") .SetLimit(pageSize) .SetOffset(offset) .Execute(); searchResults.Add(searchResponse); resultsCount += searchResponse.Results.Count; offset += pageSize; hasMoreResults = resultsCount < searchResponse.Total; } foreach (SearchResponse searchResponse in searchResults) { // Each search result includes the IDs of the Noark 5 objects whose fields are included in the index document // as well as highlighted snippets from matching fields. foreach (SearchResult searchResult in searchResponse.Results) { Console.WriteLine($"Object Ids: {string.Join(", ", searchResult.Ids.ToArray())}"); Console.WriteLine("Highlights:"); foreach (string matchingField in searchResult.Highlights.Keys) { Console.WriteLine( $"Highlights for field {matchingField}: {string.Join(", ", searchResult.Highlights[matchingField].ToArray())}"); } } foreach (Facet facet in searchResponse.Facets) { Console.WriteLine($"Facet field: {facet.Field}"); foreach (string facetValue in facet.Values.Keys) { Console.WriteLine($"Facet value: {facetValue}. Number of index documents with that value: {facet.Values[facetValue]}."); } } } }
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); }
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 void GetCaseFilesByExternalId(string seriesId, string externalId, string externalSystem) { NoarkClient client = this.documasterClients.GetNoarkClient(); //Note that folders, basic records, registry entries and document descriptions might also have an external id attached. List <Saksmappe> caseFiles = new List <Saksmappe>(); bool hasMoreResults = true; int pageSize = 30; int offset = 0; while (hasMoreResults) { QueryResponse <Saksmappe> queryResponse = client.Query <Saksmappe>( "refArkivdel.id=@seriesId && refEksternId.eksternID=@externalId && refEksternId.eksterntSystem=@externalSystem", 1) .AddQueryParam("@seriesId", seriesId) .AddQueryParam("@externalId", externalId) .AddQueryParam("@externalSystem", externalSystem) .SetOffset(offset) .Execute(); hasMoreResults = queryResponse.HasMore; offset += pageSize; caseFiles.AddRange(queryResponse.Results); } foreach (Saksmappe caseFile in caseFiles) { Console.WriteLine($"Case file: Id: {caseFile.Id}. Title: {caseFile.Tittel}"); } }
public void GetCodeLists() { NoarkClient client = this.documasterClients.GetNoarkClient(); Console.WriteLine("Get all available code lists"); List <CodeList> allLists = client.CodeLists(); foreach (CodeList codeList in allLists) { Console.WriteLine($"Field: {codeList.Field}. Type: {codeList.Type}. Values:"); foreach (CodeValue codeValue in codeList.Values) { Console.WriteLine($"===== Code: {codeValue.Code}. Value: {codeValue.Name}"); } } Console.WriteLine(); Console.WriteLine("Get a code list by field and/or type"); CodeList documentTypeList = client.CodeLists("Dokument", "dokumenttype").First(); foreach (CodeValue codeValue in documentTypeList.Values) { Console.WriteLine($"===== Code: {codeValue.Code}. Value: {codeValue.Name}"); } }
private CodeValue GetDocumentTypeByName(string name) { NoarkClient noarkClient = this.documasterClients.GetNoarkClient(); CodeList documentTypeCodeList = noarkClient.CodeLists("Dokument", "dokumenttype").First(); return(documentTypeCodeList.Values.Find(codeValue => codeValue.Name.Equals(name))); }
private CodeValue GetAdministrativeUnitByName(string name) { NoarkClient noarkClient = documasterClients.GetNoarkClient(); CodeList administrativeUnitCodeList = noarkClient.CodeLists("Saksmappe", "administrativEnhet").First(); return(administrativeUnitCodeList.Values.Find(codeValue => codeValue.Name.Equals(name))); }
private CodeValue GetScreeningCodeByName(string name) { NoarkClient noarkClient = this.documasterClients.GetNoarkClient(); CodeList screeningCodeList = noarkClient.CodeLists(null, "skjerming").First(); return(screeningCodeList.Values.Find(codeValue => codeValue.Name.Equals(name))); }
private T GetNoarkEntityById <T>(string id) where T : INoarkEntity { NoarkClient client = this.documasterClients.GetNoarkClient(); QueryResponse <T> queryResponse = client.Query <T>("id=@id", 1) .AddQueryParam("@id", id) .Execute(); if (queryResponse.Results.Any()) { return(queryResponse.Results.First()); } throw new Exception($"Object of type '{typeof(T).Name}' with id '{id}' was not found!"); }
private Klassifikasjonssystem GetSecondaryClassificationSystem(string seriesId) { NoarkClient client = this.documasterClients.GetNoarkClient(); QueryResponse <Klassifikasjonssystem> queryResponse = client .Query <Klassifikasjonssystem>("refArkivdelSomSekundaer.id=@seriesId", 1) .AddQueryParam("@seriesId", seriesId) .Execute(); if (!queryResponse.Results.Any()) { return(null); } return(queryResponse.Results.First()); }
public void CreateListValues() { Console.WriteLine($"Create list values"); NoarkClient client = this.documasterClients.GetNoarkClient(); //Create a new administrative unit AdministrativEnhet administrativeUnit = new AdministrativEnhet("TK", "Test Kommune"); AdministrativEnhet savedAdministrativeUnit = client.PutCodeListValue(administrativeUnit); //Create a new screening code Skjerming screeningCode = new Skjerming("N1", "Name", "Description", "Authority"); Skjerming savedScreeningCode = client.PutCodeListValue(screeningCode); //Create a new document type Dokumenttype documentType = new Dokumenttype("Tilbud", "Name"); Dokumenttype newDocumentType = client.PutCodeListValue(documentType); }
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(); }
private Arkivdel GetSeriesByTitle(string title) { NoarkClient client = this.documasterClients.GetNoarkClient(); QueryResponse <Arkivdel> queryResponse = client.Query <Arkivdel>("tittel=@title", 1) .AddQueryParam("@title", title) .Execute(); IEnumerable <Arkivdel> results = queryResponse.Results; if (!results.Any()) { return(null); } if (queryResponse.HasMore) { Console.WriteLine($"Found more than two series with title {title}!"); } return(results.First()); }
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 Klasse GetClassByTitle(string classificationSystemId, string title) { NoarkClient client = this.documasterClients.GetNoarkClient(); QueryResponse <Klasse> queryResponse = client .Query <Klasse>("refKlassifikasjonssystem.id=@ksId && tittel=@title", 1) .AddQueryParam("@ksId", classificationSystemId) .AddQueryParam("@title", title) .Execute(); IEnumerable <Klasse> results = queryResponse.Results; if (!results.Any()) { return(null); } if (queryResponse.HasMore) { Console.WriteLine($"Found more than two classes with title {title}!"); } return(results.First()); }
private void InitNoarkClient(Options options) { //ServerAddress is in the format https://clientname.dev.documaster.tech:8083 this.noarkClient = new NoarkClient(options.ServerAddress, true); }
public void CreateBusinessSpecificMetaDataGroupsAndFields() { Console.WriteLine($"Create business-specific metadata structure"); NoarkClient client = this.documasterClients.GetNoarkClient(); string GROUP_ID = "gr-1"; string STRING_FIELD_ID = "f-string"; string DOUBLE_FIELD_ID = "f-double"; string LONG_FIELD_ID = "f-long"; //Create a business-specific metadata group MetadataGroupInfo group = new MetadataGroupInfo(GROUP_ID, "BSM Group Name", "BSM Group Description"); MetadataGroupInfo savedGroup = client.PutBsmGroup(group); Console.WriteLine( $"New group: GroupId={savedGroup.GroupId}, GroupDescription={savedGroup.GroupDescription}, GroupName={savedGroup.GroupName}"); //Create a new string field with predefined values "value 1", "value 2" and "value 3" MetadataFieldInfo fieldStr = new MetadataFieldInfo(STRING_FIELD_ID, "BSM Field String", "BSM Field Description", FieldType.String, new List <object>() { "value 1", "value 2", "value 3" }); MetadataFieldInfo savedFieldStr = client.PutBsmField(GROUP_ID, fieldStr); Console.WriteLine( $"Created new field: FieldId={savedFieldStr.FieldId}, FieldType={savedFieldStr.FieldType}, FieldName={savedFieldStr.FieldName}, FieldValues={string.Join(",", savedFieldStr.FieldValues)}"); //Create a new long field with predefined values 1 and 2 MetadataFieldInfo fieldLong = new MetadataFieldInfo(LONG_FIELD_ID, "BSM Field Long", "BSM Field Description", FieldType.Long, new List <object>() { 1L, 2L }); MetadataFieldInfo savedFieldLong = client.PutBsmField(GROUP_ID, fieldLong); Console.WriteLine( $"Created new field: FieldId={savedFieldLong.FieldId}, FieldType={savedFieldLong.FieldType}, FieldName={savedFieldLong.FieldName}, FieldValues={string.Join(",", savedFieldLong.FieldValues)}"); //Create a new double field with no predefined values MetadataFieldInfo fieldDouble = new MetadataFieldInfo(DOUBLE_FIELD_ID, "BSM Field Double", "BSM Field Description", FieldType.Double); MetadataFieldInfo savedFielDouble = client.PutBsmField(GROUP_ID, fieldDouble); Console.WriteLine( $"Created new field: FieldId={fieldDouble.FieldId}, FieldType={fieldDouble.FieldType}, FieldName={fieldDouble.FieldName}"); //Get the business-specific metadata registry for a specific group BusinessSpecificMetadataInfo metadataInfo = client.BsmRegistry(GROUP_ID); Console.WriteLine("BusinessSpecificMetadataInfo:"); //Print the registry for this group foreach (MetadataGroupInfo groupInfo in metadataInfo.Groups) { Console.WriteLine( $"GroupInfo: GroupId={groupInfo.GroupId}, GroupName={groupInfo.GroupName}"); foreach (MetadataFieldInfo fieldInfo in groupInfo.Fields) { Console.WriteLine( $" ---- FieldInfo: FieldId={fieldInfo.FieldId}, FieldType={fieldInfo.FieldType}, FieldName={fieldInfo.FieldName}"); } } }
private static void InitClientWithoutClientCertificate(Options options) { client = new NoarkClient(options.ServerAddress, true); }
private static void InitClient(Options options) { client = new NoarkClient(options.ServerAddress, options.CertificatePath, options.CertificatePass, true); }
private Dokumentfil UploadDocument(string filePath) { NoarkClient client = this.documasterClients.GetNoarkClient(); return(client.Upload(filePath)); }
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)); }