Advanced Search: Hierarchical keys & unit tests

SVN:b1162[5539]
This commit is contained in:
Eric Espié
2018-03-27 08:13:48 +00:00
parent edcc211988
commit 7664633f18
4 changed files with 62 additions and 13 deletions

View File

@@ -1006,6 +1006,20 @@ class FieldExpression extends UnaryExpression
if (!is_null($oAttDef))
{
$sSearchType = $oAttDef->GetSearchType();
try
{
if ($sSearchType == AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_KEY)
{
// TODO Check the type of external key ? (EXTKEY_ABSOLUTE or EXTKEY_RELATIVE)
if (MetaModel::IsHierarchicalClass($oAttDef->GetTargetClass()))
{
$sSearchType = AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY;
}
}
}
catch (CoreException $e)
{
}
}
else
{
@@ -1569,16 +1583,17 @@ class FunctionExpression extends Expression
public function Display($oSearch, &$aArgs = null, $oAttDef = null)
{
$sOperation = '';
$sVerb = '';
switch ($this->m_sVerb)
{
case 'NOW':
$sOperation = '';
$sVerb = $this->VerbToNaturalLanguage();
break;
case 'DATE_SUB':
$sOperation = '-';
$sVerb = ' -';
break;
case 'DATE_ADD':
$sOperation = '+';
$sVerb = ' +';
break;
case 'DATE_FORMAT':
break;
@@ -1588,12 +1603,26 @@ class FunctionExpression extends Expression
foreach($this->m_aArgs as $oExpression)
{
if ($oExpression instanceof IntervalExpression)
{
$sOperation .= $sVerb;
$sVerb = '';
}
$sOperation .= $oExpression->Display($oSearch, $aArgs, $oAttDef);
}
if (!empty($sVerb))
{
$sOperation .= $sVerb;
}
return $sOperation;
}
private function VerbToNaturalLanguage()
{
return Dict::S('Expression:Verb:'.$this->m_sVerb, " {$this->m_sVerb} ");
}
public function GetCriterion($oSearch, &$aArgs = null, $bRetrofitParams = false, $oAttDef = null)
{
$aCriteria = array();
@@ -1728,7 +1757,7 @@ class IntervalExpression extends Expression
public function Display($oSearch, &$aArgs = null, $oAttDef = null)
{
return $this->m_oValue->Render($aArgs) . ' ' . $this->m_sUnit;
return $this->m_oValue->Render($aArgs).' '.Dict::S('Expression:Unit:Long:'.$this->m_sUnit, $this->m_sUnit);
}
}

View File

@@ -1243,8 +1243,15 @@ Lors de l\'association à un déclencheur, on attribue à chaque action un numé
Dict::Add('FR FR', 'French', 'Français', array(
'Expression:Operator:AND' => ' ET ',
'Expression:Operator:OR' => ' OU ',
'Expression:Unit:Short:DAY' => 'j',
'Expression:Unit:Short:WEEK' => 's',
'Expression:Unit:Short:MONTH' => 'm',
'Expression:Unit:Short:YEAR' => 'a',
'Expression:Unit:Long:DAY' => 'jour(s)',
'Expression:Unit:Long:HOUR' => 'heure(s)',
'Expression:Unit:Long:MINUTE' => 'minute(s)',
'Expression:Verb:NOW' => 'maintenant',
));

View File

@@ -62,6 +62,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME => 'DateTimeToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC => 'NumericToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_KEY => 'ExternalKeyToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY => 'ExternalKeyToSearchForm',
);
foreach($aAndCriterionRaw as $aCriteria)

View File

@@ -322,12 +322,15 @@ class CriterionConversionTest extends ItopDataTestCase
{
$aField = $aFields['zlist'][$aCriteria['ref']];
}
else
elseif (isset($aFields['others'][$aCriteria['ref']]))
{
$aField = $aFields['others'][$aCriteria['ref']];
}
$aCriteria['code'] = $aField['code'];
$aCriteria['class'] = $aField['class'];
if (isset($aField))
{
$aCriteria['code'] = $aField['code'];
$aCriteria['class'] = $aField['class'];
}
}
$aNewCriterion[] = $aCriteria;
@@ -347,20 +350,27 @@ class CriterionConversionTest extends ItopDataTestCase
function OqlProvider()
{
return array(
'no criteria' => array('OQL' => 'SELECT WebApplication'),
'string starts' => array('OQL' => "SELECT Contact WHERE name LIKE 'toto%'"),
'string ends' => array('OQL' => "SELECT Contact WHERE name LIKE '%toto'"),
'string contains' => array('OQL' => "SELECT Contact WHERE name LIKE '%toto%'"),
'string contains 1' => array('OQL' => "SELECT Contact WHERE name LIKE '%toto%'"),
'string contains 2' => array('OQL' => "SELECT Person AS B WHERE B.name LIKE '%A%'"),
'string regexp' => array('OQL' => "SELECT Server WHERE name REGEXP '^dbserver[0-9]+\\\\\\\\..+\\\\\\\\.[a-z]{2,3}$'"),
'enum + key =' => array('OQL' => "SELECT Contact WHERE status = 'active' AND org_id = 3"),
'enum =' => array('OQL' => "SELECT Contact WHERE status = 'active'"),
'enum IN' => array('OQL' => "SELECT Contact WHERE status IN ('active', 'inactive')"),
'enum NOT IN' => array('OQL' => "SELECT Contact WHERE status NOT IN ('active')"),
'enum undefined' => array('OQL' => "SELECT FunctionalCI WHERE ((business_criticity = 'high') OR ISNULL(business_criticity)) AND 1"),
'enum undefined1' => array('OQL' => "SELECT FunctionalCI WHERE ((business_criticity IN ('high', 'medium')) OR ISNULL(business_criticity)) AND 1"),
'enum undefined2' => array('OQL' => "SELECT FunctionalCI WHERE ISNULL(business_criticity)"),
'enum NOT IN 1' => array('OQL' => "SELECT Contact WHERE status NOT IN ('active')"),
'enum NOT IN 2' => array('OQL' => "SELECT Person AS p JOIN UserRequest AS u ON u.agent_id = p.id WHERE u.status != 'closed'"),
'enum undefined 1' => array('OQL' => "SELECT FunctionalCI WHERE ((business_criticity = 'high') OR ISNULL(business_criticity)) AND 1"),
'enum undefined 2' => array('OQL' => "SELECT FunctionalCI WHERE ((business_criticity IN ('high', 'medium')) OR ISNULL(business_criticity)) AND 1"),
'enum undefined 3' => array('OQL' => "SELECT FunctionalCI WHERE ISNULL(business_criticity)"),
'key NOT IN' => array('OQL' => "SELECT Contact WHERE org_id NOT IN ('1')"),
'key IN' => array('OQL' => "SELECT Contact WHERE org_id IN ('1')"),
'key empty' => array('OQL' => "SELECT Person WHERE location_id = '0'"),
'Date relative' => array('OQL' => "SELECT UserRequest WHERE DATE_SUB(NOW(), INTERVAL 14 DAY) < start_date"),
'Date relative 1' => array('OQL' => "SELECT UserRequest WHERE DATE_SUB(NOW(), INTERVAL 14 DAY) < start_date"),
'Date relative 2' => array('OQL' => "SELECT Contract AS c WHERE c.end_date > NOW() AND c.end_date < DATE_ADD(NOW(), INTERVAL 30 DAY)"),
'Date relative 3' => array('OQL' => "SELECT UserRequest AS u WHERE u.close_date > DATE_ADD(u.start_date, INTERVAL 8 HOUR)"),
'Date relative 4' => array('OQL' => "SELECT UserRequest AS u WHERE u.start_date < DATE_SUB(NOW(), INTERVAL 60 MINUTE) AND u.status = 'new'"),
'Date between 1' => array('OQL' => "SELECT UserRequest WHERE start_date > '2017-01-01 00:00:00' AND '2018-01-01 00:00:00' >= start_date"),
'Date between 2' => array('OQL' => "SELECT UserRequest WHERE start_date > '2017-01-01 00:00:00' AND status = 'active' AND org_id = 3 AND '2018-01-01 00:00:00' >= start_date"),
'Date between 3' => array('OQL' => "SELECT UserRequest WHERE start_date >= '2017-01-01 00:00:00' AND '2017-01-01 00:00:00' >= start_date"),
@@ -372,6 +382,8 @@ class CriterionConversionTest extends ItopDataTestCase
'Date =2' => array('OQL' => "SELECT UserRequest WHERE (DATE_FORMAT(start_date, '%Y-%m-%d') = '2018-03-21')"),
'Num between 1' => array('OQL' => "SELECT Server WHERE nb_u >= 0 AND 1 >= nb_u"),
'Num ISNULL' => array('OQL' => "SELECT Server WHERE ISNULL(nb_u)"),
'Hierarchical below' => array('OQL' => "SELECT Person AS P JOIN Organization AS Node ON P.org_id = Node.id JOIN Organization AS Root ON Node.parent_id BELOW Root.id WHERE Root.id=1"),
'IP range' => array('OQL' => "SELECT DatacenterDevice AS dev WHERE INET_ATON(dev.managementip) > INET_ATON('10.22.32.224') AND INET_ATON(dev.managementip) < INET_ATON('10.22.32.255')"),
);
}
}