Browse Source

Merge pull request #80 from nigelgbanks/fix-for-incorrect-logging

Fix for incorrect logging & Fedora exceptions
pull/79/merge
Ben Woodhead 13 years ago
parent
commit
3b8b671f3f
  1. 24
      CollectionClass.inc
  2. 4
      ObjectHelper.inc
  3. 185
      api/fedora_item.inc

24
CollectionClass.inc

@ -45,11 +45,12 @@ class CollectionClass {
* @return type * @return type
*/ */
function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper();
if (!isset($itqlquery)) { if (!isset($itqlquery)) {
// $query_string = $objectHelper->getStream($pid, 'QUERY', 0); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$itqlquery = $objectHelper->getStream($pid, 'QUERY', 0); $item = new Fedora_Item($pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$itqlquery = $item->get_datastream_dissemination('QUERY');
}
} }
return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); return $this->getRelatedItems($pid, $itqlquery, $limit, $offset);
} }
@ -78,7 +79,11 @@ class CollectionClass {
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
$query_string = $itqlquery; $query_string = $itqlquery;
if (!isset($query_string)) { if (!isset($query_string)) {
$query_string = $objectHelper->getStream($pid, 'QUERY', 0); $query_string = NULL;
$item = new Fedora_Item($pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$query_string = $item->get_datastream_dissemination('QUERY');
}
if ($query_string == NULL) { if ($query_string == NULL) {
$query_string = 'select $object $title $content from <#ri> $query_string = 'select $object $title $content from <#ri>
where ($object <fedora-model:label> $title where ($object <fedora-model:label> $title
@ -445,7 +450,7 @@ class CollectionClass {
'pidNamespace' => $pidNameSpace 'pidNamespace' => $pidNameSpace
); );
$object = $soapClient->__soapCall('getNextPID', array( $object = $soapClient->__soapCall('getNextPID', array(
$params $params
)); ));
} catch (exception $e) { } catch (exception $e) {
drupal_set_message(t('Error getting Next PID: @e', array('@e' => check_plain($e->getMessage()))), 'error'); drupal_set_message(t('Error getting Next PID: @e', array('@e' => check_plain($e->getMessage()))), 'error');
@ -498,11 +503,10 @@ class CollectionClass {
module_load_include('inc', 'fedora_repository', 'CollectionManagement'); module_load_include('inc', 'fedora_repository', 'CollectionManagement');
module_load_include('inc', 'fedora_repository', 'BatchIngest'); module_load_include('inc', 'fedora_repository', 'BatchIngest');
global $base_url; global $base_url;
$tabset = array();
global $user; global $user;
$objectHelper = new ObjectHelper(); $tabset = array();
$item = new Fedora_Item($this->pid);
$query = NULL; $query = NULL;
$item = new Fedora_Item($this->pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$query = $item->get_datastream_dissemination('QUERY'); $query = $item->get_datastream_dissemination('QUERY');
} }
@ -517,7 +521,7 @@ class CollectionClass {
$show_batch_tab = FALSE; $show_batch_tab = FALSE;
$policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE);
if(!empty($policy)){ if (!empty($policy)) {
$content_models = $policy->getContentModels(); $content_models = $policy->getContentModels();
} }
if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") { if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") {

4
ObjectHelper.inc

@ -383,8 +383,8 @@ class ObjectHelper {
$xsl->load($path . '/xsl/convertQDC.xsl'); $xsl->load($path . '/xsl/convertQDC.xsl');
$input = new DomDocument(); $input = new DomDocument();
$input->loadXML(trim($xmlstr)); $input->loadXML(trim($xmlstr));
} catch (exception $e) { } catch (Exception $e) {
watchdog(t("Fedora_Repository"), "Problem loading XSL file: @e", array('@e' => $e), NULL, WATCHDOG_ERROR); watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR);
} }
$xsl = $proc->importStylesheet($xsl); $xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input); $newdom = $proc->transformToDoc($input);

185
api/fedora_item.inc

@ -1,7 +1,7 @@
<?php <?php
/** /**
* @file * @file
* Fedora Item * Fedora Item
*/ */
define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#'); define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#');
@ -18,6 +18,22 @@ class Fedora_Item {
public $datastreams = NULL; public $datastreams = NULL;
private static $connection_helper = NULL; private static $connection_helper = NULL;
private static $instantiated_pids = array(); private static $instantiated_pids = array();
private static $SoapManagedFunctions = array(
'ingest',
'addDataStream',
'addRelationship',
'export',
'getDatastream',
'getDatastreamHistory',
'getNextPID',
'getRelationships',
'modifyDatastreamByValue',
'modifyDatastreamByReference',
'purgeDatastream',
'purgeObject',
'modifyObject',
'setDatastreamState'
);
/** /**
* Create an object to represent an item in the Fedora repository. * Create an object to represent an item in the Fedora repository.
@ -58,7 +74,7 @@ class Fedora_Item {
/** /**
* Forget this Object, do manually when memory constraints apply. * Forget this Object, do manually when memory constraints apply.
* *
* Removes this object from the static list of $instantiated_pids * Removes this object from the static list of $instantiated_pids
*/ */
function forget() { function forget() {
@ -66,8 +82,8 @@ class Fedora_Item {
} }
/** /**
* Exists * Exists
* @return type * @return type
*/ */
function exists() { function exists() {
return (!empty($this->objectProfile)); return (!empty($this->objectProfile));
@ -81,7 +97,7 @@ class Fedora_Item {
* @param type $datastream_mimetype * @param type $datastream_mimetype
* @param type $controlGroup * @param type $controlGroup
* @param type $logMessage * @param type $logMessage
* @return type * @return type
*/ */
function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
@ -116,7 +132,7 @@ class Fedora_Item {
* @param type $datastream_mimetype * @param type $datastream_mimetype
* @param type $controlGroup * @param type $controlGroup
* @param type $logMessage * @param type $logMessage
* @return type * @return type
*/ */
function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) {
if (empty($datastream_label)) { if (empty($datastream_label)) {
@ -151,7 +167,7 @@ class Fedora_Item {
* @param type $datastream_mimetype * @param type $datastream_mimetype
* @param type $controlGroup * @param type $controlGroup
* @param type $logMessage * @param type $logMessage
* @return type * @return type
*/ */
function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = NULL) { function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = NULL) {
$dir = file_directory_temp(); $dir = file_directory_temp();
@ -164,9 +180,8 @@ class Fedora_Item {
return $returnvalue; return $returnvalue;
} }
/** /**
* Wrapper to add new or modify existing datastream * Wrapper to add new or modify existing datastream
* @global url $base_url * @global url $base_url
* @param url $external_url * @param url $external_url
* @param string $dsid * @param string $dsid
@ -175,7 +190,7 @@ class Fedora_Item {
* @param string $controlGroup * @param string $controlGroup
* @param boolean $force * @param boolean $force
* @param string $logMessage * @param string $logMessage
* @param boolean $quiet * @param boolean $quiet
*/ */
function add_or_modify_by_reference($external_url, $dsid, $label, $mime_type, $controlGroup = 'M', $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { function add_or_modify_by_reference($external_url, $dsid, $label, $mime_type, $controlGroup = 'M', $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
global $base_url; global $base_url;
@ -193,7 +208,7 @@ class Fedora_Item {
* does not support rels-int yet. * does not support rels-int yet.
* @param type $relationship * @param type $relationship
* @param type $object * @param type $object
* @param type $namespaceURI * @param type $namespaceURI
*/ */
function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) {
$ds_list = $this->get_datastreams_list_as_array(); $ds_list = $this->get_datastreams_list_as_array();
@ -297,7 +312,7 @@ class Fedora_Item {
/** /**
* Export as foxml * Export as foxml
* @return type * @return type
*/ */
function export_as_foxml() { function export_as_foxml() {
$params = array( $params = array(
@ -378,7 +393,7 @@ class Fedora_Item {
* Get datastream dissemination * Get datastream dissemination
* @param type $dsid * @param type $dsid
* @param type $as_of_date_time * @param type $as_of_date_time
* @return string * @return string
*/ */
function get_datastream_dissemination($dsid, $as_of_date_time = "") { function get_datastream_dissemination($dsid, $as_of_date_time = "") {
$params = array( $params = array(
@ -401,7 +416,7 @@ class Fedora_Item {
* Get datastream * Get datastream
* @param type $dsid * @param type $dsid
* @param type $as_of_date_time * @param type $as_of_date_time
* @return type * @return type
*/ */
function get_datastream($dsid, $as_of_date_time = "") { function get_datastream($dsid, $as_of_date_time = "") {
$params = array( $params = array(
@ -417,7 +432,7 @@ class Fedora_Item {
/** /**
* Get datastream history * Get datastream history
* @param type $dsid * @param type $dsid
* @return type * @return type
*/ */
function get_datastream_history($dsid) { function get_datastream_history($dsid) {
$params = array( $params = array(
@ -439,7 +454,7 @@ class Fedora_Item {
* @param type $method_name * @param type $method_name
* @param type $parameters * @param type $parameters
* @param type $as_of_date_time * @param type $as_of_date_time
* @return string * @return string
*/ */
function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = NULL) { function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = NULL) {
$params = array( $params = array(
@ -658,18 +673,16 @@ class Fedora_Item {
return FALSE; return FALSE;
} }
/** /**
* Set the object to a deleted state * Set the object to a deleted state
*/ */
function move_to_trash($log_message = 'Flagged deleted using Islandora API.') function move_to_trash($log_message = 'Flagged deleted using Islandora API.') {
{
// Loop through the datastreams and mark them deleted // Loop through the datastreams and mark them deleted
foreach($this->get_datastreams_list_as_array() as $dsid) foreach ($this->get_datastreams_list_as_array() as $dsid) {
{
$this->set_datastream_state($dsid, 'D'); $this->set_datastream_state($dsid, 'D');
} }
// Create a message to mark the object deleted // Create a message to mark the object deleted
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -685,13 +698,13 @@ class Fedora_Item {
* Removes this object form the repository. * Removes this object form the repository.
* @param type $log_message * @param type $log_message
* @param type $force * @param type $force
* @return type * @return type
*/ */
function purge($log_message = 'Purged using Islandora API.', $force = FALSE) { function purge($log_message = 'Purged using Islandora API.', $force = FALSE) {
// Flag the object to be deleted first // Flag the object to be deleted first
$this->move_to_trash($log_message); $this->move_to_trash($log_message);
// Create the delete message // Create the delete message
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -710,7 +723,7 @@ class Fedora_Item {
* @param type $end_date * @param type $end_date
* @param type $log_message * @param type $log_message
* @param type $force * @param type $force
* @return type * @return type
*/ */
function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) { function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) {
$params = array( $params = array(
@ -727,7 +740,7 @@ class Fedora_Item {
/** /**
* URL * URL
* @global type $base_url * @global type $base_url
* @return type * @return type
*/ */
function url() { function url() {
global $base_url; global $base_url;
@ -737,7 +750,7 @@ class Fedora_Item {
/** /**
* Get Next PID in Namespace * Get Next PID in Namespace
* @param type $pid_namespace * @param type $pid_namespace
* @return type * @return type
*/ */
static function get_next_PID_in_namespace($pid_namespace = '') { static function get_next_PID_in_namespace($pid_namespace = '') {
@ -765,7 +778,7 @@ class Fedora_Item {
/** /**
* ingest from FOXML * ingest from FOXML
* @param type $foxml * @param type $foxml
* @return Fedora_Item * @return Fedora_Item
*/ */
static function ingest_from_FOXML($foxml) { static function ingest_from_FOXML($foxml) {
$params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested"); $params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested");
@ -776,7 +789,7 @@ class Fedora_Item {
/** /**
* ingest from FOXML file * ingest from FOXML file
* @param type $foxml_file * @param type $foxml_file
* @return type * @return type
*/ */
static function ingest_from_FOXML_file($foxml_file) { static function ingest_from_FOXML_file($foxml_file) {
$foxml = new DOMDocument(); $foxml = new DOMDocument();
@ -786,7 +799,7 @@ class Fedora_Item {
/** /**
* ingest from FOXML files in directory * ingest from FOXML files in directory
* @param type $path * @param type $path
*/ */
static function ingest_from_FOXML_files_in_directory($path) { static function ingest_from_FOXML_files_in_directory($path) {
// Open the directory // Open the directory
@ -814,7 +827,7 @@ class Fedora_Item {
* @param type $ownerId * @param type $ownerId
* @param type $logMessage * @param type $logMessage
* @param type $quiet * @param type $quiet
* @return type * @return type
*/ */
function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) {
@ -838,7 +851,7 @@ class Fedora_Item {
* @param type $force * @param type $force
* @param type $logMessage * @param type $logMessage
* @param type $quiet * @param type $quiet
* @return type * @return type
*/ */
function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array( $params = array(
@ -866,7 +879,7 @@ class Fedora_Item {
* @param type $force * @param type $force
* @param type $logMessage * @param type $logMessage
* @param type $quiet * @param type $quiet
* @return type * @return type
*/ */
function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array( $params = array(
@ -899,74 +912,46 @@ class Fedora_Item {
} }
/** /**
* Soap call * Make a soap call to the fedora API.
* @param type $function_name *
* @param type $params_array * @param string $function
* @param type $quiet * The name of the soap function to call.
* @return type * @param array $parameters
* Paramters to pass onto the soap call
* @param boolean $quiet
* If TRUE suppress drupal messages.
*
* @return mixed
* The return value from the soap function if successful, NULL otherwise.
*/ */
static function soap_call($function_name, $params_array, $quiet = FALSE) { static function soap_call($function, $parameters, $quiet = FALSE) {
if (!self::$connection_helper) { if (!self::$connection_helper) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
self::$connection_helper = new ConnectionHelper(); self::$connection_helper = new ConnectionHelper();
} }
switch ($function_name) { $url = (array_search($function, self::$SoapManagedFunctions) !== FALSE) ?
case 'ingest': variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl') :
case 'addDataStream': variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
case 'addRelationship': try {
case 'export': $soap_client = self::$connection_helper->getSoapClient($url);
case 'getDatastream': if (isset($soap_client)) {
case 'getDatastreamHistory': $result = $soap_client->__soapCall($function, array('parameters' => $parameters));
case 'getNextPID': }
case 'getRelationships': else {
case 'modifyDatastreamByValue': if (!$quiet) {
case 'modifyDatastreamByReference': drupal_set_message(t('Error trying to get SOAP client connection'));
case 'purgeDatastream':
case 'purgeObject':
case 'modifyObject':
case 'setDatastreamState':
$soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl'));
try {
if (!empty($soap_client)) {
$result = $soap_client->__soapCall($function_name, array('parameters' => $params_array));
}
else {
watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection.");
return NULL;
}
} catch (exception $e) {
if (!$quiet) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name)), 'error');
}
else {
drupal_set_message(t("Error trying to call SOAP function $function_name. Check watchdog logs for more information."), 'error');
}
watchdog(t("FEDORA_REPOSITORY"), "Error Trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR);
}
return NULL;
}
break;
default:
try {
$soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
if (!empty($soap_client)) {
$result = $soap_client->__soapCall($function_name, array('parameters' => $params_array));
}
else {
watchdog(t("FEDORA_REPOSITORY"), "Error trying to get SOAP client connection.");
return NULL;
}
} catch (exception $e) {
if (!$quiet) {
watchdog(t("FEDORA_REPOSITORY"), "Error trying to call SOAP function @fn: @e", array('@fn' => $function_name, '@e' => $e), NULL, WATCHDOG_ERROR);
}
return NULL;
} }
watchdog('fedora_repository', 'Error trying to get SOAP client connection.');
return NULL;
}
} catch (Exception $e) {
if (!$quiet) {
preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage()) ?
drupal_set_message(t('Insufficient permissions to call SOAP function "%func".', array('%func' => $function)), 'error') :
drupal_set_message(t('Error trying to call SOAP function "%func". Check watchdog logs for more information.', array('%func' => $function)), 'error');
}
watchdog('fedora_repository', 'Error Trying to call SOAP function "%func". Exception: @e in @f(@l)\n@t', array('%func' => $function, '@e' => $e->getMessage(), '@f' => $e->getFile(), '@l' => $e->getLine(), '@t' => $e->getTraceAsString()), NULL, WATCHDOG_ERROR);
return NULL;
} }
return $result; return $result;
} }
@ -979,7 +964,7 @@ class Fedora_Item {
* @param string $state The initial state, A - Active, I - Inactive, D - Deleted * @param string $state The initial state, A - Active, I - Inactive, D - Deleted
* @param type $label * @param type $label
* @param type $owner * @param type $owner
* @return DOMDocument * @return DOMDocument
*/ */
static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') { static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') {
$foxml = new DOMDocument("1.0", "UTF-8"); $foxml = new DOMDocument("1.0", "UTF-8");
@ -1034,16 +1019,16 @@ class Fedora_Item {
* @param type $state * @param type $state
* @param type $label * @param type $label
* @param type $owner * @param type $owner
* @return type * @return type
*/ */
static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') { static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') {
return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner)); return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner));
} }
/** /**
* fedora item exists * fedora item exists
* @param type $pid * @param type $pid
* @return type * @return type
*/ */
static function fedora_item_exists($pid) { static function fedora_item_exists($pid) {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);

Loading…
Cancel
Save