Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
soap_api_metadata_service.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/web_services/api/soap_api/soap_api.inc';
19 
31 class Soap_Api_Metadata_Service extends Soap_Api
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  public function getFunctionList()
56  {
57  return Array(
58  'SetMetadataSchema' => '1',
59  'GetMetadataFieldsOfSchema' => '1',
60  'GetMetadataFieldValues' => '1',
61  'RegenerateMetadataSchema' => '1',
62  'RegenerateMetadataAsset' => '1',
63  'GetMetadataValueByIDs' => '1',
64  'SetAssetMetadata' => '1',
65  'SetMultipleMetadataFields' => '1',
66  'SetMetadataFieldDefaultValue' => '1',
67  'GetSchemasOnAsset' => '1',
68  );
69 
70  }//end getFunctionList()
71 
72 
88  function SetMetadataSchema($request)
89  {
90  $request_info = (Array) $request;
91  $assetid = array_get_index($request_info, 'AssetID', '');
92  $schemaid = array_get_index($request_info, 'SchemaID', '');
93  $grant = array_get_index($request_info, 'Grant', ''); // Apply, Deny, Revoke = 1, 0, -1
94  $grant_level = Array (
95  'Apply' => '1',
96  'Deny' => '0',
97  'Revoke' => '-1',
98  );
99  $grant_val = $grant_level[$grant]; // We are not going check if isset index, the WSDL should check the input values for $grant
100  $cascade = array_get_index($request_info, 'Cascade', '1');
101  $dependants = $GLOBALS['SQ_SYSTEM']->am->getDependantChildren($assetid);
102  $has_dependants = !empty($dependants);
103 
104  if (!empty($assetid) && !empty($schemaid)) {
105  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
106  $running_vars = Array (
107  'schema_changes' => Array (
108  Array (
109  'assetids' => Array ( $assetid),
110  'granted' => $grant_val,
111  'schemaid' => $schemaid,
112  'cascades' => $cascade,
113  'previous_access' => NULL,
114  ),
115  ),
116  );
117 
118  $errors = $hh->freestyleHipo('hipo_job_edit_metadata_schemas', $running_vars);
119  if (empty($errors)) {
120  return Array (
121  'SetSchemaResult' => TRUE,
122  );
123  } else {
124  throw new SoapFault('Server', 'Unable to set Metadata Schema on Asset');
125  }//end else
126  } else {
127  throw new SoapFault('Server', 'Asset ID or Schema ID is not valid. Please provide a valid AssetID and SchemaID');
128  }//end else
129 
130  }//end SetMetadataSchema()
131 
132 
146  function RegenerateMetadataSchema($request)
147  {
148  $request_info = (Array) $request;
149  $schemaid = array_get_index($request_info, 'SchemaID', '');
150 
151  if (!empty($schemaid)) {
152  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
153  if (!($schema instanceof Metadata_Schema)) {
154  throw new SoapFault('Server', 'The provided Schema ID does not belong to a metadata schema');
155  }//end if
156  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
157  $running_vars = Array (
158  'schemaids' => Array ($schemaid),
159  );
160  $errors = $hh->freestyleHipo('hipo_job_regenerate_metadata', $running_vars);
161  if (empty($errors)) {
162  return Array (
163  'RegenerateMetadataSchemaResult' => TRUE,
164  );
165  } else {
166  $message = '';
167  if (isset($errors[0]['message'])) $message = $errors[0]['message'];
168  throw new SoapFault('Server', 'Unable To Regenerate Metadata For Schema. '.$message);
169  }//end else
170  } else {
171  throw new SoapFault('Server', 'Schema ID Is Not Valid. Please Provide A Valid Schema ID');
172  }//end else
173 
174  }//end RegenerateMetadataSchema()
175 
176 
190  function RegenerateMetadataAsset($request)
191  {
192  $request_info = (Array) $request;
193  $assetid = array_get_index($request_info, 'AssetID', '');
194 
195  if (!empty($assetid)) {
196  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
197  $GLOBALS['SQ_SYSTEM']->am->acquireLock($assetid, 'metadata');
198  $result = $mm->regenerateMetadata($assetid, 'all');
199  $GLOBALS['SQ_SYSTEM']->am->releaseLock($assetid, 'metadata');
200  if ($result) {
201  return Array (
202  'RegenerateMetadataAssetResult' => TRUE,
203  );
204  } else {
205  throw new SoapFault('Server', 'Unable To Regenerate Metadata For Asset');
206  }//end else
207  } else {
208  throw new SoapFault('Server', 'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
209  }//end else
210 
211  }//end RegenerateMetadataAsset()
212 
213 
229  function SetAssetMetadata($request)
230  {
231  $request_info = (Array) $request;
232  $assetid = array_get_index($request_info, 'AssetID', '');
233  $fieldid = array_get_index($request_info, 'FieldID', '');
234  $new_value = array_get_index($request_info, 'NewValue', '');
235 
236  if (!empty($assetid) && !empty($fieldid)) {
237  $field = $GLOBALS['SQ_SYSTEM']->am->getAsset($fieldid);
238  if (!($field instanceof Metadata_Field)) {
239  throw new SoapFault('Server', 'The Field ID provided does not belong to a metadata field');
240  }//end if
241  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
242  $GLOBALS['SQ_SYSTEM']->am->acquireLock($assetid, 'metadata');
243 
244  $field_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($fieldid);
245  $field_name = $field_asset->attr('name');
246 
247  // Encode value before setting metadata
248  $new_value = Metadata_Field::encodeValueString($new_value, Array());
249 
250  $metadata_info = Array (
251  $fieldid => Array (
252  Array (
253  'name' => $field_name,
254  'value' => $new_value,
255  ),
256  ),
257  );
258  $result = $mm->setMetadata($assetid, $metadata_info);
259  $GLOBALS['SQ_SYSTEM']->am->releaseLock($assetid, 'metadata');
260  if ($result) {
261  return Array (
262  'SetAssetMetadataResult' => $result,
263  );
264  } else {
265  throw new SoapFault('Server', 'Unable To Regenerate Metadata For Asset');
266  }//end else
267  } else {
268  throw new SoapFault('Server', 'Please provide both AssetID and FieldID of the metadata field.');
269  }//end else
270 
271  }//end SetAssetMetadata()
272 
273 
288  function SetMultipleMetadataFields($request)
289  {
290  $request_info = (Array) $request;
291  $assetid = array_get_index($request_info, 'AssetID', '');
292  $metadata_info = array_get_index($request_info, 'MetadataInfo', Array());
293 
294  if (!empty($assetid) && !empty($metadata_info)) {
295  $metadata_values = Array();
296  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
297  foreach ($metadata_info as $metadata) {
298  $metadata = (Array) $metadata;
299 
300  $field = $GLOBALS['SQ_SYSTEM']->am->getAsset($metadata['FieldID']);
301 
302  if (!($field instanceof Metadata_Field)) {
303  throw new SoapFault('Server', 'Field ID provided, '.$metadata['FieldID'].', does not belong to a metadata field');
304  }//end if
305 
306 
307  $field_name = $field->attr('name');
308 
309  // Encode value before setting metadata
310  $new_value = Metadata_Field::encodeValueString($metadata['FieldValue'], Array());
311 
312  $metadata_values[$field->id] = Array (
313  Array (
314  'name' => $field_name,
315  'value' => $new_value,
316  ),
317  );
318  }//end foreach
319 
320  $GLOBALS['SQ_SYSTEM']->am->acquireLock($assetid, 'metadata');
321  $result = $mm->setMetadata($assetid, $metadata_values);
322  $GLOBALS['SQ_SYSTEM']->am->releaseLock($assetid, 'metadata');
323 
324  if ($result) {
325  return Array (
326  'SetMultipleMetadataFieldsResult' => $result,
327  );
328  } else {
329  throw new SoapFault('Server', 'Unable To Set Metadata For Asset');
330  }//end else
331  } else {
332  throw new SoapFault('Server', 'Please provide both AssetID and Metadata Field id/value info.');
333  }//end else
334 
335  }//end SetMultipleMetadataFields()
336 
337 
352  function SetMetadataFieldDefaultValue($request)
353  {
354  $request_info = (Array) $request;
355  $fieldid = array_get_index($request_info, 'FieldID', '');
356  $new_def_value = array_get_index($request_info, 'NewDefaultValue', '');
357 
358  if (!empty($new_def_value) && !empty($fieldid)) {
359  $field = $GLOBALS['SQ_SYSTEM']->am->getAsset($fieldid);
360  if (!($field instanceof Metadata_Field)) {
361  throw new SoapFault('Server', 'The provided Field ID does not belong to a Metadata Field');
362  }//end if
363  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
364 
365  $GLOBALS['SQ_SYSTEM']->am->acquireLock($fieldid, 'attributes');
366 
367  $field->setAttrValue('default', $new_def_value);
368  $result = $field->saveAttributes();
369 
370  $GLOBALS['SQ_SYSTEM']->am->releaseLock($fieldid, 'attributes');
371  if ($result) {
372  return Array (
373  'SetMetadataFieldDefaultValueResult' => TRUE,
374  );
375  } else {
376  throw new SoapFault('Server', 'Unable To Set New Default Value For Metadata Field');
377  }//end else
378  } else {
379  throw new SoapFault('Server', 'Please Provide Both FieldID And New Default Value For The Field');
380  }//end else
381 
382  }//end SetMetadataFieldDefaultValue()
383 
384 
399  function GetMetadataValueByIDs($request)
400  {
401  $request_info = (Array) $request;
402  $assetid = array_get_index($request_info, 'AssetID', '');
403  $fieldid = array_get_index($request_info, 'FieldID', '');
404 
405  if (!empty($assetid) && !empty($fieldid)) {
406  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
407  $values = $mm->getMetadataValueByAssetid($assetid, $fieldid);
408  if (!empty($values)) {
409  // bug fix #4646 Empty response returned from metadata field containing non-ascii character
410  // we will need to escape the characters if we are not on a utf-8 system
411  return Array (
412  'GetMetadataValueByIDsResult' => $mm->escapeMetadata($values),
413  );
414  } else {
415  throw new SoapFault('Server', 'Unable To Get Metadata Values For Asset');
416  }//end else
417  } else {
418  throw new SoapFault('Server', 'Please provide both AssetID and FieldID of the metadata field.');
419  }//end else
420 
421  }//end GetMetadataValueByIDs()
422 
423 
437  function GetSchemasOnAsset($request)
438  {
439  $request_info = (Array) $request;
440  $assetid = array_get_index($request_info, 'AssetID', '');
441 
442  if (!empty($assetid)) {
443  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
444  $schemaids = $mm->getSchemas($assetid);
445  $formatted_result = Array();
446  $i = 0;
447  foreach ($schemaids as $schemaid => $grant) {
448  $formatted_result[$i]['SchemaID'] = $schemaid;
449  $formatted_result[$i]['Grant'] = $grant;
450  $i++;
451  }//end foreach
452  return Array (
453  'GetSchemasOnAssetResult' => $formatted_result,
454  );
455  } else {
456  throw new SoapFault('Server', 'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
457  }//end else
458 
459  }//end GetSchemasOnAsset()
460 
461 
475  function GetMetadataFieldsOfSchema($request)
476  {
477  $request_info = (Array) $request;
478  $schemaid = array_get_index($request_info, 'SchemaID', '');
479 
480  if (!empty($schemaid)) {
481  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
482  if (!($schema instanceof Metadata_Schema)) {
483  throw new SoapFault('Server', 'The schema ID provided does not belong to a metadata schema');
484  }//end if
485  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
486  $fieldids = $mm->getMetadataFields($schemaid);
487  return Array (
488  'GetMetadataFieldsOfSchemaResult' => array_keys($fieldids),
489  );
490  } else {
491  throw new SoapFault('Server', 'The schema ID provided is not valid. Please provide a valid ID.');
492  }//end else
493 
494  }//end GetMetadataFieldsOfSchema()
495 
496 
511  function GetMetadataFieldValues($request)
512  {
513  $request_info = (Array) $request;
514  $assetid = array_get_index($request_info, 'AssetID', '');
515  $field_names = array_get_index($request_info, 'FieldNames', '');
516 
517  if (!empty($assetid)) {
518  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
519  $schemas = $mm->getSchemas($assetid);
520  if (empty($schemas)) {
521  throw new SoapFault('Server', 'There is no metadata schema applied on this asset');
522  }//end if
523  if(empty ($field_names)) {
524  $field_names = Array();
525  }
526  else if (!is_array($field_names)) {
527  $field_names = Array ($field_names);
528  }//end if
529  $field_values = $mm->getMetadataFieldValues($assetid, $field_names);
530  $field_values_final = Array();
531  $i = 0;
532  foreach ($field_values as $field_name => $field_value) {
533  $field_values_final[$i]['FieldName'] = $field_name;
534  // bug fix #4646 Empty response returned from metadata field containing non-ascii character
535  // we will need to escape the characters if we are not on a utf-8 system
536  $field_values_final[$i]['FieldValue'] = $mm->escapeMetadata($field_value);
537  $i++;
538  }//end foreach
539 
540  return Array (
541  'GetMetadataFieldValuesResult' => $field_values_final,
542  );
543  } else {
544  throw new SoapFault('Server', 'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
545  }//end else
546 
547  }//end GetMetadataFieldValues()
548 
549 
556  public static function getComplexElements($func_list=Array())
557  {
558  $schema_info = self::getArgType('SchemaSetInfo', 0, 'unbounded', TRUE);
559  $field_values = self::getArgType('FieldInfo', 0, 'unbounded', TRUE);
560  $grant_type = self::getArgType('Grant', 1, 1);
561  $metadata_info = self::getArgType('MetadataInfo', 0, 'unbounded', TRUE);
562 
563  $complex_types = Array (
564  'SetMetadataSchema' => Array (
565  'SetMetadataSchema' => Array (
566  'AssetID' => self::$string_non_optional,
567  'SchemaID' => self::$string_non_optional,
568  'Grant' => $grant_type,
569  'Cascade' => self::$boolean_optional,
570  ),
571  'SetMetadataSchemaResponse' => Array (
572  'SetSchemaResult' => self::$boolean_optional,
573  ),
574  ),
575  'RegenerateMetadataSchema' => Array (
576  'RegenerateMetadataSchema' => Array (
577  'SchemaID' => self::$string_non_optional,
578  ),
579  'RegenerateMetadataSchemaResponse' => Array (
580  'RegenerateMetadataSchemaResult' => self::$boolean_optional,
581  ),
582  ),
583  'RegenerateMetadataAsset' => Array (
584  'RegenerateMetadataAsset' => Array (
585  'AssetID' => self::$string_non_optional,
586  ),
587  'RegenerateMetadataAssetResponse' => Array (
588  'RegenerateMetadataAssetResult' => self::$boolean_optional,
589  ),
590  ),
591  'SetAssetMetadata' => Array(
592  'SetAssetMetadata' => Array (
593  'AssetID' => self::$string_non_optional,
594  'FieldID' => self::$string_non_optional,
595  'NewValue' => self::$string_non_optional,
596  ),
597  'SetAssetMetadataResponse' => Array (
598  'SetAssetMetadataResult' => self::$boolean_optional,
599  ),
600  ),
601  'SetMultipleMetadataFields' => Array(
602  'SetMultipleMetadataFields' => Array (
603  'AssetID' => self::$string_non_optional,
604  'MetadataInfo' => $metadata_info,
605  ),
606  'SetMultipleMetadataFieldsResponse' => Array (
607  'SetMultipleMetadataFieldsResult' => self::$boolean_optional,
608  ),
609  ),
610  'SetMetadataFieldDefaultValue' => Array(
611  'SetMetadataFieldDefaultValue' => Array (
612  'FieldID' => self::$string_non_optional,
613  'NewDefaultValue' => self::$string_non_optional,
614  ),
615  'SetMetadataFieldDefaultValueResponse' => Array (
616  'SetMetadataFieldDefaultValueResult' => self::$boolean_optional,
617  ),
618  ),
619  'GetMetadataValueByIDs' => Array (
620  'GetMetadataValueByIDs' => Array (
621  'AssetID' => self::$string_non_optional,
622  'FieldID' => self::$string_non_optional,
623  ),
624  'GetMetadataValueByIDsResponse' => Array (
625  'GetMetadataValueByIDsResult' => self::$string_non_optional,
626  ),
627  ),
628  'GetSchemasOnAsset' => Array (
629  'GetSchemasOnAsset' => Array (
630  'AssetID' => self::$string_non_optional,
631  ),
632  'GetSchemasOnAssetResponse' => Array (
633  'GetSchemasOnAssetResult' => $schema_info,
634  ),
635  ),
636  'GetMetadataFieldsOfSchema' => Array (
637  'GetMetadataFieldsOfSchema' => Array (
638  'SchemaID' => self::$string_non_optional,
639  ),
640  'GetMetadataFieldsOfSchemaResponse' => Array (
641  'GetMetadataFieldsOfSchemaResult' => self::$string_optional_unbounded,
642  ),
643  ),
644  'GetMetadataFieldValues' => Array (
645  'GetMetadataFieldValues' => Array (
646  'AssetID' => self::$string_non_optional,
647  'FieldNames' => self::$string_optional_unbounded,
648  ),
649  'GetMetadataFieldValuesResponse' => Array (
650  'GetMetadataFieldValuesResult' => $field_values,
651  ),
652  ),
653  );
654 
655  $complex_types_available = parent::getComplexElements($complex_types);
656 
657  return $complex_types_available;
658 
659 
660  }//end getComplexTypes();
661 
662 
669  public static function getSimpleRestrictedTypes($func_list=Array())
670  {
671  $simple_restricted_types = Array (
672  'SetMetadataSchema' => Array (
673  'Grant' => Array (
674  'restriction_base' => 'string',
675  'enumeration' => Array (
676  'Apply', 'Deny', 'Revoke',
677  ),
678  ),
679  ),
680  );
681 
682  $simple_restricted_types_available = parent::processSimpleRestrictedTypes($simple_restricted_types);
683 
684  return $simple_restricted_types_available;
685 
686  }//end getSimpleRestrictedTypes()
687 
688 
695  public static function getComplexTypes($func_list=Array())
696  {
697  $complex_types = Array (
698  'GetMetadataFieldValues' => Array (
699  'FieldInfo' => Array (
700  'FieldName' => self::$string_non_optional,
701  'FieldValue' => self::$string_non_optional,
702  ),
703  ),
704  'GetSchemasOnAsset' => Array (
705  'SchemaSetInfo' => Array (
706  'SchemaID' => self::$string_non_optional,
707  'Grant' => self::$int_non_optional,
708  ),
709  ),
710  'SetMultipleMetadataFields' => Array (
711  'MetadataInfo' => Array (
712  'FieldID' => self::$string_non_optional,
713  'FieldValue' => self::$string_non_optional,
714  ),
715  ),
716  );
717 
718  $complex_types_available = parent::getComplexElements($complex_types);
719 
720  return $complex_types_available;
721 
722  }//end getComplexTypes()
723 
724 }//end class
725 ?>