comparison OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 4509:98b7b9d21d83

removed ServerContext::ReadAttachment()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Feb 2021 17:11:37 +0100
parents d9473bd5ed43
children a3635a01a945
comparison
equal deleted inserted replaced
4508:8f9090b137f1 4509:98b7b9d21d83
193 const std::string& publicId) = 0; 193 const std::string& publicId) = 0;
194 194
195 virtual void Close() = 0; 195 virtual void Close() = 0;
196 196
197 virtual void AddInstance(const std::string& instanceId, 197 virtual void AddInstance(const std::string& instanceId,
198 const FileInfo& dicom) = 0; 198 size_t uncompressedSize) = 0;
199 }; 199 };
200 200
201 201
202 class ArchiveJob::ArchiveIndex : public boost::noncopyable 202 class ArchiveJob::ArchiveIndex : public boost::noncopyable
203 { 203 {
204 private: 204 private:
205 struct Instance 205 struct Instance
206 { 206 {
207 std::string id_; 207 std::string id_;
208 FileInfo dicom_; 208 uint64_t uncompressedSize_;
209 209
210 Instance(const std::string& id, 210 Instance(const std::string& id,
211 const FileInfo& dicom) : 211 uint64_t uncompressedSize) :
212 id_(id), dicom_(dicom) 212 id_(id),
213 uncompressedSize_(uncompressedSize)
213 { 214 {
214 } 215 }
215 }; 216 };
216 217
217 // A "NULL" value for ArchiveIndex indicates a non-expanded node 218 // A "NULL" value for ArchiveIndex indicates a non-expanded node
228 if (level_ == ResourceType_Instance) 229 if (level_ == ResourceType_Instance)
229 { 230 {
230 FileInfo tmp; 231 FileInfo tmp;
231 if (index.LookupAttachment(tmp, id, FileContentType_Dicom)) 232 if (index.LookupAttachment(tmp, id, FileContentType_Dicom))
232 { 233 {
233 instances_.push_back(Instance(id, tmp)); 234 instances_.push_back(Instance(id, tmp.GetUncompressedSize()));
234 } 235 }
235 } 236 }
236 else 237 else
237 { 238 {
238 resources_[id] = NULL; 239 resources_[id] = NULL;
333 if (level_ == ResourceType_Instance) 334 if (level_ == ResourceType_Instance)
334 { 335 {
335 for (std::list<Instance>::const_iterator 336 for (std::list<Instance>::const_iterator
336 it = instances_.begin(); it != instances_.end(); ++it) 337 it = instances_.begin(); it != instances_.end(); ++it)
337 { 338 {
338 visitor.AddInstance(it->id_, it->dicom_); 339 visitor.AddInstance(it->id_, it->uncompressedSize_);
339 } 340 }
340 } 341 }
341 else 342 else
342 { 343 {
343 for (Resources::const_iterator it = resources_.begin(); 344 for (Resources::const_iterator it = resources_.begin();
368 { 369 {
369 private: 370 private:
370 Type type_; 371 Type type_;
371 std::string filename_; 372 std::string filename_;
372 std::string instanceId_; 373 std::string instanceId_;
373 FileInfo info_;
374 374
375 public: 375 public:
376 explicit Command(Type type) : 376 explicit Command(Type type) :
377 type_(type) 377 type_(type)
378 { 378 {
387 assert(type_ == Type_OpenDirectory); 387 assert(type_ == Type_OpenDirectory);
388 } 388 }
389 389
390 Command(Type type, 390 Command(Type type,
391 const std::string& filename, 391 const std::string& filename,
392 const std::string& instanceId, 392 const std::string& instanceId) :
393 const FileInfo& info) :
394 type_(type), 393 type_(type),
395 filename_(filename), 394 filename_(filename),
396 instanceId_(instanceId), 395 instanceId_(instanceId)
397 info_(info)
398 { 396 {
399 assert(type_ == Type_WriteInstance); 397 assert(type_ == Type_WriteInstance);
400 } 398 }
401 399
402 void Apply(HierarchicalZipWriter& writer, 400 void Apply(HierarchicalZipWriter& writer,
420 { 418 {
421 std::string content; 419 std::string content;
422 420
423 try 421 try
424 { 422 {
425 context.ReadAttachment(content, info_); 423 context.ReadDicom(content, instanceId_);
426 } 424 }
427 catch (OrthancException& e) 425 catch (OrthancException& e)
428 { 426 {
429 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; 427 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_;
430 return; 428 return;
575 commands_.push_back(new Command(Type_CloseDirectory)); 573 commands_.push_back(new Command(Type_CloseDirectory));
576 } 574 }
577 575
578 void AddWriteInstance(const std::string& filename, 576 void AddWriteInstance(const std::string& filename,
579 const std::string& instanceId, 577 const std::string& instanceId,
580 const FileInfo& info) 578 uint64_t uncompressedSize)
581 { 579 {
582 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId, info)); 580 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId));
583 instancesCount_ ++; 581 instancesCount_ ++;
584 uncompressedSize_ += info.GetUncompressedSize(); 582 uncompressedSize_ += uncompressedSize;
585 } 583 }
586 584
587 bool IsZip64() const 585 bool IsZip64() const
588 { 586 {
589 return IsZip64Required(GetUncompressedSize(), GetInstancesCount()); 587 return IsZip64Required(GetUncompressedSize(), GetInstancesCount());
693 { 691 {
694 commands_.AddCloseDirectory(); 692 commands_.AddCloseDirectory();
695 } 693 }
696 694
697 virtual void AddInstance(const std::string& instanceId, 695 virtual void AddInstance(const std::string& instanceId,
698 const FileInfo& dicom) ORTHANC_OVERRIDE 696 uint64_t uncompressedSize) ORTHANC_OVERRIDE
699 { 697 {
700 char filename[24]; 698 char filename[24];
701 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_); 699 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_);
702 counter_ ++; 700 counter_ ++;
703 701
704 commands_.AddWriteInstance(filename, instanceId, dicom); 702 commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
705 } 703 }
706 }; 704 };
707 705
708 706
709 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor 707 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor
730 virtual void Close() ORTHANC_OVERRIDE 728 virtual void Close() ORTHANC_OVERRIDE
731 { 729 {
732 } 730 }
733 731
734 virtual void AddInstance(const std::string& instanceId, 732 virtual void AddInstance(const std::string& instanceId,
735 const FileInfo& dicom) ORTHANC_OVERRIDE 733 uint64_t uncompressedSize) ORTHANC_OVERRIDE
736 { 734 {
737 // "DICOM restricts the filenames on DICOM media to 8 735 // "DICOM restricts the filenames on DICOM media to 8
738 // characters (some systems wrongly use 8.3, but this does not 736 // characters (some systems wrongly use 8.3, but this does not
739 // conform to the standard)." 737 // conform to the standard)."
740 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_); 738 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_);
741 commands_.AddWriteInstance(filename, instanceId, dicom); 739 commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
742 740
743 counter_ ++; 741 counter_ ++;
744 } 742 }
745 }; 743 };
746 744