ctkConfigurationAdminImpl.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkConfigurationAdminImpl_p.h"
  16. #include "ctkConfigurationAdminFactory_p.h"
  17. #include "ctkConfigurationStore_p.h"
  18. ctkConfigurationAdminImpl::ctkConfigurationAdminImpl(ctkConfigurationAdminFactory* configurationAdminFactory,
  19. ctkConfigurationStore* configurationStore,
  20. QSharedPointer<ctkPlugin> plugin)
  21. : configurationAdminFactory(configurationAdminFactory),
  22. plugin(plugin), configurationStore(configurationStore)
  23. {
  24. }
  25. ctkConfigurationPtr ctkConfigurationAdminImpl::createFactoryConfiguration(const QString& factoryPid)
  26. {
  27. checkPID(factoryPid);
  28. return configurationStore->createFactoryConfiguration(factoryPid, plugin->getLocation());
  29. }
  30. ctkConfigurationPtr ctkConfigurationAdminImpl::createFactoryConfiguration(const QString& factoryPid,
  31. const QString& location)
  32. {
  33. checkPID(factoryPid);
  34. configurationAdminFactory->checkConfigurationPermission();
  35. return configurationStore->createFactoryConfiguration(factoryPid, location);
  36. }
  37. ctkConfigurationPtr ctkConfigurationAdminImpl::getConfiguration(const QString& pid)
  38. {
  39. checkPID(pid);
  40. ctkConfigurationImplPtr config = configurationStore->getConfiguration(pid, plugin->getLocation());
  41. if (!config->getPluginLocation(false).isEmpty() && config->getPluginLocation(false) != plugin->getLocation())
  42. {
  43. configurationAdminFactory->checkConfigurationPermission();
  44. }
  45. config->bind(plugin);
  46. return config;
  47. }
  48. ctkConfigurationPtr ctkConfigurationAdminImpl::getConfiguration(const QString& pid, const QString& location)
  49. {
  50. checkPID(pid);
  51. configurationAdminFactory->checkConfigurationPermission();
  52. return configurationStore->getConfiguration(pid, location);
  53. }
  54. QList<ctkConfigurationPtr> ctkConfigurationAdminImpl::listConfigurations(const QString& filter)
  55. {
  56. QString filterString = filter;
  57. if (filterString.isEmpty())
  58. {
  59. filterString = QString("(%1=*)").arg(ctkPluginConstants::SERVICE_PID);
  60. }
  61. //TODO security
  62. //try
  63. //{
  64. configurationAdminFactory->checkConfigurationPermission();
  65. //}
  66. //catch (SecurityException e) {
  67. // filterString = "(&(" + ConfigurationAdmin.SERVICE_BUNDLELOCATION + "=" + bundle.getLocation() + ")" + filterString + ")";
  68. //}
  69. QList<ctkConfigurationImplPtr> configs = configurationStore->listConfigurations(ctkLDAPSearchFilter(filterString));
  70. QList<ctkConfigurationPtr> result;
  71. foreach(ctkConfigurationImplPtr config, configs)
  72. {
  73. result.push_back(config);
  74. }
  75. return result;
  76. }
  77. void ctkConfigurationAdminImpl::checkPID(const QString& pid)
  78. {
  79. if (pid.isEmpty())
  80. {
  81. throw std::invalid_argument("PID cannot be empty");
  82. }
  83. }