comparison OrthancServer/Scheduler/ModifyInstanceCommand.cpp @ 1099:060e8918d7a4

More fault-tolerant commands in Lua scripts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Aug 2014 10:02:22 +0200
parents 187ed107a59f
children 6e7e5ed91c2d
comparison
equal deleted inserted replaced
1098:50c889af583b 1099:060e8918d7a4
42 for (ListOfStrings::const_iterator 42 for (ListOfStrings::const_iterator
43 it = inputs.begin(); it != inputs.end(); ++it) 43 it = inputs.begin(); it != inputs.end(); ++it)
44 { 44 {
45 LOG(INFO) << "Modifying resource " << *it; 45 LOG(INFO) << "Modifying resource " << *it;
46 46
47 std::auto_ptr<ParsedDicomFile> modified; 47 try
48 {
49 std::auto_ptr<ParsedDicomFile> modified;
48 50
51 {
52 ServerContext::DicomCacheLocker lock(context_, *it);
53 modified.reset(lock.GetDicom().Clone());
54 }
55
56 modification_.Apply(*modified);
57
58 DicomInstanceToStore toStore;
59 toStore.SetParsedDicomFile(*modified);
60 // TODO other metadata
61 toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, *it);
62
63 std::string modifiedId;
64 context_.Store(modifiedId, toStore);
65
66 // Only chain with other commands if this command succeeds
67 outputs.push_back(modifiedId);
68 }
69 catch (OrthancException& e)
49 { 70 {
50 ServerContext::DicomCacheLocker lock(context_, *it); 71 LOG(ERROR) << "Unable to modify instance " << *it << " in a Lua script: " << e.What();
51 modified.reset(lock.GetDicom().Clone());
52 } 72 }
53
54 modification_.Apply(*modified);
55
56 DicomInstanceToStore toStore;
57 toStore.SetParsedDicomFile(*modified);
58 // TODO other metadata
59 toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, *it);
60
61 std::string modifiedId;
62 context_.Store(modifiedId, toStore);
63
64 outputs.push_back(modifiedId);
65 } 73 }
66 74
67 return true; 75 return true;
68 } 76 }
69 } 77 }