Source for file XMLAssetImporter.class.php

Documentation is available at XMLAssetImporter.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: XMLAssetImporter.class.php,v 1.20 2007/09/19 14:04:46 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLImporter.class.php");
  13. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLRecordImporter.class.php");
  14. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLFileRecordImporter.class.php");
  15. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLRemoteFileRecordImporter.class.php");
  16. require_once(HARMONI."Primitives/Chronology/DateAndTime.class.php");
  17. require_once(HARMONI."/utilities/StatusStars.class.php");
  18.  
  19. /**
  20. * XMLAssetImporter imports an asset into a repository
  21. *
  22. * @since 10/6/05
  23. * @package polyphony.importer
  24. *
  25. * @copyright Copyright &copy; 2005, Middlebury College
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  27. *
  28. * @version $Id: XMLAssetImporter.class.php,v 1.20 2007/09/19 14:04:46 adamfranco Exp $
  29. */
  30. class XMLAssetImporter extends XMLImporter {
  31. /**
  32. * Constructor; parses XML if passed file
  33. *
  34. *
  35. * @return object XMLAssetImporter
  36. * @access public
  37. * @since 10/6/05
  38. */
  39. function XMLAssetImporter ($existingArray) {
  40. parent::XMLImporter($existingArray);
  41. }
  42.  
  43. /**
  44. * Constructor with XML File to parse
  45. *
  46. * @param string
  47. * @param string
  48. * @param string
  49. * @return object mixed
  50. * @access public
  51. * @since 10/11/05
  52. */
  53. function withFile ($existingArray, $filepath, $type, $class = 'XMLAssetImporter') {
  54. return parent::withFile($existingArray, $filepath, $type, $class);
  55. }
  56.  
  57. /**
  58. * Constructor with XMLFile and starting object
  59. *
  60. * @param object mixed
  61. * @param string
  62. * @param string
  63. * @param string
  64. * @return object mixed
  65. * @access public
  66. * @since 10/11/05
  67. */
  68. function withObject ($existingArray, $object, $filepath, $type, $class = 'XMLAssetImporter') {
  69. return parent::withObject($existingArray, $object, $filepath, $type, $class);
  70. }
  71.  
  72. /**
  73. * Sets up importer's self-knowledge
  74. *
  75. * @access public
  76. * @since 10/6/05
  77. */
  78. function setupSelf () {
  79. $this->_childImporterList = array("XMLAssetImporter",
  80. "XMLRecordImporter", "XMLFileRecordImporter", "XMLRemoteFileRecordImporter");
  81. $this->_childElementList = array("asset", "record", "filerecord", "remotefilerecord");
  82. $this->_info = array();
  83. }
  84. /**
  85. * Filters nodes of incorrect type
  86. *
  87. * @param object DOMIT_Node
  88. * @return boolean
  89. * @static
  90. * @access public
  91. * @since 10/6/05
  92. */
  93. function isImportable ($element) {
  94. if ($element->nodeName == "asset")
  95. return true;
  96. else
  97. return false;
  98. }
  99.  
  100. /**
  101. * Imports the current node's information
  102. *
  103. * @access public
  104. * @since 10/6/05
  105. */
  106. function importNode () {
  107. $idManager = Services::getService("Id");
  108. if (!method_exists($this->_parent, "createAsset")) {
  109. $this->_stepParent =$this->_parent;
  110. $this->_parent =$this->_stepParent->getRepository();
  111. }
  112.  
  113. $this->getNodeInfo();
  114.  
  115. $hasId = $this->_node->hasAttribute("id");
  116. if ($hasId && (in_array($this->_node->getAttribute("id"),
  117. $this->_existingArray) || $this->_type == "update")) {
  118. $this->_myId =$idManager->getId($this->_node->getAttribute("id"));
  119. $this->_object =$this->_parent->getAsset($this->_myId);
  120. $this->update();
  121. } else {
  122. $this->_object =$this->_parent->createAsset(
  123. $this->_info['name'], $this->_info['description'],
  124. $this->_info['type']);
  125. $this->_myId =$this->_object->getId();
  126. if (Services::serviceRunning("Logging")) {
  127. $loggingManager = Services::getService("Logging");
  128. $log =$loggingManager->getLogForWriting("Harmoni");
  129. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  130. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  131. $priorityType = new Type("logging", "edu.middlebury",
  132. "Event_Notice", "Normal events.");
  133. $item = new AgentNodeEntryItem("Create Node",
  134. "Asset: ".$this->_myId->getIdString()." created.");
  135. $item->addNodeId($this->_myId);
  136. $item->addNodeId($this->_parent->getId());
  137. }
  138. if (isset($this->_stepParent)) {
  139. $this->_stepParent->addAsset($this->_myId);
  140. if (isset($item))
  141. $item->addNodeId($this->_stepParent->getId());
  142. }
  143. if (isset($this->_info['effectivedate']))
  144. $this->_object->updateEffectiveDate(DateAndTime::fromString(
  145. $this->_info['effectivedate']));
  146. if (isset($this->_info['expirationdate']))
  147. $this->_object->updateExpirationDate(DateAndTime::fromString(
  148. $this->_info['expirationdate']));
  149. if (isset($item))
  150. $log->appendLogWithTypes($item, $formatType, $priorityType);
  151. }
  152.  
  153. if ($this->_node->hasAttribute("maintainOrder") &&
  154. ($this->_node->getAttribute("maintainOrder") == TRUE))
  155. $this->doSets();
  156. }
  157.  
  158. /**
  159. * Does anything needed to sets
  160. *
  161. * @access public
  162. * @since 10/6/05
  163. */
  164. function doSets () {
  165. $sets = Services::getService("Sets");
  166. $this->_set =$sets->getPersistentSet($this->_myId);
  167. }
  168.  
  169. /**
  170. * Relegates Children to their classes
  171. *
  172. * @param object mixed $topImporter is the importer instance that parsed the XML
  173. * @access public
  174. * @since 10/6/05
  175. */
  176. function relegateChildren ($topImporter) {
  177. foreach ($this->_node->childNodes as $element) {
  178. foreach ($this->_childImporterList as $importer) {
  179. if (!is_subclass_of(new $importer($this->_existingArray), 'XMLImporter')) {
  180. $this->addError("Class, '$class', is not a subclass of 'XMLImporter'.");
  181. if (Services::serviceRunning("Logging")) {
  182. $loggingManager = Services::getService("Logging");
  183. $log =$loggingManager->getLogForWriting("Harmoni");
  184. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  185. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  186. $priorityType = new Type("logging", "edu.middlebury", "Error",
  187. "Events involving critical system errors.");
  188. $item = new AgentNodeEntryItem("Instantiate Undefined Importer", "$class is not a subclass of Importer");
  189. $item->addNodeId($this->_myId);
  190. $log->appendLogWithTypes($item, $formatType,
  191. $priorityType);
  192. }
  193. break;
  194. }
  195. eval('$result = '.$importer.'::isImportable($element);');
  196. if ($result) {
  197. $imp = new $importer($this->_existingArray);
  198. if (isset($this->_set) && $element->nodeName == "asset")
  199. $this->_set->addItem($imp->import($topImporter,
  200. $element, $this->_type, $this->_object));
  201. else
  202. $imp->import($topImporter, $element, $this->_type,
  203. $this->_object);
  204. if ($imp->hasErrors())
  205. foreach($imp->getErrors() as $error)
  206. $this->addError($error);
  207. unset($imp);
  208. }
  209. }
  210. if ($topImporter->_granule == $element->nodeName)
  211. $topImporter->_status->updateStatistics();
  212. }
  213. }
  214. /**
  215. * Looks for discrepencies between imported data and current data
  216. *
  217. * @access public
  218. * @since 9/12/05
  219. */
  220. function update () {
  221. $modified = false;
  222. if (isset($this->_info['name']) && !is_null($this->_info['name']) &&
  223. ($this->_info['name'] != $this->_object->getDisplayName())) {
  224. $modified = true;
  225. $this->_object->updateDisplayName($this->_info['name']);
  226. }
  227. if (isset($this->_info['description']) &&
  228. !is_null($this->_info['description']) &&
  229. ($this->_info['description'] != $this->_object->getDescription())) {
  230. $modified = true;
  231. $this->_object->updateDescription($this->_info['description']);
  232. }
  233. if (Services::serviceRunning("Logging") && $modified) {
  234. $loggingManager = Services::getService("Logging");
  235. $log =$loggingManager->getLogForWriting("Harmoni");
  236. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  237. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  238. $priorityType = new Type("logging", "edu.middlebury", "Event_Notice",
  239. "Normal Events.");
  240. $item = new AgentNodeEntryItem("Modified Node", "Asset: ".
  241. $this->_myId->getIdString()." modified.");
  242. $item->addNodeId($this->_myId);
  243. $log->appendLogWithTypes($item, $formatType, $priorityType);
  244. }
  245.  
  246.  
  247. // if (isset($this->_info['effectivedate']) &&
  248. // (DateAndTime::fromString($this->_info['effectivedate']) !=
  249. // $this->_object->getEffectiveDate()))
  250. // $this->_object->updateEffectiveDate(DateAndTime::fromString(
  251. // $this->_info['effectivedate']));
  252. // if (isset($this->_info['effectivedate']) &&
  253. // (DateAndTime::fromString($this->_info['expirationdate']) !=
  254. // $this->_object->getExpirationDate()))
  255. // $this->_object->updateExpirationDate(DateAndTime::fromString(
  256. // $this->_info['expirationdate']));
  257. }
  258.  
  259. }
  260.  
  261. ?>

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