comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5248:a7d95f951f8a db-protobuf

replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Apr 2023 22:18:37 +0200
parents 72dfa0ac84eb
children f22c8fac764b
comparison
equal deleted inserted replaced
5247:eb2684260c19 5248:a7d95f951f8a
1649 1649
1650 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE 1650 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1651 { 1651 {
1652 // TODO - CANDIDATE FOR "TransactionType_Implicit" 1652 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1653 std::list<std::string> tmp; 1653 std::list<std::string> tmp;
1654 std::set<std::string> withLabels; 1654 std::set<std::string> labels;
1655 std::set<std::string> withoutLabels; 1655 transaction.ApplyLookupResources(tmp, NULL, query_, level_, labels, LabelsConstraint_Any, 0);
1656 transaction.ApplyLookupResources(tmp, NULL, query_, level_, withLabels, withoutLabels, 0);
1657 CopyListToVector(result_, tmp); 1656 CopyListToVector(result_, tmp);
1658 } 1657 }
1659 }; 1658 };
1660 1659
1661 Operations operations(result, query, level); 1660 Operations operations(result, query, level);
1916 operations.Apply(*this, found, target, publicId, parentType); 1915 operations.Apply(*this, found, target, publicId, parentType);
1917 return found; 1916 return found;
1918 } 1917 }
1919 1918
1920 1919
1921 static void CheckValidLabels(const std::set<std::string>& labels)
1922 {
1923 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it)
1924 {
1925 ServerToolbox::CheckValidLabel(*it);
1926 }
1927 }
1928
1929
1930 void StatelessDatabaseOperations::ApplyLookupResources(std::vector<std::string>& resourcesId, 1920 void StatelessDatabaseOperations::ApplyLookupResources(std::vector<std::string>& resourcesId,
1931 std::vector<std::string>* instancesId, 1921 std::vector<std::string>* instancesId,
1932 const DatabaseLookup& lookup, 1922 const DatabaseLookup& lookup,
1933 ResourceType queryLevel, 1923 ResourceType queryLevel,
1934 const std::set<std::string>& withLabels, 1924 const std::set<std::string>& labels,
1935 const std::set<std::string>& withoutLabels, 1925 LabelsConstraint labelsConstraint,
1936 uint32_t limit) 1926 uint32_t limit)
1937 { 1927 {
1938 class Operations : public ReadOnlyOperationsT6<bool, const std::vector<DatabaseConstraint>&, ResourceType, 1928 class Operations : public ReadOnlyOperationsT6<bool, const std::vector<DatabaseConstraint>&, ResourceType,
1939 const std::set<std::string>&, const std::set<std::string>&, size_t> 1929 const std::set<std::string>&, LabelsConstraint, size_t>
1940 { 1930 {
1941 private: 1931 private:
1942 std::list<std::string> resourcesList_; 1932 std::list<std::string> resourcesList_;
1943 std::list<std::string> instancesList_; 1933 std::list<std::string> instancesList_;
1944 1934
1968 resourcesList_, NULL, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), tuple.get<4>(), tuple.get<5>()); 1958 resourcesList_, NULL, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), tuple.get<4>(), tuple.get<5>());
1969 } 1959 }
1970 } 1960 }
1971 }; 1961 };
1972 1962
1973 if ((!withLabels.empty() || !withoutLabels.empty()) && 1963 if (!labels.empty() &&
1974 !db_.HasLabelsSupport()) 1964 !db_.HasLabelsSupport())
1975 { 1965 {
1976 throw OrthancException(ErrorCode_NotImplemented, "The database backend doesn't support labels"); 1966 throw OrthancException(ErrorCode_NotImplemented, "The database backend doesn't support labels");
1977 } 1967 }
1978 1968
1979 CheckValidLabels(withLabels); 1969 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it)
1980 CheckValidLabels(withoutLabels); 1970 {
1971 ServerToolbox::CheckValidLabel(*it);
1972 }
1981 1973
1982 std::vector<DatabaseConstraint> normalized; 1974 std::vector<DatabaseConstraint> normalized;
1983 NormalizeLookup(normalized, lookup, queryLevel); 1975 NormalizeLookup(normalized, lookup, queryLevel);
1984 1976
1985 Operations operations; 1977 Operations operations;
1986 operations.Apply(*this, (instancesId != NULL), normalized, queryLevel, withLabels, withoutLabels, limit); 1978 operations.Apply(*this, (instancesId != NULL), normalized, queryLevel, labels, labelsConstraint, limit);
1987 1979
1988 CopyListToVector(resourcesId, operations.GetResourcesList()); 1980 CopyListToVector(resourcesId, operations.GetResourcesList());
1989 1981
1990 if (instancesId != NULL) 1982 if (instancesId != NULL)
1991 { 1983 {