Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancWebDav.cpp @ 4243:64f57c9d5f79
configuration options for webdav
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Oct 2020 18:10:24 +0200 |
parents | 5cfa6ba75dfc |
children | 416c35da7d25 |
comparison
equal
deleted
inserted
replaced
4242:5cfa6ba75dfc | 4243:64f57c9d5f79 |
---|---|
1189 { | 1189 { |
1190 assert(that != NULL); | 1190 assert(that != NULL); |
1191 | 1191 |
1192 boost::posix_time::ptime lastModification = GetNow(); | 1192 boost::posix_time::ptime lastModification = GetNow(); |
1193 | 1193 |
1194 while (that->running_) | 1194 while (that->uploadRunning_) |
1195 { | 1195 { |
1196 std::unique_ptr<IDynamicObject> obj(that->uploadQueue_.Dequeue(100)); | 1196 std::unique_ptr<IDynamicObject> obj(that->uploadQueue_.Dequeue(100)); |
1197 if (obj.get() != NULL) | 1197 if (obj.get() != NULL) |
1198 { | 1198 { |
1199 that->Upload(reinterpret_cast<const SingleValueObject<std::string>&>(*obj).GetValue()); | 1199 that->Upload(reinterpret_cast<const SingleValueObject<std::string>&>(*obj).GetValue()); |
1221 std::string content; | 1221 std::string content; |
1222 boost::posix_time::ptime time; | 1222 boost::posix_time::ptime time; |
1223 if (uploads_.GetFileContent(mime, content, time, uri)) | 1223 if (uploads_.GetFileContent(mime, content, time, uri)) |
1224 { | 1224 { |
1225 DicomInstanceToStore instance; | 1225 DicomInstanceToStore instance; |
1226 // instance.SetOrigin(DicomInstanceOrigin_WebDav); | 1226 // instance.SetOrigin(DicomInstanceOrigin_WebDav); // TODO |
1227 instance.SetBuffer(content.c_str(), content.size()); | 1227 instance.SetBuffer(content.c_str(), content.size()); |
1228 | 1228 |
1229 std::string publicId; | 1229 std::string publicId; |
1230 StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default); | 1230 StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default); |
1231 if (status == StoreStatus_Success || | 1231 if (status == StoreStatus_Success || |
1262 } | 1262 } |
1263 } | 1263 } |
1264 | 1264 |
1265 | 1265 |
1266 OrthancWebDav::OrthancWebDav(ServerContext& context, | 1266 OrthancWebDav::OrthancWebDav(ServerContext& context, |
1267 bool allowDicomDelete) : | 1267 bool allowDicomDelete, |
1268 bool allowUpload) : | |
1268 context_(context), | 1269 context_(context), |
1269 allowDicomDelete_(allowDicomDelete), | 1270 allowDicomDelete_(allowDicomDelete), |
1271 allowUpload_(allowUpload), | |
1270 uploads_(false /* store uploads as temporary files */), | 1272 uploads_(false /* store uploads as temporary files */), |
1271 running_(false) | 1273 uploadRunning_(false) |
1272 { | 1274 { |
1273 patientsTemplates_[ResourceType_Patient] = "{{PatientID}} - {{PatientName}}"; | 1275 patientsTemplates_[ResourceType_Patient] = "{{PatientID}} - {{PatientName}}"; |
1274 patientsTemplates_[ResourceType_Study] = "{{StudyDate}} - {{StudyDescription}}"; | 1276 patientsTemplates_[ResourceType_Study] = "{{StudyDate}} - {{StudyDescription}}"; |
1275 patientsTemplates_[ResourceType_Series] = "{{Modality}} - {{SeriesDescription}}"; | 1277 patientsTemplates_[ResourceType_Series] = "{{Modality}} - {{SeriesDescription}}"; |
1276 | 1278 |
1299 path[0] == BY_DATES) | 1301 path[0] == BY_DATES) |
1300 { | 1302 { |
1301 IWebDavBucket::Collection tmp; | 1303 IWebDavBucket::Collection tmp; |
1302 return GetRootNode(path[0]).ListCollection(tmp, UriComponents(path.begin() + 1, path.end())); | 1304 return GetRootNode(path[0]).ListCollection(tmp, UriComponents(path.begin() + 1, path.end())); |
1303 } | 1305 } |
1304 else if (path[0] == UPLOADS) | 1306 else if (allowUpload_ && |
1307 path[0] == UPLOADS) | |
1305 { | 1308 { |
1306 return uploads_.IsExistingFolder(UriComponents(path.begin() + 1, path.end())); | 1309 return uploads_.IsExistingFolder(UriComponents(path.begin() + 1, path.end())); |
1307 } | 1310 } |
1308 else | 1311 else |
1309 { | 1312 { |
1319 { | 1322 { |
1320 collection.AddResource(new Folder(BY_DATES)); | 1323 collection.AddResource(new Folder(BY_DATES)); |
1321 collection.AddResource(new Folder(BY_PATIENTS)); | 1324 collection.AddResource(new Folder(BY_PATIENTS)); |
1322 collection.AddResource(new Folder(BY_STUDIES)); | 1325 collection.AddResource(new Folder(BY_STUDIES)); |
1323 collection.AddResource(new Folder(BY_UIDS)); | 1326 collection.AddResource(new Folder(BY_UIDS)); |
1324 collection.AddResource(new Folder(UPLOADS)); | 1327 |
1328 if (allowUpload_) | |
1329 { | |
1330 collection.AddResource(new Folder(UPLOADS)); | |
1331 } | |
1332 | |
1325 return true; | 1333 return true; |
1326 } | 1334 } |
1327 else if (path[0] == BY_UIDS) | 1335 else if (path[0] == BY_UIDS) |
1328 { | 1336 { |
1329 DatabaseLookup query; | 1337 DatabaseLookup query; |
1331 size_t limit = 0; // By default, no limits | 1339 size_t limit = 0; // By default, no limits |
1332 | 1340 |
1333 if (path.size() == 1) | 1341 if (path.size() == 1) |
1334 { | 1342 { |
1335 level = ResourceType_Study; | 1343 level = ResourceType_Study; |
1336 limit = 100; // TODO | 1344 limit = 0; // TODO - Should we limit here? |
1337 } | 1345 } |
1338 else if (path.size() == 2) | 1346 else if (path.size() == 2) |
1339 { | 1347 { |
1340 AddVirtualFile(collection, path, STUDY_INFO); | 1348 AddVirtualFile(collection, path, STUDY_INFO); |
1341 | 1349 |
1367 path[0] == BY_STUDIES || | 1375 path[0] == BY_STUDIES || |
1368 path[0] == BY_DATES) | 1376 path[0] == BY_DATES) |
1369 { | 1377 { |
1370 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end())); | 1378 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end())); |
1371 } | 1379 } |
1372 else if (path[0] == UPLOADS) | 1380 else if (allowUpload_ && |
1381 path[0] == UPLOADS) | |
1373 { | 1382 { |
1374 return uploads_.ListCollection(collection, UriComponents(path.begin() + 1, path.end())); | 1383 return uploads_.ListCollection(collection, UriComponents(path.begin() + 1, path.end())); |
1375 } | 1384 } |
1376 else | 1385 else |
1377 { | 1386 { |
1447 path[0] == BY_STUDIES || | 1456 path[0] == BY_STUDIES || |
1448 path[0] == BY_DATES) | 1457 path[0] == BY_DATES) |
1449 { | 1458 { |
1450 return GetRootNode(path[0]).GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); | 1459 return GetRootNode(path[0]).GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); |
1451 } | 1460 } |
1452 else if (path[0] == UPLOADS) | 1461 else if (allowUpload_ && |
1462 path[0] == UPLOADS) | |
1453 { | 1463 { |
1454 return uploads_.GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); | 1464 return uploads_.GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); |
1455 } | 1465 } |
1456 else | 1466 else |
1457 { | 1467 { |
1461 | 1471 |
1462 | 1472 |
1463 bool OrthancWebDav::StoreFile(const std::string& content, | 1473 bool OrthancWebDav::StoreFile(const std::string& content, |
1464 const UriComponents& path) | 1474 const UriComponents& path) |
1465 { | 1475 { |
1466 if (path.size() >= 1 && | 1476 if (allowUpload_ && |
1477 path.size() >= 1 && | |
1467 path[0] == UPLOADS) | 1478 path[0] == UPLOADS) |
1468 { | 1479 { |
1469 UriComponents subpath(UriComponents(path.begin() + 1, path.end())); | 1480 UriComponents subpath(UriComponents(path.begin() + 1, path.end())); |
1470 | 1481 |
1471 if (uploads_.StoreFile(content, subpath)) | 1482 if (uploads_.StoreFile(content, subpath)) |
1488 } | 1499 } |
1489 | 1500 |
1490 | 1501 |
1491 bool OrthancWebDav::CreateFolder(const UriComponents& path) | 1502 bool OrthancWebDav::CreateFolder(const UriComponents& path) |
1492 { | 1503 { |
1493 if (path.size() >= 1 && | 1504 if (allowUpload_ && |
1505 path.size() >= 1 && | |
1494 path[0] == UPLOADS) | 1506 path[0] == UPLOADS) |
1495 { | 1507 { |
1496 return uploads_.CreateFolder(UriComponents(path.begin() + 1, path.end())); | 1508 return uploads_.CreateFolder(UriComponents(path.begin() + 1, path.end())); |
1497 } | 1509 } |
1498 else | 1510 else |
1551 { | 1563 { |
1552 return false; | 1564 return false; |
1553 } | 1565 } |
1554 } | 1566 } |
1555 | 1567 |
1556 std::cout << "\n\n" << query.Format() << "\n\n"; | |
1557 | |
1558 DicomDeleteVisitor visitor(context_, level); | 1568 DicomDeleteVisitor visitor(context_, level); |
1559 context_.Apply(visitor, query, ResourceType_Instance, 0 /* since */, 0 /* no limit */); | 1569 context_.Apply(visitor, query, ResourceType_Instance, 0 /* since */, 0 /* no limit */); |
1560 return true; | 1570 return true; |
1561 } | 1571 } |
1562 else | 1572 else |
1575 else | 1585 else |
1576 { | 1586 { |
1577 return false; // read-only | 1587 return false; // read-only |
1578 } | 1588 } |
1579 } | 1589 } |
1580 else if (path[0] == UPLOADS) | 1590 else if (allowUpload_ && |
1591 path[0] == UPLOADS) | |
1581 { | 1592 { |
1582 return uploads_.DeleteItem(UriComponents(path.begin() + 1, path.end())); | 1593 return uploads_.DeleteItem(UriComponents(path.begin() + 1, path.end())); |
1583 } | 1594 } |
1584 else | 1595 else |
1585 { | 1596 { |
1588 } | 1599 } |
1589 | 1600 |
1590 | 1601 |
1591 void OrthancWebDav::Start() | 1602 void OrthancWebDav::Start() |
1592 { | 1603 { |
1593 if (running_) | 1604 if (uploadRunning_) |
1594 { | 1605 { |
1595 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 1606 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1596 } | 1607 } |
1597 else | 1608 else if (allowUpload_) |
1598 { | 1609 { |
1599 LOG(INFO) << "Starting the WebDAV upload thread"; | 1610 LOG(INFO) << "Starting the WebDAV upload thread"; |
1600 running_ = true; | 1611 uploadRunning_ = true; |
1601 uploadThread_ = boost::thread(UploadWorker, this); | 1612 uploadThread_ = boost::thread(UploadWorker, this); |
1602 } | 1613 } |
1603 } | 1614 } |
1604 | 1615 |
1605 | 1616 |
1606 void OrthancWebDav::Stop() | 1617 void OrthancWebDav::Stop() |
1607 { | 1618 { |
1608 if (running_) | 1619 if (uploadRunning_) |
1609 { | 1620 { |
1610 LOG(INFO) << "Stopping the WebDAV upload thread"; | 1621 LOG(INFO) << "Stopping the WebDAV upload thread"; |
1611 running_ = false; | 1622 uploadRunning_ = false; |
1612 if (uploadThread_.joinable()) | 1623 if (uploadThread_.joinable()) |
1613 { | 1624 { |
1614 uploadThread_.join(); | 1625 uploadThread_.join(); |
1615 } | 1626 } |
1616 } | 1627 } |