/**
  * This class implements the Singleton pattern. There is only ever
  * one instance of the this class and it is accessed only via the 
  * ClassName::instance() method.
  * 
  * @return object 
  * @access public
  * @since 5/26/05
  * @static
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new StructuredMetaDataTagGenerator();
     }
     return self::$instance;
 }
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryId = $idManager->getId(RequestContext::value('collection_id'));
     $systemAgentId = $idManager->getId('system:concerto');
     $tagGenerator = StructuredMetaDataTagGenerator::instance();
     $tagGenerator->regenerateTagsForRepository($repositoryId, $systemAgentId, 'concerto');
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
         $item = new AgentNodeEntryItem("Regenerated Tags", "Auto-generated tags were regenerated");
         $item->addNodeId($repositoryId);
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     RequestContext::sendTo($harmoni->request->quickURL("collection", "browse", array('collection_id' => RequestContext::value('collection_id'))));
 }
Esempio n. 3
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 7/27/05
  */
 function saveWizard($cacheName)
 {
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $wizard = $this->getWizard($cacheName);
     $properties = $wizard->getAllValues();
     $centerPane = $this->getActionRows();
     ob_start();
     $path = $properties['filename']['tmp_name'];
     $filename = $properties['filename']['name'];
     if ($properties['filename']['name'] == "") {
         print "Please choose a file to upload!";
         $centerPane->add(new Block(ob_get_contents(), 1));
         ob_end_clean();
         return FALSE;
     }
     $newName = $this->moveArchive($path, $filename);
     //===== THIS ARRAY DEFINES THINGS THAT SHOULD NOT BE IMPORTED =====//
     $this->_ignore = array("REMOTE_FILE", "FILE_URL", "FILE", "FILE_DATA", "FILE_NAME", "MIME_TYPE", "THUMBNAIL_DATA", "THUMBNAIL_MIME_TYPE", "FILE_SIZE", "DIMENSIONS", "THUMBNAIL_DIMENSIONS", "edu.middlebury.harmoni.repository.asset_content", "edu.middlebury.harmoni.repository.asset_content.Content");
     $repository = $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id')));
     $startTime = DateAndTime::now();
     $this->_hasErrors = false;
     //===== Exif and Tab-Delim Importers are special =====//
     if ($properties['file_type'] == "Tab-Delimited") {
         $importer = new TabRepositoryImporter($newName, $repository->getId(), false);
     } else {
         if ($properties['file_type'] == "Exif") {
             $importer = new ExifRepositoryImporter($newName, $repository->getId(), false);
         } else {
             if ($properties['file_type'] == "FilesOnly") {
                 $importer = new FilesOnlyRepositoryImporter($newName, $repository->getId(), false);
             }
         }
     }
     if (isset($importer)) {
         if ($properties['parent']) {
             $importer->setParent($repository->getAsset($idManager->getId($properties['parent'])));
         }
         $importer->import($properties['is_archived']);
         // something happened so tell the end user
         if ($importer->hasErrors()) {
             $importer->printErrorMessages();
             $this->_hasErrors = true;
         }
     }
     //===== Done with special "RepositoryImporters" =====//
     if ($properties['file_type'] == "XML") {
         if ($properties['is_archived'] == TRUE) {
             //	define an empty importer for decompression
             $importer = new XMLImporter($this->_ignore);
             $directory = $importer->decompress($newName);
             unset($importer);
             $this->_repository = $repository;
             $this->_importType = $properties['import_type'];
             if ($properties['parent']) {
                 $parent = $repository->getAsset($idManager->getId($properties['parent']));
             } else {
                 $parent = null;
             }
             $this->importDirectoriesDown($directory, $parent);
         } else {
             // not compressed, only one xml file
             $importer = XMLRepositoryImporter::withObject($this->_ignore, $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id'))), $newName, $properties['import_type']);
             if ($properties['parent']) {
                 $importer->setParent($repository->getAsset($idManager->getId($properties['parent'])));
             }
             $importer->parseAndImportBelow("asset", 100);
             // something happened so tell the end user
             if ($importer->hasErrors()) {
                 $importer->printErrorMessages();
                 $this->_hasErrors = true;
             }
             unset($importer);
         }
     }
     // Unlink the directory
     if (isset($directory) && $directory) {
         $this->deleteRecursive($directory);
     }
     if (file_exists($newName)) {
         unlink($newName);
     }
     if ($this->_hasErrors) {
         $centerPane->add(new Block(ob_get_contents(), 1));
         ob_end_clean();
         return FALSE;
     }
     // Update any newly modified assets' tags
     $searchProperties = new HarmoniProperties(new Type("repository", "harmoni", "order"));
     $searchProperties->addProperty("order", $order = "ModificationDate");
     $searchProperties->addProperty("direction", $direction = "DESC");
     $assets = $repository->getAssetsBySearch($criteria = '*', new Type("Repository", "edu.middlebury.harmoni", "DisplayName"), $searchProperties);
     $systemAgentId = $idManager->getId('system:concerto');
     $tagGenerator = StructuredMetaDataTagGenerator::instance();
     while ($assets->hasNext()) {
         $asset = $assets->next();
         if ($startTime->isGreaterThan($asset->getModificationDate())) {
             break;
         }
         $tagGenerator->regenerateTagsForAsset($asset, $systemAgentId, 'concerto', $repository->getId());
     }
     // clean and clear
     $centerPane->add(new Block(ob_get_contents(), 1));
     ob_end_clean();
     return TRUE;
 }
Esempio n. 4
0
 /**
  * Update the given repeatable part to reflect the value changed in the wizard.
  *
  * For "Value from Wizard" = wizVal and  "value originally in Part" = partVal
  *	- If a partVal exists and is equal to a wizVal, leave it alone
  *	- If a partVal exists, but is not equal to any wizVals, remove it.
  *	- If a wizVal exists, but no partVals equal to it exist, add a new Part
  * 
  * @param array $results, the wizard results
  * @param array $initialState, the initial wizard results
  * @param object Record $record
  * @param object Id $assetId
  * @return void
  * @access public
  * @since 10/24/05
  */
 function updateRepeatablePart($partResults, $partInitialState, $partStruct, $record, $assetId)
 {
     $partStructId = $partStruct->getId();
     $partValsHandled = array();
     // 		printpre("<hr/>");
     // 		printpre($partResults);
     $parts = $record->getPartsByPartStructure($partStructId);
     while ($parts->hasNext()) {
         $part = $parts->next();
         $partVal = $part->getValue();
         $partStrVal = $partVal->asString();
         // Check for existance in the results.
         // if the value is not in the results, remove the part and continue.
         if (!$partStrVal || !$this->inWizArray($partVal, 'partvalue', $partResults)) {
             $record->deletePart($part->getId());
             $partValsHandled[] = $partStrVal;
             $partId = $part->getId();
             printpre("\tDeleting Part: Id: " . $partId->getIdString() . " Value: " . $partStrVal);
             continue;
         }
         // If the value is in the wizard results, do nothing
         $partValsHandled[] = $partStrVal;
         $partId = $part->getId();
         printpre("\tIgnoring Part: Id: " . $partId->getIdString() . " Value: " . $partStrVal);
         // Add this value to the Structured Tags list for this asset.
         $tagGenerator = StructuredMetaDataTagGenerator::instance();
         if ($tagGenerator->shouldGenerateTagsForPartStructure($partStruct->getRepositoryId(), $partStructId)) {
             $this->_newStructuredTagValues[$assetId->getIdString()][] = $partStrVal;
         }
         continue;
     }
     // Go through all of the Wizard result values. If any of them haven't
     // been handled and need to be, add them.
     foreach ($partResults as $key => $valueArray) {
         $value = $valueArray['partvalue'];
         if (is_object($value)) {
             $valueStr = $value->asString();
             $authZManager = Services::getService("AuthZ");
             $idManager = Services::getService("Id");
             $authoritativeValues = $partStruct->getAuthoritativeValues();
             if ($authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify_authority_list"), $this->getRepositoryId()) && !$partStruct->isAuthoritativeValue($value) && $authoritativeValues->hasNext()) {
                 $partStruct->addAuthoritativeValue($value);
                 printpre("\tAdding AuthoritativeValue:" . $valueStr);
             }
             if (!in_array($valueStr, $partValsHandled)) {
                 $part = $record->createPart($partStructId, $value);
                 $partId = $part->getId();
                 printpre("\tAdding Part: Id: " . $partId->getIdString() . " Value: " . $valueStr);
                 // Add this value to the Structured Tags list for this asset.
                 $tagGenerator = StructuredMetaDataTagGenerator::instance();
                 if ($tagGenerator->shouldGenerateTagsForPartStructure($partStruct->getRepositoryId(), $partStructId)) {
                     $this->_newStructuredTagValues[$assetId->getIdString()][] = $valueStr;
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // If all properties validate then go through the steps nessisary to
     // save the data.
     if ($wizard->validate()) {
         $properties = $wizard->getAllValues();
         // 			printpre($properties);
         // 			exit;
         $repository = $this->getRepository();
         $recordStructure = $this->getRecordStructure();
         if ($properties['namedesc']['display_name'] != $recordStructure->getDisplayName()) {
             $recordStructure->updateDisplayName($properties['namedesc']['display_name']);
         }
         if ($properties['namedesc']['description'] != $recordStructure->getDescription()) {
             $recordStructure->updateDescription($properties['namedesc']['description']);
         }
         if ($properties['namedesc']['format'] != $recordStructure->getFormat()) {
             $recordStructure->updateFormat($properties['namedesc']['format']);
         }
         $recordStructureId = $recordStructure->getId();
         $idManager = Services::getService("Id");
         $authZManager = Services::getService("AuthZ");
         // Create a set for the RecordStructure
         $setManager = Services::getService("Sets");
         $set = $setManager->getPersistentSet($recordStructureId);
         // Update the existing part structures
         $i = 0;
         $regenTags = false;
         $existingPartStructureIds = array();
         foreach (array_keys($properties['elementstep']['elements']) as $index) {
             $partStructProps = $properties['elementstep']['elements'][$index];
             if ($partStructProps['id']) {
                 $partStructId = $idManager->getId($partStructProps['id']);
                 $partStruct = $recordStructure->getPartStructure($partStructId);
                 if ($partStructProps['display_name'] != $partStruct->getDisplayName()) {
                     $partStruct->updateDisplayName($partStructProps['display_name']);
                 }
                 if ($partStructProps['description'] != $partStruct->getDescription()) {
                     $partStruct->updateDescription($partStructProps['description']);
                 }
                 if ($partStructProps['mandatory'] != $partStruct->isMandatory()) {
                     $partStruct->updateIsMandatory($partStructProps['mandatory']);
                 }
                 if ($partStructProps['repeatable'] != $partStruct->isRepeatable()) {
                     $partStruct->updateIsRepeatable($partStructProps['repeatable'] ? TRUE : FALSE);
                 }
                 // Data Type conversion
                 $type = HarmoniType::fromString(urldecode($partStructProps['type']), " :: ");
                 if (!$type->isEqual($partStruct->getType()) && (preg_match("/^Repository::.+\$/i", $partStructId->getIdString()) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.convert_rec_struct"), $partStruct->getRepositoryId()) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $partStruct->getRepositoryId()) || $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.convert_rec_struct"), $idManager->getId("edu.middlebury.authorization.root")) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $idManager->getId("edu.middlebury.authorization.root")))) {
                     $partStruct = $recordStructure->convertPartStructureToType($partStructId, $type, new StatusStars("Converting data type for PartStructure: " . $partStruct->getDisplayName()));
                     // Remove the old value from the set
                     if ($set->isInSet($partStructId)) {
                         $set->removeItem($partStructId);
                     }
                     // Update the id to reflect the id of the new part
                     $partStructId = $partStruct->getId();
                 }
             } else {
                 $type = HarmoniType::fromString(urldecode($partStructProps['type']), " :: ");
                 $partStruct = $recordStructure->createPartStructure($partStructProps['display_name'], $partStructProps['description'], $type, $partStructProps['mandatory'] ? TRUE : FALSE, $partStructProps['repeatable'] ? TRUE : FALSE, FALSE);
                 $partStructId = $partStruct->getId();
             }
             // Authoritative values
             $valuesString = trim($partStructProps['authoritative_values']);
             //if ($valuesString) {
             $authoritativeStrings = explode("\n", $valuesString);
             array_walk($authoritativeStrings, "removeExcessWhitespace");
             // Remove and missing values
             $authoritativeValues = $partStruct->getAuthoritativeValues();
             while ($authoritativeValues->hasNext()) {
                 $value = $authoritativeValues->next();
                 if (!in_array($value->asString(), $authoritativeStrings)) {
                     $partStruct->removeAuthoritativeValue($value);
                 }
             }
             // Add new values
             foreach ($authoritativeStrings as $valueString) {
                 if ($valueString) {
                     $partStruct->addAuthoritativeValueAsString($valueString);
                 }
             }
             //}
             // Auto-generation of tags
             $tagGenerator = StructuredMetaDataTagGenerator::instance();
             if ($partStructProps['autoGenTags']) {
                 if (!$tagGenerator->shouldGenerateTagsForPartStructure($partStruct->getRepositoryId(), $partStructId)) {
                     $tagGenerator->addPartStructureIdForTagGeneration($partStruct->getRepositoryId(), $partStructId);
                     $regenTags = true;
                 }
             } else {
                 if ($tagGenerator->shouldGenerateTagsForPartStructure($partStruct->getRepositoryId(), $partStructId)) {
                     $tagGenerator->removePartStructureIdForTagGeneration($partStruct->getRepositoryId(), $partStructId);
                     $regenTags = true;
                 }
             }
             // Order of part structures
             if (!$set->isInSet($partStructId)) {
                 $set->addItem($partStructId);
             }
             $set->moveToPosition($partStructId, $i);
             $existingPartStructureIds[$partStructId->getIdString()] = $partStructId;
             $i++;
         }
         // Delete any removed partStructures
         if (preg_match("/^Repository::.+\$/i", $recordStructureId->getIdString()) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.convert_rec_struct"), $partStruct->getRepositoryId()) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $partStruct->getRepositoryId()) || $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.convert_rec_struct"), $idManager->getId("edu.middlebury.authorization.root")) && $authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $idManager->getId("edu.middlebury.authorization.root"))) {
             $partStructs = $recordStructure->getPartStructures();
             while ($partStructs->hasNext()) {
                 $partStruct = $partStructs->next();
                 $partStructId = $partStruct->getId();
                 if (!array_key_exists($partStructId->getIdString(), $existingPartStructureIds)) {
                     // 						printpre("Deleting PartStructure: ".$partStruct->getDisplayName()." Id: ".$partStructId->getIdString());
                     $recordStructure->deletePartStructure($partStructId);
                     // Remove the old value from the set
                     if ($set->isInSet($partStructId)) {
                         $set->removeItem($partStructId);
                     }
                 }
             }
         }
         if ($regenTags) {
             $systemAgentId = $idManager->getId('system:concerto');
             $tagGenerator = StructuredMetaDataTagGenerator::instance();
             $tagGenerator->regenerateTagsForRepository($partStruct->getRepositoryId(), $systemAgentId, 'concerto');
         }
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $item = new AgentNodeEntryItem("Modify Node", "RecordStructure created:\n<br/>&nbsp; &nbsp; &nbsp; " . $recordStructure->getDisplayName());
             $item->addNodeId($repository->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }