Mercurial > hg > orthanc
diff OrthancServer/ServerJobs/SplitStudyJob.cpp @ 3941:771dbd9eb3bd transcoding
class CleaningInstancesJob to share cleaning code by merge/split jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 18 May 2020 18:20:19 +0200 |
parents | 3661e2a72482 |
children |
line wrap: on
line diff
--- a/OrthancServer/ServerJobs/SplitStudyJob.cpp Mon May 18 17:41:05 2020 +0200 +++ b/OrthancServer/ServerJobs/SplitStudyJob.cpp Mon May 18 18:20:19 2020 +0200 @@ -81,7 +81,7 @@ try { - ServerContext::DicomCacheLocker locker(context_, instance); + ServerContext::DicomCacheLocker locker(GetContext(), instance); modified.reset(locker.GetDicom().Clone(true)); } catch (OrthancException&) @@ -144,8 +144,8 @@ toStore.SetParsedDicomFile(*modified); std::string modifiedInstance; - if (context_.Store(modifiedInstance, toStore, - StoreInstanceMode_Default) != StoreStatus_Success) + if (GetContext().Store(modifiedInstance, toStore, + StoreInstanceMode_Default) != StoreStatus_Success) { LOG(ERROR) << "Error while storing a modified instance " << instance; return false; @@ -155,27 +155,9 @@ } - bool SplitStudyJob::HandleTrailingStep() - { - if (!keepSource_) - { - const size_t n = GetInstancesCount(); - - for (size_t i = 0; i < n; i++) - { - Json::Value tmp; - context_.DeleteResource(tmp, GetInstance(i), ResourceType_Instance); - } - } - - return true; - } - - SplitStudyJob::SplitStudyJob(ServerContext& context, const std::string& sourceStudy) : - context_(context), - keepSource_(false), + CleaningInstancesJob(context, false /* by default, remove source instances */), sourceStudy_(sourceStudy), targetStudyUid_(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study)) { @@ -183,7 +165,7 @@ ResourceType type; - if (!context_.GetIndex().LookupResourceType(type, sourceStudy) || + if (!GetContext().GetIndex().LookupResourceType(type, sourceStudy) || type != ResourceType_Study) { throw OrthancException(ErrorCode_UnknownResource, @@ -219,7 +201,7 @@ { throw OrthancException(ErrorCode_BadSequenceOfCalls); } - else if (!context_.GetIndex().LookupParent(parent, series, ResourceType_Study) || + else if (!GetContext().GetIndex().LookupParent(parent, series, ResourceType_Study) || parent != sourceStudy_) { throw OrthancException(ErrorCode_UnknownResource, @@ -232,7 +214,7 @@ // Add all the instances of the series as to be processed std::list<std::string> instances; - context_.GetIndex().GetChildren(instances, series); + GetContext().GetIndex().GetChildren(instances, series); for (std::list<std::string>::const_iterator it = instances.begin(); it != instances.end(); ++it) @@ -243,17 +225,6 @@ } - void SplitStudyJob::SetKeepSource(bool keep) - { - if (IsStarted()) - { - throw OrthancException(ErrorCode_BadSequenceOfCalls); - } - - keepSource_ = keep; - } - - bool SplitStudyJob::LookupTargetSeriesUid(std::string& uid, const std::string& series) const { @@ -315,7 +286,7 @@ void SplitStudyJob::GetPublicContent(Json::Value& value) { - SetOfInstancesJob::GetPublicContent(value); + CleaningInstancesJob::GetPublicContent(value); if (!targetStudy_.empty()) { @@ -326,7 +297,6 @@ } - static const char* KEEP_SOURCE = "KeepSource"; static const char* SOURCE_STUDY = "SourceStudy"; static const char* TARGET_STUDY = "TargetStudy"; static const char* TARGET_STUDY_UID = "TargetStudyUID"; @@ -338,8 +308,8 @@ SplitStudyJob::SplitStudyJob(ServerContext& context, const Json::Value& serialized) : - SetOfInstancesJob(serialized), // (*) - context_(context) + CleaningInstancesJob(context, serialized, + false /* by default, remove source instances */) // (*) { if (!HasTrailingStep()) { @@ -349,7 +319,6 @@ Setup(); - keepSource_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SOURCE); sourceStudy_ = SerializationToolbox::ReadString(serialized, SOURCE_STUDY); targetStudy_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY); targetStudyUid_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY_UID); @@ -362,13 +331,12 @@ bool SplitStudyJob::Serialize(Json::Value& target) { - if (!SetOfInstancesJob::Serialize(target)) + if (!CleaningInstancesJob::Serialize(target)) { return false; } else { - target[KEEP_SOURCE] = keepSource_; target[SOURCE_STUDY] = sourceStudy_; target[TARGET_STUDY] = targetStudy_; target[TARGET_STUDY_UID] = targetStudyUid_;