Source for file XMLRepositoryImporter.class.php

Documentation is available at XMLRepositoryImporter.class.php

  1. <?php
  2. /**
  3. * @since 10/5/05
  4. * @package polyphony.importer
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: XMLRepositoryImporter.class.php,v 1.20 2007/09/19 14:04:47 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLImporter.class.php");
  13. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLAssetImporter.class.php");
  14. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLRecordStructureImporter.class.php");
  15.  
  16. /**
  17. * XMLRepositoryImporter imports a repository via delegation to subclasses
  18. *
  19. * @since 10/5/05
  20. * @package polyphony.importer
  21. *
  22. * @copyright Copyright &copy; 2005, Middlebury College
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  24. *
  25. * @version $Id: XMLRepositoryImporter.class.php,v 1.20 2007/09/19 14:04:47 adamfranco Exp $
  26. */
  27. class XMLRepositoryImporter extends XMLImporter {
  28. /**
  29. * Constructor
  30. *
  31. *
  32. * @return object XMLRepositoryImporter
  33. * @access public
  34. * @since 10/5/05
  35. */
  36. function XMLRepositoryImporter ($existingArray) {
  37. parent::XMLImporter($existingArray);
  38. }
  39.  
  40. /**
  41. * Constructor with XML File to parse
  42. *
  43. * @param string
  44. * @param string
  45. * @param string
  46. * @return object mixed
  47. * @access public
  48. * @since 10/11/05
  49. */
  50. function withFile ($existingArray, $filepath, $type, $class = 'XMLRepositoryImporter') {
  51. return parent::withFile($existingArray, $filepath, $type, $class);
  52. }
  53.  
  54. /**
  55. * Constructor with XMLFile and starting object
  56. *
  57. * @param object mixed
  58. * @param string
  59. * @param string
  60. * @param string
  61. * @return object mixed
  62. * @access public
  63. * @since 10/11/05
  64. */
  65. function withObject ($existingArray, $object, $filepath, $type, $class = 'XMLRepositoryImporter') {
  66. return parent::withObject($existingArray, $object, $filepath, $type, $class);
  67. }
  68. /**
  69. * Sets up importer's self-knowledge
  70. *
  71. * @access public
  72. * @since 10/5/05
  73. */
  74. function setupSelf () {
  75. $this->_childImporterList = array("XMLRecordStructureImporter",
  76. "XMLAssetImporter");
  77. $this->_childElementList = array("asset", "recordstructure");
  78. $this->_info = array();
  79. }
  80. /**
  81. * This function determines the structure wanted and makes sure it is so
  82. *
  83. * sub-classes that can start an import should overwrite this function
  84. * @access public
  85. * @since 2/23/06
  86. */
  87. function _checkXMLStructure () {
  88. return ($this->_import->documentElement->nodeName == "repository");
  89. }
  90.  
  91. /**
  92. * Filters nodes of incorrect type
  93. *
  94. * @param object DOMIT_Node
  95. * @return boolean
  96. * @static
  97. * @access public
  98. * @since 10/5/05
  99. */
  100. function isImportable ($element) {
  101. if($element->nodeName == "repository")
  102. return true;
  103. else
  104. return false;
  105. }
  106. /**
  107. * Answer the parent for the importer
  108. *
  109. * @param string $importerClass
  110. * @return object
  111. * @access public
  112. * @since 4/3/07
  113. */
  114. function getParentForImporter ( $importer) {
  115. if ($importer == "XMLAssetImporter") {
  116. if ($this->_parent)
  117. $parent =$this->_parent;
  118. else
  119. $parent =$this->_object;
  120. } else {
  121. $parent =$this->_object;
  122. }
  123. return $parent;
  124. }
  125. /**
  126. * Checks this node for any changes to make to this
  127. *
  128. * @access public
  129. * @since 10/5/05
  130. */
  131. function importNode () {
  132. $idManager = Services::getService("Id");
  133. $repositoryManager = Services::getService("RepositoryManager");
  134. $this->getNodeInfo();
  135. //printpre($this->_node->nodeName);
  136. // make/find object
  137. $hasId = $this->_node->hasAttribute("id");
  138. // printpre($hasId."::".$this->_node->getAttribute("id")."::".$this->_existingArray
  139. // ."::".$this->type);
  140. if ($hasId && (in_array($this->_node->getAttribute("id"),
  141. $this->_existingArray) || $this->_type == "update")) {
  142. $this->_myId =$idManager->getId($this->_node->getAttribute("id"));
  143. $this->_object =$repositoryManager->getRepository($this->_myId);
  144. $this->update();
  145. }
  146. else {
  147. $this->_object =$repositoryManager->createRepository(
  148. $this->_info['name'], $this->_info['description'],
  149. $this->_info['type']);
  150. $this->_myId =$this->_object->getId();
  151. // log repository creation
  152. if (Services::serviceRunning("Logging")) {
  153. $loggingManager = Services::getService("Logging");
  154. $log =$loggingManager->getLogForWriting("Harmoni");
  155. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  156. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  157. $priorityType = new Type("logging", "edu.middlebury",
  158. "Event_Notice", "Normal events.");
  159. $item = new AgentNodeEntryItem("Create Node",
  160. "Repository: ".$this->_myId->getIdString()." created.");
  161. $item->addNodeId($this->_myId);
  162. $log->appendLogWithTypes($item, $formatType, $priorityType);
  163. }
  164. // add FILE record structure to repository
  165. $this->doSets();
  166. }
  167. }
  168.  
  169. /**
  170. * Does anything needed to sets
  171. *
  172. * @access public
  173. * @since 10/6/05
  174. */
  175. function doSets () {
  176. $idManager = Services::getService("Id");
  177. $sets = Services::getService("Sets");
  178. $set =$sets->getPersistentSet($this->_myId);
  179. if (!$set->isInSet($idManager->getId("FILE")))
  180. $set->addItem($idManager->getId("FILE"));
  181. }
  182.  
  183. /**
  184. * Does what is necessary to the temporary table for internal id association
  185. *
  186. * @access public
  187. * @since 10/6/05
  188. */
  189. function doIdMatrix () {
  190. $dbHandler = Services::getService("DBHandler");
  191. // define dbIndexConcerto for children
  192. $createTableQuery = new GenericSQLQuery;
  193. $createTableQuery->addSQLQuery("CREATE TEMPORARY TABLE
  194. xml_id_matrix ( xml_id varchar(255)
  195. not null , conc_id varchar(255) not null)");
  196. $dbHandler->disconnect(IMPORTER_CONNECTION);
  197. $dbHandler->connect(IMPORTER_CONNECTION);
  198. $dbHandler->beginTransaction(IMPORTER_CONNECTION);
  199. // PostgreSQL doesn't seem to like the CREATE TEMPORARY TABLE IF NOT EXISTS syntax
  200. if (!in_array('xml_id_matrix', $dbHandler->getTableList(IMPORTER_CONNECTION)))
  201. $dbHandler->query($createTableQuery, IMPORTER_CONNECTION);
  202. }
  203.  
  204. /**
  205. * Drops the temporary table for internal id association
  206. *
  207. * @access public
  208. * @since 10/6/05
  209. */
  210. function dropIdMatrix () {
  211. $dbHandler = Services::getService("DBHandler");
  212. // $dropTableQuery = new GenericSQLQuery;
  213. // $dropTableQuery->addSQLQuery("Drop table if exists
  214. // xml_id_matrix");
  215. // $dbHandler->query($dropTableQuery, $dbIndexConcerto);
  216. $dbHandler->commitTransaction(IMPORTER_CONNECTION);
  217. $dbHandler->disconnect(IMPORTER_CONNECTION);
  218. $dbHandler->pconnect(IMPORTER_CONNECTION);
  219. }
  220. /**
  221. * Looks for discrepencies between imported data and current data
  222. *
  223. * @access public
  224. * @since10/5/05
  225. */
  226. function update () {
  227. $modified = false;
  228. if (isset($this->_info['name']) && !is_null($this->_info['name']) &&
  229. ($this->_info['name'] != $this->_object->getDisplayName())) {
  230. $modified = true;
  231. $this->_object->updateDisplayName($this->_info['name']);
  232. }
  233. if (isset($this->_info['description']) &&
  234. !is_null($this->_info['description']) &&
  235. ($this->_info['description'] != $this->_object->getDescription())) {
  236. $modified = true;
  237. $this->_object->updateDescription($this->_info['description']);
  238. }
  239. if (Services::serviceRunning("Logging") && $modified) {
  240. $loggingManager = Services::getService("Logging");
  241. $log =$loggingManager->getLogForWriting("Harmoni");
  242. $formatType = new Type("logging", "edu.middlebury",
  243. "AgentsAndNodes",
  244. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  245. $priorityType = new Type("logging", "edu.middlebury",
  246. "Event_Notice", "Normal events.");
  247. $item = new AgentNodeEntryItem("Modify Node",
  248. "Repository: ".$this->_myId->getIdString()." modified.");
  249. $item->addNodeId($this->_myId);
  250. $log->appendLogWithTypes($item, $formatType, $priorityType);
  251. }
  252. // DATES GO HERE
  253. }
  254. }
  255.  
  256. ?>

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