Project

General

Profile

« Previous | Next » 

Revision fb308159

Added by Andreas Kohlbecker over 4 years ago

fix #8321 finding taxa for a given name by matching whith the whole titleCache

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.info
3 3
version = 7.x-3.0
4 4
package = "CDM"
5 5
core = 7.x
6
files[] = classes/Restriction.php
modules/cdm_dataportal/cdm_api/cdm_api.module
981 981
 * @param bool $absoluteURI
982 982
 *   TRUE when the URL should be treated as absolute URL.
983 983
 *
984
 * @return the a CDM Pager object
984
 * @return object
985
 *   A CDM Pager object
985 986
 *
986 987
 */
987 988
function cdm_ws_page($resourceURI, $pageSize, $pageNumber, array $query = array(), $method = 'GET', $absoluteURI = FALSE) {
......
992 993
  return cdm_ws_get($resourceURI, NULL, queryString($query), $method, $absoluteURI);
993 994
}
994 995

  
996

  
995 997
/**
998
 * Sends a http GET request to the generic page method which allows for filtering entities by Restrictions.
999
 *
1000
 * @param $cdm_entity_type
1001
 * @param array $restrictions
1002
 *   An array of Restriction objects
1003
 * @param array $init_strategy
1004
 *   The init strategy to initialize the entity beans while being loaded from the
1005
 *   persistent storage by the cdm
1006
 * @param int $page_size
1007
 *   The maximum number of entities returned per page.
1008
 *   The default page size as configured in the cdm server
1009
 *   will be used if set to NULL
1010
 *   to return all entities in a single page).
1011
 * @param int $page_index
1012
 *   The number of the page to be returned, the first page has the
1013
 *   pageNumber = 0
1014
 *
1015
 * @return object
1016
 *   A CDM Pager object
1017
 *
1018
 */
1019
function cdm_ws_page_by_restriction($cdm_entity_type, array $restrictions, array $init_strategy, $page_size, $page_index) {
1020

  
1021
  $restrictions_json = array(); // json_encode($restrictions);
1022
  foreach ($restrictions as $restr){
1023
    $restrictions_json[] = json_encode($restr);
1024
  }
1025
  return cdm_ws_page(
1026
      'portal/' . cdm_ws_base_uri($cdm_entity_type),
1027
      $page_size,
1028
      $page_index,
1029
      array(
1030
        'restriction' => $restrictions_json,
1031
        'initStrategy' => $init_strategy
1032
      ),
1033
      "GET"
1034
    );
1035
}
1036

  
1037
/**
1038
 * Fetches all entities returned by the the generic page method for the Restrictions applied as filter.
1039
 *
1040
 * @param $cdm_entity_type
1041
 * @param array $restrictions
1042
 *   An array of Restriction objects
1043
 * @param array $init_strategy
1044
 *   The init strategy to initialize the entity beans while being loaded from the
1045
 *   persistent storage by the cdm
1046
 * @param int $page_size
1047
 *   The maximum number of entities returned per page.
1048
 *   The default page size as configured in the cdm server
1049
 *   will be used if set to NULL
1050
 *   to return all entities in a single page).
1051
 * @param int $page_index
1052
 *   The number of the page to be returned, the first page has the
1053
 *   pageNumber = 0
1054
 *
1055
 * @return array
1056
 *   A array of CDM entities
1057
 *
1058
 */
1059
function cdm_ws_fetch_all_by_restriction($cdm_entity_type, array $restrictions, array $init_strategy){
1060
  $page_index = 0;
1061
  // using a bigger page size to avoid to many multiple requests
1062
  $page_size = 500;
1063
  $entities = array();
1064

  
1065
  while ($page_index !== FALSE && $page_index < 1){
1066
    $pager =  cdm_ws_page_by_restriction($cdm_entity_type, $restrictions, $init_strategy, $page_size, $page_index);
1067
    if(isset($pager->records) && is_array($pager->records)) {
1068
      $entities = array_merge($entities, $pager->records);
1069
      if(!empty($pager->nextIndex)){
1070
        $page_index = $pager->nextIndex;
1071
      } else {
1072
        $page_index = FALSE;
1073
      }
1074
    } else {
1075
      $page_index = FALSE;
1076
    }
1077
  }
1078
  return $entities;
1079
}
1080

  
1081

  
1082
  /**
996 1083
 * Fetches all entities from the given REST endpoint using the pager mechanism.
997 1084
 *
998 1085
 * @param string $resourceURI
modules/cdm_dataportal/cdm_api/classes/Restriction.php
1
<?php
2
/**
3
 * PHP implementation of the cdm eu.etaxonomy.cdm.persistence.dao.common.Restriction
4
 */
5

  
6
class Restriction
7
{
8
  public $propertyName;
9

  
10
  public $matchMode;
11

  
12
  public $operator;
13

  
14
  public $values = array();
15

  
16

  
17
  /**
18
   * Public constructor.
19
   */
20
  public function __construct($propertyName, $matchMode, array $values, $operator = 'AND') {
21
    $this->propertyName = $propertyName;
22
    $this->matchMode = $matchMode;
23
    $this->values = $values;
24
    $this->operator = $operator;
25
  }
26
}
modules/cdm_dataportal/cdm_api/webservice_uris.php
3 3
 * @file
