comparison OrthancServer/ServerIndex.cpp @ 1773:613df4362575

New UpdatedAttachment and UpdatedMetadata events in plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Nov 2015 15:24:23 +0100
parents 98abb8d7f905
children 9ed9458aa44f
comparison
equal deleted inserted replaced
1772:53e045b5a8ec 1773:613df4362575
1523 void ServerIndex::SetMetadata(const std::string& publicId, 1523 void ServerIndex::SetMetadata(const std::string& publicId,
1524 MetadataType type, 1524 MetadataType type,
1525 const std::string& value) 1525 const std::string& value)
1526 { 1526 {
1527 boost::mutex::scoped_lock lock(mutex_); 1527 boost::mutex::scoped_lock lock(mutex_);
1528 Transaction t(*this);
1528 1529
1529 ResourceType rtype; 1530 ResourceType rtype;
1530 int64_t id; 1531 int64_t id;
1531 if (!db_.LookupResource(id, rtype, publicId)) 1532 if (!db_.LookupResource(id, rtype, publicId))
1532 { 1533 {
1533 throw OrthancException(ErrorCode_UnknownResource); 1534 throw OrthancException(ErrorCode_UnknownResource);
1534 } 1535 }
1535 1536
1536 db_.SetMetadata(id, type, value); 1537 db_.SetMetadata(id, type, value);
1538
1539 if (IsUserMetadata(type))
1540 {
1541 LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId);
1542 }
1543
1544 t.Commit(0);
1537 } 1545 }
1538 1546
1539 1547
1540 void ServerIndex::DeleteMetadata(const std::string& publicId, 1548 void ServerIndex::DeleteMetadata(const std::string& publicId,
1541 MetadataType type) 1549 MetadataType type)
1542 { 1550 {
1543 boost::mutex::scoped_lock lock(mutex_); 1551 boost::mutex::scoped_lock lock(mutex_);
1552 Transaction t(*this);
1544 1553
1545 ResourceType rtype; 1554 ResourceType rtype;
1546 int64_t id; 1555 int64_t id;
1547 if (!db_.LookupResource(id, rtype, publicId)) 1556 if (!db_.LookupResource(id, rtype, publicId))
1548 { 1557 {
1549 throw OrthancException(ErrorCode_UnknownResource); 1558 throw OrthancException(ErrorCode_UnknownResource);
1550 } 1559 }
1551 1560
1552 db_.DeleteMetadata(id, type); 1561 db_.DeleteMetadata(id, type);
1562
1563 if (IsUserMetadata(type))
1564 {
1565 LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId);
1566 }
1567
1568 t.Commit(0);
1553 } 1569 }
1554 1570
1555 1571
1556 bool ServerIndex::LookupMetadata(std::string& target, 1572 bool ServerIndex::LookupMetadata(std::string& target,
1557 const std::string& publicId, 1573 const std::string& publicId,
1956 assert(db_.GetResourceType(patientId) == ResourceType_Patient); 1972 assert(db_.GetResourceType(patientId) == ResourceType_Patient);
1957 Recycle(attachment.GetCompressedSize(), db_.GetPublicId(patientId)); 1973 Recycle(attachment.GetCompressedSize(), db_.GetPublicId(patientId));
1958 1974
1959 db_.AddAttachment(resourceId, attachment); 1975 db_.AddAttachment(resourceId, attachment);
1960 1976
1977 if (IsUserContentType(attachment.GetContentType()))
1978 {
1979 LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId);
1980 }
1981
1961 t.Commit(attachment.GetCompressedSize()); 1982 t.Commit(attachment.GetCompressedSize());
1962 1983
1963 return StoreStatus_Success; 1984 return StoreStatus_Success;
1964 } 1985 }
1965 1986
1976 { 1997 {
1977 throw OrthancException(ErrorCode_UnknownResource); 1998 throw OrthancException(ErrorCode_UnknownResource);
1978 } 1999 }
1979 2000
1980 db_.DeleteAttachment(id, type); 2001 db_.DeleteAttachment(id, type);
2002
2003 if (IsUserContentType(type))
2004 {
2005 LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId);
2006 }
1981 2007
1982 t.Commit(0); 2008 t.Commit(0);
1983 } 2009 }
1984 2010
1985 2011