Project

General

Profile

Revision 42f2e1e0

ID42f2e1e009dcddc27f091bc1ae2b57d9050b22a1
Parent 6b5815cd
Child 37252893

Added by Andreas Kohlbecker over 8 years ago

solving bug and reducing confusion about featureTree REST services

View differences:

7.x/modules/cdm_dataportal/cdm_api/cdm_api.module
639 639
}
640 640

  
641 641
/**
642
 * Composes a CDM webservice URL with parameters and querystring.
642
 * Composes a absolute CDM web service URI with parameters and querystring.
643 643
 *
644 644
 * @param string $uri_pattern
645 645
 *   String with place holders ($0, $1, ..) that should be replaced by the
......
896 896
}
897 897

  
898 898
/**
899
 * @todo Please document this function.
900
 * @see http://drupal.org/node/1354
899
 * Composes the the absolute REST service URI to the annotations pager
900
 * for the given CDM entity.
901
 *
902
 * NOTE: Not all CDM Base types are yet supported.
903
 *
904
 * @param $cdmBase
905
 *   The CDM entity to construct the annotations pager uri for
901 906
 */
902
function cdm_compose_annotations_url($cdmBase) {
907
function cdm_compose_annotations_uri($cdmBase) {
903 908
  if (!$cdmBase->uuid) {
904 909
    return;
905 910
  }
......
970 975
 * @param int $pageNumber
971 976
 *   The number of the page to be returned, the first page has the
972 977
 *   pageNumber = 0
973
 *
978
 * @param bool $absoluteURI
979
 *   TRUE when the URL should be treated as absolute URL.
974 980
 * @return the a CDM Pager object
975 981
 *
976 982
 */
977
function cdm_ws_page($resourceURI, $pageSize, $pageNumber) {
983
function cdm_ws_page($resourceURI, $pageSize, $pageNumber,  $absoluteURI = FALSE) {
978 984
  return cdm_ws_get($resourceURI, NULL, queryString(array(
979
    "pageNumber" => $pageNumber,
980
    'pageSize' => $pageSize,
981
  )));
985
      "pageNumber" => $pageNumber,
986
      'pageSize' => $pageSize,
987
    )),
988
    'GET',
989
    $absoluteURI);
982 990
}
983 991

  
984 992
/**
985 993
 * Fetches all entities from the given REST endpoint using the pager mechanism.
986 994
 *
987 995
 * @param string $resourceURI
996
 * @param bool $absoluteURI
997
 *   TRUE when the URL should be treated as absolute URL.
988 998
 *
989 999
 * @return array
990 1000
 *     A list of CDM entitites
991 1001
 *
992 1002
 */
993
function cdm_ws_fetch_all($resourceURI) {
1003
function cdm_ws_fetch_all($resourceURI, $absoluteURI = FALSE) {
994 1004
  $page_index = 0;
995 1005
  // using a bigger page size to avoid to many multiple requests
996 1006
  $page_size = 200;
997 1007
  $entities = array();
998 1008

  
999 1009
  while ($page_index !== FALSE){
1000
    $pager =  cdm_ws_page($resourceURI, $page_size, $page_index);
1010
    $pager =  cdm_ws_page($resourceURI, $page_size, $page_index, $absoluteURI);
1001 1011
    if(isset($pager->records) && is_array($pager->records)) {
1002 1012
      $entities = $pager->records;
1003 1013
      if(!empty($pager->nextIndex)){
......
1316 1326
function cdm_ws_getAnnotationsFor(&$cdmBase, $includeTypes = FALSE) {
1317 1327

  
1318 1328
  if(!isset($cdmBase->annotations)){
1319
    $annotationUrl = cdm_compose_annotations_url($cdmBase);
1320
    $cdmBase->annotations = cdm_ws_fetch_all($annotationUrl);
1329
    $annotationUrl = cdm_compose_annotations_uri($cdmBase);
1330
    $cdmBase->annotations = cdm_ws_fetch_all($annotationUrl, TRUE);
1321 1331
  }
1322 1332

  
1323 1333
  $annotations = array();
......
1614 1624
  $data_links = '';
1615 1625
  if (_is_cdm_ws_uri($path)) {
1616 1626
    $data_links .= '<a href="'
1617
        . url($path . '.xml', array('query' => $query))
1627
        . url($path . '.xml', array('query' => $query, 'absolute' => TRUE))
1618 1628
        . '" target="data">xml</a>-';
1619 1629
    $data_links .= '<a href="'
1620 1630
        . url('cdm_api/proxy/' . urlencode(url($path . '.xml', array('query' => $query))))
1621 1631
        . '" target="data">proxied</a>';
1622 1632
    $data_links .= '<br/>';
1623 1633
    $data_links .= '<a href="'
1624
        . url($path . '.json', array('query' => $query))
1634
        . url($path . '.json', array('query' => $query, 'absolute' => TRUE))
1625 1635
        . '" target="data">json</a>-';
1626 1636
    $data_links .= '<a href="'
1627 1637
        . url('cdm_api/proxy/' . urlencode(url($path . '.json', array('query' => $query))))
......
1820 1830
  }
1821 1831

  
1822 1832
  // Get feature trees from database.
1823
  $persited_trees = cdm_ws_get(CDM_WS_FEATURETREES);
1833
  $persited_trees = cdm_ws_fetch_all(CDM_WS_FEATURETREES);
1824 1834
  if (is_array($persited_trees)) {
1825 1835
    $feature_trees = array_merge($feature_trees, $persited_trees);
1826 1836
  }
7.x/modules/cdm_dataportal/cdm_api/webservice_uris.php
88 88
/**
89 89
 * Returns FeatureTrees that are stored in this community store.
90 90
 */
91
define('CDM_WS_FEATURETREE', 'featureTree/$0');
92
define('CDM_WS_FEATURETREES', 'featureTree');
93
// define('CDM_WS_FEATURETREE_CHILDREN', 'featuretree/$0/children');
91
define('CDM_WS_FEATURETREE', 'portal/featureTree/$0');
92
define('CDM_WS_FEATURETREES', 'portal/featureTree');
93
// define('CDM_WS_FEATURETREE_CHILDREN', 'featureTree/$0/children');
94 94
define('CDM_WS_GEOSERVICE_DISTRIBUTIONMAP', 'ext/edit/mapServiceParameters/taxonDistributionFor/$0');
95 95
define('CDM_WS_GEOSERVICE_OCCURRENCEMAP', 'ext/edit/mapServiceParameters/taxonOccurrencesFor/$0');
96 96

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)