Source for file HarmoniRepositoryManager.class.php

Documentation is available at HarmoniRepositoryManager.class.php

  1. <?php
  2. require_once(OKI2."osid/repository/RepositoryManager.php");
  3. require_once(HARMONI."oki2/repository/HarmoniRepository.class.php");
  4.  
  5. /**
  6. * <p>
  7. * The RepositoryManager supports creating and deleting Repositories and Assets
  8. * as well as getting the various Types used.
  9. * </p>
  10. *
  11. * <p>
  12. * All implementations of OsidManager (manager) provide methods for accessing
  13. * and manipulating the various objects defined in the OSID package. A manager
  14. * defines an implementation of an OSID. All other OSID objects come either
  15. * directly or indirectly from the manager. New instances of the OSID objects
  16. * are created either directly or indirectly by the manager. Because the OSID
  17. * objects are defined using interfaces, create methods must be used instead
  18. * of the new operator to create instances of the OSID objects. Create methods
  19. * are used both to instantiate and persist OSID objects. Using the
  20. * OsidManager class to define an OSID's implementation allows the application
  21. * to change OSID implementations by changing the OsidManager package name
  22. * used to load an implementation. Applications developed using managers
  23. * permit OSID implementation substitution without changing the application
  24. * source code. As with all managers, use the OsidLoader to load an
  25. * implementation of this interface.
  26. * </p>
  27. *
  28. * <p></p>
  29. *
  30. * <p>
  31. * OSID Version: 2.0
  32. * </p>
  33. *
  34. * @package harmoni.osid_v2.repository
  35. *
  36. * @copyright Copyright &copy;2005, Middlebury College
  37. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  38. *
  39. * @version $Id: HarmoniRepositoryManager.class.php,v 1.39 2007/09/13 16:04:20 adamfranco Exp $
  40. */
  41.  
  42. class HarmoniRepositoryManager
  43. extends RepositoryManager
  44. {
  45. var $_configuration;
  46. var $_repositoryValidFlags;
  47. var $_hierarchy;
  48. var $_createdRepositories;
  49. /**
  50. * Constructor
  51. * @param array $configuration An array of the configuration options
  52. * nessisary to load this manager. To use the a specific manager store, a
  53. * store data source must be configured as noted in the class of said
  54. * manager store.
  55. * manager.
  56. * @access public
  57. */
  58. function HarmoniRepositoryManager ($configuration = NULL) {
  59. // Define the type to use as a key for Identifying repositories
  60. $this->repositoryKeyType = new HarmoniType("Repository", "edu.middlebury.harmoni",
  61. "Repository", "Nodes with this type are by definition Repositories.");
  62. // Cache any created repositories so that we can pass out references to them.
  63. $this->_createdRepositories = array();
  64.  
  65. $schemaMgr = Services::getService("SchemaManager");
  66. $ids = Services::getService("Id");
  67. $recordStructureId =$ids->getId("edu.middlebury.harmoni.repository.asset_content");
  68. $recordDesc = "A RecordStructure for the generic content of an asset.";
  69. if (!$schemaMgr->schemaExists($recordStructureId->getIdString())) {
  70. // Create the Schema
  71. $schema = new Schema($recordStructureId->getIdString(), "Repository Asset Content", 1, $recordDesc);
  72. $schema->addField(new SchemaField("Content", "Content", "blob", "The binary content of the Asset"));
  73. $schemaMgr->synchronize($schema);
  74. // The SchemaManager only allows you to use Schemas created by it for use with Records.
  75. $schema =$schemaMgr->getSchemaByID($recordStructureId->getIdString());
  76. debug::output("RecordStructure is being created from Schema with Id: '".$schema->getID()."'");
  77. $nullRepositoryId =$ids->getId('null');
  78. $this->_createdRecordStructures[$schema->getID()] = new HarmoniRecordStructure(
  79. $schema,
  80. $nullRepositoryId);
  81. // Add the parts to the schema
  82. // $partStructureType = new Type("Repository", "edu.middlebury.harmoni", "Blob", "");
  83. // $this->_createdRecordStructures[$schema->getID()]->createPartStructure(
  84. // "Content",
  85. // "The binary content of the Asset",
  86. // $partStructureType,
  87. // FALSE,
  88. // FALSE,
  89. // FALSE,
  90. // $ids->getId("edu.middlebury.harmoni.repository.asset_content.Content")
  91. // );
  92. }
  93. }
  94. /**
  95. * Assign the configuration of this Manager. Valid configuration options are as
  96. * follows:
  97. * database_index integer
  98. * database_name string
  99. *
  100. * @param object Properties $configuration (original type: java.util.Properties)
  101. *
  102. * @throws object OsidException An exception with one of the following
  103. * messages defined in org.osid.OsidException: {@link }
  104. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  105. * {@link org.osid.OsidException#PERMISSION_DENIED}
  106. * PERMISSION_DENIED}, {@link }
  107. * org.osid.OsidException#CONFIGURATION_ERROR
  108. * CONFIGURATION_ERROR}, {@link }
  109. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  110. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  111. *
  112. * @access public
  113. */
  114. function assignConfiguration ( $configuration ) {
  115. $this->_configuration =$configuration;
  116. $dbIndex = $configuration->getProperty('database_index');
  117. $hierarchyIdString = $configuration->getProperty('hierarchy_id');
  118. $defaultParentIdString = $configuration->getProperty('default_parent_id');
  119. // ** parameter validation
  120. ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
  121. ArgumentValidator::validate($hierarchyIdString, StringValidatorRule::getRule(), true);
  122. ArgumentValidator::validate($defaultParentIdString, OptionalRule::getRule(StringValidatorRule::getRule()), true);
  123. // ** end of parameter validation
  124. $this->_dbIndex = $dbIndex;
  125. // Set up our hierarchy
  126. $hierarchyManager = Services::getService("Hierarchy");
  127. $idManager = Services::getService("Id");
  128. $hierarchyId = $idManager->getId($hierarchyIdString);
  129. $this->_hierarchy =$hierarchyManager->getHierarchy($hierarchyId);
  130. // Record what parent to store newly created repositories under
  131. if ($defaultParentIdString) {
  132. $this->_defaultParentId = $idManager->getId($defaultParentIdString);
  133. } else {
  134. $this->_defaultParentId = NULL;
  135. }
  136. }
  137.  
  138. /**
  139. * Return context of this OsidManager.
  140. *
  141. * @return object OsidContext
  142. *
  143. * @throws object OsidException
  144. *
  145. * @access public
  146. */
  147. function getOsidContext () {
  148. return $this->_osidContext;
  149. }
  150.  
  151. /**
  152. * Assign the context of this OsidManager.
  153. *
  154. * @param object OsidContext $context
  155. *
  156. * @throws object OsidException An exception with one of the following
  157. * messages defined in org.osid.OsidException: {@link }
  158. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  159. *
  160. * @access public
  161. */
  162. function assignOsidContext ( $context ) {
  163. $this->_osidContext =$context;
  164. }
  165.  
  166. /**
  167. * Create a new Repository of the specified Type. The implementation of
  168. * this method sets the Id for the new object.
  169. *
  170. * @param string $displayName
  171. * @param string $description
  172. * @param object Type $repositoryType
  173. *
  174. * @return object Repository
  175. *
  176. * @throws object RepositoryException An exception with one of
  177. * the following messages defined in
  178. * org.osid.repository.RepositoryException may be thrown: {@link }
  179. * org.osid.repository.RepositoryException#OPERATION_FAILED
  180. * OPERATION_FAILED}, {@link }
  181. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  182. * PERMISSION_DENIED}, {@link }
  183. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  184. * CONFIGURATION_ERROR}, {@link }
  185. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  186. * UNIMPLEMENTED}, {@link }
  187. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  188. * NULL_ARGUMENT}, {@link }
  189. * org.osid.repository.RepositoryException#UNKNOWN_TYPE
  190. * UNKNOWN_TYPE}
  191. *
  192. * @access public
  193. */
  194. function createRepository ( $displayName, $description, $repositoryType, $id = NULL ){
  195. // Argument Validation
  196. ArgumentValidator::validate($displayName, StringValidatorRule::getRule());
  197. ArgumentValidator::validate($description, StringValidatorRule::getRule());
  198. ArgumentValidator::validate($repositoryType, ExtendsValidatorRule::getRule("Type"));
  199. // Create an Id for the digital Repository Node
  200. if (!is_object($id)) {
  201. $IDManager = Services::getService("Id");
  202. $id =$IDManager->createId();
  203. }
  204. // Store the type passed in our own table as we will be using
  205. // a special type, "repositoryKeyType", as definition of which
  206. // Nodes in the Hierarchy are Repositories.
  207. $dbc = Services::getService("DatabaseManager");
  208. $query = new SelectQuery;
  209. $query->addColumn("type_id");
  210. $query->addTable("dr_type");
  211. $query->addWhere("type_domain = '".addslashes($repositoryType->getDomain())."'");
  212. $query->addWhere("type_authority = '".addslashes($repositoryType->getAuthority())."'", _AND);
  213. $query->addWhere("type_keyword = '".addslashes($repositoryType->getKeyword())."'", _AND);
  214. $result =$dbc->query($query, $this->_dbIndex);
  215. if ($result->getNumberOfRows()) {
  216. $typeId = $result->field("type_id");
  217. $result->free();
  218. } else {
  219. $result->free();
  220. $query = new InsertQuery;
  221. $query->setTable("dr_type");
  222. $query->setAutoIncrementColumn("type_id", "dr_type_type_id_seq");
  223. $query->setColumns(array(
  224. "type_domain",
  225. "type_authority",
  226. "type_keyword",
  227. "type_description",
  228. ));
  229. $query->setValues(array(
  230. "'".addslashes($repositoryType->getDomain())."'",
  231. "'".addslashes($repositoryType->getAuthority())."'",
  232. "'".addslashes($repositoryType->getKeyword())."'",
  233. "'".addslashes($repositoryType->getDescription())."'",
  234. ));
  235. $result =$dbc->query($query, $this->_dbIndex);
  236. $typeId = $result->getLastAutoIncrementValue();
  237. }
  238. $query = new InsertQuery;
  239. $query->setTable("dr_repository_type");
  240. $query->setColumns(array(
  241. "repository_id",
  242. "fk_dr_type",
  243. ));
  244. $query->setValues(array(
  245. "'".addslashes($id->getIdString())."'",
  246. "'".addslashes($typeId)."'",
  247. ));
  248. $result =$dbc->query($query, $this->_dbIndex);
  249. // Add this DR's node to the hierarchy.
  250. // If we don't have a default parent specified, create
  251. // it as a root node
  252. if ($this->_defaultParentId == NULL) {
  253. $node =$this->_hierarchy->createRootNode($id,
  254. $this->repositoryKeyType, $displayName, $description);
  255. }
  256. // If we have a default parent specified, create the
  257. // Node as a child of that.
  258. else {
  259. $node =$this->_hierarchy->createNode($id,
  260. $this->_defaultParentId,
  261. $this->repositoryKeyType, $displayName, $description);
  262. }
  263. $this->_createdRepositories[$id->getIdString()] = new HarmoniRepository ($this->_hierarchy, $id, $this->_configuration);
  264. return $this->_createdRepositories[$id->getIdString()];
  265. }
  266.  
  267. /**
  268. * Delete a Repository.
  269. *
  270. * @param object Id $repositoryId
  271. *
  272. * @throws object RepositoryException An exception with one of
  273. * the following messages defined in
  274. * org.osid.repository.RepositoryException may be thrown: {@link }
  275. * org.osid.repository.RepositoryException#OPERATION_FAILED
  276. * OPERATION_FAILED}, {@link }
  277. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  278. * PERMISSION_DENIED}, {@link }
  279. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  280. * CONFIGURATION_ERROR}, {@link }
  281. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  282. * UNIMPLEMENTED}, {@link }
  283. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  284. * NULL_ARGUMENT}, {@link }
  285. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  286. *
  287. * @access public
  288. */
  289. function deleteRepository($repositoryId) {
  290. $repository =$this->getRepository($repositoryId);
  291. // Check to see if this DR has any assets.
  292. $assets =$repository->getAssets();
  293. // If so, delete them.
  294. if ($assets->hasNext()) {
  295. // We need to delete the assets by deleting the root assets
  296. $hasRootSearch = FALSE;
  297. $rootSearchType = new HarmoniType("Repository",
  298. "edu.middlebury.harmoni","RootAssets", "");
  299. $searchTypes =$repository->getSearchTypes();
  300. while ($searchTypes->hasNext()) {
  301. if ($rootSearchType->isEqual( $searchTypes->next() )) {
  302. $hasRootSearch = TRUE;
  303. break;
  304. }
  305. }
  306.  
  307. if ($hasRootSearch) {
  308. $criteria = NULL;
  309. $rootAssets =$repository->getAssetsBySearch($criteria,
  310. $rootSearchType, $searchProperties = NULL);
  311. while ($rootAssets->hasNext()) {
  312. $asset =$rootAssets->next();
  313. $repository->deleteAsset($asset->getId());
  314. }
  315. }
  316. else {
  317. // if we cant then sort the asset ids by depth
  318. $infoIterator =$this->_hierarchy->traverse(
  319. $repositoryId,
  320. Hierarchy::TRAVERSE_MODE_DEPTH_FIRST(),
  321. Hierarchy::TRAVERSE_DIRECTION_DOWN(),
  322. Hierarchy::TRAVERSE_LEVELS_ALL());
  323. $levels = array();
  324. while ($infoIterator->hasNextTraversalInfo()) {
  325. $info =$infoIterator->nextTraversalInfo();
  326. if (!is_array($levels[$info->getLevel()]))
  327. $levels[$info->getLevel()] = array();
  328. $levels[$info->getLevel()][] =$info->getNodeId();
  329. }
  330. for ($i = count($levels) - 1; $i > 0; $i--) {
  331. $level =$levels[$i];
  332. foreach (array_keys($level) as $key) {
  333. $repository->deleteAsset($level[$key]);
  334. }
  335. }
  336. }
  337. }
  338. // Delete the node for the DR
  339. $this->_hierarchy->deleteNode($repositoryId);
  340. // Delete type type for the Repository
  341. $query = new DeleteQuery;
  342. $query->setTable("dr_repository_type");
  343. $query->addWhere("repository_id = '"
  344. .addslashes($repositoryId->getIdString())
  345. ."' LIMIT 1");
  346. $dbc = Services::getService("DatabaseManager");
  347. $dbc->query($query, $this->_dbIndex);
  348. unset($this->_createdRepositories[$repositoryId->getIdString()]);
  349. }
  350.  
  351. /**
  352. * Get all the Repositories. Iterators return a set, one at a time.
  353. *
  354. * @return object RepositoryIterator
  355. *
  356. * @throws object RepositoryException An exception with one of
  357. * the following messages defined in
  358. * org.osid.repository.RepositoryException may be thrown: {@link }
  359. * org.osid.repository.RepositoryException#OPERATION_FAILED
  360. * OPERATION_FAILED}, {@link }
  361. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  362. * PERMISSION_DENIED}, {@link }
  363. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  364. * CONFIGURATION_ERROR}, {@link }
  365. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  366. * UNIMPLEMENTED}, {@link }
  367. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  368. * CONFIGURATION_ERROR}, {@link }
  369. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  370. * UNIMPLEMENTED}
  371. *
  372. * @access public
  373. */
  374. function getRepositories () {
  375. $nodes =$this->_hierarchy->getNodesByType($this->repositoryKeyType);
  376. while ($nodes->hasNext()) {
  377. $node =$nodes->next();
  378. // make sure that the dr is loaded into the createdDRs array
  379. $this->getRepository($node->getId());
  380. }
  381. // create a DigitalRepositoryIterator with all fo the DRs in the createdDRs array
  382. $repositoryIterator = new HarmoniRepositoryIterator($this->_createdRepositories);
  383. return $repositoryIterator;
  384. }
  385.  
  386.  
  387. /**
  388. * Get all the Repositories of the specified Type. Iterators return a set,
  389. * one at a time.
  390. *
  391. * @param object Type $repositoryType
  392. *
  393. * @return object RepositoryIterator
  394. *
  395. * @throws object RepositoryException An exception with one of
  396. * the following messages defined in
  397. * org.osid.repository.RepositoryException may be thrown: {@link }
  398. * org.osid.repository.RepositoryException#OPERATION_FAILED
  399. * OPERATION_FAILED}, {@link }
  400. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  401. * PERMISSION_DENIED}, {@link }
  402. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  403. * CONFIGURATION_ERROR}, {@link }
  404. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  405. * UNIMPLEMENTED}, {@link }
  406. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  407. * NULL_ARGUMENT}, {@link }
  408. * org.osid.repository.RepositoryException#UNKNOWN_TYPE
  409. * UNKNOWN_TYPE}
  410. *
  411. * @access public
  412. */
  413. function getRepositoriesByType ( $repositoryType ) {
  414. ArgumentValidator::validate($repositoryType, ExtendsValidatorRule::getRule("Type"));
  415. // Select the Ids of corresponding repositories
  416. $query = new SelectQuery;
  417. $query->addColumn("repository_id");
  418. $query->addTable("dr_repository_type");
  419. $query->addTable("dr_type", INNER_JOIN, "fk_dr_type = type_id");
  420. $query->addWhere("type_domain = '".addslashes($repositoryType->getDomain())."'");
  421. $query->addWhere("type_authority = '".addslashes($repositoryType->getAuthority())."'", _AND);
  422. $query->addWhere("type_keyword = '".addslashes($repositoryType->getKeyword())."'", _AND);
  423. $dbc = Services::getService("DatabaseManager");
  424. $result =$dbc->query($query, $this->_dbIndex);
  425. $idManager = Services::getService("Id");
  426. $rs = array();
  427. while ($result->hasMoreRows()) {
  428. $idString = $result->field("repository_id");
  429. $id =$idManager->getId($idString);
  430. // make sure that the repository is loaded into the createdRepositories array
  431. $rs[] =$this->getRepository($id);
  432. $result->advanceRow();
  433. }
  434. $result->free();
  435. // create a repositoryIterator with all fo the repositories in the createdRepositories array
  436. $repositoryIterator = new HarmoniRepositoryIterator($rs);
  437. return $repositoryIterator;
  438. }
  439.  
  440. /**
  441. * Get the Repository with the specified unique Id.
  442. *
  443. * @param object Id $repositoryId
  444. *
  445. * @return object Repository
  446. *
  447. * @throws object RepositoryException An exception with one of
  448. * the following messages defined in
  449. * org.osid.repository.RepositoryException may be thrown: {@link }
  450. * org.osid.repository.RepositoryException#OPERATION_FAILED
  451. * OPERATION_FAILED}, {@link }
  452. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  453. * PERMISSION_DENIED}, {@link }
  454. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  455. * CONFIGURATION_ERROR}, {@link }
  456. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  457. * UNIMPLEMENTED}, {@link }
  458. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  459. * NULL_ARGUMENT}, {@link }
  460. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  461. *
  462. * @access public
  463. */
  464. function getRepository ( $repositoryId ) {
  465. ArgumentValidator::validate($repositoryId, ExtendsValidatorRule::getRule("Id"));
  466. if (!isset($this->_createdRepositories[$repositoryId->getIdString()])) {
  467. // Get the node for this dr to make sure its availible
  468. if (!$node = $this->_hierarchy->getNode($repositoryId))
  469. throwError(new Error(RepositoryException::UNKNOWN_ID(), "RepositoryManager", 1));
  470. if (!$this->repositoryKeyType->isEqual($node->getType()))
  471. throwError(new Error(RepositoryException::UNKNOWN_ID(), "RepositoryManager", 1));
  472. // create the repository and add it to the cache
  473. $this->_createdRepositories[$repositoryId->getIdString()] = new HarmoniRepository($this->_hierarchy, $repositoryId, $this->_configuration);
  474. $this->_repositoryValidFlags[$repositoryId->getIdString()] = true;
  475. }
  476. // Dish out the repository.
  477. return $this->_createdRepositories[$repositoryId->getIdString()];
  478. }
  479.  
  480. /**
  481. * Get the Asset with the specified unique Id.
  482. *
  483. * @param object Id $assetId
  484. *
  485. * @return object Asset
  486. *
  487. * @throws object RepositoryException An exception with one of
  488. * the following messages defined in
  489. * org.osid.repository.RepositoryException may be thrown: {@link }
  490. * org.osid.repository.RepositoryException#OPERATION_FAILED
  491. * OPERATION_FAILED}, {@link }
  492. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  493. * PERMISSION_DENIED}, {@link }
  494. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  495. * CONFIGURATION_ERROR}, {@link }
  496. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  497. * UNIMPLEMENTED}, {@link }
  498. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  499. * NULL_ARGUMENT}, {@link }
  500. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  501. *
  502. * @access public
  503. */
  504. function getAsset ( $assetId ) {
  505. ArgumentValidator::validate($assetId, ExtendsValidatorRule::getRule("Id"));
  506. // Get the node for this asset to make sure its availible
  507. if (!$this->_hierarchy->nodeExists($assetId)) {
  508. $false = false;
  509. return $false;
  510. throwError(new Error(RepositoryException::UNKNOWN_ID(), "Digital Repository", 1));
  511. }
  512. // figure out which DR it is in.
  513. if (! $repositoryId =$this->_getAssetRepository($assetId))
  514. throwError(new Error(RepositoryException::UNKNOWN_ID(), "RepositoryManager", 1));
  515. $repository =$this->getRepository($repositoryId);
  516. // have the repostiroy create it.
  517. return $repository->getAsset($assetId);
  518. }
  519.  
  520. /**
  521. * Get the Asset with the specified Unique Id and appropriate for the date
  522. * specified. The date permits
  523. * @param object assetId
  524. * @param object date
  525. * @return object Asset
  526. * @throws osid.dr.DigitalRepositoryException An exception with one of the
  527. * following messages defined in osid.dr.DigitalRepositoryException may be
  528. * thrown:
  529. * {@link DigitalRepositoryException#OPERATION_FAILED OPERATION_FAILED},
  530. * {@link DigitalRepositoryException#PERMISSION_DENIED PERMISSION_DENIED},
  531. * {@link DigitalRepositoryException#CONFIGURATION_ERROR CONFIGURATION_ERROR},
  532. * {@link DigitalRepositoryException#UNIMPLEMENTED UNIMPLEMENTED},
  533. * {@link DigitalRepositoryException#NULL_ARGUMENT NULL_ARGUMENT},
  534. * {@link DigitalRepositoryException#NO_OBJECT_WITH_THIS_DATE NO_OBJECT_WITH_THIS_DATE}
  535. */
  536. function getAssetByDate($assetId, $date) {
  537. // figure out which DR it is in.
  538. if (! $repositoryId =$this->_getAssetRepository($assetId))
  539. throwError(new Error(RepositoryException::UNKNOWN_ID(), "RepositoryManager", 1));
  540. $repository =$this->getRepository($repositoryId);
  541. //return the assetByDate
  542. return $repository->getAssetByDate($assetId, $date);
  543. }
  544.  
  545. /**
  546. * Get all the dates for the Asset with the specified unique Id. These
  547. * dates allows a Repository implementation to support Asset versioning.
  548. *
  549. * @param object Id $assetId
  550. *
  551. * @return object LongValueIterator
  552. *
  553. * @throws object RepositoryException An exception with one of
  554. * the following messages defined in
  555. * org.osid.repository.RepositoryException may be thrown: {@link }
  556. * org.osid.repository.RepositoryException#OPERATION_FAILED
  557. * OPERATION_FAILED}, {@link }
  558. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  559. * PERMISSION_DENIED}, {@link }
  560. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  561. * CONFIGURATION_ERROR}, {@link }
  562. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  563. * UNIMPLEMENTED}, {@link }
  564. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  565. * NULL_ARGUMENT}
  566. *
  567. * @access public
  568. */
  569. function getAssetDates ( $assetId ) {
  570. // figure out which Repository it is in.
  571. if (! $repositoryId =$this->_getAssetRepository($assetId))
  572. throwError(new Error(RepositoryException::UNKNOWN_ID(), "RepositoryManager", 1));
  573. $repository =$this->getRepository($repositoryId);
  574. //return the assetByDate
  575. return $repository->getAssetDates($assetId, $date);
  576. }
  577.  
  578. /**
  579. * Perform a search of the specified Type and get all the Assets that
  580. * satisfy the SearchCriteria. The search is performed for all specified
  581. * Repositories. Iterators return a set, one at a time.
  582. *
  583. * @param object Repository[] $repositories
  584. * @param object mixed $searchCriteria (original type: java.io.Serializable)
  585. * @param object Type $searchType
  586. * @param object Properties $searchProperties
  587. *
  588. * @return object AssetIterator
  589. *
  590. * @throws object RepositoryException An exception with one of
  591. * the following messages defined in
  592. * org.osid.repository.RepositoryException may be thrown: {@link }
  593. * org.osid.repository.RepositoryException#OPERATION_FAILED
  594. * OPERATION_FAILED}, {@link }
  595. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  596. * PERMISSION_DENIED}, {@link }
  597. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  598. * CONFIGURATION_ERROR}, {@link }
  599. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  600. * UNIMPLEMENTED}, {@link }
  601. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  602. * NULL_ARGUMENT}, {@link }
  603. * org.osid.repository.RepositoryException#UNKNOWN_TYPE
  604. * UNKNOWN_TYPE}, {@link }
  605. * org.osid.repository.RepositoryException#UNKNOWN_REPOSITORY
  606. * UNKNOWN_REPOSITORY}
  607. *
  608. * @access public
  609. */
  610. function getAssetsBySearch ( $repositories, $searchCriteria, $searchType, $searchProperties ) {
  611. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  612. }
  613. /**
  614. * Perform a search of the specified Type and get all the Assets that
  615. * satisfy the SearchCriteria. The search is performed for all specified
  616. * DigitalRepositories. Iterators return a group of items, one item at a
  617. * time. The Iterator's hasNext method returns <code>true</code> if there
  618. * are additional objects available; <code>false</code> otherwise. The
  619. * Iterator's next method returns the next object.
  620. * @param object repositories
  621. * @param mixed searchCriteria
  622. * @param object searchType
  623. * @return object AssetIterator The order of the objects returned by the
  624. * Iterator is not guaranteed.
  625. * @throws osid.dr.DigitalRepositoryException An exception with one of the
  626. * following messages defined in osid.dr.DigitalRepositoryException may be
  627. * thrown:
  628. * {@link DigitalRepositoryException#OPERATION_FAILED OPERATION_FAILED},
  629. * {@link DigitalRepositoryException#PERMISSION_DENIED PERMISSION_DENIED},
  630. * {@link DigitalRepositoryException#CONFIGURATION_ERROR CONFIGURATION_ERROR},
  631. * {@link DigitalRepositoryException#UNIMPLEMENTED UNIMPLEMENTED},
  632. * {@link DigitalRepositoryException#NULL_ARGUMENT NULL_ARGUMENT},
  633. * {@link DigitalRepositoryException#UNKNOWN_TYPE UNKNOWN_TYPE},
  634. * {@link DigitalRepositoryException#UNKNOWN_DR UNKNOWN_DR}
  635. */
  636. function getAssets($repositories, $searchCriteria, $searchType, $searchProperties) {
  637. $combinedAssets = array();
  638. foreach ($digitalRepositories as $key => $val) {
  639. // Get the assets that match from this DR.
  640. $assets =$repositories[$key]->getAssetsBySearch($searchCriteria, $searchType, $searchProperties);
  641. // Add the assets from this dr into our combined array.
  642. while ($assets->hasNext()) {
  643. $combinedAssets[] =$assets->next();
  644. }
  645. }
  646. // create an AssetIterator with all fo the Assets in the createdAssets array
  647. $assetIterator = new HarmoniAssetIterator($combinedAssets);
  648. return $assetIterator;
  649. }
  650. /**
  651. * Create in a Repository a copy of an Asset. The Id, AssetType, and
  652. * Repository for the new Asset is set by the implementation. All Records
  653. * are similarly copied.
  654. *
  655. * @param object Repository $repository
  656. * @param object Id $assetId
  657. *
  658. * @return object Id
  659. *
  660. * @throws object RepositoryException An exception with one of
  661. * the following messages defined in
  662. * org.osid.repository.RepositoryException may be thrown: {@link }
  663. * org.osid.repository.RepositoryException#OPERATION_FAILED
  664. * OPERATION_FAILED}, {@link }
  665. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  666. * PERMISSION_DENIED}, {@link }
  667. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  668. * CONFIGURATION_ERROR}, {@link }
  669. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  670. * UNIMPLEMENTED}, {@link }
  671. * org.osid.repository.RepositoryException#NULL_ARGUMENT
  672. * NULL_ARGUMENT}, {@link }
  673. * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  674. *
  675. * @access public
  676. */
  677. function copyAsset ( $repository, $assetId ) {
  678. $asset =$repository->getAsset($assetId);
  679. return $repository->copyAsset( $asset );
  680. }
  681.  
  682. /**
  683. * Get all the RepositoryTypes in this RepositoryManager. RepositoryTypes
  684. * are used to categorize Repositories. Iterators return a set, one at a
  685. * time.
  686. *
  687. * @return object TypeIterator
  688. *
  689. * @throws object RepositoryException An exception with one of
  690. * the following messages defined in
  691. * org.osid.repository.RepositoryException may be thrown: {@link }
  692. * org.osid.repository.RepositoryException#OPERATION_FAILED
  693. * OPERATION_FAILED}, {@link }
  694. * org.osid.repository.RepositoryException#PERMISSION_DENIED
  695. * PERMISSION_DENIED}, {@link }
  696. * org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  697. * CONFIGURATION_ERROR}, {@link }
  698. * org.osid.repository.RepositoryException#UNIMPLEMENTED
  699. * UNIMPLEMENTED}
  700. *
  701. * @access public
  702. */
  703. function getRepositoryTypes () {
  704. $types = array();
  705. $query = new SelectQuery;
  706. $query->addColumn("type_domain");
  707. $query->addColumn("type_authority");
  708. $query->addColumn("type_keyword");
  709. $query->addColumn("type_description");
  710. $query->addTable("dr_type");
  711. $dbc = Services::getService("DatabaseManager");
  712. $result =$dbc->query($query, $this->_dbIndex);
  713. // Return our types
  714. while ($result->hasMoreRows()) {
  715. $types[] = new HarmoniType($result->field("type_domain"),
  716. $result->field("type_authority"),
  717. $result->field("type_keyword"),
  718. $result->field("type_description"));
  719. $result->advanceRow();
  720. }
  721. $result->free();
  722. $obj = new HarmoniTypeIterator($types);
  723. return $obj;
  724. }
  725.  
  726. /****************************************************************************
  727. * Private Functions:
  728. ******************************************************************************/
  729.  
  730. function _getAssetRepository ($assetId) {
  731. $node =$this->_hierarchy->getNode($assetId);
  732. // If we have reached the top of the hierarchy and don't have a parent that
  733. // is of the Repository type, then we aren't in a Repository and are therefore unknown
  734. // to the RepositoryManager.
  735. if ($node->isRoot())
  736. return FALSE;
  737. // Get the parent and return its ID if it is a root node (repositories are root nodes).
  738. $parents =$node->getParents();
  739. // Make sure that we have Parents
  740. if (!$parents->hasNext())
  741. return FALSE;
  742. // assume a single-parent hierarchy
  743. $parent =$parents->next();
  744. if ($this->repositoryKeyType->isEqual($parent->getType()))
  745. return $parent->getId();
  746. else
  747. return $this->_getAssetRepository( $parent->getId() );
  748. }
  749. }
  750.  
  751.  
  752. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:19 -0400 by phpDocumentor 1.3.0RC3