Skip to content

Commit

Permalink
Merge pull request #1165 from NatLibFi/show-newly-deprecated
Browse files Browse the repository at this point in the history
Show newly deprecated
  • Loading branch information
joelit committed Nov 3, 2021
2 parents 162e155 + e7f3bef commit b9182af
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 29 deletions.
14 changes: 11 additions & 3 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,17 @@ private function changedConcepts($request, $prop, $offset, $limit)
$simpleChangeList = array();
foreach($changeList as $conceptInfo) {
if (array_key_exists('date', $conceptInfo)) {
$simpleChangeList[] = array( 'uri' => $conceptInfo['uri'],
'prefLabel' => $conceptInfo['prefLabel'],
'date' => $conceptInfo['date']->format("Y-m-d\TH:i:sO") );
$concept = array(
'uri' => $conceptInfo['uri'],
'prefLabel' => $conceptInfo['prefLabel'],
'date' => $conceptInfo['date']->format("Y-m-d\TH:i:sO") );
if (array_key_exists('replacedBy', $conceptInfo)) {
$concept['replacedBy'] = $conceptInfo['replacedBy'];
if (array_key_exists('replacingLabel', $conceptInfo)) {
$concept['replacingLabel'] = $conceptInfo['replacingLabel'];
}
}
$simpleChangeList[] = $concept;
}
}
return $this->returnJson(array_merge_recursive($this->context,
Expand Down
2 changes: 2 additions & 0 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ public function invokeVocabularyHome($request)
if ($defaultView === 'groups') {
$this->invokeGroupIndex($request, true);
return;
} else if ($defaultView === 'new') {
$this->invokeChangeList($request);
}
$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());

Expand Down
3 changes: 2 additions & 1 deletion model/Vocabulary.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ public function verifyVocabularyLanguage($lang)
*/
public function getChangeList($prop, $clang, $offset, $limit)
{
return $this->getSparql()->queryChangeList($prop, $clang, $offset, $limit);
$showDeprecated = $this->getConfig()->getShowDeprecatedChanges();
return $this->getSparql()->queryChangeList($prop, $clang, $offset, $limit, $showDeprecated);
}

public function getTitle($lang=null) {
Expand Down
11 changes: 10 additions & 1 deletion model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function getDefaultSidebarView()
$defview = $this->resource->getLiteral('skosmos:defaultSidebarView');
if ($defview) {
$value = $defview->getValue();
if ($value === 'groups' || $value === 'hierarchy') {
if ($value === 'groups' || $value === 'hierarchy' || $value === 'new') {
return $value;
}

Expand Down Expand Up @@ -615,6 +615,15 @@ public function getShowDeprecated()
return $this->getBoolean('skosmos:showDeprecated', false);
}

/**
* Returns a boolean value set in the config.ttl config.
* @return boolean
*/
public function getShowDeprecatedChanges()
{
return $this->getBoolean('skosmos:showDeprecatedChanges', false);
}

/**
* Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration.
* @return array of objects or an empty array
Expand Down
45 changes: 36 additions & 9 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -2250,21 +2250,40 @@ public function listConceptGroupContents($groupClass, $group, $lang,$showDepreca
* @param string $lang language of labels to return
* @param int $offset offset of results to retrieve; 0 for beginning of list
* @param int $limit maximum number of results to return
* @param boolean $showDeprecated whether to include deprecated concepts in the change list
* @return string sparql query
*/
private function generateChangeListQuery($prop, $lang, $offset, $limit=200) {
private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $showDeprecated=false) {
$fcl = $this->generateFromClause();
$offset = ($offset) ? 'OFFSET ' . $offset : '';

//Additional clauses when deprecated concepts need to be included in the results
$deprecatedOptions = '';
$deprecatedVars = '';
if ($showDeprecated) {
$deprecatedVars = '?replacedBy ?deprecated ?replacingLabel';
$deprecatedOptions =
'UNION {'.
'?concept dc:isReplacedBy ?replacedBy ; dc:modified ?date2 .'.
'BIND(COALESCE(?date2, ?date) AS ?date)'.
'OPTIONAL { ?replacedBy skos:prefLabel ?replacingLabel .'.
'FILTER (langMatches(lang(?replacingLabel), \''.$lang.'\')) }}'.
'OPTIONAL { ?concept owl:deprecated ?deprecated . }';
}

$query = <<<EOQ
SELECT DISTINCT ?concept ?date ?label $fcl
SELECT ?concept ?date ?label $deprecatedVars $fcl
WHERE {
?concept a skos:Concept .
?concept $prop ?date .
?concept skos:prefLabel ?label .
FILTER (langMatches(lang(?label), '$lang'))
?concept a skos:Concept ;
skos:prefLabel ?label .
FILTER (langMatches(lang(?label), '$lang'))
{
?concept $prop ?date .
MINUS { ?concept owl:deprecated True . }
}
$deprecatedOptions
}
ORDER BY DESC(YEAR(?date)) DESC(MONTH(?date)) LCASE(?label)
ORDER BY DESC(YEAR(?date)) DESC(MONTH(?date)) LCASE(?label) DESC(?concept)
LIMIT $limit $offset
EOQ;

Expand Down Expand Up @@ -2293,6 +2312,13 @@ private function transformChangeListResults($result) {
}
}

if (isset($row->replacedBy)) {
$concept['replacedBy'] = $row->replacedBy->getURI();
}
if (isset($row->replacingLabel)) {
$concept['replacingLabel'] = $row->replacingLabel->getValue();
}

$ret[] = $concept;
}
return $ret;
Expand All @@ -2304,10 +2330,11 @@ private function transformChangeListResults($result) {
* @param string $lang language of labels to return
* @param int $offset offset of results to retrieve; 0 for beginning of list
* @param int $limit maximum number of results to return
* @param boolean $showDeprecated whether to include deprecated concepts in the change list
* @return array Result array
*/
public function queryChangeList($prop, $lang, $offset, $limit) {
$query = $this->generateChangeListQuery($prop, $lang, $offset, $limit);
public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated=false) {
$query = $this->generateChangeListQuery($prop, $lang, $offset, $limit, $showDeprecated);

$result = $this->query($query);
return $this->transformChangeListResults($result);
Expand Down
17 changes: 15 additions & 2 deletions resource/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,21 @@ tr.replaced-by > td > ul > li > a {
.nav-tabs {
background-color: #e0e4e7;
border-bottom: none;
display: flex;
}

ul.nav-tabs > li {
margin-bottom: 0;
box-sizing: content-box;
display: flex;
}

ul.nav-tabs > li > a {
box-sizing: content-box;
text-align: center;
flex-grow: 200;
align-content: stretch;
align-items: center;
}

.sidebar-buttons .nav-tabs > li > a, .sidebar-buttons .nav-tabs > li > p, .sidebar-buttons .nav-tabs > li.active > a {
Expand All @@ -1569,7 +1580,9 @@ ul.nav-tabs > li {
border: 0;
margin: 0;
padding: 10px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}

.nav-tabs > li:nth-of-type(even) > a {
Expand Down Expand Up @@ -1601,7 +1614,7 @@ ul.nav-tabs > li {
}

.nav-four-wide > li {
width: 28%;
width: 31%;
}

.nav-four-wide > #alpha {
Expand Down
Binary file modified resource/translations/en/LC_MESSAGES/skosmos.mo
Binary file not shown.
Binary file modified resource/translations/fi/LC_MESSAGES/skosmos.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ msgstr "By type"
msgid "Changes-nav"
msgstr "New"

msgid "Changes-and-deprecations-nav"
msgstr "New and deprecated"

#: /tmp/cache/587c83c09abaa/8a/8aeec9eddcf0848575d119210eda5a849c129c96ea86195b4448536a02a47817.php:122
msgid "Clear limitations"
msgstr "Clear limitations"
Expand Down
6 changes: 6 additions & 0 deletions resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ msgstr "Tyypin mukaan"
msgid "Changes-nav"
msgstr "Uudet"

msgid "Changes-and-deprecations-nav"
msgstr "Uudet ja poistetut"

#: /tmp/cache/587c830e6b9a0/8a/8aeec9eddcf0848575d119210eda5a849c129c96ea86195b4448536a02a47817.php:122
msgid "Clear limitations"
msgstr "Peru rajoitukset"
Expand Down Expand Up @@ -827,6 +830,9 @@ msgstr "Listaa käsitteet aakkosittain"
msgid "Listing vocabulary concepts by newest additions"
msgstr "Listaa käsitteet uusimpien lisäysten mukaan"

msgid "List vocabulary concepts by newest additions including removed"
msgstr "Listaa käsitteet uusimpien lisäysten tai poistojen mukaan"

msgid "Prefer using"
msgstr "Käytä termiä"

Expand Down
6 changes: 6 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ msgstr "Enligt typ"
msgid "Changes-nav"
msgstr "Nya"

msgid "Changes-and-deprecations-nav"
msgstr "Nya och ur bruk"

#: /tmp/cache/587c83500d6c9/8a/8aeec9eddcf0848575d119210eda5a849c129c96ea86195b4448536a02a47817.php:122
msgid "Clear limitations"
msgstr "Ta bort avgränsningar"
Expand Down Expand Up @@ -804,6 +807,9 @@ msgstr "Lista begrepp och grupper enligt hierarkin"
msgid "List vocabulary concepts by newest additions"
msgstr "Lista begrepp enligt de senaste tilläggen"

msgid "List vocabulary concepts by newest additions including removed"
msgstr "Lista begrepp enligt de senaste tilläggen eller raderingar"

msgid "List vocabulary concepts hierarchically"
msgstr "Lista begrepp enligt hierarkin"

Expand Down
Binary file modified resource/translations/sv/LC_MESSAGES/skosmos.mo
Binary file not shown.
25 changes: 23 additions & 2 deletions tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,32 @@ public function testListConceptGroupContentsIncludingDeprecatedConcept()
* @covers GenericSparql::generateChangeListQuery
* @covers GenericSparql::transFormChangeListResults
*/
public function testQueryChangeList()
public function testQueryChangeListCreatedNoDeprecated()
{
$voc = $this->model->getVocabulary('changes');
$graph = $voc->getGraph();
$sparql = new GenericSparql($this->endpoint, $graph, $this->model);
$actual = $sparql->queryChangeList('dc:created', 'en', 0, 10);
$actual = $sparql->queryChangeList('dc:modified', 'en', 0, 10, false);

$order = array();
foreach($actual as $concept) {
array_push($order, $concept['prefLabel']);
}
$this->assertEquals(3, sizeof($actual));
$this->assertEquals(array('A date', 'Hurr Durr', 'Second date'), $order);
}

/**
* @covers GenericSparql::queryChangeList
* @covers GenericSparql::generateChangeListQuery
* @covers GenericSparql::transFormChangeListResults
*/
public function testQueryCreatedListWithDeprecated()
{
$voc = $this->model->getVocabulary('changes');
$graph = $voc->getGraph();
$sparql = new GenericSparql($this->endpoint, $graph, $this->model);
$actual = $sparql->queryChangeList('dc:created', 'en', 0, 10, true);
$order = array();
foreach($actual as $concept) {
array_push($order, $concept['prefLabel']);
Expand All @@ -1135,6 +1155,7 @@ public function testQueryChangeList()
$this->assertEquals(array('Fourth date', 'Hurr Durr', 'Second date', 'A date'), $order);
}


/**
* @covers GenericSparql::queryChangeList
* @covers GenericSparql::generateChangeListQuery
Expand Down
46 changes: 45 additions & 1 deletion tests/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ public function testLabelNoConcept() {
*/
public function testNewConcepts() {
$request = new Request($this->model);
$request->setQueryParam('format', 'application/json');
$request->setURI('http://www.skosmos.skos/changes');
$request->setVocab('changes');
$request->setLang('en');
$request->setContentLang('en');
Expand All @@ -369,7 +371,9 @@ public function testNewConcepts() {
{
"uri": "http://www.skosmos.skos/changes/d4",
"prefLabel": "Fourth date",
"date": "2011-12-12T09:26:39+0000"
"date": "2021-01-03T12:46:33+0000",
"replacedBy": "http://www.skosmos.skos/changes/d3",
"replacingLabel": "Hurr Durr"
},
{
"uri": "http://www.skosmos.skos/changes/d3",
Expand Down Expand Up @@ -398,6 +402,8 @@ public function testNewConcepts() {
*/
public function testModifiedConcepts() {
$request = new Request($this->model);
$request->setQueryParam('format', 'application/json');
$request->setURI('http://www.skosmos.skos/test');
$request->setVocab('test');
$request->setLang('en');
$request->setContentLang('en');
Expand All @@ -423,11 +429,49 @@ public function testModifiedConcepts() {

}

/**
* @covers RestController::modifiedConcepts
* @covers RestController::changedConcepts
*/
public function testDeprecatedChanges() {
$request = new Request($this->model);
$request->setQueryParam('format', 'application/json');
$request->setURI('http://www.skosmos.skos/changes');
$request->setVocab('changes');
$request->setLang('en');
$request->setContentLang('en');
$request->setQueryParam('offset', '0');

$this->controller->modifiedConcepts($request);
$changeList = $this->getActualOutput();

$expected = <<<EOD
{"@context": {
"skos": "http://www.w3.org/2004/02/skos/core#",
"uri": "@id",
"type": "@type",
"@language": "en",
"prefLabel": "skos:prefLabel",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"date": { "@id":"http://purl.org/dc/terms/date","@type":"http://www.w3.org/2001/XMLSchema#dateTime" }
},
"changeList": [
{ "date": "2021-01-03T12:46:30+0000", "prefLabel": "A date", "uri": "http://www.skosmos.skos/changes/d1" },
{ "date": "2021-01-03T12:46:33+0000", "prefLabel": "Fourth date", "replacedBy": "http://www.skosmos.skos/changes/d3", "replacingLabel": "Hurr Durr", "uri": "http://www.skosmos.skos/changes/d4" },
{ "date": "2021-01-03T12:46:32+0000", "prefLabel": "Hurr Durr", "uri": "http://www.skosmos.skos/changes/d3" },
{ "date": "2021-01-03T12:46:31+0000", "prefLabel": "Second date", "uri": "http://www.skosmos.skos/changes/d2" }
]
}
EOD;
$this->assertJsonStringEqualsJsonString($changeList, $expected);
}

/**
* @covers RestController::vocabularyStatistics
*/
public function testVocabularyStatistics() {
$request = new Request($this->model);
$request->setQueryParam('format', 'application/json');
$request->setVocab('test');
$request->setLang('en');

Expand Down
12 changes: 10 additions & 2 deletions tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,16 @@ public function testShowChangeListDefaultValue() {
}

/**
* @covers VocabularyConfig::getSortByNotation
* @covers VocabularyConfig::getLiteral
* @covers VocabularyConfig::getShowDeprecatedChanges
* @covers VocabularyConfig::getBoolean
*/
public function testShowDeprecatedChanges() {
$vocab = $this->model->getVocabulary('changes');
$this->assertEquals(true, $vocab->getConfig()->getShowDeprecatedChanges());
}

/**
* @covers VocabularyConfig::sortByNotation
* @covers VocabularyConfig::getBoolean
*/
public function testShowSortByNotationDefaultValue() {
Expand Down
1 change: 0 additions & 1 deletion tests/WebControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public function testFormatChangeList() {
$months =$this->webController->formatChangeList($changeList, 'en');

$expected = array ('hurr durr' => array ('uri' => 'http://www.skosmos.skos/changes/d3', 'prefLabel' => 'Hurr Durr', 'date' => DateTime::__set_state(array('date' => '2010-02-12 10:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010'), 'second date' => array ('uri' => 'http://www.skosmos.skos/changes/d2', 'prefLabel' => 'Second date', 'date' => DateTime::__set_state(array('date' => '2010-02-12 15:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010'));
$this->assertEquals(array('December 2011', 'February 2010', 'January 2000'), array_keys($months));
$this->assertEquals($expected, $months['February 2010']);
}
}
1 change: 1 addition & 0 deletions tests/jenatestconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
dc:subject :cat_general ;
void:uriSpace "http://www.skosmos.skos/changes/";
skosmos:language "en";
skosmos:showDeprecatedChanges "true" ;
skosmos:sparqlGraph <http://www.skosmos.skos/changes/> .

:prefix a skosmos:Vocabulary, void:Dataset ;
Expand Down

0 comments on commit b9182af

Please sign in to comment.