Skip to content

Commit

Permalink
Mappings endpoint: Make querying external endpoints optional
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo authored and osma committed Jan 30, 2019
1 parent f85d5f1 commit 38f056a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ public function mappings(Request $request)
return $this->returnError(400, 'Bad Request', "uri parameter missing");
}

$queryExVocabs = $request->getQueryParamBoolean('external', true);

$results = $vocab->getConceptInfo($uri, $request->getContentLang());
if (empty($results)) {
return $this->returnError(404, 'Bad Request', "no concept found with given uri");
Expand All @@ -646,7 +648,7 @@ public function mappings(Request $request)
$ret = [];
foreach ($concept->getMappingProperties() as $mappingProperty) {
foreach ($mappingProperty->getValues() as $mappingPropertyValue) {
$ret[] = $mappingPropertyValue->asJskos();
$ret[] = $mappingPropertyValue->asJskos($queryExVocabs);
}
}

Expand Down
10 changes: 5 additions & 5 deletions model/ConceptMappingPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getType()
return $this->type;
}

public function getLabel($lang = '')
public function getLabel($lang = '', $queryExVocabs = true)
{
if (isset($this->labelcache[$lang])) {
return $this->labelcache[$lang];
Expand All @@ -55,7 +55,7 @@ public function getLabel($lang = '')
return $label;
}

private function queryLabel($lang = '')
private function queryLabel($lang = '', $queryExVocabs = true)
{
if ($this->clang) {
$lang = $this->clang;
Expand All @@ -68,7 +68,7 @@ private function queryLabel($lang = '')
}

// if multiple vocabularies are found, the following method will return in priority the current vocabulary of the mapping
$exvocab = $this->model->guessVocabularyFromURI($this->resource->getUri(), $this->vocab->getId());
$exvocab = $queryExVocabs ? $this->model->guessVocabularyFromURI($this->resource->getUri(), $this->vocab->getId()) : null;

// if the resource is from another vocabulary known by the skosmos instance
if ($exvocab) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getNotation()
* Return the mapping as a JSKOS-compatible array.
* @return array
*/
public function asJskos()
public function asJskos($queryExVocabs = true)
{
$ret = [
'type' => [$this->type],
Expand Down Expand Up @@ -210,7 +210,7 @@ public function asJskos()
$ret['to']['memberSet'][0]['notation'] = (string) $notation;
}

$label = $this->getLabel();
$label = $this->getLabel($queryExVocabs);
if (isset($label)) {
if (is_string($label)) {
list($labelLang, $labelValue) = ['-', $label];
Expand Down

0 comments on commit 38f056a

Please sign in to comment.