public async Task <bool> ReindexInstanceAsync( IReadOnlyCollection <ExtendedQueryTagStoreEntry> entries, VersionedInstanceIdentifier versionedInstanceId, CancellationToken cancellationToken) { EnsureArg.IsNotNull(entries, nameof(entries)); EnsureArg.IsNotNull(versionedInstanceId, nameof(versionedInstanceId)); DicomDataset dataset; try { dataset = await _metadataStore.GetInstanceMetadataAsync(versionedInstanceId, cancellationToken); } catch (ItemNotFoundException) { _logger.LogWarning("Could not find metadata for instance with {Identifier}", versionedInstanceId); return(false); } // Only reindex on valid query tags IReadOnlyCollection <QueryTag> validQueryTags = await _dicomDatasetReindexValidator.ValidateAsync( dataset, versionedInstanceId.Version, entries.Select(x => new QueryTag(x)).ToList(), cancellationToken); await _indexDataStore.ReindexInstanceAsync(dataset, versionedInstanceId.Version, validQueryTags, cancellationToken); return(true); }
public async Task GivenValidAndInvalidTagValues_WhenValidate_ThenReturnedValidTagsAndStoredFailure() { DicomTag tag1 = DicomTag.DeviceSerialNumber; DicomTag tag2 = DicomTag.DeviceID; DicomDataset ds = Samples.CreateRandomInstanceDataset(); DicomElement element1 = new DicomLongString(tag1, "testvalue1"); DicomElement element2 = new DicomLongString(tag2, "testvalue2"); ds.Add(element1); ds.Add(element2); QueryTag queryTag1 = new QueryTag(new ExtendedQueryTagStoreEntry(1, tag1.GetPath(), tag1.GetDefaultVR().Code, null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Ready, QueryStatus.Enabled, 0)); QueryTag queryTag2 = new QueryTag(new ExtendedQueryTagStoreEntry(2, tag2.GetPath(), tag2.GetDefaultVR().Code, null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Ready, QueryStatus.Enabled, 0)); // Throw exception when validate element1 var ex = ElementValidationExceptionFactory.CreateDateIsInvalidException("testname", "testvalue"); _minimumValidator.When(x => x.Validate(element1)) .Throw(ex); // only return querytag2 long watermark = 1; var validQueryTags = await _datasetValidator.ValidateAsync(ds, watermark, new[] { queryTag1, queryTag2 }); Assert.Single(validQueryTags); Assert.Same(queryTag2, validQueryTags.First()); // error for querytag1 is logged await _tagErrorsService.Received(1) .AddExtendedQueryTagErrorAsync(queryTag1.ExtendedQueryTagStoreEntry.Key, ex.ErrorCode, 1, Arg.Any <CancellationToken>()); }