Source for file XMLPartImporter.class.php

Documentation is available at XMLPartImporter.class.php

  1. <?php
  2. /**
  3. * @since 10/6/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: XMLPartImporter.class.php,v 1.23 2007/09/19 14:04:47 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLImporter.class.php");
  13.  
  14. /**
  15. * XMLPartImporter imports a part into a record
  16. *
  17. * @since 10/6/05
  18. * @package polyphony.importer
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: XMLPartImporter.class.php,v 1.23 2007/09/19 14:04:47 adamfranco Exp $
  24. */
  25. class XMLPartImporter extends XMLImporter {
  26. /**
  27. * Constructor
  28. *
  29. *
  30. * @return object XMLRepositoryImporter
  31. * @access public
  32. * @since 10/6/05
  33. */
  34. function XMLPartImporter ($existingArray) {
  35. parent::XMLImporter($existingArray);
  36. }
  37. /**
  38. * Sets up importer's self-knowledge
  39. *
  40. * @access public
  41. * @since 10/6/05
  42. */
  43. function setupSelf () {
  44. $this->_childImporterList = array("XMLPartImporter");
  45. $this->_childElementList = array("part");
  46. $this->_info = array();
  47. }
  48. /**
  49. * Filters nodes of incorrect type
  50. *
  51. * @param object DOMIT_Node
  52. * @return boolean
  53. * @static
  54. * @access public
  55. * @since 10/6/05
  56. */
  57. function isImportable ($element) {
  58. if ($element->nodeName == "part")
  59. return true;
  60. else
  61. return false;
  62. }
  63.  
  64. /**
  65. * Checks if the user is able to import underneath this level
  66. *
  67. * @param string $authZQString qualifier for authz checking
  68. * @access public
  69. * @since 11/3/05
  70. */
  71. function canImportBelow($authZQString) {
  72. return true;
  73. }
  74.  
  75. /**
  76. * Imports the current node's information
  77. *
  78. * @access public
  79. * @since 10/6/05
  80. */
  81. function importNode () {
  82. $idManager = Services::getService("Id");
  83. $this->getNodeInfo();
  84. $hasId = $this->_node->hasAttribute("id");
  85. if ($hasId && (in_array($this->_node->getAttribute("id"),
  86. $this->_existingArray) || $this->_type == "update")) {
  87. $this->_myId =$idManager->getId($this->_node->getAttribute("id"));
  88. $this->_object =$this->_parent->getPart($this->_myId);
  89. $this->update();
  90. } else if (is_null($this->_info['value'])) {
  91. return;
  92. } else {
  93. $this->_object =$this->_parent->createPart(
  94. $this->_info['partStructureId'], $this->_info['value']);
  95. $this->_myId =$this->_object->getId();
  96. }
  97. }
  98.  
  99. /**
  100. * Sets the node's internal information
  101. *
  102. * @access public
  103. * @since 10/6/05
  104. */
  105. function getNodeInfo () {
  106. $dbHandler = Services::getService("DBHandler");
  107. // $dbIndexConcerto =$dbHandler->addDatabase(new
  108. // MySQLDatabase("localhost", "whitey_concerto", "test", "test"));
  109. if (Services::serviceRunning("Logging")) {
  110. $loggingManager = Services::getService("Logging");
  111. $log =$loggingManager->getLogForWriting("Harmoni");
  112. $formatType = new Type("logging", "edu.middlebury",
  113. "AgentsAndNodes",
  114. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  115. $priorityType = new Type("logging", "edu.middlebury", "Error",
  116. "Events involving critical system errors.");
  117. }
  118. $query = new SelectQuery;
  119. $query->addTable("xml_id_matrix");
  120. $query->addColumn("conc_id");
  121. $query->addColumn("xml_id");
  122. $id = $this->_node->getAttribute("xml:id");
  123. $query->addWhere("xml_id = '".addslashes($id)."'");
  124. //$dbHandler->connect($dbIndexConcerto);
  125. $results =$dbHandler->query($query, IMPORTER_CONNECTION);
  126. if ($results->getNumberOfRows() == 1) {
  127. $result = $results->next();
  128. $idManager = Services::getService("Id");
  129. $this->_info['partStructureId'] =$idManager->getId(
  130. $result['conc_id']);
  131. } else if ($results->getNumberOfRows() > 1) {
  132. $this->addError("Multiple PartStructure matches for $result[xml_id]: ");
  133. if (isset($log))
  134. $string = "Multiple PartStructure matches for $result[xml_id]:";
  135. while ($results->hasNext()) {
  136. $result =$results->next();
  137. $this->addError("\tmatch: ".$result['conc_id']);
  138. // add matches
  139. if (isset($log))
  140. $string .= " Match: $result[conc_id]<br/>";
  141. }
  142. if (isset($log)) {
  143. $item = new AgentNodeEntryItem("PartImporter Error",
  144. $string);
  145. $log->appendLogWithTypes($item, $formatType, $priorityType);
  146. }
  147. $this->_info['partStructureId'] =$idManager->getId(
  148. $result['conc_id']);
  149. } else {
  150. $this->addError("Bad XML IDREF: ".$id);
  151. // log error
  152. if (isset($log)) {
  153. $item = new AgentNodeEntryItem("PartImport Error",
  154. "Bad XML IDREF: $id");
  155. $log->appendLogWithTypes($item, $formatType, $priorityType);
  156. }
  157. }
  158. $results->free();
  159.  
  160. $this->_info['value'] = $this->getPartObject($this->_node->getText());
  161. }
  162. /**
  163. * Looks for discrepencies between imported data and current data
  164. *
  165. * @access public
  166. * @since 10/6/05
  167. */
  168. function update () {
  169. if (isset($this->_info['value']) && !is_null($this->_info['value']) &&
  170. ($this->_info['value'] != $this->_object->getValue()))
  171. $this->_object->updateValue($this->_info['value']);
  172. }
  173. /**
  174. * creates appropriate object from given ids
  175. *
  176. * @return object mixed
  177. * @access public
  178. * @since 7/21/05
  179. */
  180. function getPartObject ($part) {
  181. $dtm = Services::getService("DataTypeManager");
  182. $recordStructure =$this->_parent->getRecordStructure();
  183. $partStructure =$recordStructure->getPartStructure(
  184. $this->_info['partStructureId']);
  185. $type = $partStructure->getType();
  186. $class = $dtm->primitiveClassForType($type->getKeyword());
  187. eval('$object = '.$class.'::fromString($part);');
  188. if (!is_object($object)) {
  189. $this->addError("Unsupported PartStructure DataType: ".
  190. HarmoniType::typeToString($type).".");
  191. // Log error
  192. if (Services::serviceRunning("Logging")) {
  193. $loggingManager = Services::getService("Logging");
  194. $log =$loggingManager->getLogForWriting("Harmoni");
  195. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  196. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  197. $priorityType = new Type("logging", "edu.middlebury", "Error",
  198. "Events involving critical system errors.");
  199. $item = new AgentNodeEntryItem("PartImport Error",
  200. "Unsupported PartStructure DataType: ".
  201. HarmoniType::typeToString($type));
  202. $log->appendLogWithTypes($item, $formatType, $priorityType);
  203. }
  204. $false = false;
  205. return $false;
  206. }
  207. return $object;
  208. }
  209. }
  210.  
  211. ?>

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