4 4
 * CDM Server URI definitions.
5 5
 */
6

  
7
define('CDM_WS_PORTAL_GENERIC', 'portal/$0');
8

  
6 9
define('CDM_WS_PORTAL_AGENT', 'portal/agent');
7 10
define('CDM_WS_REFERENCE', 'reference');
8 11
define('CDM_WS_REFERENCE_AUTHORTEAM', 'reference/$0/authorship');
modules/cdm_dataportal/cdm_dataportal.module
1788 1788
  cdm_load_tagged_full_title($taxon_name);
1789 1789
  // Searching for all the taxa connected with the taxon name on the tree
1790 1790
  // in use.
1791
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1792
  $request_params = array();
1793
  $request_params['query'] = $name_cache;
1794
  $request_params['tree'] = get_current_classification_uuid();
1795
  $request_params['doTaxa'] = 1;
1796
  $request_params['doSynonyms'] = 1;
1797
  $request_params['doTaxaByCommonNames'] = 0;
1798
  $request_params['matchMode'] = "EXACT";
1799
  $taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, NULL, queryString($request_params));
1791
  $name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1792
  $restrictions = array(new Restriction("name.titleCache","EXACT", array($name->titleCache), 'AND'));
1793
  $init_strategy = array(
1794
    "name.titleCache",
1795
    "name.nomenclaturalReference.authorship",
1796
    "name.nomenclaturalReference.inReference.authorship",
1797
    "name.nomenclaturalReference.inReference.inReference.authorship",
1798
    "name.nomenclaturalReference.inReference.inReference.inReference.authorship"
1799
  );
1800
  $taxa = cdm_ws_fetch_all_by_restriction("Taxon", $restrictions, $init_strategy);
1800 1801

  
1801 1802
  // Removing the name where we came from.
1802
  foreach ($taxon_pager->records as $k => &$taxon) {
1803
  foreach ($taxa as $k => &$taxon) {
1803 1804
    if ($taxon->uuid == $taxon_to_hide_uuid) {
1804
      unset($taxon_pager->records[$k]);
1805
      unset($taxa[$k]);
1805 1806
    }
1806 1807
  }
1807 1808
  // Show the taxa list or go to the singular taxon.
1808
  if (sizeof($taxon_pager->records) == 1 && $redirect_to_taxon) {
1809
  if (sizeof($taxa) == 1 && $redirect_to_taxon) {
1809 1810
    // redirect to the taxon if there is only one.
1810
    $singleTaxon = array_pop($taxon_pager->records);
1811
    $singleTaxon = array_pop($taxa);
1811 1812
    if ($singleTaxon->class != "Taxon") {
1812 1813
      // It is a Synonym -> look for the accepted.
1813 1814
      $accepted_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid), 'classificationFilter=' . get_current_classification_uuid());
......
1845 1846
      $content['name_relationships'] = compose_name_relationships_list($name_relations, $taxon_name->uuid, null);
1846 1847
    }
1847 1848
    // related taxa
1848
    if ($taxon_pager->records) {
1849
    if ($taxa) {
1849 1850
      $content['related_taxa_header'] = markup_to_render_array("<h5>Taxa for this name:</h5>");
1850
      $content['related_taxa'] = compose_list_of_taxa($taxon_pager->records);
1851
      $content['related_taxa'] = compose_list_of_taxa($taxa);
1851 1852
    }
1852 1853
    else {
1853 1854
      $content['related_taxa'] = markup_to_render_array('This name is not assigned to a taxon.');
src/test/java/eu/etaxonomy/dataportal/selenium/tests/reference/NameRelationshipsTest.java
89 89
        assertEquals(
90 90
                "4. Lem, Nonsens species of the developers Vol1. 2001",
91 91
                footnotes .get(3).getText());
92

  
93 92
    }
94 93

  
95 94
    @Test
......
112 111
                "3. Lem, Nonsens species of the developers Vol1. 2001",
113 112
                footnotes.get(2).getText());
114 113

  
115

  
116 114
    }
117 115

  
118 116
    /**
......
129 127
        WebElement accName = p.getAcceptedName();
130 128
        assertEquals("Bulbostylis pauciflora (Liebm.) C. B. Clarke, nom. cons. [non Bulbostylis pauciflora (Kunth) D.C.]", accName.getText());
131 129
        assertEquals("is conserved against", accName.findElement(By.className("symbol")).getAttribute("title"));
132

  
133 130
    }
134 131

  
135 132
    /**
......
148 145
        WebElement synonym2 = p.getHeterotypicalGroupSynonym(1, 2);
149 146
        assertEquals("≡\nNepenthes tupmanniana Bonstedt in Parey Blumeng. 1: 663. 1931 [non Nepenthes teysmanniana Miq., Fl. Ned. Ind. 1(1): 1073. 1858]", synonym2.getText());
150 147
        assertEquals("is misspelling for", synonym2.findElement(By.className("symbol")).getAttribute("title"));
151

  
152 148
    }
153 149

  
154 150
}

Also available in: Unified diff